Package org.one.stone.soup.core.data.EntityTree

Examples of org.one.stone.soup.core.data.EntityTree.TreeEntity


  public static EntityTree loadXml(InputStream in,boolean closeAtEnd) throws XmlParseException, IOException{
    try {

      EntityTree entityTree = new EntityTree( "root" );
      BufferedInputStream bin = new BufferedInputStream(in);
      TreeEntity entity = parseEntity( entityTree.getRoot(),bin );
      entityTree = new EntityTree(entity);
     
      return entityTree;
    } finally {
      if(closeAtEnd==true) {
View Full Code Here


    }
    if(name.equals("/"+parent.getName())) {
      return null;
    }
   
    TreeEntity entity = parent.addChild(name);

    //Add Attributes
    tag = tag.trim();
    if(tag.length()>0) {
      tag = tag.replace(" =", "=").replace("= ", "=");
      String[] attributes = StringHelper.split(tag, " ", "\"", "\"");
      for(String attribute: attributes) {
        if(attribute.indexOf("=")==-1) {
          continue;
        }
        String key = attribute.substring(0,attribute.indexOf("="));
        attribute = attribute.substring(attribute.indexOf("=")+1);
        String value = attribute.substring(attribute.indexOf("\"")+1,attribute.lastIndexOf("\""));
        entity.setAttribute(key, value);
      }
    }
   
    if(tag.length()!=0 && (tag.lastIndexOf('/')==tag.length()-1||tag.lastIndexOf('?')==tag.length()-1)) {
      return entity;
    }
   
    TreeEntity child = parseEntity(entity,in);
    while(child!=null) {
      child = parseEntity(entity,in);
    }
   
    //String closeTag = parseTo(in,'>');
View Full Code Here

    return JavaTree.toObject(tree);
  }
 
  private static TreeEntity parseEntity(TreeEntity parent,String data) throws IOException {
    String name = StringHelper.before(data, ":").trim();
    TreeEntity child = parent.addChild(name);
   
    data = StringHelper.after(data, "{");
 
    String[] parts = data.split(",");
    for(String part: parts) {
      if(part.contains("{")) {
        parseEntity(child, part);
      } else {
        KeyValuePair kvp = KeyValuePair.parseKeyAndValue(part, ":");
        child.setAttribute(kvp.getKey().trim(), kvp.getValue().trim());
      }
    }
   
    return child;
  }
View Full Code Here

TOP

Related Classes of org.one.stone.soup.core.data.EntityTree.TreeEntity

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.