List of usage examples for org.w3c.dom Element getNodeName
public String getNodeName();
From source file:com.opengamma.web.bundle.BundleParser.java
private boolean isValidRootElement(Element rootElement) { if (rootElement.getNodeName().equals("uiResourceConfig")) { return true; }/* ww w . j ava 2 s.c o m*/ throw new OpenGammaRuntimeException( "parsing bundle XML : invalid root element " + rootElement.getNodeName()); }
From source file:com.k42b3.kadabra.FileMap.java
private Element findPath(Element parent, String path) { String name;//from w ww. j a va2s.c o m path = path.trim(); if (!path.isEmpty() && path.charAt(0) == '/') { path = path.substring(1); } if (path.indexOf('/') != -1) { name = path.substring(0, path.indexOf('/')); path = path.substring(path.indexOf('/') + 1); } else { name = path; path = null; } if (name.isEmpty() || name.equals(".")) { return parent; } NodeList list = parent.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { if (list.item(i) instanceof Element) { Element el = (Element) list.item(i); if (el.getNodeName().equals("dir") && el.getAttribute("name").equals(name)) { if (path != null) { return findPath(el, path); } else { return el; } } } } return null; }
From source file:com.k42b3.kadabra.FileMap.java
public Item[] getFiles(String path) { Element dir = this.findPath(doc.getDocumentElement(), path); if (dir != null) { NodeList childs = dir.getChildNodes(); int len = 0; for (int i = 0; i < childs.getLength(); i++) { if (childs.item(i) instanceof Element) { len++;//from ww w.ja v a 2 s . co m } } Item[] items = new Item[len]; int c = 0; for (int i = 0; i < childs.getLength(); i++) { if (childs.item(i) instanceof Element) { Element el = (Element) childs.item(i); if (el.getNodeName().equals("dir")) { items[c] = new Item(el.getAttribute("name"), Item.DIRECTORY); } if (el.getNodeName().equals("file")) { items[c] = new Item(el.getAttribute("name"), Item.FILE, el.getAttribute("md5")); } c++; } } return items; } else { return null; } }
From source file:org.apromore.plugin.deployment.yawl.YAWLEngineClient.java
private Node getYAWLMessage(final String response) throws DeploymentException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try {//from ww w.j av a 2s .com DocumentBuilder db = dbf.newDocumentBuilder(); Element message = db.parse(new InputSource(new StringReader(response))).getDocumentElement(); if (message.getNodeName().equals("response")) { return message.getFirstChild(); } else { throw new DeploymentException("Could not talk to YAWL engine. Invalid respone: " + response); } } catch (SAXException | IOException | ParserConfigurationException e) { throw new DeploymentException("Could not talk to YAWL engine.", e); } }
From source file:com.microsoft.tfs.core.credentials.internal.CachedCredentialsSerializer.java
/** * {@inheritDoc}//from w ww. ja v a 2s. c om */ @Override protected Object createComponentFromDocument(final Document document) { final Element root = document.getDocumentElement(); if (!CREDENTIALS_CACHE_ELEMENT_NAME.equals(root.getNodeName())) { throw new RuntimeException(MessageFormat.format("Unexpected root element {0}", root.getNodeName())); //$NON-NLS-1$ } int schemaVersion = -1; final String sSchemaVersion = root.getAttribute(VERSION_ATTRIBUTE_NAME); if (sSchemaVersion != null && sSchemaVersion.length() > 0) { try { schemaVersion = Integer.parseInt(sSchemaVersion); } catch (final NumberFormatException ex) { // ignore } } final Map<URI, CachedCredentials> credentialsMap = PersistenceStoreCredentialsManager.newMap(); final Element[] credentialsElements = DOMUtils.getChildElements(root, CREDENTIALS_ELEMENT_NAME); for (int i = 0; i < credentialsElements.length; i++) { final CachedCredentials credentials = deserializeCredentials(credentialsElements[i], schemaVersion); if (credentials == null) { continue; } credentialsMap.put(credentials.getURI(), credentials); } return credentialsMap; }
From source file:com.google.api.ads.adwords.awreporting.util.MediaReplacedElementFactory.java
/** * @see org.xhtmlrenderer.extend.ReplacedElementFactory * #createReplacedElement(org.xhtmlrenderer.layout.LayoutContext, * org.xhtmlrenderer.render.BlockBox, org.xhtmlrenderer.extend.UserAgentCallback, int, int) *//*from w w w. j a v a2 s . c o m*/ @Override public ReplacedElement createReplacedElement(LayoutContext layoutContext, BlockBox blockBox, UserAgentCallback userAgentCallback, int cssWidth, int cssHeight) { Element element = blockBox.getElement(); if (element == null) { return null; } String nodeName = element.getNodeName(); String className = element.getAttribute("class"); // Replace any <div class="media" data-src="image.png" /> with the // binary data of `image.png` into the PDF. if ("div".equals(nodeName) && className.startsWith("media")) { if (!element.hasAttribute("data-src")) { throw new RuntimeException("An element with class `media` is missing a `data-src` " + "attribute indicating the media file."); } InputStream input = null; String dataSrc = element.getAttribute("data-src"); try { if (dataSrc.startsWith("http")) { input = new URL(dataSrc).openStream(); } else if (dataSrc.startsWith("data:image") && dataSrc.contains("base64")) { byte[] image = Base64.decode(dataSrc.split(",")[1]); input = new ByteArrayInputStream(image); } else { input = new FileInputStream(dataSrc); } final byte[] bytes = IOUtils.toByteArray(input); final Image image = Image.getInstance(bytes); final FSImage fsImage = new ITextFSImage(image); if (fsImage != null) { if ((cssWidth != -1) || (cssHeight != -1)) { fsImage.scale(cssWidth, cssHeight); } return new ITextImageElement(fsImage); } } catch (Exception e) { throw new RuntimeException("There was a problem trying to read a template embedded graphic.", e); } finally { IOUtils.closeQuietly(input); } } return this.superFactory.createReplacedElement(layoutContext, blockBox, userAgentCallback, cssWidth, cssHeight); }
From source file:com.opengamma.web.bundle.BundleParser.java
private void addToManager(Element element) { String idAttr = element.getAttribute(ID_ATTR); Bundle bundle = new Bundle(idAttr); NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) node; if (childElement.getNodeName().equals(BUNDLE_ELEMENT)) { processRefBundle(bundle, childElement); }/*from w w w .j av a2 s . c o m*/ if (childElement.getNodeName().equals(FRAGMENT_ELEMENT)) { processFragment(bundle, childElement); } } } _bundleManager.addBundle(bundle); }
From source file:eu.scenari.gephi.importer.ScenariConnector.java
public boolean initConnection() { try {//from w ww.j av a2s .co m String vXmlDocument = sendRequest(GET_WSP_LIST); Document vDoc = ImportUtils.getXMLDocument(new ByteArrayInputStream(vXmlDocument.getBytes())); Element vRootElement = vDoc.getDocumentElement(); NodeList vNodeList = vRootElement.getChildNodes(); fWorkspacesCodes = new ArrayList<String>(); fWorkspacesLabels = new ArrayList<String>(); for (int i = 0; i < vNodeList.getLength(); i++) { if (vNodeList.item(i).getNodeType() == Node.ELEMENT_NODE) { Element vElement = (Element) vNodeList.item(i); if (vElement.getNodeName() != null) { if (vElement.getNodeName().equals("wspProviderProperties")) { if (vElement.getAttributes().getNamedItem("backEnd").getNodeValue().equals("fs")) fOdbBackend = false; else fOdbBackend = true; } if (vElement.getNodeName().equals("wsp")) { String vCode = vElement.getAttributes().getNamedItem("code").getNodeValue(); String vLabel; if (!fOdbBackend) vLabel = new String(vCode); else vLabel = vElement.getAttributes().getNamedItem("title").getNodeValue(); vLabel += " (" + vElement.getAttributes().getNamedItem("wspTypes").getNodeValue().split(" ")[0] + ")"; fWorkspacesCodes.add(vCode); fWorkspacesLabels.add(vLabel); } } } } return true; } catch (Exception ex) { //Exceptions.printStackTrace(ex); return false; } }
From source file:com.msopentech.odatajclient.engine.data.impl.v3.AtomDeserializer.java
public AtomFeed feed(final Element input) { if (!ODataConstants.ATOM_ELEM_FEED.equals(input.getNodeName())) { return null; }/*from w w w .ja v a 2 s.co m*/ final AtomFeed feed = new AtomFeed(); common(input, feed); final List<Element> entries = XMLUtils.getChildElements(input, ODataConstants.ATOM_ELEM_ENTRY); for (Element entry : entries) { feed.addEntry(entry(entry)); } final List<Element> links = XMLUtils.getChildElements(input, ODataConstants.ATOM_ELEM_LINK); for (Element link : links) { if (ODataConstants.NEXT_LINK_REL.equals(link.getAttribute(ODataConstants.ATTR_REL))) { feed.setNext(URI.create(link.getAttribute(ODataConstants.ATTR_HREF))); } } final List<Element> counts = XMLUtils.getChildElements(input, ODataConstants.ATOM_ATTR_COUNT); if (!counts.isEmpty()) { try { feed.setCount(Integer.parseInt(counts.get(0).getTextContent())); } catch (Exception e) { LOG.error("Could not parse $inlinecount {}", counts.get(0).getTextContent(), e); } } return feed; }
From source file:com.microsoft.tfs.core.util.serverlist.internal.ServerListSerializer.java
/** * {@inheritDoc}/*from w w w.ja v a 2 s . c o m*/ */ @Override protected Object createComponentFromDocument(final Document document) { final Element root = document.getDocumentElement(); if (!SERVERS_ELEMENT_NAME.equals(root.getNodeName())) { throw new RuntimeException(MessageFormat.format("Unexpected root element {0}", root.getNodeName())); //$NON-NLS-1$ } final String sSchemaVersion = root.getAttribute(VERSION_ATTRIBUTE_NAME); if (sSchemaVersion != null && sSchemaVersion.length() > 0) { try { Integer.parseInt(sSchemaVersion); } catch (final NumberFormatException ex) { // ignore } } final ServerList serverList = new ServerList(); final Element[] serverElements = DOMUtils.getChildElements(root, SERVER_ELEMENT_NAME); for (int i = 0; i < serverElements.length; i++) { final String serverName = getName(serverElements[i].getAttribute(NAME_ATTRIBUTE_NAME)); final ServerListEntryType serverType = getType(serverElements[i].getAttribute(TYPE_ATTRIBUTE_NAME)); final URI serverUri = getURI(serverElements[i].getAttribute(URI_ATTRIBUTE_NAME)); if (serverName == null || serverType == null || serverUri == null) { continue; } final ServerListConfigurationEntry server = new ServerListConfigurationEntry(serverName, serverType, serverUri); final Element[] collectionsElements = DOMUtils.getChildElements(serverElements[i], COLLECTIONS_ELEMENT_NAME); for (int j = 0; j < collectionsElements.length; j++) { final Element[] collectionElements = DOMUtils.getChildElements(serverElements[i], COLLECTION_ELEMENT_NAME); for (int k = 0; k < collectionElements.length; k++) { final String collectionName = getName(collectionElements[k].getAttribute(NAME_ATTRIBUTE_NAME)); final Boolean collectionOffline = getOffline( collectionElements[k].getAttribute(OFFLINE_ATTRIBUTE_NAME)); final ServerListEntryType collectionType = getType( collectionElements[k].getAttribute(TYPE_ATTRIBUTE_NAME)); final URI collectionUri = getURI(collectionElements[k].getAttribute(URI_ATTRIBUTE_NAME)); if (collectionName == null || collectionType == null || collectionUri == null) { continue; } final ServerListCollectionEntry collection = new ServerListCollectionEntry(collectionName, collectionType, collectionUri, collectionOffline); server.getCollections().add(collection); } } serverList.add(server); } return serverList; }