List of usage examples for org.w3c.dom Element getLocalName
public String getLocalName();
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 w ww .java 2 s .c o 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 ww . ja va 2 s. c o 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); }/*from w w w . j a va2 s. co 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); }/*from ww w . j ava 2 s . 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 w w w. ja v a 2 s .co 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);// w ww . jav a 2 s .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);/*www. ja v a 2s.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.opendatakit.aggregate.parser.SubmissionParser.java
/** * //w ww .j ava 2 s . c om * Helper function to process submission by taking the form element and * extracting the corresponding value from the XML submission. Recursively * applies itself to children of the form element. * * @param node * form data model of the group or repeat group being parsed. * @param currentSubmissionElement * xml document element that marks the start of this submission set. * @param submissionSet * the submission set to add the submission values to. * @param repeatGroupIndicies * tracks the ordinal number of the last stored repeat group of this * name. * @param preExisting * true if this submission already existed in the database. If so, do * not update fields. * @throws ODKParseException * @throws ODKIncompleteSubmissionData * @throws ODKConversionException * @throws ODKDatastoreException */ private boolean processSubmissionElement(FormElementModel node, Element currentSubmissionElement, SubmissionSet submissionSet, Map<String, Integer> repeatGroupIndicies, boolean preExisting, CallingContext cc) throws ODKParseException, ODKIncompleteSubmissionData, ODKConversionException, ODKDatastoreException { if (node == null || currentSubmissionElement == null) { return true; } // the element name of the fdm is the tag name... String submissionTag = node.getElementName(); if (submissionTag == null) { return true; } // verify that the xml matches the node we are processing... if (!currentSubmissionElement.getLocalName().equals(submissionTag)) { throw new ODKParseException("Xml document element tag: " + currentSubmissionElement.getLocalName() + " does not match the xform data model tag name: " + submissionTag); } // get the structure under the fdm tag name... List<Element> elements = getElements(currentSubmissionElement); if (elements.size() == 0) { return true; // the group is not relevant... } // and for each of these, they should be fields under the given fdm // and values within the submissionSet boolean complete = true; for (Element e : elements) { FormElementModel m = node.findElementByName(e.getLocalName()); if (m == null) { continue; // throw new ODKParseException(); } switch (m.getElementType()) { case METADATA: // This keeps lint warnings down break; case GROUP: // need to recurse on these elements keeping the same // submissionSet... complete = complete & processSubmissionElement(m, e, submissionSet, repeatGroupIndicies, preExisting, cc); break; case REPEAT: // get the field that will hold the repeats... // get the repeat group... RepeatSubmissionType repeats = (RepeatSubmissionType) submissionSet.getElementValue(m); // determine the ordinal of the repeat group element we are processing. // do this by constructing the submission key for the repeat group and // seeing if that key is in the repeatGroupIndicies table. If not, the // ordinal is 1L. Otherwise, it is the value in the table plus 1L. String fullName = repeats.constructSubmissionKey().toString(); Integer idx = repeatGroupIndicies.get(fullName); if (idx == null) { idx = 1; // base case -- not yet in repeatGroupIndicies map } else { ++idx; } // save the updated index repeatGroupIndicies.put(fullName, idx); // get or create the instance's submission set for this ordinal SubmissionSet repeatableSubmissionSet; if (repeats.getNumberRepeats() >= idx) { // we already have this set defined repeatableSubmissionSet = repeats.getSubmissionSets().get(idx - 1); } else if (repeats.getNumberRepeats() == idx - 1) { // Create a submission set for a new instance... long l = repeats.getNumberRepeats() + 1L; repeatableSubmissionSet = new SubmissionSet(submissionSet, l, m, form, topLevelTableKey, cc); repeats.addSubmissionSet(repeatableSubmissionSet); } else { throw new IllegalStateException("incrementing repeats by more than one!"); } // populate the instance's submission set with values from e... complete = complete & processSubmissionElement(m, e, repeatableSubmissionSet, repeatGroupIndicies, preExisting, cc); break; case STRING: case JRDATETIME: case JRDATE: case JRTIME: case INTEGER: case DECIMAL: case BOOLEAN: case SELECT1: // identifies SelectChoice table case SELECTN: // identifies SelectChoice table if (!preExisting) { String value = getSubmissionValue(e); SubmissionField<?> subField = (SubmissionField<?>) submissionSet.getElementValue(m); subField.setValueFromString(value); } break; case GEOPOINT: if (!preExisting) { String value = getSubmissionValue(e); ((SubmissionField<?>) submissionSet.getElementValue(m)).setValueFromString(value); } break; case BINARY: // identifies BinaryContent table { String value = getSubmissionValue(e); SubmissionField<?> submissionElement = ((SubmissionField<?>) submissionSet.getElementValue(m)); complete = complete & processBinarySubmission(m, submissionElement, value, cc); } break; } } return complete; }
From source file:org.openengsb.openengsbplugin.base.ConfiguredMojo.java
private void importNodesFromNodeList(Document doc, Element parentElement, NodeList nodes) { for (int i = 0; i < nodes.getLength(); i++) { Node importedNode = doc.importNode(nodes.item(i), true); parentElement.appendChild(importedNode); LOG.trace(String.format("importing node (parent=%s): %s", parentElement.getLocalName(), importedNode.getNodeName())); }/*w w w. j a v a 2s . c o m*/ }
From source file:org.openestate.io.daft_ie.DaftIeDocument.java
/** * Checks, if a {@link Document} is readable as a {@link DaftIeDocument}. * * @param doc// w ww. j a va 2 s.c o m * document to check * * @return * true, if the document is usable, otherwise false */ public static boolean isReadable(Document doc) { Element root = XmlUtils.getRootElement(doc); return "daft".equals(root.getLocalName()); }