Package de.pdark.decentxml

Examples of de.pdark.decentxml.Attribute


            if (content!=null) {
                Document document = TolerantXMLParser.parse(xml, file.getFullPath().toOSString());
                // add the attributes of content
                List<Attribute> attributes = content.getAttributes();
                for (Iterator<Attribute> it = attributes.iterator(); it.hasNext();) {
                    Attribute anAttribute = it.next();
                    if (anAttribute.getName().equals("jcr:primaryType")) {
                        // skip this
                        continue;
                    }
                    document.getRootElement().addAttribute(anAttribute);
                }
View Full Code Here


                // then copy all the other attributes - plus children if there are nay
                Element propDomElement = properties.getDomElement();
                if (propDomElement!=null) {
                    List<Attribute> attributes = propDomElement.getAttributes();
                    for (Iterator<Attribute> it = attributes.iterator(); it.hasNext();) {
                        Attribute anAttribute = it.next();
                        if (anAttribute.getName().startsWith("xmlns:")) {
                            continue;
                        }
                        if (anAttribute.getName().equals("jcr:primaryType")) {
                            continue;
                        }
                        if (domElement.getAttributeMap().containsKey(anAttribute.getName())) {
                            domElement.setAttribute(anAttribute.getName(), anAttribute.getValue());
                        } else {
                            domElement.addAttribute(anAttribute);
                        }
                    }
                    List<Element> c2 = propDomElement.getChildren();
View Full Code Here

  void doSetPropertyValue(Object id, Object value) {
      if (id instanceof Map.Entry<?, ?>) {
          Map.Entry<String, String> entry = (Map.Entry<String, String>)id;
          entry.setValue(String.valueOf(value));
          Attribute a = domElement.getAttribute(entry.getKey());
          a.setValue(String.valueOf(value));
          genericJcrRootFile.save();
      } else if (value instanceof String) {
            Attribute a = domElement.getAttribute((String) id);
            a.setValue((String) value);
            genericJcrRootFile.save();
      } else {
          System.out.println("UNSUPPORTED VALUE TYPE: "+value.getClass());
      }
  }
View Full Code Here

  public void setNode(GenericJcrRootFile genericJcrRootFile, Element domNode) {
    this.domElement = domNode;
    final List<Attribute> attributes = domNode.getAttributes();
    if (attributes!=null) {
      for (Iterator<Attribute> it = attributes.iterator(); it.hasNext();) {
        final Attribute a = it.next();
        final String name = a.getName();
        if (name.startsWith("xmlns:")) {
            continue;
        }
                properties.put(name, a.getValue());
                propertiesOrder.add(name);
      }
    }
    this.genericJcrRootFile = genericJcrRootFile;
  }
View Full Code Here

        if (list.size()==0) {
            // then there are no attributes at all - nothing to format
            return;
        } else if (list.size()==1) {
            // only one attribute - make sure it has no preSpace
            Attribute first = list.get(0);
            first.setPreSpace("");
        } else {
            final String NL = System.getProperty("line.separator");
            final String INDENT = "    ";
            // otherwise, make sure each element has the correct preSpace
            final String correctPreSpace;
            Element parent = domElement.getParentElement();
            if (parent!=null) {
                List<Node> nodes = parent.getNodes();
                if (nodes.size()>1 && (nodes.get(0) instanceof Text) && (nodes.get(0).toXML().startsWith(NL))) {
                    correctPreSpace = nodes.get(0).toXML() + INDENT;
                } else {
                    String totalIndent = INDENT;
                    while(parent!=null) {
                        totalIndent = totalIndent + INDENT;
                        parent = parent.getParentElement();
                    }
                    correctPreSpace = NL + totalIndent;
                }
            } else {
                // guestimate
                correctPreSpace = NL + INDENT;
            }
            for (Iterator it = list.iterator(); it.hasNext();) {
                Attribute attribute = (Attribute) it.next();
                if (!attribute.getName().startsWith("xmlns:")) {
                    attribute.setPreSpace(correctPreSpace);
                }
            }
        }
    }
View Full Code Here

            }
        }
    }

    public void renameProperty(String oldKey, String newKey) {
        Attribute a = domElement.getAttribute(oldKey);
        a.setName(newKey);
        genericJcrRootFile.save();
    }
View Full Code Here

        a.setName(newKey);
        genericJcrRootFile.save();
    }

    public void changePropertyType(String key, int propertyType) {
        Attribute a = domElement.getAttribute(key);
        String value = a.getValue();
       
        // when changing the property type, the value needs to be adjusted
        // to make up a valid property
        // a simple approach is to create default values if a conversion
        // of the existing value is not possible/feasible.
        switch(propertyType) {
        case PropertyType.BINARY: {
            value = "";
            break;
        }
        case PropertyType.BOOLEAN: {
            try{
                value = String.valueOf(Boolean.parseBoolean(value));
            } catch(Exception e) {
                // hardcode to false then
                value = "false";
            }
            break;
        }
        case PropertyType.DATE: {
            try{
                value = DateTimeSupport.print(DateTimeSupport.parseAsCalendar(value));
            } catch(Exception e) {
                value = DateTimeSupport.print(Calendar.getInstance());
            }
            break;
        }
        case PropertyType.DECIMAL: {
            try{
                Float f = Float.parseFloat(value);
                value = String.valueOf(f);
            } catch(Exception e) {
                value = "0.0";
            }
            break;
        }
        case PropertyType.DOUBLE: {
            try{
                Double d = Double.parseDouble(value);
                value = String.valueOf(d);
            } catch(Exception e) {
                value = "0.0";
            }
            break;
        }
        case PropertyType.LONG: {
            try{
                value = String.valueOf(Long.parseLong(value));
            } catch(Exception e) {
                value = "0";
            }
            break;
        }
        case PropertyType.NAME:
        case PropertyType.STRING: {
            // no conversion needed, already converted
            break;
        }
        case PropertyType.PATH:
        case PropertyType.URI:
        case PropertyType.REFERENCE:
        case PropertyType.WEAKREFERENCE: {
            //TODO validation would be necessary but not implemented atm
            // no conversion needed, already converted
            break;
        }
        }
        if (value.startsWith("{") && value.contains("}")) {
            int index = value.indexOf("}");
            value = value.substring(index+1);
        }
        if (propertyType!=PropertyType.STRING) {
            value = "{" + PropertyType.nameFromValue(propertyType)+"}"+value;
        }
        a.setValue(value);
        genericJcrRootFile.save();
    }
View Full Code Here

        Activator.getLogger().warning(e);
        throw new RuntimeException(e);
     
      
      Element e = (Element)model.getNode();
      Attribute a = e.getAttribute("id");
      if (a != null) id = a.getValue();
    }
    answer.setId(id);
    answer.addRoutes(routes);
    answer.setBeans(model.beanMap());
    answer.setCamelContextEndpointUris(model.endpointUriSet());
View Full Code Here

TOP

Related Classes of de.pdark.decentxml.Attribute

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.