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:manchester.synbiochem.datacapture.SeekConnector.java
public List<Assay> getAssays() { long now = System.currentTimeMillis(); if (assayCacheTimestamp != null && assayCacheTimestamp + CACHE_TIME > now) { return cachedAssays; }/*from ww w.j a v a 2s . c o m*/ log.info("filling assays cache"); List<Assay> assays = new ArrayList<>(); try { Document d = get("/assays.xml?page=all"); Element items = (Element) d.getDocumentElement().getElementsByTagNameNS(SEEK, "items").item(0); NodeList assayElements = items.getElementsByTagNameNS(SEEK, "assay"); log.debug("found " + assayElements.getLength() + " assays"); for (int i = 0; i < assayElements.getLength(); i++) assays.add(new Assay(assayElements.item(i))); } catch (IOException | SAXException | ParserConfigurationException e) { log.warn("falling back to old assay list due to " + e); return cachedAssays; } for (Assay assay : assays) addExtra(assay); sort(assays, assayComparator); cachedAssays = assays; assayCacheTimestamp = now; return assays; }
From source file:manchester.synbiochem.datacapture.SeekConnector.java
public List<Study> getStudies() { long now = System.currentTimeMillis(); if (studyCacheTimestamp != null && studyCacheTimestamp + CACHE_TIME > now) { return cachedStudies; }//from w w w . j a va2 s.c o m log.info("filling studies cache"); List<Study> studies = new ArrayList<>(); try { Document d = get("/studies.xml?page=all"); Element items = (Element) d.getDocumentElement().getElementsByTagNameNS(SEEK, "items").item(0); NodeList studyElements = items.getElementsByTagNameNS(SEEK, "study"); log.debug("found " + studyElements.getLength() + " studies"); for (int i = 0; i < studyElements.getLength(); i++) studies.add(new Study(studyElements.item(i))); } catch (IOException | SAXException | ParserConfigurationException e) { log.warn("falling back to old study list due to " + e); return cachedStudies; } for (Study study : studies) addExtra(study); sort(studies, studyComparator); cachedStudies = studies; studyCacheTimestamp = now; return studies; }
From source file:org.gege.caldavsyncadapter.caldav.CaldavFacade.java
public ArrayList<CalendarEvent> getCalendarEvents(DavCalendar calendar) throws URISyntaxException, ClientProtocolException, IOException, ParserConfigurationException, SAXException { ArrayList<CalendarEvent> calendarEventList = new ArrayList<CalendarEvent>(); String requestBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<D:propfind xmlns:D=\"DAV:\">" + "<D:prop>" + "<D:getetag/>" + "</D:prop>" + "</D:propfind>"; HttpPropFind request = null;/* www. j a v a2s . c om*/ /*request = new HttpPropFind(); request.setURI(calendar.getURI()); request.setHeader("Host", targetHost.getHostName()); request.setHeader("Depth", "1"); request.setHeader("Content-Type", "application/xml;charset=\"UTF-8\""); try { request.setEntity(new StringEntity(requestBody, "UTF-8")); } catch (UnsupportedEncodingException e) { throw new AssertionError("UTF-8 is unknown"); }*/ request = this.createPropFindRequest(calendar.getURI(), requestBody, 1); Log.d(TAG, "Getting eTag by PROPFIND at " + request.getURI()); HttpResponse response = httpClient.execute(targetHost, request, mContext); BufferedReader reader = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), "UTF-8")); String line; String body = ""; do { line = reader.readLine(); if (line != null) body += line; } while (line != null); Log.d(TAG, "HttpResponse status=" + response.getStatusLine() + " body= " + body); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document dom = builder.parse(new InputSource(new ByteArrayInputStream(body.getBytes("utf-8")))); Element root = dom.getDocumentElement(); NodeList items = root.getElementsByTagNameNS("*", "getetag"); for (int i = 0; i < items.getLength(); i++) { CalendarEvent calendarEvent = new CalendarEvent(this.mAccount, this.mProvider); Node node = items.item(i); if (node.getTextContent().trim().length() == 0) continue; // not an event calendarEvent.setETag(node.getTextContent().trim()); //calendarEvent.calendarURL = this.url; calendarEvent.calendarURL = calendar.getURI().toURL(); node = node.getParentNode(); // prop node = node.getParentNode(); // propstat node = node.getParentNode(); // response NodeList children = node.getChildNodes(); for (int j = 0; j < children.getLength(); j++) { Node childNode = children.item(j); if ((childNode.getLocalName() != null) && (childNode.getLocalName().equalsIgnoreCase("href"))) { calendarEvent.setUri(new URI(childNode.getTextContent().trim())); } } calendarEventList.add(calendarEvent); } return calendarEventList; }
From source file:org.jmxtrans.embedded.spring.EmbeddedJmxTransBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { builder.setRole(BeanDefinition.ROLE_APPLICATION); builder.getRawBeanDefinition().setSource(parserContext.extractSource(element)); if (element.hasAttribute(IGNORE_CONFIGURATION_NOT_FOUND_ATTRIBUTE)) { builder.addPropertyValue("ignoreConfigurationNotFound", element.getAttribute(IGNORE_CONFIGURATION_NOT_FOUND_ATTRIBUTE)); }/*w w w. j ava 2 s .co m*/ List<String> configurationUrls = new ArrayList<String>(); if (element.hasAttribute(CONFIGURATION_ATTRIBUTE)) { String configurationUrl = element.getAttribute(CONFIGURATION_ATTRIBUTE); logger.debug("Add configuration from attribute {}", configurationUrl); configurationUrls.add(configurationUrl); } NodeList configurationNodeList = element.getElementsByTagNameNS(element.getNamespaceURI(), CONFIGURATION_ATTRIBUTE); for (int i = 0; i < configurationNodeList.getLength(); i++) { Node node = configurationNodeList.item(i); if (node instanceof Element) { String configurationUrl = node.getTextContent(); logger.debug("Add configuration from attribute {}", configurationUrl); configurationUrls.add(configurationUrl); } else { throw new EmbeddedJmxTransException("Invalid configuration child element " + node); } } builder.addPropertyValue("configurationUrls", configurationUrls); }
From source file:eu.domibus.ebms3.sender.ReliabilityChecker.java
public boolean check(SOAPMessage request, SOAPMessage response, String pmodeKey) throws EbMS3Exception { LegConfiguration legConfiguration = this.pModeProvider.getLegConfiguration(pmodeKey); assert legConfiguration != null; // we would have crashed in the security handler if (legConfiguration.getReliability() != null && ReplyPattern.RESPONSE.equals(legConfiguration.getReliability().getReplyPattern())) { ReliabilityChecker.LOG.debug("Checking reliability for outgoing message"); Messaging messaging;/*from www . j av a2 s. co m*/ try { messaging = this.jaxbContext .createUnmarshaller().unmarshal((Node) response.getSOAPHeader() .getChildElements(ObjectFactory._Messaging_QNAME).next(), Messaging.class) .getValue(); } catch (JAXBException | SOAPException e) { ReliabilityChecker.LOG.error(e.getMessage(), e); return false; } SignalMessage signalMessage = messaging.getSignalMessage(); //ReceiptionAwareness or NRR found but not expected? report if configuration=true //TODO: make configurable in domibus.properties //SignalMessage with Receipt expected if (signalMessage.getReceipt() != null && signalMessage.getReceipt().getAny().size() == 1) { String contentOfReceiptString = signalMessage.getReceipt().getAny().get(0); try { if (!legConfiguration.getReliability().isNonRepudiation()) { UserMessage userMessage = this.jaxbContext.createUnmarshaller() .unmarshal( new StreamSource( new ByteArrayInputStream(contentOfReceiptString.getBytes())), UserMessage.class) .getValue(); UserMessage userMessageInRequest = this.jaxbContext.createUnmarshaller() .unmarshal( (Node) request.getSOAPHeader() .getChildElements(ObjectFactory._Messaging_QNAME).next(), Messaging.class) .getValue().getUserMessage(); return userMessage.equals(userMessageInRequest); } Iterator<Element> elementIterator = response.getSOAPHeader() .getChildElements(new QName(WSConstants.WSSE_NS, WSConstants.WSSE_LN)); if (!elementIterator.hasNext()) { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0302, "Invalid NonRepudiationInformation: No security header found", null, MSHRole.SENDING); } Element securityHeaderResponse = elementIterator.next(); if (elementIterator.hasNext()) { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0302, "Invalid NonRepudiationInformation: Multiple security headers found", null, MSHRole.SENDING); } String wsuIdOfMEssagingElement = messaging.getOtherAttributes() .get(new QName(WSConstants.WSU_NS, "Id")); ReliabilityChecker.LOG.debug(wsuIdOfMEssagingElement); NodeList nodeList = securityHeaderResponse.getElementsByTagNameNS(WSConstants.SIG_NS, WSConstants.REF_LN); boolean signatureFound = false; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (this.compareReferenceIgnoreHashtag( node.getAttributes().getNamedItem("URI").getNodeValue(), wsuIdOfMEssagingElement)) { signatureFound = true; break; } } if (!signatureFound) { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0302, "Invalid NonRepudiationInformation: eb:Messaging not signed", null, MSHRole.SENDING); } NodeList referencesFromSecurityHeader = this.getNonRepudiationNodeList(request.getSOAPHeader() .getElementsByTagNameNS(WSConstants.SIG_NS, WSConstants.SIG_LN).item(0)); NodeList referencesFromNonRepudiationInformation = this.getNonRepudiationNodeList(response .getSOAPHeader() .getElementsByTagNameNS(NonRepudiationConstants.NS_NRR, NonRepudiationConstants.NRR_LN) .item(0)); if (!this.compareUnorderedReferenceNodeLists(referencesFromSecurityHeader, referencesFromNonRepudiationInformation)) { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0302, "Invalid NonRepudiationInformation: non repudiation information and request message do not match", null, MSHRole.SENDING); } return true; } catch (JAXBException e) { ReliabilityChecker.LOG.error("", e); } catch (SOAPException e) { ReliabilityChecker.LOG.error("", e); } } else { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0302, "There is no content inside the receipt element received by the responding gateway", signalMessage.getMessageInfo().getMessageId(), signalMessage.getMessageInfo().getMessageId(), null, MSHRole.SENDING); } } return false; }
From source file:com.legstar.jaxb.gen.CobolJAXBCustomizer.java
/** * Inject a serializable element in the JAXB global bindings annotation. * <p/>/*from www . j av a2 s. co m*/ * If the element is already present we update its attributes. * * @param globalbindingsEl the global bindings node * @param jaxbNamespace the JAXB namespace * @param jaxbNamespacePrefix the JAXB namespace prefix */ public void injectJaxbSerializableAnnotation(final Element globalbindingsEl, final String jaxbNamespace, final String jaxbNamespacePrefix) { Element serializableEl = null; NodeList nl = globalbindingsEl.getElementsByTagNameNS(jaxbNamespace, JAXB_SERIALIZABLE); if (nl.getLength() > 0) { serializableEl = (Element) nl.item(0); } else { serializableEl = globalbindingsEl.getOwnerDocument().createElementNS(jaxbNamespace, jaxbNamespacePrefix + ':' + JAXB_SERIALIZABLE); globalbindingsEl.appendChild(serializableEl); } serializableEl.setAttribute(JAXB_UID, Long.toString(getJaxbGenModel().getSerializableUid())); }
From source file:com.legstar.jaxb.gen.CobolJAXBCustomizer.java
/** * Inject a XmlTransform element in the JAXB schema bindings annotation. * <p/>/*from w w w . j av a 2 s . c o m*/ * If the element is already present we update its attributes. * * @param schemabindingsEl the schema bindings node * @param jaxbNamespace the JAXB namespace * @param jaxbNamespacePrefix the JAXB namespace prefix */ public void injectJaxbXmlTransformAnnotation(final Element schemabindingsEl, final String jaxbNamespace, final String jaxbNamespacePrefix) { Element xmltransformEl = null; NodeList nl = schemabindingsEl.getElementsByTagNameNS(jaxbNamespace, JAXB_XMLTRANSFORM); if (nl.getLength() > 0) { xmltransformEl = (Element) nl.item(0); } else { xmltransformEl = schemabindingsEl.getOwnerDocument().createElementNS(jaxbNamespace, jaxbNamespacePrefix + ':' + JAXB_XMLTRANSFORM); schemabindingsEl.appendChild(xmltransformEl); } if (getJaxbGenModel().needTypeNameXmlTransform()) { injectJaxbTypeNameXmlTransformAnnotation(xmltransformEl, jaxbNamespace, jaxbNamespacePrefix); } if (getJaxbGenModel().needElementNameXmlTransform()) { injectJaxbElementNameXmlTransformAnnotation(xmltransformEl, jaxbNamespace, jaxbNamespacePrefix); } }
From source file:com.legstar.jaxb.gen.CobolJAXBCustomizer.java
/** * Inject a TypeNameXmlTransform element in the JAXB XmlTransform * annotation.// w w w.jav a 2 s. c o m * <p/> * If the element is already present we update its attributes. * * @param xmltransformEl the XmlTransform node * @param jaxbNamespace the JAXB namespace * @param jaxbNamespacePrefix the JAXB namespace prefix */ public void injectJaxbTypeNameXmlTransformAnnotation(final Element xmltransformEl, final String jaxbNamespace, final String jaxbNamespacePrefix) { Element typenamexmltransformEl = null; NodeList nl = xmltransformEl.getElementsByTagNameNS(jaxbNamespace, JAXB_TYPENAME); if (nl.getLength() > 0) { typenamexmltransformEl = (Element) nl.item(0); } else { typenamexmltransformEl = xmltransformEl.getOwnerDocument().createElementNS(jaxbNamespace, jaxbNamespacePrefix + ':' + JAXB_TYPENAME); xmltransformEl.appendChild(typenamexmltransformEl); } if (getJaxbGenModel().getTypeNamePrefix() != null) { typenamexmltransformEl.setAttribute(JAXB_PREFIX, getJaxbGenModel().getTypeNamePrefix()); } if (getJaxbGenModel().getTypeNameSuffix() != null) { typenamexmltransformEl.setAttribute(JAXB_SUFFIX, getJaxbGenModel().getTypeNameSuffix()); } }
From source file:com.legstar.jaxb.gen.CobolJAXBCustomizer.java
/** * Inject a ElementNameXmlTransform element in the JAXB XmlTransform * annotation./*from ww w . ja v a2 s . c o m*/ * <p/> * If the element is already present we update its attributes. * * @param xmltransformEl the XmlTransform node * @param jaxbNamespace the JAXB namespace * @param jaxbNamespacePrefix the JAXB namespace prefix */ public void injectJaxbElementNameXmlTransformAnnotation(final Element xmltransformEl, final String jaxbNamespace, final String jaxbNamespacePrefix) { Element elementnamexmltransformEl = null; NodeList nl = xmltransformEl.getElementsByTagNameNS(jaxbNamespace, JAXB_ELEMENTNAME); if (nl.getLength() > 0) { elementnamexmltransformEl = (Element) nl.item(0); } else { elementnamexmltransformEl = xmltransformEl.getOwnerDocument().createElementNS(jaxbNamespace, jaxbNamespacePrefix + ':' + JAXB_ELEMENTNAME); xmltransformEl.appendChild(elementnamexmltransformEl); } if (getJaxbGenModel().getElementNamePrefix() != null) { elementnamexmltransformEl.setAttribute(JAXB_PREFIX, getJaxbGenModel().getElementNamePrefix()); } if (getJaxbGenModel().getElementNameSuffix() != null) { elementnamexmltransformEl.setAttribute(JAXB_SUFFIX, getJaxbGenModel().getElementNameSuffix()); } }
From source file:de.mpg.mpdl.inge.exportmanager.Export.java
/** * Walk around the itemList XML, fetch all files from components via URIs and put them into the * archive {@link OutputStream} aos/*from ww w .j a va 2 s.c om*/ * * @param aos - array {@link OutputStream} * @param itemList - XML with the files to be fetched, see NS: * http://www.escidoc.de/schemas/components/0.7 * @throws ExportManagerException */ private void fetchComponentsDo(OutputStream aos, String itemList) throws ExportManagerException { Document doc = parseDocument(itemList); NodeIterator ni = getFilteredNodes(new ComponentNodeFilter(), doc); // login only once String userHandle; try { userHandle = AdminHelper.loginUser(USER_ID, PASSWORD); } catch (Exception e) { throw new ExportManagerException("Cannot login", e); } String fileName; Node n; while ((n = ni.nextNode()) != null) { Element componentElement = (Element) n; NodeList nl = componentElement.getElementsByTagNameNS(COMPONENTS_NS, "content"); Element contentElement = (Element) nl.item(0); if (contentElement == null) { throw new ExportManagerException( "Wrong item XML: {" + COMPONENTS_NS + "}component element doesn't contain content element. " + "Component id: " + componentElement.getAttributeNS(XLINK_NS, "href")); } String href = contentElement.getAttributeNS(XLINK_NS, "href"); String storageStatus = contentElement.getAttribute("storage"); // get file name if ("internal-managed".equals(storageStatus)) { NodeIterator nif = ((DocumentTraversal) doc).createNodeIterator(componentElement, NodeFilter.SHOW_ELEMENT, new FileNameNodeFilter(), true); Node nf; if ((nf = nif.nextNode()) != null) { fileName = ((Element) nf).getTextContent(); // names of files for Matcher m = Pattern.compile("^([\\w.]+?)(\\s+|$)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL) .matcher(fileName); m.find(); fileName = m.group(1); } else { throw new ExportManagerException("Missed file property: {" + COMPONENTS_NS + "}component element doesn't contain file-name element (md-records/md-record/file:file/dc:title). " + "Component id: " + componentElement.getAttributeNS(XLINK_NS, "href")); } } // TODO: the external-managed will be processed later else { throw new ExportManagerException("Missed internal-managed file in {" + COMPONENTS_NS + "}component: components/component/content[@storage=\"internal-managed\"]" + "Component id: " + componentElement.getAttributeNS(XLINK_NS, "href")); } logger.info("link to the content: " + href); logger.info("storage status: " + storageStatus); logger.info("fileName: " + fileName); // get file via URI String url; try { url = PropertyReader.getFrameworkUrl() + href; } catch (Exception e) { throw new ExportManagerException("Cannot get framework url", e); } logger.info("url=" + url); GetMethod method = new GetMethod(url); method.setFollowRedirects(false); method.setRequestHeader("Cookie", "escidocCookie=" + userHandle); // Execute the method with HttpClient. HttpClient client = new HttpClient(); try { ProxyHelper.executeMethod(client, method); } catch (Exception e) { throw new ExportManagerException("Cannot execute HttpMethod", e); } int status = method.getStatusCode(); logger.info("Status=" + status); if (status != 200) fileName += ".error" + status; byte[] responseBody; try { responseBody = method.getResponseBody(); } catch (Exception e) { throw new ExportManagerException("Cannot get Response Body", e); } InputStream bis = new BufferedInputStream(new ByteArrayInputStream(responseBody)); if (aos instanceof ZipOutputStream) { ZipEntry ze = new ZipEntry(fileName); ze.setSize(responseBody.length); try { ((ZipOutputStream) aos).putNextEntry(ze); writeFromStreamToStream(bis, aos); ((ZipOutputStream) aos).closeEntry(); } catch (Exception e) { throw new ExportManagerException("zip2stream generation problem", e); } } else if (aos instanceof TarOutputStream) { TarEntry te = new TarEntry(fileName); te.setSize(responseBody.length); try { ((TarOutputStream) aos).putNextEntry(te); writeFromStreamToStream(bis, aos); ((TarOutputStream) aos).closeEntry(); } catch (Exception e) { throw new ExportManagerException("tar2stream generation problem", e); } } else { throw new ExportManagerException("Unsupported archive output stream: " + aos.getClass()); } try { bis.close(); } catch (Exception e) { throw new ExportManagerException("Cannot close InputStream", e); } } }