Search in sources :

Example 76 with Attr

use of org.w3c.dom.Attr in project jackrabbit by apache.

the class SearchInfo method createFromXml.

/**
     * Create a new <code>SearchInfo</code> from the specifying document
     * retrieved from the request body.
     *
     * @param searchRequest
     * @throws DavException if the root element's name is other than
     * 'searchrequest' or if it does not contain a single child element specifying
     * the query language to be used.
     */
public static SearchInfo createFromXml(Element searchRequest) throws DavException {
    if (searchRequest == null || !XML_SEARCHREQUEST.equals(searchRequest.getLocalName())) {
        log.warn("The root element must be 'searchrequest'.");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    Element first = DomUtil.getFirstChildElement(searchRequest);
    Attr[] nsAttributes = DomUtil.getNamespaceAttributes(searchRequest);
    Map<String, String> namespaces = new HashMap<String, String>();
    for (Attr nsAttribute : nsAttributes) {
        // filter out xmlns namespace and DAV namespace
        if (!IGNORED_NAMESPACES.contains(nsAttribute.getValue())) {
            namespaces.put(nsAttribute.getLocalName(), nsAttribute.getValue());
        }
    }
    SearchInfo sInfo;
    if (first != null) {
        sInfo = new SearchInfo(first.getLocalName(), DomUtil.getNamespace(first), DomUtil.getText(first), namespaces);
    } else {
        log.warn("A single child element is expected with the 'DAV:searchrequest'.");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    Element limit = DomUtil.getChildElement(searchRequest, LIMIT, NAMESPACE);
    if (limit != null) {
        // try to get the value DAV:nresults element
        String nresults = DomUtil.getChildTextTrim(limit, NRESULTS, NAMESPACE);
        if (nresults != null) {
            try {
                sInfo.setNumberResults(Long.valueOf(nresults));
            } catch (NumberFormatException e) {
                log.error("DAV:nresults cannot be parsed into a long -> ignore.");
            }
        }
        // try of an offset is defined within the DAV:limit element.
        String offset = DomUtil.getChildTextTrim(limit, OFFSET, Namespace.EMPTY_NAMESPACE);
        if (offset != null) {
            try {
                sInfo.setOffset(Long.valueOf(offset));
            } catch (NumberFormatException e) {
                log.error("'offset' cannot be parsed into a long -> ignore.");
            }
        }
    }
    return sInfo;
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) Attr(org.w3c.dom.Attr)

Example 77 with Attr

use of org.w3c.dom.Attr in project poi by apache.

the class AbstractWordUtils method canBeMerged.

static boolean canBeMerged(Node node1, Node node2, String requiredTagName) {
    if (node1.getNodeType() != Node.ELEMENT_NODE || node2.getNodeType() != Node.ELEMENT_NODE)
        return false;
    Element element1 = (Element) node1;
    Element element2 = (Element) node2;
    if (!equals(requiredTagName, element1.getTagName()) || !equals(requiredTagName, element2.getTagName()))
        return false;
    NamedNodeMap attributes1 = element1.getAttributes();
    NamedNodeMap attributes2 = element2.getAttributes();
    if (attributes1.getLength() != attributes2.getLength())
        return false;
    for (int i = 0; i < attributes1.getLength(); i++) {
        final Attr attr1 = (Attr) attributes1.item(i);
        final Attr attr2;
        if (isNotEmpty(attr1.getNamespaceURI()))
            attr2 = (Attr) attributes2.getNamedItemNS(attr1.getNamespaceURI(), attr1.getLocalName());
        else
            attr2 = (Attr) attributes2.getNamedItem(attr1.getName());
        if (attr2 == null || !equals(attr1.getTextContent(), attr2.getTextContent()))
            return false;
    }
    return true;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Element(org.w3c.dom.Element) Attr(org.w3c.dom.Attr)

Example 78 with Attr

use of org.w3c.dom.Attr in project cubrid-manager by CUBRID.

the class XMLMemento method getFloat.

/**
	 * @param key String The given key
	 * @return Float
	 * @see IXMLMemento#getFloat(String)
	 */
public Float getFloat(String key) {
    Attr attr = element.getAttributeNode(key);
    if (attr == null) {
        return null;
    }
    String strValue = attr.getValue();
    try {
        return new Float(strValue);
    } catch (NumberFormatException e) {
        return null;
    }
}
Also used : Attr(org.w3c.dom.Attr)

Example 79 with Attr

use of org.w3c.dom.Attr in project cubrid-manager by CUBRID.

the class XMLMemento method getBoolean.

/**
	 * @param key String The give key
	 * @return Boolean
	 * @see IXMLMemento#getBoolean(String)
	 */
public Boolean getBoolean(String key) {
    Attr attr = element.getAttributeNode(key);
    if (attr == null) {
        return false;
    }
    String strValue = attr.getValue();
    if ("true".equalsIgnoreCase(strValue)) {
        return true;
    }
    return false;
}
Also used : Attr(org.w3c.dom.Attr)

Example 80 with Attr

use of org.w3c.dom.Attr in project cubrid-manager by CUBRID.

the class XMLMemento method getInteger.

/**
	 * @param key String The give key
	 * @return Integer
	 * @see IXMLMemento#getInteger(String)
	 */
public Integer getInteger(String key) {
    Attr attr = element.getAttributeNode(key);
    if (attr == null) {
        return null;
    }
    String strValue = attr.getValue();
    try {
        return new Integer(strValue);
    } catch (NumberFormatException e) {
        return null;
    }
}
Also used : Attr(org.w3c.dom.Attr)

Aggregations

Attr (org.w3c.dom.Attr)461 Element (org.w3c.dom.Element)215 NamedNodeMap (org.w3c.dom.NamedNodeMap)194 Node (org.w3c.dom.Node)153 Document (org.w3c.dom.Document)147 NodeList (org.w3c.dom.NodeList)89 ArrayList (java.util.ArrayList)33 DOMException (org.w3c.dom.DOMException)32 QName (javax.xml.namespace.QName)22 HashMap (java.util.HashMap)18 DocumentBuilder (javax.xml.parsers.DocumentBuilder)17 Text (org.w3c.dom.Text)14 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)13 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)10 RubyString (org.jruby.RubyString)10 IOException (java.io.IOException)9 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)8 File (java.io.File)8 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)8 ParseException (java.text.ParseException)6