Esempio n. 1
0
  @Test
  public void testAddRemoveChild() throws Exception {
    //		builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setNamespaceAware(true);

    String xml =
        "<?xml version=\"1.0\"?>"
            + "<root>"
            + "<item id=\"a\"/>"
            + "<child id=\"1\"/>"
            + "<item id=\"b\"/>"
            + "<child id=\"2\"/>"
            + "</root>";

    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
    Element root = doc.getDocumentElement();

    Element newElem = doc.createElement("tail");
    newElem.setAttribute("id", "3");
    Node appended = root.appendChild(newElem);

    Assert.assertEquals("added element", "tail", root.getLastChild().getNodeName());
    Assert.assertEquals("added attribute", "3", ((Element) root.getLastChild()).getAttribute("id"));

    root.setAttribute("id", "root");
    Assert.assertEquals("root attribute set", "root", root.getAttribute("id"));
    root.removeAttribute("id");
    Assert.assertEquals("root attribute remove", null, root.getAttribute("id"));

    root.removeChild(appended);
    Assert.assertEquals("removed element", "child", root.getLastChild().getNodeName());
    Assert.assertEquals("removed element", "2", ((Element) root.getLastChild()).getAttribute("id"));
  }
Esempio n. 2
0
 private ArrayList<Element> serializeFields(
     Field[] fields, Object object, Document doc) // serializes the fields
     {
   Class currentClass = object.getClass();
   ArrayList<Element> elements = new ArrayList<Element>();
   for (Field f : fields) {
     try {
       if (!f.getType().isPrimitive()) // Field not primitive, is a reference to another object
       {
       } else // field is primitive
       {
         Element newField = new Element("field");
         newField.setAttribute("name", f.getName());
         newField.setAttribute("declaringclass", f.getDeclaringClass().getName());
         Element newValue = new Element("value");
         newValue.addContent(f.get(object).toString());
         newField.addContent(newValue);
         elements.add(newField);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   return elements;
 }
Esempio n. 3
0
  /**
   * This method exports the single pattern decision instance to the XML. It MUST be called by an
   * XML exporter, as this will not have a complete header.
   *
   * @param ratDoc The ratDoc generated by the XML exporter
   * @return the SAX representation of the object.
   */
  public Element toXML(Document ratDoc) {
    Element decisionE;
    RationaleDB db = RationaleDB.getHandle();

    // Now, add pattern to doc
    String entryID = db.getRef(this);
    if (entryID == null) {
      entryID = db.addPatternDecisionRef(this);
    }

    decisionE = ratDoc.createElement("DR:patternDecision");
    decisionE.setAttribute("rid", entryID);
    decisionE.setAttribute("name", name);
    decisionE.setAttribute("type", type.toString());
    decisionE.setAttribute("phase", devPhase.toString());
    decisionE.setAttribute("status", status.toString());
    // decisionE.setAttribute("artifact", artifact);

    Element descE = ratDoc.createElement("description");
    Text descText = ratDoc.createTextNode(description);
    descE.appendChild(descText);
    decisionE.appendChild(descE);

    // Add child pattern references...
    Iterator<Pattern> cpi = candidatePatterns.iterator();
    while (cpi.hasNext()) {
      Pattern cur = cpi.next();
      Element curE = ratDoc.createElement("refChildPattern");
      Text curText = ratDoc.createTextNode("p" + new Integer(cur.getID()).toString());
      curE.appendChild(curText);
      decisionE.appendChild(curE);
    }

    return decisionE;
  }
Esempio n. 4
0
  public Element getLookupElement() {
    Element e = new Element("lookup");
    if (saveErrors.size() != 0) {
      saveErrors.clear();
    }
    ObjEntityView view = objEntityViewField.getObjEntityView();
    DataView dataView = view.getDataView();
    String fieldPath =
        "<b>"
            + dataView.getName()
            + "."
            + view.getName()
            + "."
            + objEntityViewField.getName()
            + "</b><br>";
    if (lookupObjEntityView != null) {
      e.setAttribute(new Attribute("obj-entity-view-name", lookupObjEntityView.getName()));
    } else {
      e.setAttribute(new Attribute("obj-entity-view-name", ""));
      saveErrors.add(fieldPath + "lookup hasn't attribute \"obj-entity-view-name\"<br><br>");
    }
    if (lookupField != null) {
      e.setAttribute(new Attribute("field-name", lookupField.getName()));
    } else {
      e.setAttribute(new Attribute("field-name", ""));
      saveErrors.add(fieldPath + "lookup hasn't attribute \"field-name\"<br><br>");
    }
    e.addContent("");

    return e;
  }
Esempio n. 5
0
 @Override
 public void apply(Element e) {
   if (isNodeWithPrototype(e, nodePrototype)) {
     Element port = e.getOwnerDocument().createElement("port");
     port.setAttribute("name", this.name);
     port.setAttribute("type", this.type);
     port.setAttribute("value", this.value);
     e.appendChild(port);
   }
 }
Esempio n. 6
0
  @Override
  protected void fillVoiceXmlDocument(
      Document document, Element formElement, VoiceXmlDialogueContext dialogueContext)
      throws VoiceXmlDocumentRenderingException {

    List<String> submitNameList = new ArrayList<String>();
    VariableList submitVariableList = mSubmitParameters;
    if (submitVariableList != null) {
      addVariables(formElement, submitVariableList);

      for (Entry<String, String> entry : mSubmitParameters) {
        submitNameList.add(entry.getKey());
      }
    }

    Element subdialogueElement = DomUtils.appendNewElement(formElement, SUBDIALOG_ELEMENT);
    subdialogueElement.setAttribute(NAME_ATTRIBUTE, SUBDIALOGUE_FORM_ITEM_NAME);
    subdialogueElement.setAttribute(SRC_ATTRIBUTE, mUri);

    if (!submitNameList.isEmpty()) {
      subdialogueElement.setAttribute(NAME_LIST_ATTRIBUTE, StringUtils.join(submitNameList, " "));
    }

    for (Parameter parameter : mParameters) {
      Element paramElement = DomUtils.appendNewElement(subdialogueElement, PARAM_ELEMENT);
      paramElement.setAttribute(NAME_ATTRIBUTE, parameter.getName());
      setAttribute(paramElement, VALUE_ATTRIBUTE, parameter.getValue());
      setAttribute(paramElement, EXPR_ATTRIBUTE, parameter.getExpression());
    }

    SubmitMethod submitMethod = mMethod;
    if (submitMethod != null) {
      subdialogueElement.setAttribute(METHOD_ATTRIBUTE, submitMethod.name());
    }

    DocumentFetchConfiguration fetchConfiguration = mFetchConfiguration;
    if (fetchConfiguration != null) {
      applyFetchAudio(subdialogueElement, fetchConfiguration.getFetchAudio());
      applyRessourceFetchConfiguration(subdialogueElement, fetchConfiguration);
    }

    Element filledElement = DomUtils.appendNewElement(subdialogueElement, FILLED_ELEMENT);

    createVarElement(
        filledElement, SUBDIALOGUE_RESULT_VARIABLE_NAME, "dialog." + SUBDIALOGUE_FORM_ITEM_NAME);

    if (mPostDialogueScript != null) {
      createScript(filledElement, mPostDialogueScript);
    }

    createScript(
        filledElement,
        RIVR_SCOPE_OBJECT + ".addValueResult(" + SUBDIALOGUE_RESULT_VARIABLE_NAME + ");");
    createGotoSubmit(filledElement);
  }
Esempio n. 7
0
 public void apply(Element e) {
   if (isNodeWithPrototype(e, prototype)) {
     Element port = portWithName(e, portName);
     if (port == null) {
       port = e.getOwnerDocument().createElement("port");
       port.setAttribute("name", portName);
       port.setAttribute("type", "string");
       port.setAttribute("value", deviceName);
       e.appendChild(port);
     }
   }
 }
Esempio n. 8
0
  private Element generatePortNode(Document doc, Port port) {
    Element portEl = doc.createElement(EL_PORT);

    portEl.setAttribute(ATR_NAME, port.getName());
    portEl.setAttribute(ATR_TYPE, port.getType());
    portEl.setAttribute(ATR_X, Integer.toString(port.getX()));
    portEl.setAttribute(ATR_Y, Integer.toString(port.getY()));
    portEl.setAttribute(ATR_PORT_CONNECTION, port.isArea() ? "area" : "");
    portEl.setAttribute(ATR_STRICT, Boolean.toString(port.isStrict()));
    portEl.setAttribute(ATR_MULTI, Boolean.toString(port.isMulti()));

    return portEl;
  }
Esempio n. 9
0
  private Node generateFieldNode(Document doc, ClassField field) {
    Element fieldEl = doc.createElement(EL_FIELD);

    fieldEl.setAttribute(ATR_NAME, field.getName());
    fieldEl.setAttribute(ATR_TYPE, field.getType());

    if (field.isInput()) fieldEl.setAttribute(ATR_NATURE, "input");
    else if (field.isGoal()) fieldEl.setAttribute(ATR_NATURE, "goal");

    if (field.getValue() != null) fieldEl.setAttribute(ATR_VALUE, field.getValue());

    return fieldEl;
  }
Esempio n. 10
0
  public Document serialize(Object object, Document doc) {
    Class c = object.getClass();
    Integer id = getID(object);
    map.put(object, id);
    String mapSize = Integer.toString(map.size());

    // creating serialization objects
    Element objectElement = new Element("object");
    objectElement.setAttribute(new Attribute("class", c.getName()));
    objectElement.setAttribute(new Attribute("id", mapSize));
    doc.getRootElement().addContent(objectElement);

    if (!c.isArray()) // class is not an array
    {
      Field[] fields = c.getDeclaredFields();
      ArrayList<Element> fieldXML = serializeFields(fields, object, doc);
      for (int i = 0; i < fieldXML.size(); i++) {
        objectElement.addContent(fieldXML.get(i));
      }
    } else // class is an array
    {
      Object array = object;
      objectElement.setAttribute(new Attribute("length", Integer.toString(Array.getLength(array))));
      if (c.getComponentType().isPrimitive()) // class is array of primitives
      {
        for (int i = 0; i < Array.getLength(array); i++) {
          Element value = new Element("value");
          value.setText(Array.get(c, i).toString());
          objectElement.addContent(value);
        }
      } else // class is array of references
      {
        for (int j = 0; j < Array.getLength(array); j++) {
          Element ref = new Element("reference");
          id = getID(Array.get(c, j));
          if (id != -1) {
            ref.setText(Integer.toString(id));
          }
        }
        for (int k = 0; k < Array.getLength(array); k++) {
          serialize(Array.get(array, k), doc);
        }
      }
    }
    if (currentElement == 0) {
      referenceID = 0;
    }

    return doc;
  }
Esempio n. 11
0
 private void declareNamespace(Element e, String prefix, String uri) {
   if (prefix.length() > 0) {
     e.setAttributeNS(XML_NAMESPACES_NAMESPACE_URI, "xmlns:" + prefix, uri);
   } else {
     e.setAttribute("xmlns", uri);
   }
 }
 /**
  * Marshall an array of Genes to an XML Element representation.
  *
  * @param a_geneValues the genes to represent as an XML element
  * @param a_xmlDocument a Document instance that will be used to create the Element instance. Note
  *     that the element will NOT be added to the document by this method
  * @return an Element object representing the given genes
  * @author Neil Rotstan
  * @author Klaus Meffert
  * @since 1.0
  * @deprecated use XMLDocumentBuilder instead
  */
 public static Element representGenesAsElement(
     final Gene[] a_geneValues, final Document a_xmlDocument) {
   // Create the parent genes element.
   // --------------------------------
   Element genesElement = a_xmlDocument.createElement(GENES_TAG);
   // Now add gene sub-elements for each gene in the given array.
   // -----------------------------------------------------------
   Element geneElement;
   for (int i = 0; i < a_geneValues.length; i++) {
     // Create the allele element for this gene.
     // ----------------------------------------
     geneElement = a_xmlDocument.createElement(GENE_TAG);
     // Add the class attribute and set its value to the class
     // name of the concrete class representing the current Gene.
     // ---------------------------------------------------------
     geneElement.setAttribute(CLASS_ATTRIBUTE, a_geneValues[i].getClass().getName());
     // Create a text node to contain the string representation of
     // the gene's value (allele).
     // ----------------------------------------------------------
     Element alleleRepresentation = representAlleleAsElement(a_geneValues[i], a_xmlDocument);
     // And now add the text node to the gene element, and then
     // add the gene element to the genes element.
     // -------------------------------------------------------
     geneElement.appendChild(alleleRepresentation);
     genesElement.appendChild(geneElement);
   }
   return genesElement;
 }
Esempio n. 13
0
  private static UpgradeStringResult transformXml(
      String xml, String newFormatVersion, UpgradeOp... ops) {
    try {

      DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder;
      builder = builderFactory.newDocumentBuilder();
      Document document = builder.parse(new InputSource(new StringReader(xml)));

      // Check that this is a NodeBox document and set the new formatVersion.
      Element root = document.getDocumentElement();
      checkArgument(root.getTagName().equals("ndbx"), "This is not a valid NodeBox document.");
      root.setAttribute("formatVersion", newFormatVersion);

      // Loop through all upgrade operations.
      ArrayList<String> warnings = new ArrayList<String>();
      for (UpgradeOp op : ops) {
        op.start(root);
        transformXmlRecursive(document.getDocumentElement(), op);
        op.end(root);
        warnings.addAll(op.getWarnings());
      }

      TransformerFactory transformerFactory = TransformerFactory.newInstance();
      Transformer transformer = transformerFactory.newTransformer();
      DOMSource source = new DOMSource(document);
      StringWriter sw = new StringWriter();
      StreamResult result = new StreamResult(sw);
      transformer.transform(source, result);
      return new UpgradeStringResult(sw.toString(), warnings);
    } catch (Exception e) {
      throw new RuntimeException("Error while upgrading to " + newFormatVersion + ".", e);
    }
  }
 protected void setAttribute(String name, String attName, String attValue) {
   Element elt = getElement(name);
   if (elt == null) {
     elt = doc.createElement(name);
     docElt.appendChild(elt);
   }
   elt.setAttribute(attName, attValue);
 }
 private void saveWorkspaceHomeAttr(Element element, XModelObject o) {
   Properties p = o.getModel().getProperties();
   String project = p.getProperty(IModelNature.ECLIPSE_PROJECT);
   String workspace = p.getProperty(XModelConstants.WORKSPACE);
   if (project == null) return;
   String relative =
       workspace.startsWith(project + XModelObjectConstants.SEPARATOR)
           ? "." + workspace.substring(project.length())
           : workspace; //$NON-NLS-1$
   element.setAttribute("workspace-home", relative); // $NON-NLS-1$
 }
Esempio n. 16
0
  protected void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    try {
      DateFormat df = DateFormat.getDateTimeInstance();
      String titleStr = "C3P0 Status - " + df.format(new Date());

      DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = fact.newDocumentBuilder();
      Document doc = db.newDocument();

      Element htmlElem = doc.createElement("html");
      Element headElem = doc.createElement("head");

      Element titleElem = doc.createElement("title");
      titleElem.appendChild(doc.createTextNode(titleStr));

      Element bodyElem = doc.createElement("body");

      Element h1Elem = doc.createElement("h1");
      h1Elem.appendChild(doc.createTextNode(titleStr));

      Element h3Elem = doc.createElement("h3");
      h3Elem.appendChild(doc.createTextNode("PooledDataSources"));

      Element pdsDlElem = doc.createElement("dl");
      pdsDlElem.setAttribute("class", "PooledDataSources");
      for (Iterator ii = C3P0Registry.getPooledDataSources().iterator(); ii.hasNext(); ) {
        PooledDataSource pds = (PooledDataSource) ii.next();
        StatusReporter sr = findStatusReporter(pds, doc);
        pdsDlElem.appendChild(sr.reportDtElem());
        pdsDlElem.appendChild(sr.reportDdElem());
      }

      headElem.appendChild(titleElem);
      htmlElem.appendChild(headElem);

      bodyElem.appendChild(h1Elem);
      bodyElem.appendChild(h3Elem);
      bodyElem.appendChild(pdsDlElem);
      htmlElem.appendChild(bodyElem);

      res.setContentType("application/xhtml+xml");

      TransformerFactory tf = TransformerFactory.newInstance();
      Transformer transformer = tf.newTransformer();
      Source src = new DOMSource(doc);
      Result result = new StreamResult(res.getOutputStream());
      transformer.transform(src, result);
    } catch (IOException e) {
      throw e;
    } catch (Exception e) {
      throw new ServletException(e);
    }
  }
Esempio n. 17
0
  /**
   * Converts value object to XML representation.
   *
   * @return Element.
   */
  public Element toXml(Document doc) {
    Element root = doc.createElement("ProductViewDef");

    Element node;

    root.setAttribute("Id", String.valueOf(mProductViewDefId));

    node = doc.createElement("StatusCd");
    node.appendChild(doc.createTextNode(String.valueOf(mStatusCd)));
    root.appendChild(node);

    node = doc.createElement("AccountId");
    node.appendChild(doc.createTextNode(String.valueOf(mAccountId)));
    root.appendChild(node);

    node = doc.createElement("Attributename");
    node.appendChild(doc.createTextNode(String.valueOf(mAttributename)));
    root.appendChild(node);

    node = doc.createElement("SortOrder");
    node.appendChild(doc.createTextNode(String.valueOf(mSortOrder)));
    root.appendChild(node);

    node = doc.createElement("Width");
    node.appendChild(doc.createTextNode(String.valueOf(mWidth)));
    root.appendChild(node);

    node = doc.createElement("StyleClass");
    node.appendChild(doc.createTextNode(String.valueOf(mStyleClass)));
    root.appendChild(node);

    node = doc.createElement("ProductViewCd");
    node.appendChild(doc.createTextNode(String.valueOf(mProductViewCd)));
    root.appendChild(node);

    node = doc.createElement("AddDate");
    node.appendChild(doc.createTextNode(String.valueOf(mAddDate)));
    root.appendChild(node);

    node = doc.createElement("AddBy");
    node.appendChild(doc.createTextNode(String.valueOf(mAddBy)));
    root.appendChild(node);

    node = doc.createElement("ModDate");
    node.appendChild(doc.createTextNode(String.valueOf(mModDate)));
    root.appendChild(node);

    node = doc.createElement("ModBy");
    node.appendChild(doc.createTextNode(String.valueOf(mModBy)));
    root.appendChild(node);

    return root;
  }
  /**
   * Get the named properties for this resource and (potentially) its children.
   *
   * @param names an arrary of property names to retrieve
   * @return a MultiStatus of PropertyResponses
   * @exception com.ibm.webdav.WebDAVException
   */
  public MultiStatus getProperties(PropertyName[] names) throws WebDAVException {
    MultiStatus multiStatus = resource.getProperties(resource.getContext());
    MultiStatus newMultiStatus = new MultiStatus();

    Enumeration responses = multiStatus.getResponses();

    while (responses.hasMoreElements()) {
      PropertyResponse response = (PropertyResponse) responses.nextElement();
      PropertyResponse newResponse = new PropertyResponse(response.getResource());
      newResponse.setDescription(response.getDescription());
      newMultiStatus.addResponse(newResponse);

      Hashtable properties = (Hashtable) response.getPropertiesByPropName();

      // Hashtable newProperties = (Hashtable) newResponse.getProperties();
      for (int i = 0; i < names.length; i++) {
        if (properties.containsKey(names[i])) {
          PropertyValue srcval = response.getProperty(names[i]);
          newResponse.setProperty(names[i], srcval);

          // newProperties.put(names[i], properties.get(names[i]));
        } else {
          Document factory = null;

          try {
            factory = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
          } catch (Exception e) {
            throw new WebDAVException(WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
          }

          // we'll create an xml element with no value because that's
          //    what webdav will need to return for most methods... even if the
          //    property doesn't exist.   That's because the
          //    distinction between a propertyname and propertyvalue
          //    is fuzzy in WebDAV xml. A property name is
          //    essentially an empty property value because
          //    all property values have their property
          //    name stuck on.
          // if we decide to set reviewStatus to null instead (as
          //    we did previously, then the code for MultiStatus.asXML()
          //    needs to be updated to expect null values.
          // (jlc 990520)
          Element elTm = factory.createElementNS("X", "X:" + names[i].getLocal());

          elTm.setAttribute("xmlns:X", names[i].getNamespace());

          newResponse.addProperty(names[i], elTm, WebDAVStatus.SC_NOT_FOUND);
        }
      }
    }

    return newMultiStatus;
  }
Esempio n. 19
0
  /**
   * Converts value object to XML representation.
   *
   * @return Element.
   */
  public Element toXml(Document doc) {
    Element root = doc.createElement("InvoiceCustDetail");
    root.setAttribute("Id", String.valueOf(mOrderItemData));

    Element node;

    node = doc.createElement("InvoiceCustDetailData");
    node.appendChild(doc.createTextNode(String.valueOf(mInvoiceCustDetailData)));
    root.appendChild(node);

    return root;
  }
Esempio n. 20
0
 protected Element copyElementToName(Element element, String tagName) {
   Element newElement = element.getOwnerDocument().createElement(tagName);
   NamedNodeMap attrs = element.getAttributes();
   for (int i = 0; i < attrs.getLength(); i++) {
     Node attribute = attrs.item(i);
     newElement.setAttribute(attribute.getNodeName(), attribute.getNodeValue());
   }
   for (int i = 0; i < element.getChildNodes().getLength(); i++) {
     newElement.appendChild(element.getChildNodes().item(i).cloneNode(true));
   }
   return newElement;
 }
Esempio n. 21
0
 @Override
 public void apply(Element e) {
   if (e.getTagName().equals("property")) {
     Element parent = (Element) e.getParentNode();
     if (parent != null && parent.getTagName().equals("ndbx")) {
       Attr name = e.getAttributeNode("name");
       Attr value = e.getAttributeNode("value");
       if (name != null && name.getValue().equals("oscPort")) {
         if (value != null) {
           Element device = e.getOwnerDocument().createElement("device");
           device.setAttribute("name", "osc1");
           device.setAttribute("type", "osc");
           Element portProperty = e.getOwnerDocument().createElement("property");
           portProperty.setAttribute("name", "port");
           portProperty.setAttribute("value", value.getValue());
           device.appendChild(portProperty);
           Element autostartProperty = e.getOwnerDocument().createElement("property");
           autostartProperty.setAttribute("name", "autostart");
           autostartProperty.setAttribute("value", "true");
           device.appendChild(autostartProperty);
           parent.replaceChild(device, e);
         } else {
           parent.removeChild(e);
         }
       }
     }
   }
 }
Esempio n. 22
0
 @Override
 public void apply(Element e) {
   if (isNodeWithPrototype(e, nodePrototype)) {
     String nodeName = e.getAttribute("name");
     Element port = portWithName(e, oldPortName);
     if (port != null) port.setAttribute("name", newPortName);
     Element parent = (Element) e.getParentNode();
     List<Element> connections = childElementsWithName(parent, "conn");
     renamePortInNodeList(connections, "input", nodeName, oldPortName, newPortName);
     List<Element> ports = childElementsWithName(parent, "port");
     renamePortInNodeList(ports, "childReference", nodeName, oldPortName, newPortName);
   }
 }
Esempio n. 23
0
  /**
   * Converts value object to XML representation.
   *
   * @return Element.
   */
  public Element toXml(Document doc) {
    Element root = doc.createElement("Event");

    Element node;

    root.setAttribute("Id", String.valueOf(mEventId));

    node = doc.createElement("Type");
    node.appendChild(doc.createTextNode(String.valueOf(mType)));
    root.appendChild(node);

    node = doc.createElement("Status");
    node.appendChild(doc.createTextNode(String.valueOf(mStatus)));
    root.appendChild(node);

    node = doc.createElement("Cd");
    node.appendChild(doc.createTextNode(String.valueOf(mCd)));
    root.appendChild(node);

    node = doc.createElement("Attempt");
    node.appendChild(doc.createTextNode(String.valueOf(mAttempt)));
    root.appendChild(node);

    node = doc.createElement("AddDate");
    node.appendChild(doc.createTextNode(String.valueOf(mAddDate)));
    root.appendChild(node);

    node = doc.createElement("AddBy");
    node.appendChild(doc.createTextNode(String.valueOf(mAddBy)));
    root.appendChild(node);

    node = doc.createElement("ModDate");
    node.appendChild(doc.createTextNode(String.valueOf(mModDate)));
    root.appendChild(node);

    node = doc.createElement("ModBy");
    node.appendChild(doc.createTextNode(String.valueOf(mModBy)));
    root.appendChild(node);

    node = doc.createElement("EventPriority");
    node.appendChild(doc.createTextNode(String.valueOf(mEventPriority)));
    root.appendChild(node);

    node = doc.createElement("ProcessTime");
    node.appendChild(doc.createTextNode(String.valueOf(mProcessTime)));
    root.appendChild(node);

    return root;
  }
Esempio n. 24
0
  /**
   * Converts value object to XML representation.
   *
   * @return Element.
   */
  public Element toXml(Document doc) {
    Element root = doc.createElement("OrderAssoc");

    Element node;

    root.setAttribute("Id", String.valueOf(mOrderAssocId));

    node = doc.createElement("Order1Id");
    node.appendChild(doc.createTextNode(String.valueOf(mOrder1Id)));
    root.appendChild(node);

    node = doc.createElement("Order2Id");
    node.appendChild(doc.createTextNode(String.valueOf(mOrder2Id)));
    root.appendChild(node);

    node = doc.createElement("OrderAssocCd");
    node.appendChild(doc.createTextNode(String.valueOf(mOrderAssocCd)));
    root.appendChild(node);

    node = doc.createElement("OrderAssocStatusCd");
    node.appendChild(doc.createTextNode(String.valueOf(mOrderAssocStatusCd)));
    root.appendChild(node);

    node = doc.createElement("AddDate");
    node.appendChild(doc.createTextNode(String.valueOf(mAddDate)));
    root.appendChild(node);

    node = doc.createElement("AddBy");
    node.appendChild(doc.createTextNode(String.valueOf(mAddBy)));
    root.appendChild(node);

    node = doc.createElement("ModDate");
    node.appendChild(doc.createTextNode(String.valueOf(mModDate)));
    root.appendChild(node);

    node = doc.createElement("ModBy");
    node.appendChild(doc.createTextNode(String.valueOf(mModBy)));
    root.appendChild(node);

    node = doc.createElement("WorkOrderItemId");
    node.appendChild(doc.createTextNode(String.valueOf(mWorkOrderItemId)));
    root.appendChild(node);

    node = doc.createElement("ServiceTicketId");
    node.appendChild(doc.createTextNode(String.valueOf(mServiceTicketId)));
    root.appendChild(node);

    return root;
  }
Esempio n. 25
0
 /** Add an attribute to the given XML Element. Attributes are kept in alphabetical order. */
 protected Element addAttributes(Element el) {
   // Use a TreeMap to keep the attributes sorted on output
   Map atts = new TreeMap(getAttributes());
   Iterator iter = atts.keySet().iterator();
   while (iter.hasNext()) {
     String key = (String) iter.next();
     String value = (String) atts.get(key);
     if (value == null) {
       Log.warn("Attribute '" + key + "' value was null in step " + getXMLTag());
       value = "";
     }
     el.setAttribute(key, value);
   }
   return el;
 }
Esempio n. 26
0
  /**
   * Retruns the xml string equivalent of this object
   *
   * @param document instance of Xml Document.
   * @return org.w3c.dom.Node
   * @exception FioranoException thrown in case of error.
   */
  protected Node toJXMLString(Document document) throws FioranoException {
    Node root0 = document.createElement("InPort");

    ((Element) root0).setAttribute("isSyncRequestType", "" + isSyncRequestType());

    Node child = null;

    child = XMLDmiUtil.getNodeObject("Name", m_strPortName, document);
    if (child != null) {
      root0.appendChild(child);
    }

    child = XMLDmiUtil.getNodeObject("Description", m_strDscription, document);
    if (child != null) {
      root0.appendChild(child);
    }

    if (m_strXSD != null) {
      Element elem = document.createElement("XSD");
      CDATASection cdata = document.createCDATASection(m_strXSD);

      elem.appendChild(cdata);
      root0.appendChild(elem);
    }

    child = XMLDmiUtil.getNodeObject("JavaClass", m_strJavaClass, document);
    if (child != null) {
      root0.appendChild(child);
    }

    if (m_params != null && m_params.size() > 0) {
      Enumeration _enum = m_params.elements();

      while (_enum.hasMoreElements()) {
        Param param = (Param) _enum.nextElement();
        if (!StringUtil.isEmpty(param.getParamName())
            && !StringUtil.isEmpty(param.getParamValue())) {
          Node paramNode = param.toJXMLString(document);

          root0.appendChild(paramNode);
        }
      }
    }

    return root0;
  }
 /**
  * Marshall a Chromosome instance to an XML Element representation, including its contained Genes
  * as sub-elements. This may be useful in scenarios where representation as an entire Document is
  * undesirable, such as when the representation of this Chromosome is to be combined with other
  * elements in a single Document.
  *
  * @param a_subject the chromosome to represent as an XML element
  * @param a_xmlDocument a Document instance that will be used to create the Element instance. Note
  *     that the element will NOT be added to the document by this method
  * @return an Element object representing the given Chromosome
  * @author Neil Rotstan
  * @since 1.0
  * @deprecated use XMLDocumentBuilder instead
  */
 public static Element representChromosomeAsElement(
     final IChromosome a_subject, final Document a_xmlDocument) {
   // Start by creating an element for the chromosome and its size
   // attribute, which represents the number of genes in the chromosome.
   // ------------------------------------------------------------------
   Element chromosomeElement = a_xmlDocument.createElement(CHROMOSOME_TAG);
   chromosomeElement.setAttribute(SIZE_ATTRIBUTE, Integer.toString(a_subject.size()));
   // Next create the genes element with its nested gene elements,
   // which will contain string representations of the alleles.
   // --------------------------------------------------------------
   Element genesElement = representGenesAsElement(a_subject.getGenes(), a_xmlDocument);
   // Add the new genes element to the chromosome element and then
   // return the chromosome element.
   // -------------------------------------------------------------
   chromosomeElement.appendChild(genesElement);
   return chromosomeElement;
 }
 /**
  * Marshall a Genotype instance into an XML Element representation, including its population of
  * Chromosome instances as sub-elements. This may be useful in scenarios where representation as
  * an entire Document is undesirable, such as when the representation of this Genotype is to be
  * combined with other elements in a single Document.
  *
  * @param a_subject the genotype to represent as an XML element
  * @param a_xmlDocument a Document instance that will be used to create the Element instance. Note
  *     that the element will NOT be added to the document by this method
  * @return an Element object representing the given Genotype
  * @author Neil Rotstan
  * @since 1.0
  * @deprecated use XMLDocumentBuilder instead
  */
 public static Element representGenotypeAsElement(
     final Genotype a_subject, final Document a_xmlDocument) {
   Population population = a_subject.getPopulation();
   // Start by creating the genotype element and its size attribute,
   // which represents the number of chromosomes present in the
   // genotype.
   // --------------------------------------------------------------
   Element genotypeTag = a_xmlDocument.createElement(GENOTYPE_TAG);
   genotypeTag.setAttribute(SIZE_ATTRIBUTE, Integer.toString(population.size()));
   // Next, add nested elements for each of the chromosomes in the
   // genotype.
   // ------------------------------------------------------------
   for (int i = 0; i < population.size(); i++) {
     Element chromosomeElement =
         representChromosomeAsElement(population.getChromosome(i), a_xmlDocument);
     genotypeTag.appendChild(chromosomeElement);
   }
   return genotypeTag;
 }
Esempio n. 29
0
  /**
   * Save the XML description of the circuit
   *
   * @param output an output stream to write in
   * @return true if the dump was successful, false either
   */
  public boolean dumpToXml(OutputStream output) {
    Document doc;
    Element root;

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;

    try {
      builder = factory.newDocumentBuilder();
      doc = builder.newDocument();
    } catch (ParserConfigurationException pce) {
      System.err.println("dumpToXmlFile: unable to write XML save file.");
      return false;
    }

    root = doc.createElement("Circuit");
    root.setAttribute("name", this.getName());

    for (iterNodes = this.nodes.iterator(); iterNodes.hasNext(); )
      iterNodes.next().dumpToXml(doc, root);

    root.normalize();
    doc.appendChild(root);

    try {
      TransformerFactory tffactory = TransformerFactory.newInstance();
      Transformer transformer = tffactory.newTransformer();
      transformer.setOutputProperty(OutputKeys.INDENT, "yes");
      DOMSource source = new DOMSource(doc);
      StreamResult result = new StreamResult(output);
      transformer.transform(source, result);
    } catch (TransformerConfigurationException tce) {
      System.err.println("dumpToXmlFile:  Configuration Transformer exception.");
      return false;
    } catch (TransformerException te) {
      System.err.println("dumpToXmlFile: Transformer exception.");
      return false;
    }

    return true;
  }
  /**
   * Converts value object to XML representation.
   *
   * @return Element.
   */
  public Element toXml(Document doc) {
    Element root = doc.createElement("InboundPollockOrderGuideLoader");
    root.setAttribute("Id", String.valueOf(mEditType));

    Element node;

    node = doc.createElement("RecordType");
    node.appendChild(doc.createTextNode(String.valueOf(mRecordType)));
    root.appendChild(node);

    node = doc.createElement("RecordValue1");
    node.appendChild(doc.createTextNode(String.valueOf(mRecordValue1)));
    root.appendChild(node);

    node = doc.createElement("RecordValue2");
    node.appendChild(doc.createTextNode(String.valueOf(mRecordValue2)));
    root.appendChild(node);

    node = doc.createElement("RecordValue3");
    node.appendChild(doc.createTextNode(String.valueOf(mRecordValue3)));
    root.appendChild(node);

    return root;
  }