Package er.rest

Examples of er.rest.ERXRestRequestNode


  public ERXRestRequestNode parseRestRequest(String contentStr, ERXRestFormat.Delegate delegate, ERXRestContext context) {
    return parseRestRequest(new ERXStringRestRequest(contentStr), delegate, context);
  }
 
  public ERXRestRequestNode parseRestRequest(IERXRestRequest request, ERXRestFormat.Delegate delegate, ERXRestContext context) {
    ERXRestRequestNode rootRequestNode = null;
    String contentString = request.stringContent();
    if (contentString != null && contentString.length() > 0) {
      // MS: Support direct updating of primitive type keys -- so if you don't want to
      // wrap your request in XML, this will allow it
      if (!contentString.trim().startsWith("<")) {
        contentString = "<FakeWrapper>" + contentString.trim() + "</FakeWrapper>";
      }

      Document document;
      try {
        document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(contentString)));
        document.normalize();
        Element rootElement = document.getDocumentElement();
        rootRequestNode = createRequestNodeForElement(rootElement, true, delegate, context);
      }
      catch (Exception e) {
        throw new IllegalArgumentException("Failed to parse request document.", e);
      }
    }
    else {
      rootRequestNode = new ERXRestRequestNode(null, true);
      rootRequestNode.setNull(true);
    }

    return rootRequestNode;
  }
View Full Code Here


    String str = "<Company><id>100</id><type>Company</type><name>mDT</name><firstName nil=\"true\"/><employees><Employee id=\"101\" type=\"Employee\"/><Employee id=\"102\"><name>Mike</name></Employee></employees></Company>";
    //String str = "<Employees><Employee id=\"101\" type=\"Employee\"/><Employee id=\"102\"><name>Mike</name></Employee></Employees>";
    ERXRestNameRegistry.registry().setExternalNameForInternalName("Super", "Company");
    ERXRestNameRegistry.registry().setExternalNameForInternalName("Super2", "Employee");
    ERXRestContext context = new ERXRestContext();
    ERXRestRequestNode n = new ERXXmlRestParser().parseRestRequest(new ERXStringRestRequest(str), new ERXRestFormatDelegate(), context);
    ERXStringBufferRestResponse response = new ERXStringBufferRestResponse();
    new ERXXmlRestWriter().appendToResponse(n, response, new ERXRestFormatDelegate(), context);
    System.out.println("ERXXmlRestParser.main: " + response);
  }
View Full Code Here

import er.rest.ERXRestRequestNode;

public class ERXSproutCoreRestWriter extends ERXJSONRestWriter {
  @Override
  protected ERXRestRequestNode processNode(ERXRestRequestNode node) {
    ERXRestRequestNode rootNode = new ERXRestRequestNode(null, true);

    ERXRestRequestNode recordsNode = new ERXRestRequestNode("content", false);
    recordsNode.setArray(true);
    rootNode.addChild(recordsNode);

    if (node.isArray()) {
      for (ERXRestRequestNode child : node.children()) {
        recordsNode.addChild(child);
      }
    }
    else {
      recordsNode.addChild(node);
    }

    ERXRestRequestNode idsNode = new ERXRestRequestNode("ids", false);
    idsNode.setArray(true);
    rootNode.addChild(idsNode);

    for (ERXRestRequestNode child : recordsNode.children()) {
      Object id = child.id();
      idsNode.addChild(new ERXRestRequestNode(null, id, false));
    }

    ERXRestRequestNode countNode = new ERXRestRequestNode("count", Integer.valueOf(recordsNode.children().size()), false);
    rootNode.addChild(countNode);

    return rootNode;
  }
View Full Code Here

*
* @author mschrag
*/
public class ERXJSONRestParser implements IERXRestParser {
  public static ERXRestRequestNode createRequestNodeForJSON(String name, JSON json, boolean rootNode, ERXRestFormat.Delegate delegate) {
    ERXRestRequestNode requestNode = new ERXRestRequestNode(name, rootNode);

    if (json instanceof JSONNull) {
      // just leave the value null
    }
    else if (json instanceof JSONArray) {
      requestNode.setArray(true);
      JSONArray jsonArray = (JSONArray) json;
      for (Object obj : jsonArray) {
        if (ERXRestUtils.isPrimitive(obj)) {
          ERXRestRequestNode primitiveChild = new ERXRestRequestNode(null, obj, false);
          requestNode.addChild(primitiveChild);
          if (delegate != null) {
            delegate.nodeDidParse(primitiveChild);
          }
        }
        else {
          requestNode.addChild(ERXJSONRestParser.createRequestNodeForJSON(null, (JSON) obj, true, delegate));
        }
      }
    }
    else if (json instanceof JSONObject) {
      JSONObject jsonObject = (JSONObject) json;
      for (Object key : jsonObject.keySet()) {
        String strKey = (String) key;
        Object value = jsonObject.get(key);
        if (ERXRestUtils.isPrimitive(value)) {
          ERXRestRequestNode primitiveChild = new ERXRestRequestNode(strKey, value, false);
          requestNode.addChild(primitiveChild);
          if (delegate != null) {
            delegate.nodeDidParse(primitiveChild);
          }
        }
View Full Code Here

  protected JsonConfig configWithContext(ERXRestContext context) {
    return _ERXJSONConfig.createDefaultConfig(context);
  }

  public ERXRestRequestNode parseRestRequest(IERXRestRequest request, ERXRestFormat.Delegate delegate, ERXRestContext context) {
    ERXRestRequestNode rootRequestNode = null;
    String contentString = request.stringContent();
    if (contentString != null) {
      contentString = contentString.trim();
    }
    if (contentString != null && contentString.length() > 0 && !"undefined".equals(contentString)) {
     
      // MS: Support direct updating of primitive type keys -- so if you don't want to
      // wrap your request in XML, this will allow it
      // if (!contentStr.trim().startsWith("<")) {
      // contentStr = "<FakeWrapper>" + contentStr.trim() + "</FakeWrapper>";
      // }
      JSON rootJSON = JSONSerializer.toJSON(contentString, configWithContext(context));
      rootRequestNode = createRequestNodeForJSON(null, rootJSON, true, delegate);
    }
    else {
      rootRequestNode = new ERXRestRequestNode(null, true);
      rootRequestNode.setNull(true);
    }

    return rootRequestNode;
  }
View Full Code Here

import er.rest.ERXRestRequestNode;

public class ERXEmberRestParser extends ERXJSONRestParser
  public ERXRestRequestNode parseRestRequest(IERXRestRequest request, ERXRestFormat.Delegate delegate, ERXRestContext context) {
    // unwrapping type node
    ERXRestRequestNode node = super.parseRestRequest(request, delegate, context);
    node = node.childAtIndex(0);
    return node;
  }
View Full Code Here

   * @return the parsed request node
   */
  public ERXRestRequestNode parse(String str) {
    EOEditingContext editingContext = ERXEC.newEditingContext();
    try {
      ERXRestRequestNode node = parse(str, new ERXRestContext(editingContext));
      return node;
    }
    finally {
      editingContext.dispose();
    }
View Full Code Here

*
* @author mschrag
*/
public class ERXFormRestParser implements IERXRestParser {
  public ERXRestRequestNode parseRestRequest(IERXRestRequest request, Delegate delegate, ERXRestContext context) {
    ERXRestRequestNode rootNode = new ERXRestRequestNode();
    for (String keyPath : request.keyNames()) {
      rootNode.takeValueForKeyPath(request.objectForKey(keyPath), keyPath);
    }
    return rootNode;
  }
View Full Code Here

*/
public class ERXBinaryPListRestParser implements IERXRestParser {
 
 
  protected ERXRestRequestNode createRequestNodeForObject(String name, Object object, boolean rootNode, ERXRestFormat.Delegate delegate) {
    ERXRestRequestNode requestNode = new ERXRestRequestNode(name, rootNode);

    if (object == null) {
      // just leave the value null
    }
    else if (object instanceof List) {
      requestNode.setArray(true);
      List list = (List) object;
      for (Object obj : list) {
        if (ERXRestUtils.isPrimitive(obj)) {
          ERXRestRequestNode primitiveChild = new ERXRestRequestNode(null, object, false);
          requestNode.addChild(primitiveChild);
          delegate.nodeDidParse(primitiveChild);
        }
        else {
          requestNode.addChild(createRequestNodeForObject(null, obj, true, delegate));
        }
      }
    }
    else if (object instanceof Map) {
      Map map = (Map) object;
      for (Object key : map.keySet()) {
        String strKey = (String) key;
        Object value = map.get(key);
        if (ERXRestUtils.isPrimitive(value)) {
          ERXRestRequestNode primitiveChild = new ERXRestRequestNode(strKey, value, false);
          requestNode.addChild(primitiveChild);
          delegate.nodeDidParse(primitiveChild);
        }
        else {
          requestNode.addChild(createRequestNodeForObject(strKey, value, false, delegate));
View Full Code Here

    return requestNode;
  }

  public ERXRestRequestNode parseRestRequest(IERXRestRequest request, ERXRestFormat.Delegate delegate, ERXRestContext context) {
    ERXRestRequestNode rootRequestNode = null;

    if (request != null) {
      InputStream in = request.streamContent();
      Object rootObj = ERXPropertyListSerialization.propertyListWithStream(in, ERXPropertyListSerialization.PListFormat.NSPropertyListBinaryFormat_v1_0, CharEncoding.UTF_8);
      rootRequestNode = createRequestNodeForObject(null, rootObj, true, delegate);
    }
    else {
      rootRequestNode = new ERXRestRequestNode(null, true);
      rootRequestNode.setNull(true);
    }

    return rootRequestNode;
  }
View Full Code Here

TOP

Related Classes of er.rest.ERXRestRequestNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.