List of usage examples for org.w3c.dom Element getAttribute
public String getAttribute(String name);
From source file:biz.webgate.tools.urlfetcher.URLFetcher.java
private static void check4OpenGraphTags(NodeList ndlMeta, PageAnalyse analyse) { for (int nCounter = 0; nCounter < ndlMeta.getLength(); nCounter++) { Element elMeta = (Element) ndlMeta.item(nCounter); // Test if property is available if (elMeta.hasAttribute("property")) { String strProperty = elMeta.getAttribute("property"); // CHECK if we have a OpenGraphProperty if (strProperty.toLowerCase().startsWith("og:")) { analyse.addOpenGraph(strProperty, elMeta.getAttribute("content")); }/*from ww w . j a v a2 s .c o m*/ if ("og:image".equalsIgnoreCase(strProperty)) { analyse.addImageURL(elMeta.getAttribute("content")); } if ("og:title".equalsIgnoreCase(strProperty)) { analyse.setTitle(elMeta.getAttribute("content")); } if ("og:description".equalsIgnoreCase(strProperty)) { analyse.setDescription(elMeta.getAttribute("content")); } } } }
From source file:org.apache.ftpserver.config.spring.SpringUtil.java
/** * Parses a attribute value into a boolean. If the attribute is missing or * has no content, a default value is returned * /*from w ww.j av a 2 s. co m*/ * @param parent * The element * @param attrName * The attribute name * @param defaultValue * The default value * @return The value, or the default value */ public static boolean parseBoolean(final Element parent, final String attrName, final boolean defaultValue) { if (StringUtils.hasText(parent.getAttribute(attrName))) { return Boolean.parseBoolean(parent.getAttribute(attrName)); } return defaultValue; }
From source file:filehandling.FilePreprocessor.java
public static List<FileData> extractMDFilesFromXMLEmbedding(byte[] bytes, String basename, String extension) { List<FileData> returnList = new ArrayList<FileData>(); try {/* w w w .j a v a 2 s . c om*/ FileUtils.writeByteArrayToFile(new File("/tmp/debugData/instreamBeforeExtraction.xml"), bytes); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder dBuilder = dbf.newDocumentBuilder(); Document doc = dBuilder.parse(new InputSource(new ByteArrayInputStream(bytes))); if (Master.DEBUG_LEVEL > Master.LOW) { System.out.println("Root element: " + doc.getDocumentElement().getNodeName()); } NodeList entryElements = doc.getElementsByTagNameNS("http://www.w3.org/2005/Atom", "entry"); for (int i = 0; i < entryElements.getLength(); i++) { Element entryElement = (Element) entryElements.item(i); FileData fd = null; /* * First try to find a <link> element pointing to Metadata as * this should be included by default */ if (fd == null) { NodeList linkElements = entryElement.getElementsByTagNameNS("http://www.w3.org/2005/Atom", "link"); String iso19139Link = null; String iso19139_2Link = null; for (int j = 0; j < linkElements.getLength(); j++) { Element linkElement = (Element) linkElements.item(j); String relAttrValue = linkElement.getAttribute("rel"); String typeAttributeValue = linkElement.getAttribute("type"); if (relAttrValue != null && relAttrValue.equals("alternate") && typeAttributeValue != null) { switch (typeAttributeValue) { case "application/vnd.iso.19139+xml": iso19139Link = linkElement.getAttribute("href"); break; case "application/vnd.iso.19139-2+xml": iso19139_2Link = linkElement.getAttribute("href"); break; } } } /* iso19139-2 gets priority */ String url = iso19139_2Link != null ? iso19139_2Link : iso19139Link; if (url != null) { try (InputStream is = FileFetcher.fetchFileFromUrl(url)) { Document doc2 = dBuilder.parse(new InputSource(is)); fd = processMDList(doc2.getDocumentElement(), extension, url); } } } /* * Fallback to finding Metadata embedded directly in <entry>. * There will be either MI_Metadata or MD_Metadata, not both */ if (fd == null) { fd = processMDList(entryElement.getElementsByTagName("gmi:MI_Metadata").item(0), extension, null); } if (fd == null) { fd = processMDList(entryElement.getElementsByTagName("gmd:MD_Metadata").item(0), extension, null); } if (fd != null) { returnList.add(fd); } } } catch (Exception e) { // TODO: handle exception if (Master.DEBUG_LEVEL > Master.LOW) System.out.println(e.getLocalizedMessage()); GUIrefs.displayAlert("Error in FilePreprocessor.extractMDFilesFromXMLEmbedding" + StringUtilities.escapeQuotes(e.getMessage())); } return returnList; }
From source file:org.apache.ftpserver.config.spring.SpringUtil.java
/** * Return the string value of an attribute, or null if the attribute is * missing// w ww . ja v a 2 s.com * * @param parent * The element * @param attrName * The attribute name * @return The attribute string value */ public static String parseString(final Element parent, final String attrName) { if (parent.hasAttribute(attrName)) { return parent.getAttribute(attrName); } else { return null; } }
From source file:es.usc.citius.composit.transformer.wsc.wscxml.WSCTransformer.java
public static URL obtainXmlBaseUri(InputStream owlStream) throws IOException, XPathExpressionException, ParserConfigurationException, SAXException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); // Detect namespaces dbf.setNamespaceAware(true);//from w w w . jav a2 s.c o m DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(owlStream); // Obtain the document element where the xml:base is Element rootElement = document.getDocumentElement(); String baseUri = rootElement.getAttribute("xml:base"); return new URL(baseUri); }
From source file:com.concursive.connect.web.modules.admin.utils.AdminPortalUtils.java
public static DashboardPage retrieveDashboardPage(AdminPortalBean portalBean) throws Exception { // Use the admin-portal-config.xml to determine the dashboard page to use for the current url URL resource = AdminPortalUtils.class.getResource("/portal/admin-portal-config.xml"); LOG.debug("portal config file: " + resource.toString()); XMLUtils library = new XMLUtils(resource); // The nodes are listed under the <module> tag Element portal = XMLUtils.getFirstChild(library.getDocumentElement(), "portal", "type", "controller"); String moduleLayout = null;/* w w w . j ava2 s . c o m*/ String page = null; // Look through the modules NodeList moduleNodeList = portal.getElementsByTagName("module"); for (int i = 0; i < moduleNodeList.getLength(); i++) { Node thisModule = moduleNodeList.item(i); NodeList urlNodeList = ((Element) thisModule).getElementsByTagName("url"); for (int j = 0; j < urlNodeList.getLength(); j++) { Element urlElement = (Element) urlNodeList.item(j); // Construct a AdminPortalURL and add to the list for retrieving String name = urlElement.getAttribute("name"); // <url name="/show" object="/" page="default"/> if (name.equals("/" + portalBean.getAction())) { String object = urlElement.getAttribute("object"); if (object.equals("/" + portalBean.getDomainObject())) { // Set the module for tab highlighting portalBean.setModule(((Element) thisModule).getAttribute("name")); // Set the page for looking up page = urlElement.getAttribute("page"); // Set the layout filename to find the referenced page moduleLayout = ((Element) thisModule).getAttribute("layout"); break; } } } } URL moduleResource = AdminPortalUtils.class.getResource("/portal/" + moduleLayout); LOG.debug("module config file: " + moduleResource.toString()); XMLUtils module = new XMLUtils(moduleResource); Element moduleElement = XMLUtils.getFirstChild(module.getDocumentElement(), "controller"); NodeList pageNodeList = moduleElement.getElementsByTagName("page"); if (pageNodeList.getLength() == 0) { LOG.warn("No pages found in moduleLayout: " + moduleLayout); } for (int j = 0; j < pageNodeList.getLength(); j++) { Node thisPage = pageNodeList.item(j); String pageName = ((Element) thisPage).getAttribute("name"); if (pageName.equals(page)) { LOG.debug("Found page " + pageName); // Find a portal template to use LOG.debug("Trying a specific portal: " + page); DashboardPage dashboardPage = DashboardUtils.loadDashboardPage( DashboardTemplateList.TYPE_CONTROLLER, (portalBean.isPopup() ? page + "-popup" : page), moduleLayout); if (dashboardPage == null) { LOG.warn("Page not found: " + page); return null; } return dashboardPage; } } return null; }
From source file:DOMUtils.java
public static Element getElementByID(Element el, String id) { if (el == null) return null; String thisId = el.getAttribute("id"); if (id.equals(thisId)) return el; NodeList list = el.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node instanceof Element) { Element ret = getElementByID((Element) node, id); if (ret != null) return ret; }/*www . j av a2s . co m*/ } return null; }
From source file:org.apache.ftpserver.config.spring.SpringUtil.java
/** * Return an attribute value after checking it is a valid {@link InetAddress} * /*from www . ja v a 2 s . c o m*/ * @param parent * The element * @param attrName * The attribute name * @return The attribute string value. */ public static String parseStringFromInetAddress(final Element parent, final String attrName) { if (parseInetAddress(parent, attrName) != null) { return parent.getAttribute(attrName); } return null; }
From source file:com.karlchu.mo.web.sitemesh.MyConfigLoader.java
private static String getAttribute(Element element, String name) { if (element != null && element.getAttribute(name) != null && element.getAttribute(name).trim() != "") { return element.getAttribute(name).trim(); } else {//w w w. ja va 2 s .c o m return null; } }
From source file:com.cburch.draw.shapes.SvgReader.java
private static AbstractCanvasObject createPath(Element elt) { Matcher patt = PATH_REGEX.matcher(elt.getAttribute("d")); List<String> tokens = new ArrayList<String>(); int type = -1; // -1 error, 0 start, 1 curve, 2 polyline while (patt.find()) { String token = patt.group(); tokens.add(token);//from w ww .j av a 2s.co m if (Character.isLetter(token.charAt(0))) { switch (token.charAt(0)) { case 'M': if (type == -1) type = 0; else type = -1; break; case 'Q': case 'q': if (type == 0) type = 1; else type = -1; break; /* not supported case 'L': case 'l': case 'H': case 'h': case 'V': case 'v': if (type == 0 || type == 2) type = 2; else type = -1; break; */ default: type = -1; } if (type == -1) { throw new NumberFormatException("Unrecognized path command '" + token.charAt(0) + "'"); } } } if (type == 1) { if (tokens.size() == 8 && tokens.get(0).equals("M") && tokens.get(3).toUpperCase().equals("Q")) { int x0 = Integer.parseInt(tokens.get(1)); int y0 = Integer.parseInt(tokens.get(2)); int x1 = Integer.parseInt(tokens.get(4)); int y1 = Integer.parseInt(tokens.get(5)); int x2 = Integer.parseInt(tokens.get(6)); int y2 = Integer.parseInt(tokens.get(7)); if (tokens.get(3).equals("q")) { x1 += x0; y1 += y0; x2 += x0; y2 += y0; } Location e0 = Location.create(x0, y0); Location e1 = Location.create(x2, y2); Location ct = Location.create(x1, y1); return new Curve(e0, e1, ct); } else { throw new NumberFormatException("Unexpected format for curve"); } } else { throw new NumberFormatException("Unrecognized path"); } }