List of usage examples for org.w3c.dom Element getElementsByTagNameNS
public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException;
NodeList
of all the descendant Elements
with a given local name and namespace URI in document order. From source file:org.globus.wsrf.tools.wsdl.TypesProcessor.java
private void populateImportsMap(Element schema) { if (this.imports == null) { this.imports = new HashMap(); NodeList importNodes = schema.getElementsByTagNameNS(XSD_NS, "import"); for (int i = 0; i < importNodes.getLength(); i++) { Element xsdImport = (Element) importNodes.item(i); String namespace = xsdImport.getAttribute("namespace") == null ? schema.getAttribute("targetNamespace") : xsdImport.getAttribute("namespace"); Map locations = (Map) this.imports.get(namespace); if (locations == null) { locations = new HashMap(); this.imports.put(namespace, locations); }//from w w w . j a va 2 s .c o m locations.put(xsdImport.getAttribute("schemaLocation"), null); } } }
From source file:org.globus.wsrf.tools.wsdl.TypesProcessor.java
private void populateIncludesMap(Element schema) { if (this.includes == null) { this.includes = new HashMap(); NodeList includeNodes = schema.getElementsByTagNameNS(XSD_NS, "include"); for (int i = 0; i < includeNodes.getLength(); i++) { Element include = (Element) includeNodes.item(i); String namespace = schema.getAttribute("targetNamespace"); Map locations = (Map) this.includes.get(namespace); if (locations == null) { locations = new HashMap(); this.includes.put(namespace, locations); }/* w ww .java2 s. c om*/ locations.put(include.getAttribute("schemaLocation"), null); } } }
From source file:org.kuali.coeus.propdev.impl.budget.subaward.PropDevPropDevBudgetSubAwardServiceImpl.java
/** * extracts XML from PDF// www. j a v a 2s .c om */ protected byte[] getXMLFromPDF(PdfReader reader) throws Exception { XfaForm xfaForm = reader.getAcroFields().getXfa(); Node domDocument = xfaForm.getDomDocument(); if (domDocument == null) return null; Element documentElement = ((Document) domDocument).getDocumentElement(); Element datasetsElement = (Element) documentElement.getElementsByTagNameNS(XFA_NS, "datasets").item(0); Element dataElement = (Element) datasetsElement.getElementsByTagNameNS(XFA_NS, "data").item(0); Element xmlElement = (Element) dataElement.getChildNodes().item(0); Node budgetElement = getBudgetElement(xmlElement); byte[] serializedXML = XfaForm.serializeDoc(budgetElement); return serializedXML; }
From source file:org.kuali.coeus.propdev.impl.s2s.connect.OpportunitySchemaParserServiceImpl.java
/** * This method fetches all the forms required from a given schema of opportunity * /*from w w w. j a v a 2s . c o m*/ * @param schema {@link String} * @return {@link HashMap} containing all form information */ @Override public List<S2sOppForms> getForms(String proposalNumber, String schema) throws S2sCommunicationException { if (StringUtils.isBlank(proposalNumber)) { throw new IllegalArgumentException("proposalNumber is blank"); } if (StringUtils.isBlank(schema)) { throw new IllegalArgumentException("schema is blank"); } boolean mandatory; boolean available; DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); DocumentBuilder builder = null; ArrayList<S2sOppForms> schemaList = new ArrayList<S2sOppForms>(); Document document; try { builder = domFactory.newDocumentBuilder(); InputStream is = (InputStream) new URL(schema).getContent(); document = builder.parse(is); } catch (ParserConfigurationException e) { throw new S2sCommunicationException(KeyConstants.ERROR_GRANTSGOV_FORM_PARSING, e.getMessage(), schema); } catch (SAXException e) { throw new S2sCommunicationException(KeyConstants.ERROR_GRANTSGOV_FORM_PARSING_SAXEXCEPTION, e.getMessage(), schema); } catch (IOException e) { throw new S2sCommunicationException(KeyConstants.ERROR_GRANTSGOV_FORM_SCHEMA_NOT_FOUND, e.getMessage(), schema); } Element schemaElement = document.getDocumentElement(); NodeList importList = document.getElementsByTagNameNS(XSD_NS, IMPORT); Node allForms = document.getElementsByTagNameNS(XSD_NS, ALL).item(0); // If there is no "Forms" element, it's probably because this is an NIH complex project if (allForms == null) { Node topElementName = schemaElement.getElementsByTagNameNS(XSD_NS, ELEMENT).item(0).getAttributes() .item(0); if (topElementName.getNodeName().equals("name") && !topElementName.getNodeValue().equals("GrantApplication")) { throw new S2sCommunicationException(KeyConstants.ERROR_GRANTSGOV_NO_FORM_ELEMENT, "", ""); } } NodeList formsList = ((Element) allForms).getElementsByTagNameNS(XSD_NS, ELEMENT); String[] formNames = new String[formsList.getLength()]; for (int formIndex = 0; formIndex < formsList.getLength(); formIndex++) { Node form = formsList.item(formIndex); String fullFormName = ((Element) form).getAttribute(REF); String formName = fullFormName.substring(0, fullFormName.indexOf(CH_COLON)); String minOccurs = ((Element) form).getAttribute(MIN_OCCURS); String nameSpace = schemaElement.getAttribute(XMLNS + formName); FormMappingInfo info = formMappingService.getFormInfo(nameSpace, proposalNumber); String displayFormName = info == null ? formName : info.getFormName(); formNames[formIndex] = nameSpace; for (int impIndex = 0; impIndex < importList.getLength(); impIndex++) { Node importNode = importList.item(impIndex); if (((Element) importNode).getAttribute(NAMESPACE).equalsIgnoreCase(nameSpace)) { String schemaUrl = ((Element) importNode).getAttribute(SCHEMA_LOCATION); S2sOppForms oppForm = new S2sOppForms(); oppForm.setFormName(displayFormName); S2sOppFormsId oppFormId = new S2sOppFormsId(); oppFormId.setProposalNumber(proposalNumber); oppFormId.setOppNameSpace(nameSpace); oppForm.setS2sOppFormsId(oppFormId); oppForm.getS2sOppFormsId().setOppNameSpace(nameSpace); oppForm.setSchemaUrl(schemaUrl); mandatory = (minOccurs == null || minOccurs.trim().equals("") || Integer.parseInt(minOccurs) > 0); oppForm.setMandatory(mandatory); if (info != null) { available = true; oppForm.setUserAttachedForm(info.getUserAttachedForm()); } else { available = false; } oppForm.setAvailable(available); oppForm.setInclude(mandatory && available); schemaList.add(oppForm); } } } return schemaList; }
From source file:org.kuali.kra.proposaldevelopment.budget.service.impl.BudgetSubAwardServiceImpl.java
/** * extracts XML from PDF/* www . j a v a 2 s.c o m*/ */ protected byte[] getXMLFromPDF(PdfReader reader) throws Exception { XfaForm xfaForm = reader.getAcroFields().getXfa(); Node domDocument = xfaForm.getDomDocument(); if (domDocument == null) throw new Exception("Not a valid pdf form"); Element documentElement = ((Document) domDocument).getDocumentElement(); Element datasetsElement = (Element) documentElement.getElementsByTagNameNS(XFA_NS, "datasets").item(0); Element dataElement = (Element) datasetsElement.getElementsByTagNameNS(XFA_NS, "data").item(0); Element xmlElement = (Element) dataElement.getChildNodes().item(0); Node budgetElement = getBudgetElement(xmlElement); byte[] serializedXML = XfaForm.serializeDoc(budgetElement); return serializedXML; }
From source file:org.milyn.smooks.mule.core.MuleDispatcher.java
/** * @param executionContext//from w w w . j av a2 s . co m * @param lMessageProperties * @param messagePropertiesParamElement */ private void resolvePropertiesExtendedConfig(ExecutionContext executionContext, List<MessageProperty> lMessageProperties, Element messagePropertiesParamElement) { NodeList properties = messagePropertiesParamElement.getElementsByTagNameNS(Constants.MULE_SMOOKS_NAMESPACE, MESSAGE_PROPERTIES_NODE_NAME); for (int i = 0; properties != null && i < properties.getLength(); i++) { Element node = (Element) properties.item(i); String name = DomUtils.getAttributeValue(node, MESSAGE_PROPERTIES_ATTRIBUTE_NAME); if (StringUtils.isBlank(name)) { throw new SmooksConfigurationException( "The 'name' attribute isn't a defined or empty for the message property: " + node); } name = name.trim(); MessagePropertyValue messageValue = null; String rawValue = DomUtils.getAttributeValue(node, MESSAGE_PROPERTIES_PARAMETER_VALUE); if (rawValue == null) { Element expressionElement = (Element) DomUtils.getElement(node, MESSAGE_EXPRESSION_NODE_NAME, 1, Constants.MULE_SMOOKS_NAMESPACE); String expression = DomUtils.getAllText(expressionElement, true); if (StringUtils.isNotBlank(expression)) { MVELExpressionEvaluator evaluator = new MVELExpressionEvaluator(); try { evaluator.setExpression(expression); } catch (RuntimeException e) { throw new RuntimeException( "Exception while setting the expression on the MVELExpressionEvaluator", e); } messageValue = new MVELEvaluatingMessagePropertyValue(evaluator); } } else { rawValue = rawValue.trim(); Object value = null; String decoder = DomUtils.getAttributeValue(node, MESSAGE_PROPERTIES_PARAMETER_DECODER); if (decoder != null) { decoder = decoder.trim(); value = getDecoder(executionContext, decoder).decode(rawValue); } else { value = rawValue; } messageValue = new StaticMessagePropertyValue(value); } lMessageProperties.add(new MessageProperty(name, messageValue)); } }
From source file:org.obm.caldav.server.reports.FilterParser.java
private static CompFilter parseCompFilter(String componentUrl, Element compFilterNode) { CompFilter compFilter = null;/*from ww w . j a va 2s .co m*/ if (compFilterNode != null) { compFilter = new CompFilter(); compFilter.setDavComponentURL(componentUrl); String name = compFilterNode.getAttribute("name"); compFilter.setName(DavComponentType.valueOf(name)); compFilter.setIsNotDefined(getIsNotDefined(compFilterNode)); compFilter.setTimeRange(getTimeRange(compFilterNode)); NodeList compFilters = compFilterNode.getElementsByTagNameNS(Filter.NAMESPACE, "comp-filter"); for (int i = 0; i < compFilters.getLength(); i++) { Element cf = (Element) compFilters.item(i); compFilter.addCompFilter(parseCompFilter(componentUrl, cf)); } NodeList propFilters = compFilterNode.getElementsByTagNameNS(Filter.NAMESPACE, "prop-filter"); for (int i = 0; i < propFilters.getLength(); i++) { Element pf = (Element) propFilters.item(i); compFilter.addPropFilter(parsePropFilter(pf)); } } return compFilter; }
From source file:org.obm.caldav.server.reports.FilterParser.java
private static PropFilter parsePropFilter(Element propFilterNode) { PropFilter propFilter = new PropFilter(); propFilter.setName(propFilterNode.getAttribute("name")); propFilter.setNotDefined(getIsNotDefined(propFilterNode)); propFilter.setTimeRange(getTimeRange(propFilterNode)); propFilter.setTextMatch(getTextMatch(propFilterNode)); NodeList paramFilters = propFilterNode.getElementsByTagNameNS(Filter.NAMESPACE, "param-filter"); for (int i = 0; i < paramFilters.getLength(); i++) { Element pf = (Element) paramFilters.item(i); propFilter.addParamFilter(parseParamFilter(pf)); }/*ww w. java2 s. com*/ return propFilter; }
From source file:ORG.oclc.os.SRW.OpenSearchQueryResult.java
private void processRssResponse(SearchRetrieveRequestType request, HttpURLConnection conn) throws IOException, ParserConfigurationException, SAXException { Document doc = parseInput(conn.getInputStream()); Element root = doc.getDocumentElement(); channel = (Element) root.getElementsByTagName("channel").item(0); log.debug("channel=" + channel); Node title = channel.getElementsByTagName("title").item(0); NodeList nodes = channel.getElementsByTagName("*"); for (int i = 0; i < nodes.getLength(); i++) log.debug("node[" + i + "]=" + nodes.item(i).getNodeName()); log.debug("title=" + title.getTextContent()); Node totalResults = root.getElementsByTagNameNS("*", "totalResults").item(0); log.debug("totalResults=" + totalResults); numberOfRecords = Long.parseLong(totalResults.getTextContent()); }
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);// w ww . j a v a2 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()); }