GI Support

View: New views
6 Messages — Rating Filter:   Alert me  

GI Support

by dio :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

DWR has any JavaScript utility class to convert JSON to GI's CDF format?

-- Deha Peker

Re: GI Support

by Joe Walker-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


The attached should be part of the next release of DWR
Joe

On 10/29/07, dio <deha.peker@...> wrote:

DWR has any JavaScript utility class to convert JSON to GI's CDF format?

-- Deha Peker
--
View this message in context: http://www.nabble.com/GI-Support-tf4713348.html#a13472961
Sent from the DWR - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...



/*
 * Copyright 2005 Joe Walker
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Declare an object to which we can add real functions.
 */
if (dwr == null) { var dwr = {}; }
if (dwr.gi == null) { dwr.gi = {}; }

/**
 * Convert a javascript object into a CDF document with the given jsxid
 * @param data The data that we want to publish in a CDF document
 * @param jsxid The jsxid of the returned document
 */
dwr.gi.toCdfDocument = function(data, jsxid) {
  var cdfstr = dwr.gi._toCdfDocumentString(data, jsxid);
  var cdf = new jsx3.xml.Document();
  cdf.loadXML(cdfstr);
  return cdf;
};

/**
 * Convert a javascript object into a CDF RecordSet
 * @param data The data that we want to publish in a CDF record set
 */
dwr.gi.toRecordSet = function(data) {
  if (data == null) return "";
  if (data instanceof Array) {
    return dwr.gi._convertArray(data, "", 0);
  }
  if (data instanceof Object) {
    return dwr.gi._convertObject(data, "", 0);
  }
  return dwr.gi._convertOther(data, "root", 0);
};

/** @private Convert any Javascript object to a CDF Document string */
dwr.gi._toCdfDocumentString = function(data, jsxid) {
  return "<data jsxid='" + jsxid + "'>\n" + dwr.gi.toRecordSet(data) + "</data>\n";
};

/** @private Convert an array to a JSX string */
dwr.gi._convertArray = function(data, name, depth) {
  var reply = "";
  for (var i = 0; i < data.length; i++) {
    reply += dwr.gi._convertAttributes(data[i], name + i, depth);
  }
  for (var i = 0; i < data.length; i++) {
    reply += dwr.gi._convertElements(data[i], name + i, depth);
  }
  return reply;
};

/** @private Convert an object to a JSX string */
dwr.gi._convertObject = function(data, name, depth) {
  var reply = "";
  for (var element in data) {
    reply += dwr.gi._convertAttributes(data[element], element, depth);
  }
  for (var element in data) {
    reply += dwr.gi._convertElements(data[element], element, depth);
  }
  return reply;
};

/** @private Convert an object of unknown type to a JSX string */
dwr.gi._convertAttributes = function(data, name, depth) {
  if (typeof data == "function") {
    return ""; // ignore functions
  }
  if (typeof data == "string" || data instanceof String) {
    // TODO: escape the string
    return " " + name + "='" + data + "'";
  }
  if (typeof data == "object") {
    if (data instanceof Date) {
      return " " + name + "='" + data.toUTCString() + "'";
    }
    return "";
  }
  return " " + name + "='" + data + "'";
};

/** @private Convert an object of unknown type to a JSX string */
dwr.gi._convertElements = function(data, name, depth) {
  var reply;
  if (data == null) {
    return ""; // don't create an empty element for null objects
  }
  if (typeof data == "function") {
    return ""; // ignore functions
  }
  if (typeof data == "object") {
    if (data instanceof Date) {
      return "";
    }
    if (data instanceof Array) {
      reply = dwr.gi._indent(depth) + "<record index='0' jsxid='" + name + "' jsxtext='" + name + "' >\n";
      reply += dwr.gi._convertArray(data, name + ".", depth + 1);
      reply += dwr.gi._indent(depth) + "</record>\n";
      return reply;
    }
    reply = dwr.gi._indent(depth) + "<record";
    for (var element in data) {
      reply += dwr.gi._convertAttributes(data[element], element, depth + 1);
    }
    reply += ">\n";
    for (var element in data) {
      reply += dwr.gi._convertElements(data[element], element, depth + 1);
    }
    reply += dwr.gi._indent(depth) + "</record>\n";
    return reply;
  }
  return "";
};

/** @private Do we try to keep the generated source looking good? */
dwr.gi._prettyPrint = false;

/** @private Pretty printing */
dwr.gi._indent = function(depth) {
  if (!dwr.gi._prettyPrint) return "";
  for (var i = 0; i < depth; i++) {
      reply += "  ";
  }
  return reply;
};

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...

Re: GI Support

by dio :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joe,
This is great. Thanks,
-- Deha Peker
Joe Walker-3 wrote:
The attached should be part of the next release of DWR
Joe

On 10/29/07, dio <deha.peker@gmail.com> wrote:
>
>
> DWR has any JavaScript utility class to convert JSON to GI's CDF format?
>
> -- Deha Peker
> --
> View this message in context:
> http://www.nabble.com/GI-Support-tf4713348.html#a13472961
> Sent from the DWR - Dev mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@dwr.dev.java.net
> For additional commands, e-mail: dev-help@dwr.dev.java.net
>
>

/*
 * Copyright 2005 Joe Walker
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Declare an object to which we can add real functions.
 */
if (dwr == null) { var dwr = {}; }
if (dwr.gi == null) { dwr.gi = {}; }

/**
 * Convert a javascript object into a CDF document with the given jsxid
 * @param data The data that we want to publish in a CDF document
 * @param jsxid The jsxid of the returned document
 */
dwr.gi.toCdfDocument = function(data, jsxid) {
  var cdfstr = dwr.gi._toCdfDocumentString(data, jsxid);
  var cdf = new jsx3.xml.Document();
  cdf.loadXML(cdfstr);
  return cdf;
};

/**
 * Convert a javascript object into a CDF RecordSet
 * @param data The data that we want to publish in a CDF record set
 */
dwr.gi.toRecordSet = function(data) {
  if (data == null) return "";
  if (data instanceof Array) {
    return dwr.gi._convertArray(data, "", 0);
  }
  if (data instanceof Object) {
    return dwr.gi._convertObject(data, "", 0);
  }
  return dwr.gi._convertOther(data, "root", 0);
};

/** @private Convert any Javascript object to a CDF Document string */
dwr.gi._toCdfDocumentString = function(data, jsxid) {
  return "<data jsxid='" + jsxid + "'>\n" + dwr.gi.toRecordSet(data) + "</data>\n";
};

/** @private Convert an array to a JSX string */
dwr.gi._convertArray = function(data, name, depth) {
  var reply = "";
  for (var i = 0; i < data.length; i++) {
    reply += dwr.gi._convertAttributes(data[i], name + i, depth);
  }
  for (var i = 0; i < data.length; i++) {
    reply += dwr.gi._convertElements(data[i], name + i, depth);
  }
  return reply;
};

/** @private Convert an object to a JSX string */
dwr.gi._convertObject = function(data, name, depth) {
  var reply = "";
  for (var element in data) {
    reply += dwr.gi._convertAttributes(data[element], element, depth);
  }
  for (var element in data) {
    reply += dwr.gi._convertElements(data[element], element, depth);
  }
  return reply;
};

/** @private Convert an object of unknown type to a JSX string */
dwr.gi._convertAttributes = function(data, name, depth) {
  if (typeof data == "function") {
    return ""; // ignore functions
  }
  if (typeof data == "string" || data instanceof String) {
    // TODO: escape the string
    return " " + name + "='" + data + "'";
  }
  if (typeof data == "object") {
    if (data instanceof Date) {
      return " " + name + "='" + data.toUTCString() + "'";
    }
    return "";
  }
  return " " + name + "='" + data + "'";
};

/** @private Convert an object of unknown type to a JSX string */
dwr.gi._convertElements = function(data, name, depth) {
  var reply;
  if (data == null) {
    return ""; // don't create an empty element for null objects
  }
  if (typeof data == "function") {
    return ""; // ignore functions
  }
  if (typeof data == "object") {
    if (data instanceof Date) {
      return "";
    }
    if (data instanceof Array) {
      reply = dwr.gi._indent(depth) + "<record index='0' jsxid='" + name + "' jsxtext='" + name + "' >\n";
      reply += dwr.gi._convertArray(data, name + ".", depth + 1);
      reply += dwr.gi._indent(depth) + "</record>\n";
      return reply;
    }
    reply = dwr.gi._indent(depth) + "<record";
    for (var element in data) {
      reply += dwr.gi._convertAttributes(data[element], element, depth + 1);
    }
    reply += ">\n";
    for (var element in data) {
      reply += dwr.gi._convertElements(data[element], element, depth + 1);
    }
    reply += dwr.gi._indent(depth) + "</record>\n";
    return reply;
  }
  return "";
};

/** @private Do we try to keep the generated source looking good? */
dwr.gi._prettyPrint = false;

/** @private Pretty printing */
dwr.gi._indent = function(depth) {
  if (!dwr.gi._prettyPrint) return "";
  for (var i = 0; i < depth; i++) {
      reply += "  ";
  }
  return reply;
};

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@dwr.dev.java.net
For additional commands, e-mail: dev-help@dwr.dev.java.net

Re: GI Support

by dio :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
When this release (DWR with GI support) will be available?
Is there any working sample of DWR & GI collaboration?
-- Deha Peker

Re: GI Support

by dio :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joe

I downloaded  DWR 2.0.2 source, I still can't see any GI utility code.
I would assume GI releated stuff has not been released yet officially.
Can you tell me any time line for this support?

-- Deha Peker

Joe Walker-3 wrote:
The attached should be part of the next release of DWR
Joe

Re: GI Support

by Joe Walker-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I hope that 2.1 (in which this code should feature) will be out early next year. However, I'm not sure that this code will change between now and then, so you could just copy the javascript into your project.

Joe.

On Nov 23, 2007 12:34 AM, dio <deha.peker@...> wrote:

Joe

I downloaded  DWR 2.0.2 source, I still can't see any GI utility code.
I would assume GI releated stuff has not been released yet officially.
Can you tell me any time line for this support?

-- Deha Peker


Joe Walker-3 wrote:
>
> The attached should be part of the next release of DWR
> Joe
>

--
View this message in context: http://www.nabble.com/GI-Support-tf4713348.html#a13905395
Sent from the DWR - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...