List of usage examples for org.w3c.dom Element getAttribute
public String getAttribute(String name);
From source file:com.samknows.measurement.schedule.datacollection.LocationDataCollector.java
public static BaseDataCollector parseXml(Element node) { LocationDataCollector c = new LocationDataCollector(); String time = node.getAttribute("time"); c.time = XmlUtils.convertTime(time); String listenerDelay = node.getAttribute("listenerDelay"); c.listenerDelay = XmlUtils.convertTime(listenerDelay); // c.listenerMinDst = Float.valueOf(node.getAttribute("listenerMinDistance")); c.getLastKnown = Boolean.parseBoolean(node.getAttribute("lastKnown")); return c;//from ww w .ja v a 2 s. co m }
From source file:org.apache.smscserver.config.spring.SpringUtil.java
/** * Return an attribute value as an {@link InetAddress} * /*from w w w .j a v a2 s. c o m*/ * @param parent * The element * @param attrName * The attribute name * @return The attribute value parsed into a {@link InetAddress} */ public static InetAddress parseInetAddress(final Element parent, final String attrName) { if (StringUtils.hasText(parent.getAttribute(attrName))) { try { return InetAddress.getByName(parent.getAttribute(attrName)); } catch (UnknownHostException e) { throw new SmscServerConfigurationException("Unknown host", e); } } return null; }
From source file:org.apache.ftpserver.config.spring.SpringUtil.java
/** * Return an attribute value as an {@link InetAddress} * //from w w w .j a v a 2s. co m * @param parent * The element * @param attrName * The attribute name * @return The attribute value parsed into a {@link InetAddress} */ public static InetAddress parseInetAddress(final Element parent, final String attrName) { if (StringUtils.hasText(parent.getAttribute(attrName))) { try { return InetAddress.getByName(parent.getAttribute(attrName)); } catch (UnknownHostException e) { throw new FtpServerConfigurationException("Unknown host", e); } } return null; }
From source file:cz.incad.kramerius.rest.api.k5.client.utils.SOLRUtils.java
public static <T> T value(final Element doc, final String attributeName, Class<T> clz) { if (doc == null) { throw new IllegalArgumentException("element must not be null"); }//from w ww .j a v a 2 s. com synchronized (doc.getOwnerDocument()) { final String expectedTypeName = SOLR_TYPE_NAMES.get(clz); List<Element> elms = XMLUtils.getElements(doc, new XMLUtils.ElementsFilter() { @Override public boolean acceptElement(Element element) { return (element.getNodeName().equals(expectedTypeName) && element.hasAttribute("name") && element.getAttribute("name").equals(attributeName)); } }); Object obj = elms.isEmpty() ? null : elms.get(0).getTextContent(); if (obj != null) return value(obj.toString(), clz); else return null; } }
From source file:com.cburch.draw.shapes.SvgReader.java
private static AbstractCanvasObject createText(Element elt) { int x = Integer.parseInt(elt.getAttribute("x")); int y = Integer.parseInt(elt.getAttribute("y")); String text = elt.getTextContent(); Text ret = new Text(x, y, text); String fontFamily = elt.getAttribute("font-family"); String fontStyle = elt.getAttribute("font-style"); String fontWeight = elt.getAttribute("font-weight"); String fontSize = elt.getAttribute("font-size"); int styleFlags = 0; if (fontStyle.equals("italic")) styleFlags |= Font.ITALIC; if (fontWeight.equals("bold")) styleFlags |= Font.BOLD;/*from w ww . j a va 2s.co m*/ int size = Integer.parseInt(fontSize); ret.setValue(DrawAttr.FONT, new Font(fontFamily, styleFlags, size)); String alignStr = elt.getAttribute("text-anchor"); AttributeOption halign; if (alignStr.equals("start")) { halign = DrawAttr.ALIGN_LEFT; } else if (alignStr.equals("end")) { halign = DrawAttr.ALIGN_RIGHT; } else { halign = DrawAttr.ALIGN_CENTER; } ret.setValue(DrawAttr.ALIGNMENT, halign); // fill color is handled after we return return ret; }
From source file:fr.aliasource.webmail.server.proxy.client.http.DOMUtils.java
/** * Renvoie sous la forme d'un tableau la valeur des attributs donns pour * toutes les occurences d'un lment donne dans le dom * /*from w w w. j av a 2 s .c o m*/ * <code> * <toto> * <titi id="a" val="ba"/> * <titi id="b" val="bb"/> * </toto> * </code> * * et getAttributes(<toto>, "titi", { "id", "val" }) renvoie { { "a", * "ba" } { "b", "bb" } } * * @param root * @param elementName * @param wantedAttributes * @return */ public static String[][] getAttributes(Element root, String elementName, String[] wantedAttributes) { NodeList list = root.getElementsByTagName(elementName); String[][] ret = new String[list.getLength()][wantedAttributes.length]; for (int i = 0; i < list.getLength(); i++) { Element elem = (Element) list.item(i); for (int j = 0; j < wantedAttributes.length; j++) { ret[i][j] = elem.getAttribute(wantedAttributes[j]); } } return ret; }
From source file:com.twinsoft.convertigo.engine.AttachmentManager.java
static public AttachmentDetails getAttachment(Element eAttachment) { try {/*from w w w .j av a 2s.co m*/ if ("attachment".equals(eAttachment.getTagName()) && "attachment".equals(eAttachment.getAttribute("type"))) { String attr; final String name = eAttachment.getAttribute("name"); final String contentType = eAttachment.getAttribute("content-type"); final byte[][] data = new byte[1][]; if ((attr = eAttachment.getAttribute("local-url")) != null && attr.length() > 0) { FileInputStream fis = null; try { fis = new FileInputStream(attr); fis.read(data[0] = new byte[fis.available()]); } finally { if (fis != null) fis.close(); } } else if ((attr = eAttachment.getAttribute("encoding")) != null && attr.length() > 0) { if ("base64".equals(attr)) { data[0] = Base64.decodeBase64(eAttachment.getTextContent()); } } if (data[0] != null) { return new AttachmentDetails() { public byte[] getData() { return data[0]; } public String getName() { return name; } public String getContentType() { return contentType; } }; } } } catch (Exception e) { Engine.logEngine.error("failed to make AttachmentDetails", e); } return null; }
From source file:Main.java
private static List<Element> getJsModulesForSpecificPlatform(Document doc, String platformName) { List<Element> suitableJsModules = new ArrayList<Element>(); Element documentElement = doc.getDocumentElement(); NodeList childNodes = documentElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (isJsModuleElement(element)) { // Common js-module for all types of projects (ios, android, wp8 etc.) suitableJsModules.add(element); } else if (isPlatformElement(element) && (element.getAttribute(ATTRIBUTE_NAME) != null) && element.getAttribute(ATTRIBUTE_NAME).equals(platformName)) { // platform-specific js-module List<Element> androidJsModules = getChildElementsByName(element, TAG_JS_MODULE); suitableJsModules.addAll(androidJsModules); }/*from ww w . jav a2 s.co m*/ } } return suitableJsModules; }
From source file:Main.java
/** * Get one element by tag name and attribute value. * @return An Element object or null if no matching element. *///from w ww.j a v a 2 s.c om //// // METHOD: getOneElement //// public static Element getOneElement(Element inParentElement, String inTagName, String inAttrName, String inAttrValue) { Element retElement = null; Element wkElement = null; try { NodeList wkNodeList = inParentElement.getElementsByTagName(inTagName); for (int ix = 0; ix < wkNodeList.getLength(); ++ix) { wkElement = (Element) wkNodeList.item(ix); if (inAttrValue.equals(wkElement.getAttribute(inAttrName))) { retElement = wkElement; break; } } } catch (Exception excp) { ; } return retElement; }
From source file:org.apache.ftpserver.config.spring.SpringUtil.java
/** * Parses a attribute value into an integer. If the attribute is missing or * has no content, a default value is returned * /*from w w w .java 2 s. com*/ * @param parent * The element * @param attrName * The attribute name * @param defaultValue * The default value * @return The value, or the default value */ public static int parseInt(final Element parent, final String attrName, final int defaultValue) { if (StringUtils.hasText(parent.getAttribute(attrName))) { return Integer.parseInt(parent.getAttribute(attrName)); } return defaultValue; }