List of usage examples for org.w3c.dom Attr getValue
public String getValue();
From source file:org.exist.dom.ElementImpl.java
private Node appendChild(Txn transaction, NodeId newNodeId, NodeImplRef last, NodePath lastPath, Node child, StreamListener listener) throws DOMException { if (last == null || last.getNode() == null) //TODO : same test as above ? -pb {// ww w.j a va2s. c o m throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, "invalid node"); } final DocumentImpl owner = (DocumentImpl) getOwnerDocument(); DBBroker broker = null; try { broker = ownerDocument.getBrokerPool().get(null); switch (child.getNodeType()) { case Node.DOCUMENT_FRAGMENT_NODE: appendChildren(transaction, newNodeId, null, last, lastPath, child.getChildNodes(), listener); return null; // TODO: implement document fragments so //we can return all newly appended children case Node.ELEMENT_NODE: // create new element final ElementImpl elem = new ElementImpl( new QName(child.getLocalName() == null ? child.getNodeName() : child.getLocalName(), child.getNamespaceURI(), child.getPrefix()), broker.getBrokerPool().getSymbols()); elem.setNodeId(newNodeId); elem.setOwnerDocument(owner); final NodeListImpl ch = new NodeListImpl(); final NamedNodeMap attribs = child.getAttributes(); int numActualAttribs = 0; for (int i = 0; i < attribs.getLength(); i++) { final Attr attr = (Attr) attribs.item(i); if (!attr.getNodeName().startsWith("xmlns")) { ch.add(attr); numActualAttribs++; } else { final String xmlnsDecl = attr.getNodeName(); final String prefix = xmlnsDecl.length() == 5 ? "" : xmlnsDecl.substring(6); elem.addNamespaceMapping(prefix, attr.getNodeValue()); } } final NodeList cl = child.getChildNodes(); for (int i = 0; i < cl.getLength(); i++) { final Node n = cl.item(i); if (n.getNodeType() != Node.ATTRIBUTE_NODE) { ch.add(n); } } elem.setChildCount(ch.getLength()); if (numActualAttribs != (short) numActualAttribs) { throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, "Too many attributes"); } elem.setAttributes((short) numActualAttribs); lastPath.addComponent(elem.getQName()); // insert the node broker.insertNodeAfter(transaction, last.getNode(), elem); broker.indexNode(transaction, elem, lastPath); broker.getIndexController().indexNode(transaction, elem, lastPath, listener); elem.setChildCount(0); last.setNode(elem); //process child nodes elem.appendChildren(transaction, newNodeId.newChild(), null, last, lastPath, ch, listener); broker.endElement(elem, lastPath, null); broker.getIndexController().endElement(transaction, elem, lastPath, listener); lastPath.removeLastComponent(); return elem; case Node.TEXT_NODE: final TextImpl text = new TextImpl(newNodeId, ((Text) child).getData()); text.setOwnerDocument(owner); // insert the node broker.insertNodeAfter(transaction, last.getNode(), text); broker.indexNode(transaction, text, lastPath); broker.getIndexController().indexNode(transaction, text, lastPath, listener); last.setNode(text); return text; case Node.CDATA_SECTION_NODE: final CDATASectionImpl cdata = new CDATASectionImpl(newNodeId, ((CDATASection) child).getData()); cdata.setOwnerDocument(owner); // insert the node broker.insertNodeAfter(transaction, last.getNode(), cdata); broker.indexNode(transaction, cdata, lastPath); last.setNode(cdata); return cdata; case Node.ATTRIBUTE_NODE: final Attr attr = (Attr) child; final String ns = attr.getNamespaceURI(); final String prefix = (Namespaces.XML_NS.equals(ns) ? "xml" : attr.getPrefix()); String name = attr.getLocalName(); if (name == null) { name = attr.getName(); } final QName attrName = new QName(name, ns, prefix); final AttrImpl attrib = new AttrImpl(attrName, attr.getValue(), broker.getBrokerPool().getSymbols()); attrib.setNodeId(newNodeId); attrib.setOwnerDocument(owner); if (ns != null && attrName.compareTo(Namespaces.XML_ID_QNAME) == Constants.EQUAL) { // an xml:id attribute. Normalize the attribute and set its type to ID attrib.setValue(StringValue.trimWhitespace(StringValue.collapseWhitespace(attrib.getValue()))); attrib.setType(AttrImpl.ID); } else { attrName.setNameType(ElementValue.ATTRIBUTE); } broker.insertNodeAfter(transaction, last.getNode(), attrib); broker.indexNode(transaction, attrib, lastPath); broker.getIndexController().indexNode(transaction, attrib, lastPath, listener); last.setNode(attrib); return attrib; case Node.COMMENT_NODE: final CommentImpl comment = new CommentImpl(((Comment) child).getData()); comment.setNodeId(newNodeId); comment.setOwnerDocument(owner); // insert the node broker.insertNodeAfter(transaction, last.getNode(), comment); broker.indexNode(transaction, comment, lastPath); last.setNode(comment); return comment; case Node.PROCESSING_INSTRUCTION_NODE: final ProcessingInstructionImpl pi = new ProcessingInstructionImpl(newNodeId, ((ProcessingInstruction) child).getTarget(), ((ProcessingInstruction) child).getData()); pi.setOwnerDocument(owner); //insert the node broker.insertNodeAfter(transaction, last.getNode(), pi); broker.indexNode(transaction, pi, lastPath); last.setNode(pi); return pi; default: throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, "Unknown node type: " + child.getNodeType() + " " + child.getNodeName()); } } catch (final EXistException e) { LOG.warn("Exception while appending node: " + e.getMessage(), e); } finally { if (broker != null) broker.release(); } return null; }
From source file:org.exist.dom.ElementImpl.java
/** * @see org.w3c.dom.Element#getAttribute(java.lang.String) *//*w w w .j a v a2 s .c o m*/ public String getAttribute(String name) { final Attr attr = findAttribute(name); return attr != null ? attr.getValue() : ""; }
From source file:org.exist.dom.ElementImpl.java
/** * @see org.w3c.dom.Element#getAttributeNS(java.lang.String, java.lang.String) *///from w ww. j a va 2 s.c o m public String getAttributeNS(String namespaceURI, String localName) { final Attr attr = findAttribute(new QName(localName, namespaceURI)); return attr != null ? attr.getValue() : ""; //XXX: if not present must return null }
From source file:org.exist.dom.ElementImpl.java
@Deprecated //move as soon as getAttributeNS null issue resolved public String _getAttributeNS(String namespaceURI, String localName) { final Attr attr = findAttribute(new QName(localName, namespaceURI)); return attr != null ? attr.getValue() : null; }
From source file:org.firesoa.common.schema.DOMInitializer.java
private static String getQualifiedName(Document doc, QName qName) { Element rootElement = (Element) doc.getDocumentElement(); if (rootElement != null && !equalStrings(qName.getNamespaceURI(), rootElement.getNamespaceURI())) { // Attr attrTmp = rootElement.getAttributeNodeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, "ns0"); // System.out.println("===========found attrTmp=="+attrTmp); String nsPrefix = null;//from ww w . java2 s.c om nsPrefix = rootElement.lookupPrefix(qName.getNamespaceURI()); if (nsPrefix == null || nsPrefix.trim().equals("")) { int nsNumber = 1; NamedNodeMap attrMap = rootElement.getAttributes(); int length = attrMap.getLength(); for (int i = 0; i < length; i++) { Attr attr = (Attr) attrMap.item(i); String name = attr.getName(); if (name.startsWith(Constants.XMLNS_ATTRIBUTE)) { if (attr.getValue().equals(qName.getNamespaceURI())) { // Namespace? nsPrefix = attr.getLocalName(); break; } nsNumber++; } } if (nsPrefix == null) { nsPrefix = "ns" + nsNumber; } } Attr attr = doc.createAttributeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, Constants.XMLNS_ATTRIBUTE + ":" + nsPrefix); attr.setValue(qName.getNamespaceURI()); rootElement.setAttributeNode(attr); return nsPrefix + ":" + qName.getLocalPart(); } else { return "ns0:" + qName.getLocalPart(); } }
From source file:org.getobjects.appserver.templates.WOxElemBuilder.java
public WOAssociation associationForAttribute(Attr _attr) { if (_attr == null) return null; /* get namespace */ String ns = _attr.getNamespaceURI(); if (ns == null) ns = ""; /* this will get the default */ /* map namespace to Class */ Class assocClass = nsToAssocClass.get(ns); if (assocClass == null) assocClass = nsToAssocClass.get(""); if (assocClass == null) { this.log.error("could not find association class: " + _attr); return null; }// w ww . j a v a 2s.co m /* construct */ WOAssociation assoc = (WOAssociation) NSJavaRuntime.NSAllocateObject(assocClass, String.class, _attr.getValue()); return assoc; }
From source file:org.infoscoop.service.SiteAggregationMenuService.java
private static void buildAuthorizedMenuXml(Element siteNode, StringBuffer buf, boolean noAuth) throws ClassNotFoundException { NodeList childNodes = siteNode.getChildNodes(); Collection childSites = new ArrayList(); Element propertiesNode = null; boolean accessible = true; for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if ("auths".equals(node.getNodeName()) && !noAuth) { accessible = false;/*w ww. j a v a 2 s . c om*/ Element rolesEl = (Element) node; NodeList roles = rolesEl.getElementsByTagName("auth"); for (int j = 0; j < roles.getLength(); j++) { Element auth = (Element) roles.item(j); String type = auth.getAttribute("type"); String regx = auth.getAttribute("regx"); if (RoleUtil.isPermitted(type, regx)) { accessible = true; } } } if ("site".equals(node.getNodeName())) { childSites.add(node); } if ("properties".equals(node.getNodeName())) { propertiesNode = (Element) node; } } if (!accessible) { return; } buf.append("<").append(siteNode.getNodeName()); NamedNodeMap attrs = siteNode.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Attr attr = (Attr) attrs.item(i); buf.append(" ").append(attr.getName()).append("=\"").append(XmlUtil.escapeXmlEntities(attr.getValue())) .append("\""); } buf.append(">\n"); if (propertiesNode != null) { NodeList properties = propertiesNode.getElementsByTagName("property"); buf.append("<properties>\n"); for (int i = 0; i < properties.getLength(); i++) { Element property = (Element) properties.item(i); setElement2Buf(property, buf); } buf.append("</properties>\n"); } for (Iterator it = childSites.iterator(); it.hasNext();) { Element site = (Element) it.next(); buildAuthorizedMenuXml(site, buf, noAuth); } buf.append("</").append(siteNode.getNodeName()).append(">\n"); }
From source file:org.infoscoop.service.SiteAggregationMenuService.java
private static void setElement2Buf(Element xml, StringBuffer buf) { buf.append("<").append(xml.getNodeName()); NamedNodeMap attrs = xml.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Attr attr = (Attr) attrs.item(i); buf.append(" ").append(attr.getName()).append("=\"").append(XmlUtil.escapeXmlEntities(attr.getValue())) .append("\""); }/* w w w . j a v a2 s . c om*/ if (xml.hasChildNodes()) { buf.append(">").append(XmlUtil.escapeXmlEntities(xml.getFirstChild().getNodeValue())).append("</") .append(xml.getNodeName()).append(">"); } else { buf.append("/>\n"); } }
From source file:org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore.java
/** When user preferences are stored in the database for changes made to an incorporated node the node id can not be used because it does not represent a row in the up_layout_struct table for the user. The plfid must be used. Null will never be returned unless the layout or processing has really been screwed up. This is because changes made to the user prefs calls UserPrefsHandler which generates a shadow node in the db and sets the plfid of that node into the corresponding node in the PLF prior to the call to update the user prefs in the db. */// ww w . j a va 2s. c o m private String getPlfId(Document PLF, String incdId) { Element element = null; try { final XPathFactory fac = XPathFactory.newInstance(); final XPath xp = fac.newXPath(); element = (Element) xp.evaluate("//*[@ID = '" + incdId + "']", PLF, XPathConstants.NODE); } catch (final XPathExpressionException xpee) { throw new RuntimeException(xpee); } if (element == null) { this.log.warn("The specified folderId was not found in the user's PLF: " + incdId); return null; } final Attr attr = element.getAttributeNode(Constants.ATT_PLF_ID); if (attr == null) { return null; } return attr.getValue(); }
From source file:org.jbpm.bpel.xml.BpelReader.java
public Boolean readTBoolean(Attr attribute, Boolean defaultValue) { if (attribute == null) return defaultValue; String text = attribute.getValue(); return BpelConstants.YES.equals(text) ? Boolean.TRUE : BpelConstants.NO.equals(text) ? Boolean.FALSE : defaultValue; }