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;
}
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;
}
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;
}
}
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;
}
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;
}
}
Aggregations