List of usage examples for org.w3c.dom Element getAttribute
public String getAttribute(String name);
From source file:cz.incad.kramerius.utils.solr.SolrUtils.java
public static String disectPid(Element topElem) throws XPathExpressionException { synchronized (topElem.getOwnerDocument()) { Element foundElement = XMLUtils.findElement(topElem, new XMLUtils.ElementsFilter() { @Override//from ww w . j a v a2 s .c o m public boolean acceptElement(Element element) { return (element.getNodeName().equals("str") && element.getAttribute("name") != null && element.getAttribute("name").equals("PID")); } }); if (foundElement != null) { return foundElement.getTextContent().trim(); } else return null; } }
From source file:com.cburch.draw.shapes.SvgReader.java
private static AbstractCanvasObject createPolyline(Element elt) { return new Poly(false, parsePoints(elt.getAttribute("points"))); }
From source file:com.cburch.draw.shapes.SvgReader.java
private static AbstractCanvasObject createRectangle(Element elt) { int x = Integer.parseInt(elt.getAttribute("x")); int y = Integer.parseInt(elt.getAttribute("y")); int w = Integer.parseInt(elt.getAttribute("width")); int h = Integer.parseInt(elt.getAttribute("height")); if (elt.hasAttribute("rx")) { AbstractCanvasObject ret = new RoundRectangle(x, y, w, h); int rx = Integer.parseInt(elt.getAttribute("rx")); ret.setValue(DrawAttr.CORNER_RADIUS, Integer.valueOf(rx)); return ret; } else {//from w w w .java2 s . c o m return new Rectangle(x, y, w, h); } }
From source file:cz.incad.kramerius.rest.api.k5.client.utils.SOLRUtils.java
public static <T> List<T> array(final Element doc, final String attributeName, Class<T> clz) { synchronized (doc.getOwnerDocument()) { List<T> ret = new ArrayList<T>(); List<Element> elms = XMLUtils.getElements(doc, new XMLUtils.ElementsFilter() { @Override/* ww w. j a va 2 s .co m*/ public boolean acceptElement(Element element) { return (element.getNodeName().equals("arr") && element.hasAttribute("name") && element.getAttribute("name").equals(attributeName)); } }); for (Element e : elms) { ret.add(value(e.getTextContent(), clz)); } return ret; } }
From source file:com.ibm.rpe.web.service.docgen.impl.GenerateBaseTemplate.java
private static void createTemplateXmls(String inputFile, BaseTemplateInput data) throws ParserConfigurationException, SAXException, IOException { String directory = (new File(inputFile)).getParent() + File.separator; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; builder = factory.newDocumentBuilder(); Document document = builder.parse(new File(inputFile)); NodeList nlist = document.getElementsByTagName("element"); if (nlist != null && nlist.getLength() > 0) { for (int i = 0; i < nlist.getLength(); i++) { Node node = nlist.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element ele = (Element) node; String attr = ele.getAttribute("id"); if (attr.contentEquals(data.getElementId())) { Node newNode = document.createTextNode(data.getReplacement()); node.getParentNode().insertBefore(newNode, node); try { } catch (Exception e1) { e1.printStackTrace(); }// www.ja va 2s .c om Node removedNode = node.getParentNode().removeChild(node); // System.out.println(nodeToString(removedNode)); String removed = nodeToString(removedNode); removed = replace(removed, data.getReplaceMap()); if (data.isReplaceElementId()) { removed = replaceElementId(removed); } document.normalize(); FileUtils.writeFile(directory + data.getOutputFile(), removed); System.out.println("Removed : " + ((Element) removedNode).getAttribute("id")); try { // prettyPrint(document); } catch (Exception e) { e.printStackTrace(); } break; } } } FileUtils.writeFile(inputFile, transformToString(document)); } }
From source file:com.cburch.draw.shapes.SvgReader.java
private static AbstractCanvasObject createOval(Element elt) { double cx = Double.parseDouble(elt.getAttribute("cx")); double cy = Double.parseDouble(elt.getAttribute("cy")); double rx = Double.parseDouble(elt.getAttribute("rx")); double ry = Double.parseDouble(elt.getAttribute("ry")); int x = (int) Math.round(cx - rx); int y = (int) Math.round(cy - ry); int w = (int) Math.round(rx * 2); int h = (int) Math.round(ry * 2); return new Oval(x, y, w, h); }
From source file:org.jboss.windup.config.spring.namespace.java.SpringNamespaceHandlerUtil.java
public static void setNestedList(BeanDefinitionBuilder beanBuilder, Element bean, String nestedTagName, ParserContext context) {/*from w w w. j a v a 2s .co m*/ BeanDefinition beanDef = beanBuilder.getRawBeanDefinition(); Element test = XmlElementUtil.getChildByTagName(bean, nestedTagName); if (test != null) { if (test.hasAttribute("ref")) { beanBuilder.addPropertyReference(nestedTagName, test.getAttribute("ref")); return; } } Element nestElement = XmlElementUtil.getChildByTagName(bean, nestedTagName); if (nestElement != null) { ManagedList<BeanDefinition> nested = SpringNamespaceHandlerUtil.parseManagedList(beanDef, XmlElementUtil.getChildElements(nestElement), context); beanBuilder.addPropertyValue(nestedTagName, nested); } }
From source file:cz.incad.kramerius.rest.api.k5.client.utils.SOLRUtils.java
public static <T> List<T> narray(final Element doc, final String attributeName, Class<T> clz) { synchronized (doc.getOwnerDocument()) { List<T> ret = new ArrayList<T>(); List<Element> elms = XMLUtils.getElements(doc, new XMLUtils.ElementsFilter() { @Override//from w w w .ja v a2 s.c om public boolean acceptElement(Element element) { return (element.getNodeName().equals("arr") && element.hasAttribute("name") && element.getAttribute("name").equals(attributeName)); } }); if (elms.size() >= 1) { Element parentE = elms.get(0); NodeList chnds = parentE.getChildNodes(); for (int i = 0, ll = chnds.getLength(); i < ll; i++) { Node n = chnds.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { ret.add(value(n.getTextContent(), clz)); } } } return ret; } }
From source file:org.apache.ftpserver.config.spring.SpringUtil.java
/** * Parses a attribute value into an integer. * //from www. j a v a 2 s .co m * @param parent * The element * @param attrName * The attribute name * @return The value * @throws NumberFormatException * If the attribute does not contain a number */ public static int parseInt(final Element parent, final String attrName) { return Integer.parseInt(parent.getAttribute(attrName)); }
From source file:org.apache.ftpserver.config.spring.SpringUtil.java
/** * Return an attribute value as a {@link File} * // ww w . ja v a 2 s . co m * @param parent * The element * @param attrName * The attribute name * @return The file representing the path used in the attribute */ public static File parseFile(final Element parent, final String attrName) { if (StringUtils.hasText(parent.getAttribute(attrName))) { return new File(parent.getAttribute(attrName)); } return null; }