List of usage examples for org.w3c.dom Document getChildNodes
public NodeList getChildNodes();
NodeList
that contains all children of this node. From source file:org.ecoinformatics.seek.datasource.darwincore.DarwinCoreSchema.java
public void complete(DataCacheObject item) { try {//from w w w .j a v a 2 s . com if (!item.isReady()) { // TODO : proper error handling. } Document dom = null; try { dom = EcogridUtils.readXMLFile2DOM(item.getAbsoluteFileName()); if (dom == null) { // TODO: proper error handling return; } } catch (Exception e) { log.error("Exception occurred while parsing schema", e); return; } // EcogridUtils.printNode(dom, 0); Node schemaNode = null; StringBuffer nameStrBuf = new StringBuffer(); StringBuffer nameSpaceStrBuf = new StringBuffer(); NodeList list = dom.getChildNodes(); if (list != null) { for (int i = 0; i < list.getLength(); i++) { Node child = list.item(i); if (child != null) { EcogridUtils.parseForNameAndNamespace(child.getNodeName(), nameStrBuf, nameSpaceStrBuf); if (nameStrBuf.toString().equals("schema")) { schemaNode = child; break; } } } } if (schemaNode == null) return; mSchemaDef = new DSSchemaDef(); DSTableDef tableDef = new DSTableDef("DarwinCode"); mSchemaDef.addTable(tableDef); // XXX should substitute this later with XSLT transform for easier // processing String elementName = nameSpaceStrBuf.length() > 0 ? nameSpaceStrBuf.toString() + ":element" : "element"; EcogridUtilsNamedNodeIterator iter = new EcogridUtilsNamedNodeIterator(schemaNode, elementName); while (iter.hasMoreNodes()) { Node elementNode = iter.nextNode(); String name = EcogridUtils.findAttrValue(elementNode, "name"); StringBuffer nameSB = new StringBuffer(); StringBuffer nsSB = new StringBuffer(); EcogridUtils.parseForNameAndNamespace(name, nameSB, nsSB); // System.out.println("nameSB: "+nameSB); StringBuffer typeSB = new StringBuffer(); StringBuffer typeNSSB = new StringBuffer(); String type = EcogridUtils.findAttrValue(elementNode, "type"); if (type == null) { String restrictionName = nameSpaceStrBuf.length() > 0 ? nameSpaceStrBuf.toString() + ":restriction" : "restriction"; Node restriction = EcogridUtils.findNode(elementNode, restrictionName); if (restriction != null) { type = EcogridUtils.findAttrValue(restriction, "base"); } } EcogridUtils.parseForNameAndNamespace(type, typeSB, typeNSSB); // System.out.println("typeSB: "+typeSB); if (nameSB.length() > 0 && typeSB.length() > 0) { String keplerType = (String) mXSD2KeplerHashtable.get(typeSB.toString()); if (keplerType == null) { keplerType = typeSB.toString(); log.error("Missing a Mapping from XSD [" + typeSB.toString() + "] to Kepler type."); } tableDef.addField(nameSB.toString(), keplerType, null); mFieldNameToType.put(nameSB.toString(), keplerType); } else { // XXX // System.err.println("["+nameSB.toString()+"]["+typeSB.toString()+"]"); } } // XXX // System.out.println(DBSchemaParserEmitter.emitXML(mSchemaDef)); } finally { mFinished.release(); } }
From source file:org.eshark.xmlprog.cache.ClassCache.java
public void loadFromXML(File aXMLFile) throws XMLProgFormatException { try {/*from w ww . j ava2s . co m*/ DocumentBuilder lDocumentBuilder = getDocumentBuilder(); lDocumentBuilder.setEntityResolver(new Resolver()); // For XML Document lXMLDocument = null; if (aXMLFile == null) lXMLDocument = lDocumentBuilder.parse(new File(FILE_PATH + "\\xmls", FILE_NAME)); else lXMLDocument = lDocumentBuilder.parse(aXMLFile); // normalize the document lXMLDocument.getDocumentElement().normalize(); // Read the XML and create the cache Element daoElement = (Element) lXMLDocument.getChildNodes().item(1); String xmlVersion = daoElement.getAttribute("version"); if (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new XMLProgFormatException("Exported Class Cache file format version " + xmlVersion + " is not supported. This XMLProg Configuration installation can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You" + " may need to check the configuration."); importClasses(daoElement); } catch (ParserConfigurationException PCE) { PCE.printStackTrace(); } catch (SAXException SXE) { SXE.printStackTrace(); } catch (IOException IOE) { IOE.printStackTrace(); } }
From source file:org.etudes.ambrosia.impl.UiServiceImpl.java
/** * {@inheritDoc}/*from w ww. j a v a 2 s . co m*/ */ public Fragment newFragment(InputStream in) { UiFragment frag = null; Document doc = Xml.readDocumentFromStream(in); if ((doc == null) || (!doc.hasChildNodes())) return frag; // allowing for comments, use the first element node that is our fragment NodeList nodes = doc.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) continue; if (!(((Element) node).getTagName().equals("fragment"))) continue; // build the fragment from this element frag = new UiFragment(this, (Element) node); break; } // else we have an invalid if (frag == null) { M_log.warn("newFragment: element \"fragment\" not found in stream xml"); frag = new UiFragment(); } return frag; }
From source file:org.etudes.ambrosia.impl.UiServiceImpl.java
/** * {@inheritDoc}//w w w.j a v a2s .c om */ public Interface newInterface(InputStream in) { UiInterface iface = null; Document doc = Xml.readDocumentFromStream(in); if ((doc == null) || (!doc.hasChildNodes())) return iface; // allowing for comments, use the first element node that is our interface NodeList nodes = doc.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) continue; if (!(((Element) node).getTagName().equals("interface"))) continue; // build the interface from this element iface = new UiInterface(this, (Element) node); break; } // else we have an invalid if (iface == null) { M_log.warn("newInterface: element \"interface\" not found in stream xml"); iface = new UiInterface(); } return iface; }
From source file:org.exoplatform.wcm.connector.authoring.TestLifecycleConnector.java
/** * Test method LifecycleConnector.byDate() * Input: /authoring/bydate?fromstate=staged&date=2&lang=en&workspace=collaboration * Expect:a collection of nodes in XML type that contains 2 nodes: * Node 1: name is Mock node1//from w ww .j a v a2 s .c om * path is /node1 * Node 2: name is Mock node2 * path is /node2 * title is Mock node 2 * publication:startPublishedDate is 03/18/2012 * @throws Exception */ public void testByDate() throws Exception { String restPath = "/authoring/bydate?fromstate=staged&date=2&lang=en&workspace=collaboration"; ContainerResponse response = service(HTTPMethods.GET.toString(), restPath, StringUtils.EMPTY, null, null); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); DOMSource object = (DOMSource) response.getEntity(); Document document = (Document) object.getNode(); Element element = (Element) document.getChildNodes().item(0); assertEquals("contents", element.getNodeName()); NodeList nodes = element.getChildNodes(); Node firstNode = nodes.item(0); Node secondNode = nodes.item(1); assertEquals("content", firstNode.getNodeName()); assertEquals("Mock node1", firstNode.getAttributes().getNamedItem("name").getNodeValue()); assertEquals("/node1", firstNode.getAttributes().getNamedItem("path").getNodeValue()); assertEquals("content", secondNode.getNodeName()); assertEquals("Mock node2", secondNode.getAttributes().getNamedItem("name").getNodeValue()); assertEquals("/node2", secondNode.getAttributes().getNamedItem("path").getNodeValue()); assertEquals("Mock node2", secondNode.getAttributes().getNamedItem("title").getNodeValue()); assertEquals("03/18/2012", secondNode.getAttributes().getNamedItem("publishedDate").getNodeValue()); }
From source file:org.exoplatform.wcm.connector.fckeditor.TestPortalLinkConnector.java
/** * Test method PortalLinkConnector.getPageURI() * Input 1: /portalLinks/getFoldersAndFiles/ * Expect 1: Connector return data in XML format as: * <Connector command="" resourceType="PortalPageURI"> * <CurrentFolder path="" url=""> * </CurrentFolder>//from w w w .j av a 2s.c o m * <Folders> * <Folder name="classic" url="" path="/"> * </Folder> * </Folders> * </Connector> * * Input 2: /portalLinks/getFoldersAndFiles?currentFolder=/classic/ * Expect 2: Connector return data in XML format OK * * Input 3: /portalLinks/getFoldersAndFiles?currentFolder=/classic/home * Expect 3: Connector return data in XML format as: * <Connector command="" resourceType="PortalPageURI"> * <CurrentFolder path="/classic/home" url=""> * </CurrentFolder> * <Folders> * <Folder name="classic" url="" path="/"> * </Folder> * </Folders> * <Files> * </Files> * </Connector> * @throws Exception */ public void testGetPageURI() throws Exception { ConversationState.setCurrent(new ConversationState(new Identity("root"))); String restPath = "/portalLinks/getFoldersAndFiles/"; ContainerResponse response = service(HTTPMethods.GET.toString(), restPath, StringUtils.EMPTY, null, null); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); DOMSource object = (DOMSource) response.getEntity(); Document node = (Document) object.getNode(); Element connector = (Element) node.getChildNodes().item(0); NodeList ConnectorChildren = connector.getChildNodes(); assertEquals("Connector", connector.getNodeName()); assertEquals("", connector.getAttribute("command")); assertEquals("PortalPageURI", connector.getAttribute("resourceType")); assertEquals(2, ConnectorChildren.getLength()); Element currentFolder = (Element) ConnectorChildren.item(0); assertEquals("CurrentFolder", currentFolder.getNodeName()); assertEquals("/", currentFolder.getAttribute("path")); assertEquals("", currentFolder.getAttribute("url")); Node folders = ConnectorChildren.item(1); assertEquals("Folders", folders.getNodeName()); Element firstFolder = (Element) folders.getChildNodes().item(0); assertNotNull(firstFolder); assertEquals("classic", firstFolder.getAttribute("name")); assertEquals("", firstFolder.getAttribute("url")); assertEquals("", firstFolder.getAttribute("folderType")); restPath = "/portalLinks/getFoldersAndFiles?currentFolder=/classic/"; response = service(HTTPMethods.GET.toString(), restPath, StringUtils.EMPTY, null, null); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); restPath = "/portalLinks/getFoldersAndFiles?currentFolder=/classic/home"; response = service(HTTPMethods.GET.toString(), restPath, StringUtils.EMPTY, null, null); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); object = (DOMSource) response.getEntity(); node = (Document) object.getNode(); connector = (Element) node.getChildNodes().item(0); ConnectorChildren = connector.getChildNodes(); assertEquals("Connector", connector.getNodeName()); assertEquals("", connector.getAttribute("command")); assertEquals("PortalPageURI", connector.getAttribute("resourceType")); assertEquals(3, ConnectorChildren.getLength()); currentFolder = (Element) ConnectorChildren.item(0); assertEquals("CurrentFolder", currentFolder.getNodeName()); assertEquals("/classic/home", currentFolder.getAttribute("path")); assertEquals("", currentFolder.getAttribute("url")); folders = ConnectorChildren.item(1); assertEquals("Folders", folders.getNodeName()); Node files = ConnectorChildren.item(2); assertEquals("Files", files.getNodeName()); }
From source file:org.infoglue.cms.applications.structuretool.actions.ViewSiteNodePageComponentsAction.java
/** * This method creates a parameter for the given input type. * This is to support form steering information later. *///from w w w . j av a 2s . com private void addBindingElement(Element parent, String qualifyerXML) throws Exception { Document document = XMLHelper.readDocumentFromByteArray(qualifyerXML.getBytes("utf-8")); NodeList nl = document.getChildNodes().item(0).getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Element qualifyerElement = (Element) nl.item(i); //logger.info("qualifyerElement:" + qualifyerElement); String entityName = qualifyerElement.getNodeName(); String assetKey = qualifyerElement.getAttribute("assetKey"); String entityId = qualifyerElement.getFirstChild().getNodeValue(); String supplementingEntityId = qualifyerElement.getAttribute("supplementingEntityId"); String supplementingAssetKey = qualifyerElement.getAttribute("supplementingAssetKey"); //logger.info("entityName:" + entityName); //logger.info("entityId:" + entityId); Element element = parent.getOwnerDocument().createElement("binding"); element.setAttribute("entityId", entityId); element.setAttribute("entity", entityName); element.setAttribute("assetKey", assetKey); if (supplementingEntityId != null && !"".equals(supplementingEntityId)) { Element supplementingElement = parent.getOwnerDocument().createElement("supplementing-binding"); supplementingElement.setAttribute("entityId", supplementingEntityId); supplementingElement.setAttribute("assetKey", StringEscapeUtils.escapeXml(supplementingAssetKey)); element.appendChild(supplementingElement); } parent.appendChild(element); } }
From source file:org.jboss.dashboard.displayer.AbstractDataDisplayerXMLFormat.java
public DataDisplayer parse(String xml, ImportResults results) throws Exception { DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dFactory.newDocumentBuilder(); dFactory.setIgnoringComments(true);//from www. j av a2 s . co m StringReader isr = new StringReader(xml); Document doc = dBuilder.parse(new InputSource(isr)); isr.close(); return parse(doc.getChildNodes(), results); }
From source file:org.jboss.dashboard.export.ImportManagerImpl.java
/** * Creates elements (KPI, DataProvider ,..) parsing the specified XML fragment. */// ww w .ja va2 s .c o m public ImportResults parse(String xml, ImportOptions options) throws Exception { StringReader isr = new StringReader(xml); DocumentBuilder dBuilder = createDocumentBuilder(); Document doc = dBuilder.parse(new InputSource(isr)); isr.close(); return parse(doc.getChildNodes(), options); }
From source file:org.jboss.dashboard.export.ImportManagerImpl.java
/** * Creates elements (KPI, DataProvider ,..) parsing the specified XML stream. *//*from w ww . ja v a 2s .c o m*/ public ImportResults parse(InputStream xml, ImportOptions options) throws Exception { DocumentBuilder dBuilder = createDocumentBuilder(); Document doc = dBuilder.parse(xml); return parse(doc.getChildNodes(), options); }