Example usage for org.w3c.dom Document getFirstChild

List of usage examples for org.w3c.dom Document getFirstChild

Introduction

In this page you can find the example usage for org.w3c.dom Document getFirstChild.

Prototype

public Node getFirstChild();

Source Link

Document

The first child of this node.

Usage

From source file:netinf.common.communication.MessageEncoderXML.java

private void encodeESFFetchMissedEventsRequest(Document xml, ESFFetchMissedEventsRequest m,
        SerializeFormat serializeFormat) {
    appendElementWithValue(xml, xml.getFirstChild(), EL_PRIVATE_KEY, m.getPrivateKey().toString());
    appendElementWithValue(xml, xml.getFirstChild(), EL_USER_NAME, m.getUserName().toString());
    appendElementWithValue(xml, xml.getFirstChild(), EL_ERROR_MESSAGE, m.getErrorMessage().toString());

}

From source file:netinf.common.communication.MessageEncoderXML.java

private void encodeRSGetRequest(Document xml, RSGetRequest m, SerializeFormat serializeFormat) {
    appendElementWithValue(xml, xml.getFirstChild(), EL_IDENTIFIER, m.getIdentifier().toString());

    if (m.isFetchAllVersions()) {
        appendElementWithValue(xml, xml.getFirstChild(), EL_FETCH_ALL_VERSIONS, VALUE_TRUE);
    }//ww  w . ja  v  a2  s .co  m

    if (m.isDownloadBinaryObject()) {
        appendElementWithValue(xml, xml.getFirstChild(), EL_DOWNLOAD_BINARY_OBJECT, VALUE_TRUE);
    }

    if (m.getResolutionServicesToUse() != null) {
        Element resolutionServicesToUseElement = xml.createElement(EL_RESOLUTION_SERVICES_TO_USE);
        for (ResolutionServiceIdentityObject rsIdentityObject : m.getResolutionServicesToUse()) {
            String value = serializeObject(rsIdentityObject, serializeFormat);
            appendElementWithValue(xml, resolutionServicesToUseElement, EL_IDENTITY, value);
        }

        xml.getDocumentElement().appendChild(resolutionServicesToUseElement);
    }
}

From source file:netinf.common.communication.MessageEncoderXML.java

private void encodeTCChangeTransferRequest(Document xml, TCChangeTransferRequest m,
        SerializeFormat serializeFormat) {
    if (m.isProceed()) {
        appendElementWithValue(xml, xml.getFirstChild(), EL_PROCEED, VALUE_TRUE);
    }//from w ww.j av a2s  .  c om

    if (m.getNewDestination() != null) {
        appendElementWithValue(xml, xml.getFirstChild(), EL_NEW_DESTINATION, m.getNewDestination());
    }

    appendElementWithValue(xml, xml.getFirstChild(), EL_JOB_ID, m.getJobId());
}

From source file:netinf.common.communication.MessageEncoderXML.java

private void encodeTCChangeTransferResponse(Document xml, TCChangeTransferResponse m,
        SerializeFormat serializeFormat) {
    appendElementWithValue(xml, xml.getFirstChild(), EL_SOURCE, m.getSource());

    if (m.getNewDestination() != null) {
        appendElementWithValue(xml, xml.getFirstChild(), EL_NEW_DESTINATION, m.getNewDestination());
    }//w ww.ja v  a2 s . c  om

    appendElementWithValue(xml, xml.getFirstChild(), EL_JOB_ID, m.getJobId());
}

From source file:netinf.common.communication.MessageEncoderXML.java

private void encodeTCStartTransferRequest(Document xml, TCStartTransferRequest m,
        SerializeFormat serializeFormat) {
    appendElementWithValue(xml, xml.getFirstChild(), EL_SOURCE, m.getSource());

    if (m.getDestination() != null) {
        appendElementWithValue(xml, xml.getFirstChild(), EL_DESTINATION, m.getDestination());
    }/*from   www. j  av  a  2  s  .co m*/

    if (m.getTransferServiceToUse() != null) {
        appendElementWithValue(xml, xml.getFirstChild(), EL_TRANSFER_SERVICE_TO_USE,
                m.getTransferServiceToUse());
    }
}

From source file:netinf.common.communication.MessageEncoderXML.java

private void encodeTCStartTransferResponse(Document xml, TCStartTransferResponse m,
        SerializeFormat serializeFormat) {
    appendElementWithValue(xml, xml.getFirstChild(), EL_SOURCE, m.getSource());

    if (m.getDestination() != null) {
        appendElementWithValue(xml, xml.getFirstChild(), EL_DESTINATION, m.getDestination());
    }/* w w w.  j a v a2s. c om*/

    appendElementWithValue(xml, xml.getFirstChild(), EL_JOB_ID, m.getJobId());
}

From source file:nl.b3p.imagetool.CombineArcIMSUrl.java

/**
 * Create a new CombineImageUrl with the given values
 * In this implementation the body is changed.
 * @param width width//from w ww.j  a v a  2s .com
 * @param height height
 * @param bbox bbox
 * @return new clone of this CombineImageUrl but with changed values.
 * @see CombineImageUrl#calculateNewUrl(java.lang.Integer, java.lang.Integer, nl.b3p.viewer.image.Bbox) 
 */
@Override
public List<CombineImageUrl> calculateNewUrl(ImageBbox bbox) {
    Integer width = bbox.getWidth();
    Integer height = bbox.getHeight();
    Bbox bb = bbox.getBbox();
    CombineArcIMSUrl ciu = new CombineArcIMSUrl(this);
    try {
        Document doc = bodyAsDocument();
        Node root = doc.getFirstChild();
        //change the bbox
        Node envelope = (Node) xPathEnvelope.evaluate(root, XPathConstants.NODE);
        NamedNodeMap nnm = envelope.getAttributes();
        nnm.getNamedItem("minx").setNodeValue("" + bb.getMinx());
        nnm.getNamedItem("maxx").setNodeValue("" + bb.getMaxx());
        nnm.getNamedItem("miny").setNodeValue("" + bb.getMiny());
        nnm.getNamedItem("maxy").setNodeValue("" + bb.getMaxy());
        //
        Node imageSize = (Node) xPathImageSize.evaluate(root, XPathConstants.NODE);
        nnm = imageSize.getAttributes();
        nnm.getNamedItem("width").setNodeValue(width.toString());
        nnm.getNamedItem("height").setNodeValue(height.toString());

        ciu.setBody(doc);
    } catch (Exception e) {
        log.warn("Error while changing body fragment", e);
    }
    List<CombineImageUrl> list = new ArrayList<CombineImageUrl>();
    list.add(ciu);
    return list;
}

From source file:nl.b3p.imagetool.CombineArcServerUrl.java

/**
 * Create a new CombineImageUrl with the given values
 * In this implementation the body is changed.
 * @param width width/*from   w w w.  j a  va2  s  .  c  o  m*/
 * @param height height
 * @param bbox bbox
 * @return new clone of this CombineImageUrl but with changed values.
 * @see CombineImageUrl#calculateNewUrl(java.lang.Integer, java.lang.Integer, nl.b3p.viewer.image.Bbox) 
 */
@Override
public List<CombineImageUrl> calculateNewUrl(ImageBbox imbbox) {
    Integer width = imbbox.getWidth();
    Integer height = imbbox.getHeight();
    Bbox bbox = imbbox.getBbox();

    CombineArcServerUrl ciu = new CombineArcServerUrl(this);
    try {
        Document doc = bodyAsDocument();
        Node root = doc.getFirstChild();
        //change the bbox
        Node extent = (Node) xPathExtent.evaluate(root, XPathConstants.NODE);
        NodeList nl = extent.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node child = nl.item(i);
            if ("XMin".equals(child.getLocalName())) {
                child.setTextContent("" + bbox.getMinx());
            } else if ("YMin".equals(child.getLocalName())) {
                child.setTextContent("" + bbox.getMiny());
            } else if ("XMax".equals(child.getLocalName())) {
                child.setTextContent("" + bbox.getMaxx());
            } else if ("YMax".equals(child.getLocalName())) {
                child.setTextContent("" + bbox.getMaxy());
            }
        }
        //image size
        Node imageSize = (Node) xPathImageDisplay.evaluate(root, XPathConstants.NODE);
        nl = imageSize.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node child = nl.item(i);
            if ("ImageHeight".equals(child.getLocalName())) {
                child.setTextContent(height.toString());
            } else if ("ImageWidth".equals(child.getLocalName())) {
                child.setTextContent(width.toString());
            }
        }
        ciu.setBody(doc);
    } catch (Exception e) {
        log.warn("Error while changing body fragment", e);
    }

    List<CombineImageUrl> list = new ArrayList<CombineImageUrl>();
    list.add(ciu);
    return list;
}

From source file:nl.nn.adapterframework.extensions.bis.BisWrapperPipe.java

private String prepareReply(String rawReply, String messageHeader, String result, boolean resultInPayload)
        throws DomBuilderException, IOException, TransformerException {
    ArrayList messages = new ArrayList();
    if (messageHeader != null) {
        messages.add(messageHeader);/*www .j  a v  a  2 s.  com*/
    }
    messages.add(rawReply);

    String payload = null;
    if (result == null) {
        payload = Misc.listToString(messages);
    } else {
        if (resultInPayload) {
            String message = Misc.listToString(messages);
            Document messageDoc = XmlUtils.buildDomDocument(message);
            Node messageRootNode = messageDoc.getFirstChild();
            Node resultNode = messageDoc.importNode(XmlUtils.buildNode(result), true);
            messageRootNode.appendChild(resultNode);
            payload = XmlUtils.nodeToString(messageDoc);
        } else {
            messages.add(result);
            payload = Misc.listToString(messages);
        }
    }
    return payload;
}

From source file:org.adeptnet.auth.saml.SAMLClient.java

private void initMap() {
    if (!map.isEmpty()) {
        return;/*from  w  w  w .j  a v  a  2 s .  c o m*/
    }
    final InputStream is = org.apache.xml.security.Init.class.getResourceAsStream("resource/config.xml");
    if (is == null) {
        LOG.error("cannot read resource/config.xml");
        return;
    }
    try {
        /* read library configuration file */
        final DocumentBuilder db = createDocumentBuilder(false, true);
        final Document doc = db.parse(is);
        Node node = doc.getFirstChild();
        for (; node != null; node = node.getNextSibling()) {
            if ("Configuration".equals(node.getLocalName())) {
                break;
            }
        }
        if (node == null) {
            LOG.error("Error in reading configuration file - Configuration element not found");
            return;
        }
        for (Node el = node.getFirstChild(); el != null; el = el.getNextSibling()) {
            if (Node.ELEMENT_NODE != el.getNodeType()) {
                continue;
            }
            if (!"JCEAlgorithmMappings".equals(el.getLocalName())) {
                continue;
            }
            final Node algorithmsNode = ((Element) el).getElementsByTagName("Algorithms").item(0);
            if (algorithmsNode == null) {
                continue;
            }

            final Element[] algorithms = selectNodes(algorithmsNode.getFirstChild(), Init.CONF_NS, "Algorithm");
            for (final Element element : algorithms) {
                final String algoClass = element.getAttributeNS(null, "AlgorithmClass");
                if (!"Signature".equals(algoClass)) {
                    continue;
                }
                final String uri = element.getAttributeNS(null, "URI");
                final String name = element.getAttributeNS(null, "JCEName");
                map.put(name, uri);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(String.format("Mapping %s - %s", name, uri));
                }
            }
        }
    } catch (ParserConfigurationException | SAXException | IOException | DOMException ex) {
        LOG.error(ex.getMessage(), ex);
    }
}