Example usage for org.w3c.dom Element getNamespaceURI

List of usage examples for org.w3c.dom Element getNamespaceURI

Introduction

In this page you can find the example usage for org.w3c.dom Element getNamespaceURI.

Prototype

public String getNamespaceURI();

Source Link

Document

The namespace URI of this node, or null if it is unspecified (see ).

Usage

From source file:org.ojbc.bundles.adapters.staticmock.StaticMockQuery.java

Document personSearchDocuments(Document personSearchRequestMessage, DateTime baseDate) throws Exception {

    Document errorReturn = getPersonSearchStaticErrorResponse(personSearchRequestMessage);

    if (errorReturn != null) {
        return errorReturn;
    }//from www. j  a  v a2 s.  co  m

    // gets documents from each source system requested
    List<IdentifiableDocumentWrapper> instanceWrappers = personSearchDocumentsAsList(personSearchRequestMessage,
            baseDate);

    Document ret = createNewDocument();

    Element root = ret.createElementNS(OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_DOC,
            "PersonSearchResults");
    ret.appendChild(root);
    String prefix = XmlUtils.OJBC_NAMESPACE_CONTEXT
            .getPrefix(OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_DOC);
    root.setPrefix(prefix);

    for (IdentifiableDocumentWrapper instanceWrapper : instanceWrappers) {

        Document specificDetailSourceDoc = instanceWrapper.getDocument();

        Element psrElement = XmlUtils.appendElement(root, OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT,
                "PersonSearchResult");
        Element personElement = XmlUtils.appendElement(psrElement,
                OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT, "Person");
        Element documentRootElement = specificDetailSourceDoc.getDocumentElement();

        String rootNamespace = documentRootElement.getNamespaceURI();

        String rootLocalName = documentRootElement.getLocalName();

        SearchValueXPaths xPaths = null;

        if (OjbcNamespaceContext.NS_CH_DOC.equals(rootNamespace) && "CriminalHistory".equals(rootLocalName)) {
            xPaths = getCriminalHistoryXPaths();

        } else if (OjbcNamespaceContext.NS_WARRANT.equals(rootNamespace) && "Warrants".equals(rootLocalName)) {
            xPaths = getWarrantXPaths();

        } else if (OjbcNamespaceContext.NS_FIREARM_DOC.equals(rootNamespace)
                && "PersonFirearmRegistrationQueryResults".equals(rootLocalName)) {
            xPaths = getFirearmRegistrationXPaths();

        } else if (OjbcNamespaceContext.NS_IR.equals(rootNamespace) && "IncidentReport".equals(rootLocalName)) {
            xPaths = getIncidentXPaths();

        } else if (OjbcNamespaceContext.NS_JUVENILE_HISTORY_CONTAINER.equals(rootNamespace)
                && "JuvenileHistoryContainer".equals(rootLocalName)) {
            xPaths = getJuvenileHistoryXPaths();

        } else if (OjbcNamespaceContext.NS_CUSTODY_QUERY_RESULTS_EXCH_DOC.equals(rootNamespace)
                && "CustodyQueryResults".equals(rootLocalName)) {

            LOG.info(
                    "\n\n\n ****** \n\n personSearchDocuments(...) found CustodyQueryResults  \n\n ****** \n\n\n");

            xPaths = getCustodyXPaths();

        } else if (OjbcNamespaceContext.NS_COURT_CASE_QUERY_RESULTS_EXCH_DOC.equals(rootNamespace)
                && "CourtCaseQueryResults".equals(rootLocalName)) {
            xPaths = getCourtCaseXPaths();

        } else if (OjbcNamespaceContext.NS_VEHICLE_CRASH_QUERY_RESULT_EXCH_DOC.equals(rootNamespace)
                && "VehicleCrashQueryResults".equals(rootLocalName)) {
            xPaths = getVehicleCrashXPaths();

        } else {
            throw new IllegalStateException("Unsupported document root element: " + rootLocalName);
        }

        Element dobElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc, xPaths.birthdateXPath);
        Element ageElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc, xPaths.ageXPath);

        if (dobElement != null) {

            Element e = XmlUtils.appendElement(personElement, OjbcNamespaceContext.NS_NC, "PersonAgeMeasure");
            e = XmlUtils.appendElement(e, OjbcNamespaceContext.NS_NC, "MeasurePointValue");

            String dob = dobElement.getTextContent();

            dob = dob.trim();

            e.setTextContent(String.valueOf(
                    Years.yearsBetween(DATE_FORMATTER_YYYY_MM_DD.parseDateTime(dob), baseDate).getYears()));

            e = XmlUtils.appendElement(personElement, OjbcNamespaceContext.NS_NC, "PersonBirthDate");
            e = XmlUtils.appendElement(e, OjbcNamespaceContext.NS_NC, "Date");
            e.setTextContent(dob);

        } else if (ageElement != null) {

            Element e = XmlUtils.appendElement(personElement, OjbcNamespaceContext.NS_NC, "PersonAgeMeasure");
            e = XmlUtils.appendElement(e, OjbcNamespaceContext.NS_NC, "MeasurePointValue");
            e.setTextContent(ageElement.getTextContent());
        }

        Element heightElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc, xPaths.heightXPath);
        if (heightElement != null) {
            Element phm = XmlUtils.appendElement(personElement, OjbcNamespaceContext.NS_NC,
                    "PersonHeightMeasure");
            Element e = XmlUtils.appendElement(phm, OjbcNamespaceContext.NS_NC, "MeasurePointValue");
            e.setTextContent(heightElement.getTextContent());
            e = XmlUtils.appendElement(phm, OjbcNamespaceContext.NS_NC, "LengthUnitCode");
            e.setTextContent("INH");
        }
        Element lastNameElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc,
                xPaths.lastNameXPath);
        Element firstNameElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc,
                xPaths.firstNameXPath);
        Element middleNameElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc,
                xPaths.middleNameXPath);
        if (lastNameElement != null || firstNameElement != null || middleNameElement != null) {
            Element nameElement = XmlUtils.appendElement(personElement, OjbcNamespaceContext.NS_NC,
                    "PersonName");
            Element e = null;
            if (firstNameElement != null) {
                e = XmlUtils.appendElement(nameElement, OjbcNamespaceContext.NS_NC, "PersonGivenName");
                e.setTextContent(firstNameElement.getTextContent());
            }
            if (middleNameElement != null) {
                e = XmlUtils.appendElement(nameElement, OjbcNamespaceContext.NS_NC, "PersonMiddleName");
                e.setTextContent(middleNameElement.getTextContent());
            }
            if (lastNameElement != null) {
                e = XmlUtils.appendElement(nameElement, OjbcNamespaceContext.NS_NC, "PersonSurName");
                e.setTextContent(lastNameElement.getTextContent());
            }
        }
        Element raceElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc, xPaths.raceXPath);
        if (raceElement != null) {
            Element e = XmlUtils.appendElement(personElement, OjbcNamespaceContext.NS_NC, "PersonRaceCode");
            e.setTextContent(raceElement.getTextContent());
        }
        Element sexElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc, xPaths.sexXPath);
        if (sexElement != null) {
            Element e = XmlUtils.appendElement(personElement, OjbcNamespaceContext.NS_NC, "PersonSexCode");
            e.setTextContent(sexElement.getTextContent());
        }
        Element ssnElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc, xPaths.ssnXPath);
        if (ssnElement != null) {
            Element e = XmlUtils.appendElement(personElement, OjbcNamespaceContext.NS_NC,
                    "PersonSSNIdentification");
            e = XmlUtils.appendElement(e, OjbcNamespaceContext.NS_NC, "IdentificationID");
            e.setTextContent(ssnElement.getTextContent());
        }
        Element weightElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc, xPaths.weightXPath);
        if (weightElement != null) {
            Element phm = XmlUtils.appendElement(personElement, OjbcNamespaceContext.NS_NC,
                    "PersonWeightMeasure");
            Element e = XmlUtils.appendElement(phm, OjbcNamespaceContext.NS_NC, "MeasurePointValue");
            e.setTextContent(weightElement.getTextContent());
            e = XmlUtils.appendElement(phm, OjbcNamespaceContext.NS_NC, "WeightUnitCode");
            e.setTextContent("LBR");
        }
        Element dlElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc, xPaths.dlXPath);
        Element fbiElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc, xPaths.fbiXPath);
        Element sidElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc, xPaths.sidXPath);
        if (dlElement != null || fbiElement != null || sidElement != null) {
            Element personAugElement = XmlUtils.appendElement(personElement, OjbcNamespaceContext.NS_JXDM_41,
                    "PersonAugmentation");
            if (dlElement != null) {
                Element dlJurisdictionElement = (Element) XmlUtils.xPathNodeSearch(specificDetailSourceDoc,
                        xPaths.dlJurisdictionXPath);
                Element e = XmlUtils.appendElement(personAugElement, OjbcNamespaceContext.NS_NC,
                        "DriverLicense");
                Element dlIdElement = XmlUtils.appendElement(e, OjbcNamespaceContext.NS_NC,
                        "DriverLicenseIdentification");
                e = XmlUtils.appendElement(dlIdElement, OjbcNamespaceContext.NS_NC, "IdentificationID");
                e.setTextContent(dlElement.getTextContent());
                if (dlJurisdictionElement != null) {
                    e = XmlUtils.appendElement(dlIdElement, OjbcNamespaceContext.NS_NC,
                            "IdentificationSourceText");
                    e.setTextContent(dlJurisdictionElement.getTextContent());
                }
            }
            if (fbiElement != null) {
                Element e = XmlUtils.appendElement(personAugElement, OjbcNamespaceContext.NS_JXDM_41,
                        "PersonFBIIdentification");
                e = XmlUtils.appendElement(e, OjbcNamespaceContext.NS_NC, "IdentificationID");
                e.setTextContent(fbiElement.getTextContent());
            }
            if (sidElement != null) {
                Element e = XmlUtils.appendElement(personAugElement, OjbcNamespaceContext.NS_JXDM_41,
                        "PersonStateFingerprintIdentification");
                e = XmlUtils.appendElement(e, OjbcNamespaceContext.NS_NC, "IdentificationID");
                e.setTextContent(sidElement.getTextContent());
            }
        }

        Element sourceSystem = XmlUtils.appendElement(psrElement,
                OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT, "SourceSystemNameText");
        sourceSystem.setTextContent(xPaths.searchSystemId);
        Element sourceSystemIdentifierParentElement = XmlUtils.appendElement(psrElement,
                OjbcNamespaceContext.NS_INTEL, "SystemIdentifier");
        Element e = XmlUtils.appendElement(sourceSystemIdentifierParentElement, OjbcNamespaceContext.NS_NC,
                "IdentificationID");
        e.setTextContent(xPaths.getSystemIdentifier(instanceWrapper));
        e = XmlUtils.appendElement(sourceSystemIdentifierParentElement, OjbcNamespaceContext.NS_INTEL,
                "SystemName");
        e.setTextContent(xPaths.systemName);
        e = XmlUtils.appendElement(psrElement, OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT,
                "SearchResultCategoryText");
        e.setTextContent(xPaths.recordType);

    }

    XmlUtils.OJBC_NAMESPACE_CONTEXT.populateRootNamespaceDeclarations(root);
    return ret;

}

From source file:org.ojbc.bundles.adapters.staticmock.StaticMockQuery.java

List<IdentifiableDocumentWrapper> incidentPersonSearchDocumentsAsList(
        Document incidentPersonSearchRequestMessage, DateTime baseDate) throws Exception {

    Element rootElement = incidentPersonSearchRequestMessage.getDocumentElement();
    String rootNamespaceURI = rootElement.getNamespaceURI();
    String rootLocalName = rootElement.getLocalName();
    if (!(OjbcNamespaceContext.NS_INCIDENT_SEARCH_REQUEST_DOC.equals(rootNamespaceURI)
            && "IncidentPersonSearchRequest".equals(rootLocalName))) {
        throw new IllegalArgumentException(
                "Invalid message, must have {" + OjbcNamespaceContext.NS_INCIDENT_SEARCH_REQUEST_DOC
                        + "}IncidentPersonSearchRequest as the root " + "instead of {" + rootNamespaceURI + "}"
                        + rootLocalName);
    }/*from w w w.j a v a2 s . co m*/

    NodeList systemElements = XmlUtils.xPathNodeListSearch(rootElement, "isr:SourceSystemNameText");
    int systemElementCount;
    if (systemElements == null || (systemElementCount = systemElements.getLength()) == 0) {
        throw new IllegalArgumentException(
                "Invalid query request message:  must specify at least one system to query.");
    }

    Element personIdElement = (Element) XmlUtils.xPathNodeSearch(incidentPersonSearchRequestMessage,
            "/isr-doc:IncidentPersonSearchRequest/nc:Person/nc:PersonOtherIdentification/nc:IdentificationID");

    List<IdentifiableDocumentWrapper> ret = new ArrayList<IdentifiableDocumentWrapper>();

    if (personIdElement != null) {

        String id = personIdElement.getTextContent();

        for (int i = 0; i < systemElementCount; i++) {
            for (IdentifiableDocumentWrapper dw : incidentDataSource.getDocuments()) {

                Document d = dw.getDocument();
                Element documentPersonIdElement = (Element) XmlUtils.xPathNodeSearch(d,
                        "/ir:IncidentReport/lexspd:doPublish/lexs:PublishMessageContainer/lexs:PublishMessage/lexs:DataItemPackage/lexs:Digest/lexsdigest:EntityPerson[jxdm40:IncidentSubject]/lexsdigest:Person/nc:PersonOtherIdentification/nc:IdentificationID");
                String documentPersonId = documentPersonIdElement.getTextContent();
                if (id.equals(documentPersonId)) {
                    ret.add(dw);
                }
            }
        }

    }

    return ret;

}

From source file:org.ojbc.bundles.adapters.staticmock.StaticMockQuery.java

List<IdentifiableDocumentWrapper> firearmSearchDocumentsAsList(Document firearmSearchRequestMessage)
        throws Exception {

    List<IdentifiableDocumentWrapper> ret = new ArrayList<IdentifiableDocumentWrapper>();

    Element rootElement = firearmSearchRequestMessage.getDocumentElement();
    String rootNamespaceURI = rootElement.getNamespaceURI();
    String rootLocalName = rootElement.getLocalName();
    if (!(OjbcNamespaceContext.NS_FIREARM_SEARCH_REQUEST_DOC.equals(rootNamespaceURI)
            && "FirearmSearchRequest".equals(rootLocalName))) {
        throw new IllegalArgumentException("Invalid message, must have {"
                + OjbcNamespaceContext.NS_FIREARM_SEARCH_REQUEST_DOC + "}FirearmSearchRequest as the root "
                + "instead of {" + rootNamespaceURI + "}" + rootLocalName);
    }/*w  w  w .jav  a 2  s.  c o m*/
    NodeList systemElements = XmlUtils.xPathNodeListSearch(rootElement,
            "firearm-search-req-ext:SourceSystemNameText");
    if (systemElements == null || (systemElements.getLength()) == 0) {
        throw new IllegalArgumentException(
                "Invalid query request message:  must specify at least one system to query.");
    }

    String searchXPath = buildFirearmSearchXPathFromMessage(firearmSearchRequestMessage);
    //LOG.info(searchXPath);

    if (searchXPath == null) {
        return ret;
    }

    for (IdentifiableDocumentWrapper dw : firearmRegistrationDataSource.getDocuments()) {

        Document d = dw.getDocument();
        LOG.debug("Searching document " + dw.getId());

        NodeList matches = XmlUtils.xPathNodeListSearch(d, searchXPath);
        for (int i = 0; i < matches.getLength(); i++) {
            Node match = matches.item(i);
            String firearmId = XmlUtils.xPathStringSearch(match, "@s:id");
            ret.add(new IdentifiableDocumentWrapper(
                    createFirearmRegistrationDocument(dw.getDocument(), firearmId),
                    dw.getId() + ":" + firearmId));
        }

    }
    return ret;
}

From source file:org.ojbc.bundles.adapters.staticmock.StaticMockQuery.java

List<IdentifiableDocumentWrapper> personSearchDocumentsAsList(Document personSearchRequestMessage,
        DateTime baseDate) throws Exception {

    Element rootElement = personSearchRequestMessage.getDocumentElement();
    String rootNamespaceURI = rootElement.getNamespaceURI();
    String rootLocalName = rootElement.getLocalName();

    if (!(OjbcNamespaceContext.NS_PERSON_SEARCH_REQUEST_DOC.equals(rootNamespaceURI)
            && "PersonSearchRequest".equals(rootLocalName))) {

        throw new IllegalArgumentException("Invalid message, must have {"
                + OjbcNamespaceContext.NS_PERSON_SEARCH_REQUEST_DOC + "}PersonSearchRequest as the root "
                + "instead of {" + rootNamespaceURI + "}" + rootLocalName);
    }//w w w  .jav a2s  . c  o  m

    NodeList systemElements = XmlUtils.xPathNodeListSearch(rootElement, "psr:SourceSystemNameText");
    int systemElementCount;

    if (systemElements == null || (systemElementCount = systemElements.getLength()) == 0) {
        throw new IllegalArgumentException(
                "Invalid query request message:  must specify at least one system to query.");
    }

    List<IdentifiableDocumentWrapper> rDocList = new ArrayList<IdentifiableDocumentWrapper>();

    for (int i = 0; i < systemElementCount; i++) {

        Element systemElement = (Element) systemElements.item(i);

        String systemId = systemElement.getTextContent();

        if (CRIMINAL_HISTORY_MOCK_ADAPTER_SEARCH_SYSTEM_ID.equals(systemId)) {
            rDocList.addAll(personSearchCriminalHistoryDocuments(personSearchRequestMessage, baseDate));

        } else if (WARRANT_MOCK_ADAPTER_SEARCH_SYSTEM_ID.equals(systemId)) {
            rDocList.addAll(personSearchWarrantDocuments(personSearchRequestMessage, baseDate));

        } else if (FIREARM_MOCK_ADAPTER_SEARCH_SYSTEM_ID.equals(systemId)) {
            rDocList.addAll(personSearchFirearmRegistrationDocuments(personSearchRequestMessage, baseDate));

        } else if (INCIDENT_MOCK_ADAPTER_SEARCH_SYSTEM_ID.equals(systemId)) {
            rDocList.addAll(personSearchIncidentDocuments(personSearchRequestMessage, baseDate));

        } else if (JUVENILE_HISTORY_MOCK_ADAPTER_SEARCH_SYSTEM_ID.equals(systemId)) {
            rDocList.addAll(personSearchJuvenileHistoryDocuments(personSearchRequestMessage, baseDate));

        } else if (CUSTODY_PERSON_SEARCH_SYSTEM_ID.equals(systemId)) {

            LOG.info(
                    "\n\n\n ***** \n\n   personSearchDocumentsAsList(....) sysId match for CUSTODY   \n\n ******* \n\n\n");

            rDocList.addAll(custodySearchCustodyDocuments(personSearchRequestMessage, baseDate));

            LOG.info("\n\n\n  rDocList size ==  " + rDocList == null ? null
                    : String.valueOf(rDocList.size()) + "\n\n\n");

        } else if (COURT_CASE_PERSON_SEARCH_SYSTEM_ID.equals(systemId)) {
            rDocList.addAll(courtCaseSearchCourtCaseDocuments(personSearchRequestMessage, baseDate));

        } else if (VEHICLE_CRASH_SEARCH_SYSTEM_ID.equals(systemId)) {
            rDocList.addAll(vehicleCrashSearchDocuments(personSearchRequestMessage, baseDate));

        } else {
            throw new IllegalArgumentException("Unsupported system name: " + systemId);
        }
    }
    return rDocList;
}

From source file:org.ojbc.util.camel.processor.audit.SQLLoggingProcessorTest.java

private void assertDbContents()
        throws UnknownHostException, IOException, SAXException, ParserConfigurationException {

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);/*from   www.j  ava 2 s . c o m*/

    List<Map<String, Object>> rows = sqlLoggingProcessor.getJdbcTemplate()
            .queryForList("select * from AuditLog");

    assertEquals(1, rows.size());

    Map<String, Object> row = rows.get(0);

    assertEquals(row.get("origin"), "http://www.ojbc.org/from");
    assertEquals(row.get("destination"), "http://www.ojbc.org/to");
    assertEquals(row.get("messageID"), "12345");
    assertEquals(row.get("federationID"), "HIJIS:IDP:HCJDC:USER:admin");
    assertEquals(row.get("employerName"), "Department of Attorney General");
    assertEquals(row.get("employerSubUnitName"), "HCJDC ISDI");
    assertEquals(row.get("userLastName"), "owen");
    assertEquals(row.get("userFirstName"), "andrew");
    assertEquals(row.get("identityProviderID"), "https://idp.ojbc-local.org:9443/idp/shibboleth");
    assertEquals(row.get("camelContextID"),
            "org.ojbc.util.camel.processor.audit.SQLLoggingProcessorTest CamelContext");

    String hostAddress = (String) row.get("hostAddress");
    InetAddress ia = InetAddress.getByName(hostAddress);
    assertTrue(ia.isReachable(1000));

    String messageDocS = (String) row.get("soapMessage");

    Document messageDoc = dbf.newDocumentBuilder().parse(new InputSource(new StringReader(messageDocS)));

    Element ee = messageDoc.getDocumentElement();
    assertEquals("root", ee.getLocalName());
    assertEquals("http://ojbc.org", ee.getNamespaceURI());
    NodeList nl = ee.getElementsByTagNameNS("http://ojbc.org", "child");
    ee = (Element) nl.item(0);
    assertEquals("Child contents", ee.getTextContent());

    Date d = (Date) row.get("timestamp");
    DateTime dt = new DateTime(d);
    assertEquals(0, Minutes.minutesBetween(new DateTime(), dt).getMinutes());
}

From source file:org.ojbc.util.xml.TestXmlUtils.java

@Test
public void testNodeSearch() throws Exception {
    Document d = db.newDocument();
    Element e1 = d.createElementNS(OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT, "e1");
    d.appendChild(e1);//from w  w w .  ja va  2s.  c o  m
    Element e2 = d.createElementNS(OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT, "e2");
    e1.appendChild(e2);
    Node n = XmlUtils.xPathNodeSearch(d, OjbcNamespaceContext.NS_PREFIX_PERSON_SEARCH_RESULTS_EXT + ":e1");
    assertNotNull(n);
    assertTrue(n instanceof Element);
    Element ee = (Element) n;
    assertEquals(ee.getLocalName(), "e1");
    assertEquals(ee.getNamespaceURI(), OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT);
}

From source file:org.ojbc.util.xml.TestXmlUtils.java

@Test
public void testAppendElement() throws Exception {
    Document d = db.newDocument();
    Element e1 = d.createElementNS(OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT, "e1");
    d.appendChild(e1);/*ww  w  .j  a v a  2  s .c om*/
    XmlUtils.appendElement(e1, OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT, "e2");
    Node n = XmlUtils.xPathNodeSearch(e1, OjbcNamespaceContext.NS_PREFIX_PERSON_SEARCH_RESULTS_EXT + ":e2");
    assertNotNull(n);
    assertTrue(n instanceof Element);
    Element ee = (Element) n;
    assertEquals(ee.getLocalName(), "e2");
    assertEquals(ee.getNamespaceURI(), OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT);
}

From source file:org.openestate.io.core.XmlUtils.java

/**
 * Create a {@link XPath} expression./*from   w  ww.j av a 2s.c  o m*/
 *
 * @param expression
 * string with the XPath expression to create
 *
 * @param doc
 * the document, whose namespace is bound to the XPath expression
 *
 * @param namespacePrefix
 * prefix of the document namespace, that is bound to the XPath expression
 *
 * @return
 * the created XPath expression
 *
 * @throws JaxenException
 * if the XPath is not creatable
 */
public static XPath newXPath(String expression, Document doc, String namespacePrefix) throws JaxenException {
    DOMXPath xpath = new DOMXPath(expression);
    //LOGGER.debug( "new xpath: " + xpath.debug() );
    if (doc != null && namespacePrefix != null) {
        Element root = XmlUtils.getRootElement(doc);
        String uri = StringUtils.trimToEmpty(root.getNamespaceURI());
        xpath.addNamespace(namespacePrefix, uri);
    }
    return xpath;
}

From source file:org.openestate.io.core.XmlUtils.java

private static void printNode(Element node, int indent) {
    String prefix = (indent > 0) ? StringUtils.repeat(">", indent) + " " : "";
    LOGGER.debug(prefix + "<" + node.getTagName() + "> / " + node.getNamespaceURI() + " / " + node.getPrefix());

    prefix = StringUtils.repeat(">", indent + 1) + " ";
    NamedNodeMap attribs = node.getAttributes();
    for (int i = 0; i < attribs.getLength(); i++) {
        Attr attrib = (Attr) attribs.item(i);
        LOGGER.debug(prefix + "@" + attrib.getName() + " / " + attrib.getNamespaceURI() + " / "
                + attrib.getPrefix());//from www . java  2  s  .co m
    }
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element) {
            XmlUtils.printNode((Element) child, indent + 1);
        }
    }
}

From source file:org.openestate.io.immoxml.ImmoXmlUtils.java

/**
 * Helper method to create a &lt;user_defined_simplefield&gt; element with a
 * "feldname" attribute and a string value.
 *
 * @param doc/*from   w  w  w  .j av a  2s  .  c o  m*/
 * document, for which the element is created
 *
 * @param name
 * value of the "feldname" attribute in the created element
 *
 * @param value
 * text value of the created element
 *
 * @return
 * created element
 */
public static Element createUserDefinedSimplefield(Document doc, String name, String value) {
    Element root = XmlUtils.getRootElement(doc);
    Element node = doc.createElementNS(root.getNamespaceURI(), "user_defined_simplefield");
    node.setAttribute("feldname", name);
    node.setTextContent(value);
    return node;
}