public void renderTo(ClassDoc classDoc, Element parent) {
    Document document = parent.getOwnerDocument();

    Element title = document.createElement("title");
    parent.appendChild(title);
    title.appendChild(document.createTextNode(classDoc.getSimpleName()));

    Element list = document.createElement("segmentedlist");
    parent.appendChild(list);
    Element segtitle = document.createElement("segtitle");
    list.appendChild(segtitle);
    segtitle.appendChild(document.createTextNode("API Documentation"));
    Element listItem = document.createElement("seglistitem");
    list.appendChild(listItem);
    Element seg = document.createElement("seg");
    listItem.appendChild(seg);
    Element apilink = document.createElement("apilink");
    seg.appendChild(apilink);
    apilink.setAttribute("class", classDoc.getName());
    apilink.setAttribute("style", classDoc.getStyle());

    warningsRenderer.renderTo(classDoc, "class", parent);

    for (Element element : classDoc.getComment()) {
      parent.appendChild(document.importNode(element, true));
    }
    NodeList otherContent = classDoc.getClassSection().getChildNodes();
    for (int i = 0; i < otherContent.getLength(); i++) {
      Node child = otherContent.item(i);
      if (child instanceof Element && !((Element) child).getTagName().equals("section")) {
        parent.appendChild(document.importNode(child, true));
      }
    }
  }
  public IXArchElement cloneElement(int depth) {
    synchronized (DOMUtils.getDOMLock(elt)) {
      Document doc = elt.getOwnerDocument();
      if (depth == 0) {
        Element cloneElt = (Element) elt.cloneNode(false);
        cloneElt = (Element) doc.importNode(cloneElt, true);
        AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt);
        cloneImpl.setXArch(getXArch());
        return cloneImpl;
      } else if (depth == 1) {
        Element cloneElt = (Element) elt.cloneNode(false);
        cloneElt = (Element) doc.importNode(cloneElt, true);
        AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt);
        cloneImpl.setXArch(getXArch());

        NodeList nl = elt.getChildNodes();
        int size = nl.getLength();
        for (int i = 0; i < size; i++) {
          Node n = nl.item(i);
          Node cloneNode = (Node) n.cloneNode(false);
          cloneNode = doc.importNode(cloneNode, true);
          cloneElt.appendChild(cloneNode);
        }
        return cloneImpl;
      } else /* depth = infinity */ {
        Element cloneElt = (Element) elt.cloneNode(true);
        cloneElt = (Element) doc.importNode(cloneElt, true);
        AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt);
        cloneImpl.setXArch(getXArch());
        return cloneImpl;
      }
    }
  }
Example #3
0
  /**
   * Sign a node in a document
   *
   * @param doc
   * @param nodeToBeSigned
   * @param keyPair
   * @param publicKey
   * @param digestMethod
   * @param signatureMethod
   * @param referenceURI
   * @return
   * @throws ParserConfigurationException
   * @throws XMLSignatureException
   * @throws MarshalException
   * @throws GeneralSecurityException
   */
  public static Document sign(
      Document doc,
      Node nodeToBeSigned,
      KeyPair keyPair,
      String digestMethod,
      String signatureMethod,
      String referenceURI,
      X509Certificate x509Certificate)
      throws ParserConfigurationException, GeneralSecurityException, MarshalException,
          XMLSignatureException {
    if (nodeToBeSigned == null) throw logger.nullArgumentError("Node to be signed");

    if (logger.isTraceEnabled()) {
      logger.trace("Document to be signed=" + DocumentUtil.asString(doc));
    }

    Node parentNode = nodeToBeSigned.getParentNode();

    // Let us create a new Document
    Document newDoc = DocumentUtil.createDocument();
    // Import the node
    Node signingNode = newDoc.importNode(nodeToBeSigned, true);
    newDoc.appendChild(signingNode);

    if (!referenceURI.isEmpty()) {
      propagateIDAttributeSetup(nodeToBeSigned, newDoc.getDocumentElement());
    }
    newDoc = sign(newDoc, keyPair, digestMethod, signatureMethod, referenceURI, x509Certificate);

    // if the signed element is a SAMLv2.0 assertion we need to move the signature element to the
    // position
    // specified in the schema (before the assertion subject element).
    if (nodeToBeSigned.getLocalName().equals("Assertion")
        && WSTrustConstants.SAML2_ASSERTION_NS.equals(nodeToBeSigned.getNamespaceURI())) {
      Node signatureNode =
          DocumentUtil.getElement(newDoc, new QName(WSTrustConstants.DSIG_NS, "Signature"));
      Node subjectNode =
          DocumentUtil.getElement(
              newDoc, new QName(WSTrustConstants.SAML2_ASSERTION_NS, "Subject"));
      if (signatureNode != null && subjectNode != null) {
        newDoc.getDocumentElement().removeChild(signatureNode);
        newDoc.getDocumentElement().insertBefore(signatureNode, subjectNode);
      }
    }

    // Now let us import this signed doc into the original document we got in the method call
    Node signedNode = doc.importNode(newDoc.getFirstChild(), true);

    if (!referenceURI.isEmpty()) {
      propagateIDAttributeSetup(newDoc.getDocumentElement(), (Element) signedNode);
    }

    parentNode.replaceChild(signedNode, nodeToBeSigned);
    // doc.getDocumentElement().replaceChild(signedNode, nodeToBeSigned);

    return doc;
  }
Example #4
0
 /** Transform into formatted XML. */
 public static String getFormattedXml(Node node) {
   Document document =
       node.getOwnerDocument().getImplementation().createDocument("", "fake", null);
   Element copy = (Element) document.importNode(node, true);
   document.importNode(node, false);
   document.removeChild(document.getDocumentElement());
   document.appendChild(copy);
   DOMImplementation domImpl = document.getImplementation();
   DOMImplementationLS domImplLs = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");
   LSSerializer serializer = domImplLs.createLSSerializer();
   serializer.getDomConfig().setParameter("format-pretty-print", true);
   return serializer.writeToString(document);
 }
Example #5
0
  /**
   * Create some content in the context of a given document
   *
   * @return
   *     <ul>
   *       <li>A {@link DocumentFragment} if <code>text</code> is well-formed.
   *       <li><code>null</code>, if <code>text</code> is plain text or not well formed
   *     </ul>
   */
  static final DocumentFragment createContent(Document doc, String text) {

    // Text might hold XML content
    if (text != null && text.contains("<")) {
      DocumentBuilder builder = builder();

      try {

        // [#128] Trimming will get rid of leading and trailing whitespace, which would
        // otherwise cause a HIERARCHY_REQUEST_ERR raised by the parser
        text = text.trim();

        // There is a processing instruction. We can safely assume
        // valid XML and parse it as such
        if (text.startsWith("<?xml")) {
          Document parsed = builder.parse(new InputSource(new StringReader(text)));
          DocumentFragment fragment = parsed.createDocumentFragment();
          fragment.appendChild(parsed.getDocumentElement());

          return (DocumentFragment) doc.importNode(fragment, true);
        }

        // Any XML document fragment. To be on the safe side, fragments
        // are wrapped in a dummy root node
        else {
          String wrapped = "<dummy>" + text + "</dummy>";
          Document parsed = builder.parse(new InputSource(new StringReader(wrapped)));
          DocumentFragment fragment = parsed.createDocumentFragment();
          NodeList children = parsed.getDocumentElement().getChildNodes();

          // appendChild removes children also from NodeList!
          while (children.getLength() > 0) {
            fragment.appendChild(children.item(0));
          }

          return (DocumentFragment) doc.importNode(fragment, true);
        }
      }

      // This does not occur
      catch (IOException ignore) {
      }

      // The XML content is invalid
      catch (SAXException ignore) {
      }
    }

    // Plain text or invalid XML
    return null;
  }
Example #6
0
  public void test1() throws Exception {

    // Creates graph with model
    mxGraph graph = new mxGraph();
    Object parent = graph.getDefaultParent();
    Object v1, v2;

    graph.getModel().beginUpdate();
    try {
      v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80, 30);
      v2 = graph.insertVertex(parent, null, "World!", 200, 150, 80, 30);
      graph.insertEdge(parent, null, "e1", v1, v2);
    } finally {
      graph.getModel().endUpdate();
    }

    mxCodec codec = new mxCodec();
    Node node = codec.encode(graph.getModel());
    String xml1 = mxXmlUtils.getXml(node);

    System.out.println("xml=" + mxUtils.getPrettyXml(node));

    Document doc = mxDomUtils.createDocument();
    doc.appendChild(doc.importNode(node, true));
    codec = new mxCodec(doc);
    Object model = codec.decode(node);

    codec = new mxCodec();
    node = codec.encode(model);
    String xml2 = mxXmlUtils.getXml(node);

    assertEquals(xml1, xml2);
  }
Example #7
0
  /*
   * ???
   *
   * @param response
   * @param responseBean
   * @return
   * @throws TransformerException
   * @throws SOAPException
   * @throws ParserConfigurationException
   */
  private Document handleSoapResponse(SOAPMessage response, HttpResponseBean responseBean)
      throws TransformerException, SOAPException, ParserConfigurationException {

    Node responseNode = null;

    if (response != null) {
      responseNode = extractResponseNode(response);
      extractHeaderDataSOAP(response, responseBean);
    }

    // build new xml document for assertion
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document newDocument = builder.newDocument();

    Node adoptedBlob = newDocument.importNode(responseNode, true);
    newDocument.appendChild(adoptedBlob);

    // Output as String if required
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    transformer.transform(new DOMSource(newDocument), new StreamResult(out));

    if (logger.isDebugEnabled()) {
      logger.debug("\n Return Doc \n");
      logger.debug(new String(out.toByteArray()));
    }

    return newDocument;
  }
  /**
   * Parses a string containing XML and returns a DocumentFragment containing the nodes of the
   * parsed XML.
   */
  public static void loadFragment(Element el, String fragment) {
    // Wrap the fragment in an arbitrary element
    fragment = "<fragment>" + fragment + "</fragment>";
    try {
      // Create a DOM builder and parse the fragment
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(fragment)));

      Document doc = el.getOwnerDocument();

      // Import the nodes of the new document into doc so that they
      // will be compatible with doc
      Node node = doc.importNode(d.getDocumentElement(), true);

      // Create the document fragment node to hold the new nodes
      DocumentFragment docfrag = doc.createDocumentFragment();

      // Move the nodes into the fragment
      while (node.hasChildNodes()) {
        el.appendChild(node.removeChild(node.getFirstChild()));
      }

    } catch (Exception e) {
      log.error(e, e);
    }
  }
  private static Element addLink(Element parent, Entry entry, Document doc) {
    Element link = doc.createElementNS(null, "link");
    parent.appendChild(link);

    link.setAttributeNS(null, "class", "- topic/link ");

    link.setAttributeNS(null, "href", entry.href);

    if (entry.scope != null) {
      link.setAttributeNS(null, "scope", entry.scope);
    }

    if (entry.format != null) {
      link.setAttributeNS(null, "format", entry.format);
    }

    if (entry.linktext != null) {
      Element linktext = (Element) doc.importNode(entry.linktext, /*deep*/ true);
      linktext.setAttributeNS(null, "class", "- topic/linktext ");
      link.appendChild(linktext);
    }

    if (entry.shortdesc != null) {
      Element desc = doc.createElementNS(null, "desc");
      desc.setAttributeNS(null, "class", "- topic/desc ");
      link.appendChild(desc);

      DOMUtil.copyChildren(entry.shortdesc, desc, doc);
    }

    return link;
  }
 public static EDLController createEDLController(
     EDocLiteAssociation edlAssociation,
     EDLGlobalConfig edlGlobalConfig,
     DocumentRouteHeaderValue document) {
   EDLController edlController = createEDLController(edlAssociation, edlGlobalConfig);
   try {
     Document defaultDom = edlController.getDefaultDOM();
     Document documentDom = XmlHelper.readXml(document.getDocContent());
     // get the data node and import it into our default DOM
     Element documentData = (Element) documentDom.getElementsByTagName(EDLXmlUtils.DATA_E).item(0);
     if (documentData != null) {
       Element defaultDomEDL = EDLXmlUtils.getEDLContent(defaultDom, false);
       Element defaultDomData =
           (Element) defaultDomEDL.getElementsByTagName(EDLXmlUtils.DATA_E).item(0);
       defaultDomEDL.replaceChild(defaultDom.importNode(documentData, true), defaultDomData);
     }
     if (LOG.isDebugEnabled()) {
       LOG.debug(
           "Created default Node from document id "
               + document.getDocumentId()
               + " content "
               + XmlJotter.jotNode(defaultDom));
     }
   } catch (Exception e) {
     throw new WorkflowRuntimeException(
         "Problems creating controller for EDL "
             + edlAssociation.getEdlName()
             + " document "
             + document.getDocumentId(),
         e);
   }
   return edlController;
 }
Example #11
0
  /**
   * Exports a instance of {@link GetRecordByIdResult} to a {@link GetRecordByIdResultDocument}.
   *
   * @param response
   * @return a new document
   * @throws XMLException
   */
  public static GetRecordByIdResultDocument export(GetRecordByIdResult response)
      throws XMLException {

    GetRecordByIdResultDocument doc = new GetRecordByIdResultDocument();

    try {
      doc.createEmptyDocument(response.getRequest().getVersion());
      Document owner = doc.getRootElement().getOwnerDocument();
      if (response != null && response.getRecords() != null) {
        for (Node record : response.getRecords()) {
          Node copy = owner.importNode(record, true);
          doc.getRootElement().appendChild(copy);
        }
      } else if ("2.0.2".equals(response.getRequest().getVersion())
          && (response == null || response.getRecord() == null)) {
        throw new OGCWebServiceException(
            "A record with the given ID does nor exist in the CSW",
            CSWExceptionCode.INVALIDPARAMETERVALUE);
      }
    } catch (Exception e) {
      LOG.logError(e.getMessage(), e);
      throw new XMLException(e.getMessage());
    }

    return doc;
  }
  /**
   * Set a property of a resource to a value.
   *
   * @param name the property name
   * @param value the property value
   * @exception com.ibm.webdav.WebDAVException
   */
  public void setProperty(String name, Element value) throws WebDAVException {
    // load the properties
    Document propertiesDocument = resource.loadProperties();
    Element properties = propertiesDocument.getDocumentElement();
    String ns = value.getNamespaceURI();

    Element property = null;
    if (ns == null) {
      property = (Element) ((Element) properties).getElementsByTagName(value.getTagName()).item(0);
    } else {
      property = (Element) properties.getElementsByTagNameNS(ns, value.getLocalName()).item(0);
    }

    if (property != null) {
      try {
        properties.removeChild(property);
      } catch (DOMException exc) {
      }
    }

    properties.appendChild(propertiesDocument.importNode(value, true));

    // write out the properties
    resource.saveProperties(propertiesDocument);
  }
  /**
   * This method will read and load the existing services.xml file and append the provided document
   * in the existing XML
   *
   * @param serviceDoc Document XML generated earlier
   * @param dirName Directory where file exists
   * @param fileName Name of the file to load the previous xml from
   * @return Modified XML document to be written on file
   */
  public Document appendXMLDoc(Document xmlDoc, String dirName, String fileName) {
    Document doc = null;
    try {
      File file = new File(dirName, fileName);
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      doc = db.parse(file);
      Element existingRoot = doc.getDocumentElement();

      List<Node> importTo = new ArrayList<Node>();
      List<Node> nodeToImport = new ArrayList<Node>();
      if (fileName.equals("ejb-jar.xml")
          || fileName.equals("jboss.xml")
          || fileName.equals("jboss-ejb3.xml")) {
        importTo.add(existingRoot.getElementsByTagName("enterprise-beans").item(0));
        nodeToImport.add(xmlDoc.getDocumentElement().getElementsByTagName("session").item(0));
        if (fileName.equals("ejb-jar.xml")) {
          // Additional security config to append
          importTo.add(existingRoot.getElementsByTagName("assembly-descriptor").item(0));
          nodeToImport.add(
              xmlDoc.getDocumentElement().getElementsByTagName("method-permission").item(0));
        } else if (fileName.equals("jboss-ejb3.xml")) {
          // Additional security config to append
          importTo.add(existingRoot.getElementsByTagName("assembly-descriptor").item(0));
          nodeToImport.add(xmlDoc.getDocumentElement().getElementsByTagName("s:security").item(0));
        }
      } else if (fileName.equals("ibm-ejb-jar-bnd.xml")) {
        importTo.add(existingRoot);
        nodeToImport.add(xmlDoc.getDocumentElement().getElementsByTagName("session").item(0));
      } else if (fileName.equals("weblogic-ejb-jar.xml")) {
        importTo.add(existingRoot);
        nodeToImport.add(
            xmlDoc
                .getDocumentElement()
                .getElementsByTagName("wls:weblogic-enterprise-bean")
                .item(0));
      }
      if (importTo.size() > 0 && nodeToImport.size() > 0) {
        for (int i = 0; i < importTo.size(); i++) {
          importTo.get(i).appendChild(doc.importNode(nodeToImport.get(i), true));
        }
      }
      return doc;
    } catch (ParserConfigurationException pe) {
      System.out.println(
          "Failed to parse existing services XML. ParserConfigException : " + pe.getMessage());
    } catch (SAXException sae) {
      System.out.println(
          "Failed to parse existing services XML. SAXException : " + sae.getMessage());
    } catch (DOMException dome) {
      System.out.println(
          "Failed to parse existing services XML. DOMException : " + dome.getMessage());
    } catch (IOException ioe) {
      System.out.println("Failed to locate services.xml . IOException : " + ioe.getMessage());
    } catch (Exception e) {
      System.out.println("Failed to parse services.xml . Exception : " + e.getMessage());
    }
    // Return the original one back
    return xmlDoc;
  }
  protected Element createElement(String tagName, String xmlContent) {

    try {
      // try to parse the xml content
      parser.parse(
          new InputSource(
              new StringReader(
                  "<"
                      + tagName
                      + ">"
                      + xmlContent.replaceAll("&", "&amp;")
                      + "</"
                      + tagName
                      + ">")));

      Element e = parser.getDocument().getDocumentElement();
      return (Element) doc.importNode(e, true);
    } catch (Exception exception) {
      // if that fails, just dump the xml content as a text node within the element. All special
      // characters will be escaped.

      Element e = doc.createElement(tagName);
      e.appendChild(doc.createTextNode(xmlContent));
      return e;
    }
  }
 private static Element cloneSafely(Element el) {
   // #50198: for thread safety, use a separate document.
   // Using XMLUtil.createDocument is much too slow.
   synchronized (db) {
     Document dummy = db.newDocument();
     return (Element) dummy.importNode(el, true);
   }
 }
Example #16
0
 /** @param eNewParent */
 public static void debugOutput(Element eNewParent) {
   try {
     Document d = XML.newDocument("test");
     d.getDocumentElement().appendChild(d.importNode(eNewParent, true));
     System.err.println(XML.saveString(d).replaceAll("(^(.|[\\n\\r])*<test>)|(</test>$)", ""));
   } catch (Exception e) {
   }
 }
Example #17
0
 /**
  * Checks if child element has same owner document before appending to the parent, and imports it
  * to the parent's document if necessary.
  */
 public static void appendChild(Node parent, Node child) {
   Document ownerDoc = getOwnerDocument(parent);
   if (child.getOwnerDocument() != ownerDoc) {
     parent.appendChild(ownerDoc.importNode(child, true));
   } else {
     parent.appendChild(child);
   }
 }
Example #18
0
  private Element parseMetadata(
      @NotNull String systemId, @NotNull ServiceDescriptor serviceDescriptor) {
    List<? extends Source> mexWsdls = serviceDescriptor.getWSDLs();
    List<? extends Source> mexSchemas = serviceDescriptor.getSchemas();
    Document root = null;
    for (Source src : mexWsdls) {
      if (src instanceof DOMSource) {
        Node n = ((DOMSource) src).getNode();
        Document doc;
        if (n.getNodeType() == Node.ELEMENT_NODE && n.getOwnerDocument() == null) {
          doc = DOMUtil.createDom();
          doc.importNode(n, true);
        } else {
          doc = n.getOwnerDocument();
        }

        //                Element e = (n.getNodeType() == Node.ELEMENT_NODE)?(Element)n:
        // DOMUtil.getFirstElementChild(n);
        if (root == null) {
          // check if its main wsdl, then set it to root
          NodeList nl =
              doc.getDocumentElement().getElementsByTagNameNS(WSDLConstants.NS_WSDL, "service");
          if (nl.getLength() > 0) {
            root = doc;
            rootWSDL = src.getSystemId();
          }
        }
        NodeList nl =
            doc.getDocumentElement().getElementsByTagNameNS(WSDLConstants.NS_WSDL, "import");
        for (int i = 0; i < nl.getLength(); i++) {
          Element imp = (Element) nl.item(i);
          String loc = imp.getAttribute("location");
          if (loc != null) {
            if (!externalReferences.contains(loc)) externalReferences.add(loc);
          }
        }
        if (core.keySet().contains(systemId)) core.remove(systemId);
        core.put(src.getSystemId(), doc);
        resolvedCache.put(systemId, doc.getDocumentURI());
        isMexMetadata = true;
      }

      // TODO:handle SAXSource
      // TODO:handler StreamSource
    }

    for (Source src : mexSchemas) {
      if (src instanceof DOMSource) {
        Node n = ((DOMSource) src).getNode();
        Element e =
            (n.getNodeType() == Node.ELEMENT_NODE) ? (Element) n : DOMUtil.getFirstElementChild(n);
        inlinedSchemaElements.add(e);
      }
      // TODO:handle SAXSource
      // TODO:handler StreamSource
    }
    return root.getDocumentElement();
  }
 public void setSpecifications(EfficiencySpecification[] specifications) {
   if (specifications != null)
     if (specifications.length <= 24 && specifications.length >= 0) {
       this.specifications = specifications;
       Element x = (Element) efficiencyProfileElement.cloneNode(false);
       for (EfficiencySpecification es : specifications)
         x.appendChild(doc.importNode(es.getEfficiencySpecificationElement(), true));
     }
 }
 protected void appendDescription(Document tgt, Document src) {
   Element tgtRoot = tgt.getDocumentElement();
   Element srcRoot = src.getDocumentElement();
   NodeList nodes = srcRoot.getChildNodes();
   for (int i = 0; i < nodes.getLength(); i++) {
     Node node = tgt.importNode(nodes.item(i), true);
     tgtRoot.appendChild(node);
   }
 }
  /**
   * Copies childnodes to destination element
   *
   * @param src source element
   * @param doc destination document
   * @param dst destination element
   * @return void
   */
  private void importAndAppendChildNodes(Element src, Document doc, Element dst) {
    NodeList childNodes = src.getChildNodes();

    for (int j = 0; j < childNodes.getLength(); j++) {
      Node node = childNodes.item(j);
      Node importedNode = doc.importNode(node, true);
      dst.appendChild(importedNode);
    }
  }
Example #22
0
 protected Element importElement(Element element) {
   Document document = getOwnerDocument();
   Document oldDocument = element.getOwnerDocument();
   if (!oldDocument.equals(document)) {
     return (Element) document.importNode(element, true);
   } else {
     return element;
   }
 }
 private static synchronized Map cloneConfigMap(Map configMap, Document defaultDom) {
   Map tempConfigProcessors = new LinkedHashMap();
   for (Iterator iter = configMap.entrySet().iterator(); iter.hasNext(); ) {
     Map.Entry configProcessorMapping = (Map.Entry) iter.next();
     tempConfigProcessors.put(
         defaultDom.importNode((Node) configProcessorMapping.getKey(), true),
         configProcessorMapping.getValue());
   }
   return tempConfigProcessors;
 }
  /**
   * Serialize the given node to a String.
   *
   * @param node Node to be serialized.
   * @return The serialized node as a java.lang.String instance.
   */
  public static String nodeToString(Node node) {

    if (importerDoc == null) {
      OMDOMFactory fac = new OMDOMFactory();
      importerDoc = (Document) fac.createOMDocument();
    }
    // Import the node as an AXIOM-DOOM node and use toSting()
    Node axiomNode = importerDoc.importNode(node, true);
    return axiomNode.toString();
  }
 private List<Node> convertNodesToDocuments(List<Node> nodeList)
     throws ParserConfigurationException {
   DocumentBuilder documentBuilder = this.getNewDocumentBuilder();
   List<Node> docList = new ArrayList<Node>(nodeList.size());
   for (Node node : nodeList) {
     Document doc = documentBuilder.newDocument();
     doc.appendChild(doc.importNode(node, true));
     docList.add(doc);
   }
   return docList;
 }
  private DynamicRemoteSetExportFormat(Element el) {
    super();
    this.formatName = el.getAttribute("name");
    this.extension = el.getAttribute("extension");
    this.simpleSequence = Boolean.parseBoolean(el.getAttribute("simpleSequence"));
    this.binary = Boolean.parseBoolean(el.getAttribute("binary"));

    xslt = XmlUtils.newDocument();
    Node stylesheet = el.getElementsByTagName("xsl:stylesheet").item(0);
    xslt.appendChild(xslt.importNode(stylesheet, true));
  }
 public void addSpecification(EfficiencySpecification es) {
   specifications[es.getHour()] = es;
   NodeList nl = efficiencyProfileElement.getElementsByTagName("Efficiency_Specification");
   Element x = (Element) doc.importNode(es.getEfficiencySpecificationElement(), true);
   for (int i = 0; i < nl.getLength(); i++)
     if (((Element) nl.item(i)).getAttribute("hour").equals("" + es.getHour())) {
       efficiencyProfileElement.removeChild(nl.item(i));
       efficiencyProfileElement.insertBefore(x, nl.item(i));
       return;
     }
   efficiencyProfileElement.appendChild(x);
 }
 public Track add(Track track) {
   synchronized (this) {
     Track copy;
     if ((copy = getTrack(track)) == null) {
       copy = new Track((Element) doc.importNode(track.getElement(), false));
       docElt.appendChild(copy.getElement());
       tracks.add(copy);
       hash.put(copy.getKey(), copy);
     }
     return copy;
   }
 }
Example #29
0
 private DocumentFragment appendPushContent(
     final DocumentFragment pushcontent, final DocumentFragment target) {
   DocumentFragment df = target;
   if (df == null) {
     df = pushDocument.createDocumentFragment();
   }
   final NodeList children = pushcontent.getChildNodes();
   for (int i = 0; i < children.getLength(); i++) {
     df.appendChild(pushDocument.importNode(children.item(i), true));
   }
   return df;
 }
 private Document buildSubscribeRequestMessage(Element subscribe)
     throws ParserConfigurationException, DOMException {
   Document document = null;
   DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
   DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
   document = docBuilder.newDocument();
   Element subscribeRequestElement = null;
   subscribeRequestElement =
       document.createElementNS("http://docs.oasis-open.org/wsn/b-2", "SubscribeRequest");
   Node subscribeNode = document.importNode(subscribe, true);
   subscribeRequestElement.appendChild(subscribeNode);
   document.appendChild(subscribeRequestElement);
   return document;
 }