List of usage examples for org.w3c.dom Node ATTRIBUTE_NODE
short ATTRIBUTE_NODE
To view the source code for org.w3c.dom Node ATTRIBUTE_NODE.
Click Source Link
Attr
. From source file:org.exist.dom.ElementImpl.java
/** * Method toString./*from w ww. j a v a 2 s.c o m*/ * */ public String toString(boolean top, TreeSet<String> namespaces) { final StringBuilder buf = new StringBuilder(); final StringBuilder attributes = new StringBuilder(); final StringBuilder children = new StringBuilder(); buf.append('<'); buf.append(nodeName); //Remove false to have a verbose output //if (top && false) { //buf.append(" xmlns:exist=\""+ Namespaces.EXIST_NS + "\""); //buf.append(" exist:id=\""); //buf.append(getNodeId()); //buf.append("\" exist:document=\""); //buf.append(((DocumentImpl)getOwnerDocument()).getFileURI()); //buf.append("\""); //} if (declaresNamespacePrefixes()) { // declare namespaces used by this element Map.Entry<String, String> entry; String namespace, prefix; for (final Iterator<Map.Entry<String, String>> i = namespaceMappings.entrySet().iterator(); i .hasNext();) { entry = i.next(); prefix = entry.getKey(); namespace = entry.getValue(); if (prefix.length() == 0) { buf.append(" xmlns=\""); //buf.append(namespace); buf.append("..."); } else { buf.append(" xmlns:"); buf.append(prefix); buf.append("=\""); //buf.append(namespace); buf.append("..."); } buf.append("\" "); namespaces.add(namespace); } } if (nodeName.getNamespaceURI().length() > 0 && (!namespaces.contains(nodeName.getNamespaceURI()))) { buf.append(" xmlns:").append(nodeName.getPrefix()).append("=\""); buf.append(nodeName.getNamespaceURI()); buf.append("\" "); } final NodeList childNodes = getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { final Node child = childNodes.item(i); switch (child.getNodeType()) { case Node.ATTRIBUTE_NODE: attributes.append(' '); attributes.append(((Attr) child).getName()); attributes.append("=\""); attributes.append(escapeXml(child)); attributes.append("\""); break; case Node.ELEMENT_NODE: children.append(((ElementImpl) child).toString(false, namespaces)); break; default: children.append(child.toString()); } } if (attributes.length() > 0) { buf.append(attributes.toString()); } if (childNodes.getLength() > 0) { buf.append(">"); buf.append(children.toString()); buf.append("</"); buf.append(nodeName); buf.append(">"); } else { buf.append("/>"); } return buf.toString(); }
From source file:org.exist.dom.ElementImpl.java
/** * Update the contents of this element. The passed list of nodes * becomes the new content.//from ww w . j ava2 s.c o m * * @param newContent * @throws DOMException */ public void update(Txn transaction, NodeList newContent) throws DOMException { final NodePath path = getPath(); // remove old child nodes final NodeList nodes = getChildNodes(); StreamListener listener = null; DBBroker broker = null; //May help getReindexRoot() to make some useful things try { broker = ownerDocument.getBrokerPool().get(null); broker.getIndexController().setDocument(ownerDocument); final StoredNode reindexRoot = broker.getIndexController().getReindexRoot(this, path, true, true); broker.getIndexController().setMode(StreamListener.REMOVE_SOME_NODES); if (reindexRoot == null) { listener = broker.getIndexController().getStreamListener(); } else { broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.REMOVE_SOME_NODES); } // TODO: fix once range index has been moved to new architecture final StoredNode valueReindexRoot = broker.getValueIndex().getReindexRoot(this, path); broker.getValueIndex().reindex(valueReindexRoot); StoredNode last = this; int i = nodes.getLength(); for (; i > 0; i--) { StoredNode child = (StoredNode) nodes.item(i - 1); if (child.getNodeType() == Node.ATTRIBUTE_NODE) { last = child; break; } if (child.getNodeType() == Node.ELEMENT_NODE) { path.addComponent(child.getQName()); } broker.removeAllNodes(transaction, child, path, listener); if (child.getNodeType() == Node.ELEMENT_NODE) { path.removeLastComponent(); } } broker.getIndexController().flush(); broker.getIndexController().setMode(StreamListener.STORE); broker.getIndexController().getStreamListener(); broker.endRemove(transaction); children = i; final NodeId newNodeId = last == this ? nodeId.newChild() : last.nodeId.nextSibling(); //Append new content appendChildren(transaction, newNodeId, null, new NodeImplRef(last), path, newContent, listener); broker.updateNode(transaction, this, false); broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.STORE); broker.getValueIndex().reindex(valueReindexRoot); broker.flush(); } catch (final EXistException e) { LOG.warn("Exception while inserting node: " + e.getMessage(), e); } finally { if (broker != null) broker.release(); } }
From source file:org.exist.dom.ElementImpl.java
/** * Update a child node. This method will only update the child node * but not its potential descendant nodes. * * @param oldChild/*w w w .ja va 2 s .co m*/ * @param newChild * @throws DOMException */ @Override public StoredNode updateChild(Txn transaction, Node oldChild, Node newChild) throws DOMException { if (!(oldChild instanceof StoredNode)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Wrong node type"); } if (!(newChild instanceof StoredNode)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Wrong node type"); } StoredNode oldNode = (StoredNode) oldChild; final StoredNode newNode = (StoredNode) newChild; if (!oldNode.nodeId.getParentId().equals(nodeId)) { throw new DOMException(DOMException.NOT_FOUND_ERR, "Node is not a child of this element"); } if (newNode.getNodeType() == Node.ATTRIBUTE_NODE) { if (newNode.getQName().equalsSimple(Namespaces.XML_ID_QNAME)) { // an xml:id attribute. Normalize the attribute and set its type to ID final AttrImpl attr = (AttrImpl) newNode; attr.setValue(StringValue.trimWhitespace(StringValue.collapseWhitespace(attr.getValue()))); attr.setType(AttrImpl.ID); } } StoredNode previousNode = (StoredNode) oldNode.getPreviousSibling(); if (previousNode == null) { previousNode = this; } else { previousNode = getLastNode(previousNode); } final NodePath currentPath = getPath(); final NodePath oldPath = oldNode.getPath(currentPath); DBBroker broker = null; try { broker = ownerDocument.getBrokerPool().get(null); //May help getReindexRoot() to make some useful things broker.getIndexController().setDocument(ownerDocument); //Check if the change affects any ancestor nodes, which then need to be reindexed later StoredNode reindexRoot = broker.getIndexController().getReindexRoot(oldNode, oldPath, false); //Remove indexes if (reindexRoot == null) { reindexRoot = oldNode; } broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.REMOVE_SOME_NODES); //TODO: fix once range index has been moved to new architecture final StoredNode valueReindexRoot = broker.getValueIndex().getReindexRoot(this, oldPath); broker.getValueIndex().reindex(valueReindexRoot); //Remove the actual node data broker.removeNode(transaction, oldNode, oldPath, null); broker.endRemove(transaction); newNode.nodeId = oldNode.nodeId; //Reinsert the new node data broker.insertNodeAfter(transaction, previousNode, newNode); final NodePath path = newNode.getPath(currentPath); broker.indexNode(transaction, newNode, path); if (newNode.getNodeType() == Node.ELEMENT_NODE) { broker.endElement(newNode, path, null); } broker.updateNode(transaction, this, true); //Recreate indexes on ancestor nodes broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.STORE); broker.getValueIndex().reindex(valueReindexRoot); broker.flush(); } catch (final EXistException e) { LOG.warn("Exception while inserting node: " + e.getMessage(), e); } finally { if (broker != null) broker.release(); } return newNode; }
From source file:org.exist.dom.ElementImpl.java
/** * @see org.w3c.dom.Node#removeChild(org.w3c.dom.Node) *//* www .jav a2 s .c o m*/ @Override public Node removeChild(Txn transaction, Node oldChild) throws DOMException { if (!(oldChild instanceof StoredNode)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "wrong node type"); } final StoredNode oldNode = (StoredNode) oldChild; if (!oldNode.nodeId.getParentId().equals(nodeId)) { throw new DOMException(DOMException.NOT_FOUND_ERR, "node is not a child of this element"); } final NodePath oldPath = oldNode.getPath(); StreamListener listener = null; DBBroker broker = null; try { //May help getReindexRoot() to make some useful things broker = ownerDocument.getBrokerPool().get(null); broker.getIndexController().setDocument(ownerDocument); final StoredNode reindexRoot = broker.getIndexController().getReindexRoot(oldNode, oldPath, false); broker.getIndexController().setMode(StreamListener.REMOVE_SOME_NODES); if (reindexRoot == null) { listener = broker.getIndexController().getStreamListener(); } else { broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.REMOVE_SOME_NODES); } broker.removeAllNodes(transaction, oldNode, oldPath, listener); --children; if (oldChild.getNodeType() == Node.ATTRIBUTE_NODE) { --attributes; } broker.endRemove(transaction); setDirty(true); broker.updateNode(transaction, this, false); broker.flush(); if (reindexRoot != null && !reindexRoot.getNodeId().equals(oldNode.getNodeId())) { broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.STORE); } } catch (final EXistException e) { LOG.warn("Exception while inserting node: " + e.getMessage(), e); } finally { if (broker != null) broker.release(); } return oldNode; }
From source file:org.exist.storage.dom.DOMFile.java
public String debugPageContents(DOMPage page) { final StringBuilder buf = new StringBuilder(); buf.append("Page " + page.getPageNum() + ": "); short count = 0; final int dataLength = page.getPageHeader().getDataLength(); for (int pos = 0; pos < dataLength; count++) { buf.append(pos + "/"); final short tupleID = ByteConversion.byteToShort(page.data, pos); pos += LENGTH_TID;//from w ww.j a va2 s. co m buf.append(ItemId.getId(tupleID)); if (ItemId.isLink(tupleID)) { buf.append("L"); } else if (ItemId.isRelocated(tupleID)) { buf.append("R"); } if (ItemId.isLink(tupleID)) { final long forwardLink = ByteConversion.byteToLong(page.data, pos); buf.append(':').append(forwardLink).append(" "); pos += LENGTH_FORWARD_LOCATION; } else { final short valueLength = ByteConversion.byteToShort(page.data, pos); pos += LENGTH_DATA_LENGTH; if (valueLength < 0) { LOG.warn("Illegal length: " + valueLength); return buf.append("[Illegal length : " + valueLength + "] ").toString(); //Probably unable to continue... } else if (ItemId.isRelocated(tupleID)) { //TODO : output to buffer ? pos += LENGTH_ORIGINAL_LOCATION; } else { buf.append("["); switch (Signatures.getType(page.data[pos])) { case Node.ELEMENT_NODE: { buf.append("element "); int readOffset = pos; readOffset += 1; final int children = ByteConversion.byteToInt(page.data, readOffset); readOffset += ElementImpl.LENGTH_ELEMENT_CHILD_COUNT; final int dlnLen = ByteConversion.byteToShort(page.data, readOffset); readOffset += NodeId.LENGTH_NODE_ID_UNITS; //That might happen during recovery runs : TODO, investigate if (owner == null) { buf.append("(Can't read data, owner is null)"); } else { try { final NodeId nodeId = ((NativeBroker) owner).getBrokerPool().getNodeFactory() .createFromData(dlnLen, page.data, readOffset); readOffset += nodeId.size(); buf.append("(" + nodeId.toString() + ")"); final short attributes = ByteConversion.byteToShort(page.data, readOffset); buf.append(" children: " + children); buf.append(" attributes: " + attributes); } catch (final Exception e) { //TODO : more friendly message. Provide the array of bytes ? buf.append("(Unable to read the node ID at: " + readOffset); buf.append(" children : " + children); //Probably a wrong offset so... don't read it buf.append(" attributes : unknown"); } } break; } case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: { if (Signatures.getType(page.data[pos]) == Node.TEXT_NODE) { buf.append("text "); } else { buf.append("CDATA "); } int readOffset = pos; readOffset += 1; final int dlnLen = ByteConversion.byteToShort(page.data, readOffset); readOffset += NodeId.LENGTH_NODE_ID_UNITS; //That might happen during recovery runs : TODO, investigate if (owner == null) { buf.append("(Can't read data, owner is null)"); } else { try { final NodeId nodeId = ((NativeBroker) owner).getBrokerPool().getNodeFactory() .createFromData(dlnLen, page.data, readOffset); readOffset += nodeId.size(); buf.append("(" + nodeId.toString() + ")"); final ByteArrayOutputStream os = new ByteArrayOutputStream(); os.write(page.data, readOffset, valueLength - (readOffset - pos)); String value = new String(os.toByteArray(), UTF_8); if (value.length() > 15) { value = value.substring(0, 8) + "..." + value.substring(value.length() - 8); } buf.append(":'" + value + "'"); } catch (final Exception e) { //TODO : more friendly message. Provide the array of bytes ? buf.append("(unable to read the node ID at : " + readOffset); } } break; } case Node.ATTRIBUTE_NODE: { buf.append("["); buf.append("attribute "); int readOffset = pos; final byte idSizeType = (byte) (page.data[readOffset] & 0x3); final boolean hasNamespace = (page.data[readOffset] & 0x10) == 0x10; readOffset += 1; final int dlnLen = ByteConversion.byteToShort(page.data, readOffset); readOffset += NodeId.LENGTH_NODE_ID_UNITS; //That might happen during recovery runs : TODO, investigate if (owner == null) { buf.append("(can't read data, owner is null)"); } else { try { final NodeId nodeId = ((NativeBroker) owner).getBrokerPool().getNodeFactory() .createFromData(dlnLen, page.data, readOffset); readOffset += nodeId.size(); buf.append("(" + nodeId.toString() + ")"); readOffset += Signatures.getLength(idSizeType); if (hasNamespace) { //Untested final short NSId = ByteConversion.byteToShort(page.data, readOffset); readOffset += AttrImpl.LENGTH_NS_ID; final short prefixLen = ByteConversion.byteToShort(page.data, readOffset); readOffset += AttrImpl.LENGTH_PREFIX_LENGTH + prefixLen; final ByteArrayOutputStream os = new ByteArrayOutputStream(); os.write(page.data, readOffset, valueLength - (readOffset - prefixLen)); String prefix = new String(os.toByteArray(), UTF_8); final String NsURI = ((NativeBroker) owner).getBrokerPool().getSymbols() .getNamespace(NSId); buf.append(prefix + "{" + NsURI + "}"); } final ByteArrayOutputStream os = new ByteArrayOutputStream(); os.write(page.data, readOffset, valueLength - (readOffset - pos)); String value = new String(os.toByteArray(), UTF_8); if (value.length() > 15) { value = value.substring(0, 8) + "..." + value.substring(value.length() - 8); } buf.append(":'" + value + "'"); } catch (final Exception e) { //TODO : more friendly message. Provide the array of bytes ? buf.append("(unable to read the node ID at : " + readOffset); } } buf.append("] "); break; } default: buf.append("Unknown node type !"); } buf.append("] "); } pos += valueLength; } } buf.append("; records in page: " + count + " (header says: " + page.getPageHeader().getRecordCount() + ")"); buf.append("; currentTupleID: " + page.getPageHeader().getCurrentTupleID()); buf.append("; data length: " + page.getPageHeader().getDataLength()); for (int i = page.data.length; i > 0; i--) { if (page.data[i - 1] != 0) { buf.append(" (last non-zero byte: " + i + ")"); break; } } return buf.toString(); }
From source file:org.exist.storage.dom.DOMFile.java
/** * Recursive method to retrieve the string values of the root node * and all its descendants.// ww w. j av a 2s . co m */ private void getNodeValue(BrokerPool pool, DocumentImpl doc, ByteArrayOutputStream os, RecordPos rec, boolean isTopNode, boolean addWhitespace) { if (!lock.hasLock()) { LOG.warn("The file doesn't own a lock"); } //Locate the next real node, skipping relocated nodes boolean foundNext = false; do { final DOMFilePageHeader pageHeader = rec.getPage().getPageHeader(); if (rec.offset > pageHeader.getDataLength()) { // end of page reached, proceed to the next page final long nextPage = pageHeader.getNextDataPage(); if (nextPage == Page.NO_PAGE) { SanityCheck.TRACE("Bad link to next page! " + "Offset: " + rec.offset + ", Len: " + pageHeader.getDataLength() + ", Page info : " + rec.getPage().page.getPageInfo()); //TODO : throw exception ? -pb return; } rec.setPage(getDOMPage(nextPage)); dataCache.add(rec.getPage()); rec.offset = LENGTH_TID; } //Position the stream at the very beginning of the record final short tupleID = ByteConversion.byteToShort(rec.getPage().data, rec.offset - LENGTH_TID); rec.setTupleID(tupleID); if (ItemId.isLink(rec.getTupleID())) { //This is a link: skip it //We position the offset *after* the next TupleID rec.offset += (LENGTH_FORWARD_LOCATION + LENGTH_TID); } else { //OK: node found foundNext = true; } } while (!foundNext); final short valueLength = ByteConversion.byteToShort(rec.getPage().data, rec.offset); int realLen = valueLength; rec.offset += LENGTH_DATA_LENGTH; //Check if the node was relocated if (ItemId.isRelocated(rec.getTupleID())) { rec.offset += LENGTH_ORIGINAL_LOCATION; } byte[] data = rec.getPage().data; int readOffset = rec.offset; boolean inOverflow = false; if (valueLength == OVERFLOW) { //If we have an overflow value, load it from the overflow page final long p = ByteConversion.byteToLong(data, rec.offset); data = getOverflowValue(p); //We position the offset *after* the next TID rec.offset += LENGTH_OVERFLOW_LOCATION + LENGTH_TID; realLen = data.length; readOffset = 0; inOverflow = true; } // check the type of the node final short type = Signatures.getType(data[readOffset]); readOffset += StoredNode.LENGTH_SIGNATURE_LENGTH; //Switch on the node type switch (type) { case Node.ELEMENT_NODE: { final int children = ByteConversion.byteToInt(data, readOffset); readOffset += ElementImpl.LENGTH_ELEMENT_CHILD_COUNT; final int dlnLen = ByteConversion.byteToShort(data, readOffset); readOffset += NodeId.LENGTH_NODE_ID_UNITS; final int nodeIdLen = pool.getNodeFactory().lengthInBytes(dlnLen, data, readOffset); readOffset += nodeIdLen; final short attributes = ByteConversion.byteToShort(data, readOffset); //Ignore the following NS data which are of no use //We position the offset *after* the next TID rec.offset += realLen + LENGTH_TID; final boolean extraWhitespace = addWhitespace && (children - attributes) > 1; for (int i = 0; i < children; i++) { //recursive call : we ignore attributes children getNodeValue(pool, doc, os, rec, false, addWhitespace); if (extraWhitespace) { os.write((byte) ' '); } } return; } case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: { final int dlnLen = ByteConversion.byteToShort(data, readOffset); readOffset += NodeId.LENGTH_NODE_ID_UNITS; final int nodeIdLen = pool.getNodeFactory().lengthInBytes(dlnLen, data, readOffset); readOffset += nodeIdLen; os.write(data, readOffset, realLen - (StoredNode.LENGTH_SIGNATURE_LENGTH + NodeId.LENGTH_NODE_ID_UNITS + nodeIdLen)); break; } case Node.PROCESSING_INSTRUCTION_NODE: { final int dlnLen = ByteConversion.byteToShort(data, readOffset); readOffset += NodeId.LENGTH_NODE_ID_UNITS; final int nodeIdLen = pool.getNodeFactory().lengthInBytes(dlnLen, data, readOffset); readOffset += nodeIdLen; final int targetLen = ByteConversion.byteToInt(data, readOffset); readOffset += 4 + targetLen; os.write(data, readOffset, realLen - (StoredNode.LENGTH_SIGNATURE_LENGTH + NodeId.LENGTH_NODE_ID_UNITS + nodeIdLen + targetLen + 4)); break; } case Node.ATTRIBUTE_NODE: { if (isTopNode) { final int start = readOffset - StoredNode.LENGTH_SIGNATURE_LENGTH; final byte idSizeType = (byte) (data[start] & 0x3); final boolean hasNamespace = (data[start] & 0x10) == 0x10; final int dlnLen = ByteConversion.byteToShort(data, readOffset); readOffset += NodeId.LENGTH_NODE_ID_UNITS; final int nodeIdLen = pool.getNodeFactory().lengthInBytes(dlnLen, data, readOffset); readOffset += nodeIdLen; readOffset += Signatures.getLength(idSizeType); if (hasNamespace) { readOffset += AttrImpl.LENGTH_NS_ID; // skip namespace id final short prefixLen = ByteConversion.byteToShort(data, readOffset); readOffset += AttrImpl.LENGTH_PREFIX_LENGTH; readOffset += prefixLen; // skip prefix } os.write(data, readOffset, realLen - (readOffset - start)); } break; } case Node.COMMENT_NODE: { if (isTopNode) { final int dlnLen = ByteConversion.byteToShort(data, readOffset); readOffset += NodeId.LENGTH_NODE_ID_UNITS; final int nodeIdLen = pool.getNodeFactory().lengthInBytes(dlnLen, data, readOffset); readOffset += nodeIdLen; os.write(data, readOffset, realLen - (StoredNode.LENGTH_SIGNATURE_LENGTH + NodeId.LENGTH_NODE_ID_UNITS + nodeIdLen)); } break; } } if (!inOverflow) { //If it isn't an overflow value, add the value length to the current offset //We position the offset *after* the next TID rec.offset += realLen + LENGTH_TID; } }
From source file:org.jbpm.bpel.xml.util.XmlUtil.java
/** * Retrieves the prefix associated with a namespace URI in the given context node. * @param namespaceURI the namespace whose prefix is required * @param contextNode the node where to search for namespace declarations * @return the prefix associated with the namespace URI; the empty string indicates the default * namespace, while <code>null</code> indicates no association *//* w w w . j a va2 s .co m*/ public static String getPrefix(String namespaceURI, Node contextNode) { switch (contextNode.getNodeType()) { case Node.ATTRIBUTE_NODE: contextNode = ((Attr) contextNode).getOwnerElement(); break; case Node.ELEMENT_NODE: break; default: contextNode = contextNode.getParentNode(); } while (contextNode != null && contextNode.getNodeType() == Node.ELEMENT_NODE) { NamedNodeMap attributes = contextNode.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { Node attr = attributes.item(i); // is attribute a namespace declaration and matches the given URI? if (BpelConstants.NS_XMLNS.equals(attr.getNamespaceURI()) && namespaceURI.equals(attr.getNodeValue())) { String prefix = attr.getLocalName(); return "xmlns".equals(prefix) ? "" : prefix; } } contextNode = contextNode.getParentNode(); } return null; }
From source file:ORG.oclc.os.SRW.SRUServerTester.java
private String getNodeText(Node doc, String xPath) { Node node = doc;// ww w.j a va2s. c o m if (xPath != null) try { node = XPathAPI.selectSingleNode(doc, xPath, ns); } catch (TransformerException e) { return null; } String strRet = ""; if (null != node) { if (node.getNodeType() == Node.ATTRIBUTE_NODE) return node.getNodeValue(); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node item = children.item(i); switch (item.getNodeType()) { case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: strRet += item.getNodeValue().trim(); } } } return strRet; }
From source file:org.ojbc.intermediaries.sn.notification.NotificationRequest.java
public NotificationRequest(Document document) throws Exception { this.requestDocument = document; String notificationEventDateTimeString = XmlUtils.xPathStringSearch(document, getNotificationEventDateRootXpath() + "/nc:DateTime"); String notificationEventDateOnlyString = XmlUtils.xPathStringSearch(document, getNotificationEventDateRootXpath() + "/nc:Date"); if (StringUtils.isNotEmpty(notificationEventDateTimeString)) { notificationEventDate = XmlUtils.parseXmlDateTime(notificationEventDateTimeString); isNotificationEventDateInclusiveOfTime = true; } else if (StringUtils.isNotEmpty(notificationEventDateOnlyString)) { notificationEventDate = XmlUtils.parseXmlDate(notificationEventDateOnlyString); isNotificationEventDateInclusiveOfTime = false; } else {/* w ww . j a va 2s.c o m*/ notificationEventDate = null; } personActivityInvolvementText = XmlUtils.xPathStringSearch(document, "/b-2:Notify/b-2:NotificationMessage/b-2:Message/notfm-exch:NotificationMessage/nc:ActivityInvolvedPersonAssociation/nc:PersonActivityInvolvementText"); String personReference = XmlUtils.xPathStringSearch(document, "/b-2:Notify/b-2:NotificationMessage/b-2:Message/notfm-exch:NotificationMessage/nc:ActivityInvolvedPersonAssociation/nc:PersonReference/@s:ref"); if (StringUtils.isNotBlank(personReference)) { personFirstName = StringUtils.strip(XmlUtils.xPathStringSearch(document, "/b-2:Notify/b-2:NotificationMessage/b-2:Message/notfm-exch:NotificationMessage/jxdm41:Person[@s:id='" + personReference + "']/nc:PersonName/nc:PersonGivenName")); personMiddleName = StringUtils.strip(XmlUtils.xPathStringSearch(document, "/b-2:Notify/b-2:NotificationMessage/b-2:Message/notfm-exch:NotificationMessage/jxdm41:Person[@s:id='" + personReference + "']/nc:PersonName/nc:PersonMiddleName")); personLastName = StringUtils.strip(XmlUtils.xPathStringSearch(document, "/b-2:Notify/b-2:NotificationMessage/b-2:Message/notfm-exch:NotificationMessage/jxdm41:Person[@s:id='" + personReference + "']/nc:PersonName/nc:PersonSurName")); personNameSuffix = StringUtils.strip(XmlUtils.xPathStringSearch(document, "/b-2:Notify/b-2:NotificationMessage/b-2:Message/notfm-exch:NotificationMessage/jxdm41:Person[@s:id='" + personReference + "']/nc:PersonName/nc:PersonNameSuffixText")); personBirthDate = StringUtils.strip(XmlUtils.xPathStringSearch(document, "/b-2:Notify/b-2:NotificationMessage/b-2:Message/notfm-exch:NotificationMessage/jxdm41:Person[@s:id='" + personReference + "']/nc:PersonBirthDate/nc:Date")); try { personAge = NotificationBrokerUtils.calculatePersonAgeFromDate(personBirthDate); } catch (Exception ex) { log.error("Unable to calculate person age."); } NodeList aliasNodes = XmlUtils.xPathNodeListSearch(document, "/b-2:Notify/b-2:NotificationMessage/b-2:Message/notfm-exch:NotificationMessage/jxdm41:Person[@s:id='" + personReference + "']/nc:PersonAlternateName"); if (aliasNodes != null && aliasNodes.getLength() > 0) { for (int i = 0; i < aliasNodes.getLength(); i++) { if (aliasNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { Element aliasElement = (Element) aliasNodes.item(i); Alias alias = new Alias(); alias.setPersonFirstName( StringUtils.strip(XmlUtils.xPathStringSearch(aliasElement, "nc:PersonGivenName"))); alias.setPersonLastName( StringUtils.strip(XmlUtils.xPathStringSearch(aliasElement, "nc:PersonSurName"))); aliases.add(alias); } } } String personContactInfoReference = XmlUtils.xPathStringSearch(document, "/b-2:Notify/b-2:NotificationMessage/b-2:Message/notfm-exch:NotificationMessage/nc:PersonContactInformationAssociation/nc:ContactInformationReference/@s:ref"); NodeList telephoneNumberNodes = XmlUtils.xPathNodeListSearch(document, "/b-2:Notify/b-2:NotificationMessage/b-2:Message/notfm-exch:NotificationMessage//nc:ContactInformation[@s:id='" + personContactInfoReference + "']/nc:ContactTelephoneNumber/nc:FullTelephoneNumber/nc:TelephoneNumberFullID"); if (telephoneNumberNodes != null && telephoneNumberNodes.getLength() > 0) { for (int i = 0; i < telephoneNumberNodes.getLength(); i++) { if (telephoneNumberNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { if (StringUtils.isNotBlank(telephoneNumberNodes.item(i).getTextContent())) { personTelephoneNumbers .add(StringUtils.strip(telephoneNumberNodes.item(i).getTextContent())); } } } } } else { log.error("Unable to find person reference. Unable to XQuery for person name."); } NodeList officerReferences = XmlUtils.xPathNodeListSearch(document, getOfficerNameReferenceXPath()); if (officerReferences != null && officerReferences.getLength() > 0) { for (int i = 0; i < officerReferences.getLength(); i++) { if (officerReferences.item(i).getNodeType() == Node.ATTRIBUTE_NODE) { String officerReference = officerReferences.item(i).getTextContent(); String officerName = XmlUtils.xPathStringSearch(document, "/b-2:Notify/b-2:NotificationMessage/b-2:Message/notfm-exch:NotificationMessage/jxdm41:Person[@s:id='" + officerReference + "']/nc:PersonName/nc:PersonFullName"); if (StringUtils.isNotEmpty(officerName)) { officerNames.add(StringUtils.strip(officerName)); } } } } notificationEventIdentifier = XmlUtils.xPathStringSearch(document, getNotificationEventIdentifierXpath()); notificationEventIdentifier = StringUtils.strip(notificationEventIdentifier); notifyingAgencyName = XmlUtils.xPathStringSearch(document, getNotifyingAgencyXpath()); notifyingAgencyName = StringUtils.strip(notifyingAgencyName); notifyingAgencyOri = StringUtils .trimToNull(XmlUtils.xPathStringSearch(document, getNotifyingAgencyOriXpath())); notifyingAgencyPhoneNumber = XmlUtils.xPathStringSearch(document, getNotificationAgencyPhoneNumberXpath()); notifyingAgencyPhoneNumber = StringUtils.strip(notifyingAgencyPhoneNumber); notifyingSystemName = XmlUtils.xPathStringSearch(document, getNotifyingSystemNameXPath()); notifyingSystemName = StringUtils.strip(notifyingSystemName); // subjectIdentification intentionally omitted - should be populated in subclass Node topicNode = XmlUtils.xPathNodeSearch(document, "/b-2:Notify/b-2:NotificationMessage/b-2:Topic"); String unqualifiedTopic = topicNode.getTextContent(); topic = NotificationBrokerUtils.getFullyQualifiedTopic(unqualifiedTopic); }
From source file:org.opensingular.internal.lib.commons.xml.MElement.java
/** * Retorna o valor do no passado como parmetro. Se for um Element retorna o * texto imediatamente abaixo.//from w ww . j a v a2s .com * * @param no do qual ser extraido o texto * @return pdoe ser null */ static String getValorTexto(Node no) { //No private, pois a classe XMLToolkit tambm utiliza if (no == null) { return null; } switch (no.getNodeType()) { case Node.ELEMENT_NODE: Node n = no.getFirstChild(); if (XmlUtil.isNodeTypeText(n)) { return n.getNodeValue(); } break; case Node.ATTRIBUTE_NODE: case Node.TEXT_NODE: String valor = no.getNodeValue(); if (!StringUtils.isEmpty(valor)) { return valor; } break; default: throw new SingularException("getValorTexto(Node) no trata n " + XPathToolkit.getNomeTipo(no)); } return null; }