List of usage examples for org.w3c.dom Element getTagName
public String getTagName();
From source file:com.netscape.cms.servlet.csadmin.ConfigurationUtils.java
public static int getSubsystemCount(String hostname, int https_admin_port, boolean https, String type) throws Exception { logger.debug("getSubsystemCount start"); String c = getDomainXML(hostname, https_admin_port, true); if (c != null) { ByteArrayInputStream bis = new ByteArrayInputStream(c.getBytes()); XMLObject obj = new XMLObject(bis); String containerName = type + "List"; Node n = obj.getContainer(containerName); NodeList nlist = n.getChildNodes(); String countS = ""; for (int i = 0; i < nlist.getLength(); i++) { Element nn = (Element) nlist.item(i); String tagname = nn.getTagName(); if (tagname.equals("SubsystemCount")) { NodeList nlist1 = nn.getChildNodes(); Node nn1 = nlist1.item(0); countS = nn1.getNodeValue(); break; }/* w ww. j a v a 2 s . c o m*/ } logger.debug("getSubsystemCount: SubsystemCount=" + countS); int num = 0; if (countS != null && !countS.equals("")) { try { num = Integer.parseInt(countS); } catch (Exception ee) { } } return num; } return -1; }
From source file:com.bluexml.xforms.controller.alfresco.AlfrescoController.java
public void executeBatch(AlfrescoTransaction alfrescoTransaction) throws ServletException { Map<String, String> parameters = new TreeMap<String, String>(); parameters.put("datas", MappingAgent.marshalBatch(alfrescoTransaction)); Map<String, String> ids = new HashMap<String, String>(); Document result = requestDocumentFromAlfresco(alfrescoTransaction, parameters, MsgId.INT_WEBSCRIPT_OPCODE_BATCH); if (result == null) { throw new ServletException(MsgId.INT_MSG_ALFRESCO_SERVER_DOWN.getText()); }/*from ww w . jav a 2 s .c om*/ Element idsElement = result.getDocumentElement(); NodeList childNodes = idsElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node idNode = childNodes.item(i); if (idNode instanceof Element) { Element idElement = (Element) idNode; String to = null; String from = null; NodeList idChildNodes = idElement.getChildNodes(); for (int j = 0; j < idChildNodes.getLength(); j++) { Node node = idChildNodes.item(j); if (node instanceof Element) { Element element = (Element) node; if (StringUtils.equals(element.getTagName(), "from")) { from = StringUtils.trim(element.getTextContent()); } if (StringUtils.equals(element.getTagName(), "to")) { to = StringUtils.trim(element.getTextContent()); } } } ids.put(from, to); } } alfrescoTransaction.setIds(ids); }
From source file:com.bluexml.xforms.controller.alfresco.AlfrescoController.java
/** * Sets initial values for workflow fields from BlueXML properties (stored * in the repository) of/*from w w w . j av a 2 s .c o m*/ * the workflow instance. * * @param wkFormName * the name of the workflow form to display * @param doc * the XForms instance * @param instanceId * the workflow instance Id (previously provided by Alfresco) * @return false if a lethal exception occurred. True if the normal end of * the function was * reached, which does not imply anything about the setting of * initial values. */ public boolean workflowPatchInstance(AlfrescoTransaction transaction, String wkFormName, Document doc, String instanceId) { if (logger.isDebugEnabled()) { logger.debug("Patching workflow instance with Id:'" + instanceId + "', form name: " + wkFormName); } QName qname; String namespaceURI = null; // to be set once Map<QName, Serializable> properties = null; // to be set once if (StringUtils.trimToNull(instanceId) == null) { if (logger.isDebugEnabled()) { logger.debug(" No patching performed: the instanceId is null"); } return true; } if (instanceId.equals("null")) { if (logger.isDebugEnabled()) { logger.debug(" No patching performed, invalid instanceId with string 'null'"); } return true; } Element root = doc.getDocumentElement(); Element formElt = DOMUtil.getChild(root, wkFormName); List<Element> allFields = DOMUtil.getAllChildren(formElt); // we need to fail silently so that the form is displayed even in the event of errors for (Element field : allFields) { String fieldUniqueName = field.getTagName(); Serializable fieldValue = null; String localName = getWorkflowFieldAlfrescoName(wkFormName, fieldUniqueName); if (localName != null) { // build the QName if (namespaceURI == null) { String processName = workflowExtractProcessNameFromFormName(wkFormName); namespaceURI = getWorkflowNamespaceURI(processName); } qname = QName.createQName(namespaceURI, localName); // read the QName value from the collected properties of the workflow instance if (properties == null) { properties = workflowCollectInstanceProperties(transaction, instanceId); if (properties == null) { return false; // there's no point in continuing without the properties } } try { // set the initial value fieldValue = properties.get(qname); if (fieldValue != null) { field.setTextContent(fieldValue.toString()); } } catch (NullPointerException e) { // we'll get this when displaying workflow forms while the webscript is down return false; } } } return true; }
From source file:com.glaf.core.config.Configuration.java
private Resource loadResource(Properties properties, Resource wrapper, boolean quiet) { String name = UNKNOWN_RESOURCE; try {/* w w w .ja va 2 s .c om*/ Object resource = wrapper.getResource(); name = wrapper.getName(); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); // ignore all comments inside the xml file docBuilderFactory.setIgnoringComments(true); // allow includes in the xml file docBuilderFactory.setNamespaceAware(true); try { docBuilderFactory.setXIncludeAware(true); } catch (UnsupportedOperationException e) { LOG.error("Failed to set setXIncludeAware(true) for parser " + docBuilderFactory + ":" + e, e); } DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); Document doc = null; Element root = null; boolean returnCachedProperties = false; if (resource instanceof URL) { // an URL resource doc = parse(builder, (URL) resource); } else if (resource instanceof String) { // a CLASSPATH resource URL url = getResource((String) resource); doc = parse(builder, url); } else if (resource instanceof InputStream) { doc = parse(builder, (InputStream) resource, null); returnCachedProperties = true; } else if (resource instanceof Properties) { overlay(properties, (Properties) resource); } else if (resource instanceof Element) { root = (Element) resource; } if (root == null) { if (doc == null) { if (quiet) { return null; } throw new RuntimeException(resource + " not found"); } root = doc.getDocumentElement(); } Properties toAddTo = properties; if (returnCachedProperties) { toAddTo = new Properties(); } if (!"configuration".equals(root.getTagName())) LOG.fatal("bad conf file: top-level element not <configuration>"); NodeList props = root.getChildNodes(); for (int i = 0; i < props.getLength(); i++) { Node propNode = props.item(i); if (!(propNode instanceof Element)) continue; Element prop = (Element) propNode; if ("configuration".equals(prop.getTagName())) { loadResource(toAddTo, new Resource(prop, name), quiet); continue; } if (!"property".equals(prop.getTagName())) LOG.warn("bad conf file: element not <property>"); NodeList fields = prop.getChildNodes(); String attr = null; String value = null; boolean finalParameter = false; LinkedList<String> source = new LinkedList<String>(); for (int j = 0; j < fields.getLength(); j++) { Node fieldNode = fields.item(j); if (!(fieldNode instanceof Element)) continue; Element field = (Element) fieldNode; if ("name".equals(field.getTagName()) && field.hasChildNodes()) attr = StringInterner.weakIntern(((Text) field.getFirstChild()).getData().trim()); if ("value".equals(field.getTagName()) && field.hasChildNodes()) value = StringInterner.weakIntern(((Text) field.getFirstChild()).getData()); if ("final".equals(field.getTagName()) && field.hasChildNodes()) finalParameter = "true".equals(((Text) field.getFirstChild()).getData()); if ("source".equals(field.getTagName()) && field.hasChildNodes()) source.add(StringInterner.weakIntern(((Text) field.getFirstChild()).getData())); } source.add(name); // Ignore this parameter if it has already been marked as // 'final' if (attr != null) { loadProperty(toAddTo, name, attr, value, finalParameter, source.toArray(new String[source.size()])); } } if (returnCachedProperties) { overlay(properties, toAddTo); return new Resource(toAddTo, name); } return null; } catch (IOException e) { LOG.fatal("error parsing conf " + name, e); throw new RuntimeException(e); } catch (DOMException e) { LOG.fatal("error parsing conf " + name, e); throw new RuntimeException(e); } catch (SAXException e) { LOG.fatal("error parsing conf " + name, e); throw new RuntimeException(e); } catch (ParserConfigurationException e) { LOG.fatal("error parsing conf " + name, e); throw new RuntimeException(e); } }
From source file:com.photon.phresco.framework.rest.api.QualityService.java
private List<String> getScreenShot(String testAgainst, String resultFile, String rootModulePath, String subModule, String from) throws PhrescoException { List<String> imgSources = new ArrayList<String>(); try {/* w w w .j a va2s .c o m*/ String testDir = ""; if (PERFORMACE.equals(from)) { testDir = FrameworkServiceUtil.getPerformanceTestDir(rootModulePath, subModule); } else { testDir = FrameworkServiceUtil.getLoadTestDir(rootModulePath, subModule); } ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModule); File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModule); StringBuilder sb = new StringBuilder(testFolderLocation.getPath()); sb.append(testDir).append(File.separator).append(testAgainst); int lastDot = resultFile.lastIndexOf("."); String resultName = resultFile.substring(0, lastDot); File testPomFile = new File(sb.toString() + File.separator + POM_XML); PomProcessor pomProcessor = new PomProcessor(testPomFile); Plugin plugin = pomProcessor.getPlugin(COM_LAZERYCODE_JMETER, JMETER_MAVEN_PLUGIN); com.phresco.pom.model.Plugin.Configuration jmeterConfiguration = plugin.getConfiguration(); List<Element> jmeterConfigs = jmeterConfiguration.getAny(); for (Element element : jmeterConfigs) { if (PLUGIN_TYPES.equalsIgnoreCase(element.getTagName()) && element.hasChildNodes()) { NodeList types = element.getChildNodes(); for (int i = 0; i < types.getLength(); i++) { Node pluginType = types.item(i); if (StringUtils.isNotEmpty(pluginType.getTextContent())) { File imgFile = new File(sb.toString() + RESULTS_JMETER_GRAPHS + resultName + HYPHEN + pluginType.getTextContent() + PNG); if (imgFile.exists()) { InputStream imageStream = new FileInputStream(imgFile); String imgSrc = new String(Base64.encodeBase64(IOUtils.toByteArray(imageStream))); imgSources.add( imgSrc + "#NAME_SEP#" + resultName + HYPHEN + pluginType.getTextContent()); } } } } } } catch (Exception e) { throw new PhrescoException(e); } return imgSources; }
From source file:co.cask.cdap.common.conf.Configuration.java
private void loadResource(Properties properties, Object name, boolean quiet) { try {// w w w .j a v a 2s . co m DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); //ignore all comments inside the xml file docBuilderFactory.setIgnoringComments(true); //allow includes in the xml file docBuilderFactory.setNamespaceAware(true); try { docBuilderFactory.setXIncludeAware(true); } catch (UnsupportedOperationException e) { LOG.error("Failed to set setXIncludeAware(true) for parser " + docBuilderFactory + ":" + e, e); } DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); Document doc = null; Element root = null; if (name instanceof URL) { // an URL resource URL url = (URL) name; if (url != null) { if (!quiet) { LOG.info("parsing " + url); } doc = builder.parse(url.toString()); } } else if (name instanceof String) { // a CLASSPATH resource URL url = getResource((String) name); if (url != null) { if (!quiet) { LOG.info("parsing " + url); } doc = builder.parse(url.toString()); } } else if (name instanceof InputStream) { try { doc = builder.parse((InputStream) name); } finally { ((InputStream) name).close(); } } else if (name instanceof Element) { root = (Element) name; } if (doc == null && root == null) { if (quiet) { return; } throw new RuntimeException(name + " not found"); } if (root == null) { root = doc.getDocumentElement(); } if (!"configuration".equals(root.getTagName())) { LOG.fatal("bad conf file: top-level element not <configuration>"); } NodeList props = root.getChildNodes(); for (int i = 0; i < props.getLength(); i++) { Node propNode = props.item(i); if (!(propNode instanceof Element)) { continue; } Element prop = (Element) propNode; if ("configuration".equals(prop.getTagName())) { loadResource(properties, prop, quiet); continue; } if (!"property".equals(prop.getTagName())) { LOG.warn("bad conf file: element not <property>"); } NodeList fields = prop.getChildNodes(); String attr = null; String value = null; boolean finalParameter = false; for (int j = 0; j < fields.getLength(); j++) { Node fieldNode = fields.item(j); if (!(fieldNode instanceof Element)) { continue; } Element field = (Element) fieldNode; if ("name".equals(field.getTagName()) && field.hasChildNodes()) { attr = ((Text) field.getFirstChild()).getData().trim(); } if ("value".equals(field.getTagName()) && field.hasChildNodes()) { value = ((Text) field.getFirstChild()).getData(); } if ("final".equals(field.getTagName()) && field.hasChildNodes()) { finalParameter = "true".equals(((Text) field.getFirstChild()).getData()); } } // Ignore this parameter if it has already been marked as 'final' if (attr != null) { if (deprecatedKeyMap.containsKey(attr)) { DeprecatedKeyInfo keyInfo = deprecatedKeyMap.get(attr); keyInfo.accessed = false; for (String key : keyInfo.newKeys) { // update new keys with deprecated key's value loadProperty(properties, name, key, value, finalParameter); } } else { loadProperty(properties, name, attr, value, finalParameter); } } } } catch (IOException e) { LOG.fatal("error parsing conf file: " + e); throw new RuntimeException(e); } catch (DOMException e) { LOG.fatal("error parsing conf file: " + e); throw new RuntimeException(e); } catch (SAXException e) { LOG.fatal("error parsing conf file: " + e); throw new RuntimeException(e); } catch (ParserConfigurationException e) { LOG.fatal("error parsing conf file: " + e); throw new RuntimeException(e); } }
From source file:ucar.unidata.idv.flythrough.Flythrough.java
/** * _more_/*from w w w. j a v a2s. c om*/ * * @param root _more_ */ private void importKml(Element root) { try { List tourNodes = XmlUtil.findDescendants(root, KmlUtil.TAG_TOUR); if (tourNodes.size() == 0) { LogUtil.userMessage("Could not find any tours"); return; } Element tourNode = (Element) tourNodes.get(0); List<FlythroughPoint> thePoints = new ArrayList<FlythroughPoint>(); Element playListNode = XmlUtil.findChild(tourNode, KmlUtil.TAG_PLAYLIST); if (playListNode == null) { LogUtil.userMessage("Could not find playlist"); return; } NodeList elements = XmlUtil.getElements(playListNode); for (int i = 0; i < elements.getLength(); i++) { Element child = (Element) elements.item(i); if (child.getTagName().equals(KmlUtil.TAG_FLYTO)) { Element cameraNode = XmlUtil.findChild(child, KmlUtil.TAG_CAMERA); /* <Camera> <longitude>170.157</longitude> <latitude>-43.671</latitude> <altitude>9700</altitude> <heading>-6.333</heading> <tilt>33.5</tilt> </Camera>*/ if (cameraNode == null) { cameraNode = XmlUtil.findChild(child, KmlUtil.TAG_LOOKAT); } if (cameraNode == null) { // System.err.println ("no camera:" + XmlUtil.toString(child)); continue; } FlythroughPoint pt = new FlythroughPoint( makePoint(XmlUtil.getGrandChildText(cameraNode, KmlUtil.TAG_LATITUDE), XmlUtil.getGrandChildText(cameraNode, KmlUtil.TAG_LONGITUDE), XmlUtil.getGrandChildText(cameraNode, KmlUtil.TAG_ALTITUDE))); pt.setTiltX(-new Double(XmlUtil.getGrandChildText(cameraNode, KmlUtil.TAG_TILT, "0")) .doubleValue()); pt.setTiltY(new Double(XmlUtil.getGrandChildText(cameraNode, KmlUtil.TAG_HEADING, "0")) .doubleValue()); pt.setTiltZ( new Double(XmlUtil.getGrandChildText(cameraNode, KmlUtil.TAG_ROLL, "0")).doubleValue()); thePoints.add(pt); } else if (child.getTagName().equals(KmlUtil.TAG_WAIT)) { } else { } } flythrough(thePoints); doMakeContents(true); setAnimationTimes(); } catch (Exception exc) { logException("Importing kml", exc); } }
From source file:ucar.unidata.idv.flythrough.Flythrough.java
/** * _more_//from ww w . j a v a 2s . c om */ public void doImport() { try { String filename = FileManager.getReadFile(FileManager.FILTER_XML); if (filename == null) { return; } Element root = XmlUtil.getRoot(filename, getClass()); if (root.getTagName().equals(KmlUtil.TAG_KML)) { importKml(root); return; } if (!root.getTagName().equals(TAG_FLYTHROUGH)) { throw new IllegalStateException("Unknown tag:" + root.getTagName()); } for (int i = 0; i < tilt.length; i++) { tilt[i] = XmlUtil.getAttribute(root, ATTR_TILT[i], tilt[i]); } zoom = XmlUtil.getAttribute(root, ATTR_ZOOM, zoom); List<FlythroughPoint> thePoints = new ArrayList<FlythroughPoint>(); NodeList elements = XmlUtil.getElements(root); for (int i = 0; i < elements.getLength(); i++) { Element child = (Element) elements.item(i); if (!child.getTagName().equals(TAG_POINT)) { throw new IllegalStateException("Unknown tag:" + child.getTagName()); } FlythroughPoint pt = new FlythroughPoint(); pt.setDescription(XmlUtil.getGrandChildText(child, TAG_DESCRIPTION)); pt.setEarthLocation(makePoint(XmlUtil.getAttribute(child, ATTR_LAT, 0.0), XmlUtil.getAttribute(child, ATTR_LON, 0.0), XmlUtil.getAttribute(child, ATTR_ALT, 0.0))); if (XmlUtil.hasAttribute(child, ATTR_DATE)) { pt.setDateTime(parseDate(XmlUtil.getAttribute(child, ATTR_DATE))); } pt.setTiltX(XmlUtil.getAttribute(child, ATTR_TILT[0], Double.NaN)); pt.setTiltY(XmlUtil.getAttribute(child, ATTR_TILT[1], Double.NaN)); pt.setTiltZ(XmlUtil.getAttribute(child, ATTR_TILT[2], Double.NaN)); pt.setZoom(XmlUtil.getAttribute(child, ATTR_ZOOM, Double.NaN)); String matrixS = XmlUtil.getAttribute(child, ATTR_MATRIX, (String) null); if (matrixS != null) { List<String> toks = (List<String>) StringUtil.split(matrixS, ",", true, true); double[] m = new double[toks.size()]; for (int tokIdx = 0; tokIdx < m.length; tokIdx++) { m[tokIdx] = new Double(toks.get(tokIdx)).doubleValue(); } pt.setMatrix(m); } thePoints.add(pt); } flythrough(thePoints); doMakeContents(true); setAnimationTimes(); } catch (Exception exc) { logException("Initializing flythrough", exc); } }
From source file:marytts.tools.voiceimport.HTKLabeler.java
/** * /* w w w .j ava2 s.c o m*/ * This computes a string of phonetic symbols out of an prompt allophones mary xml: * - standard phones are taken from "ph" attribute * @param tokens * @return */ private String collectTranscription(NodeList tokens) { // TODO: make delims argument // String Tokenizer devides transcriptions into syllables // syllable delimiters and stress symbols are retained String delims = "',-"; // String storing the original transcription begins with a pause String orig = " pau "; // get original phone String for (int tNr = 0; tNr < tokens.getLength(); tNr++) { Element token = (Element) tokens.item(tNr); // only look at it if there is a sampa to change if (token.hasAttribute("ph")) { String sampa = token.getAttribute("ph"); List<String> sylsAndDelims = new ArrayList<String>(); StringTokenizer sTok = new StringTokenizer(sampa, delims, true); while (sTok.hasMoreElements()) { String currTok = sTok.nextToken(); if (delims.indexOf(currTok) == -1) { // current Token is no delimiter for (Allophone ph : allophoneSet.splitIntoAllophones(currTok)) { // orig += ph.name() + " "; if (ph.name().trim().equals("_")) continue; orig += replaceTrickyPhones(ph.name().trim()) + " "; } // ... for each phone } // ... if no delimiter } // ... while there are more tokens } // TODO: simplify if (token.getTagName().equals("t")) { // if the following element is no boundary, insert a non-pause delimiter if (tNr == tokens.getLength() - 1 || !((Element) tokens.item(tNr + 1)).getTagName().equals("boundary")) { orig += "vssil "; // word boundary } } else if (token.getTagName().equals("boundary")) { orig += "ssil "; // phrase boundary } else { // should be "t" or "boundary" elements assert (false); } } // ... for each t-Element orig += "pau"; return orig; }
From source file:act.installer.pubchem.PubchemParser.java
/** * Incrementally parses a stream of XML events from a PubChem file, extracting the next available PC-Compound entry * as a Chemical object./*from w w w . j a v a2 s . c o m*/ * @param eventReader The xml event reader we are parsing the XML from * @return The constructed chemical * @throws XMLStreamException * @throws XPathExpressionException */ public Chemical extractNextChemicalFromXMLStream(XMLEventReader eventReader) throws XMLStreamException, JaxenException { Document bufferDoc = null; Element currentElement = null; StringBuilder textBuffer = null; /* With help from * http://stackoverflow.com/questions/7998733/loading-local-chunks-in-dom-while-parsing-a-large-xml-file-in-sax-java */ while (eventReader.hasNext()) { XMLEvent event = eventReader.nextEvent(); switch (event.getEventType()) { case XMLStreamConstants.START_ELEMENT: String eventName = event.asStartElement().getName().getLocalPart(); if (COMPOUND_DOC_TAG.equals(eventName)) { // Create a new document if we've found the start of a compound object. bufferDoc = documentBuilder.newDocument(); currentElement = bufferDoc.createElement(eventName); bufferDoc.appendChild(currentElement); } else if (currentElement != null) { // Wait until we've found a compound entry to start slurping up data. // Create a new child element and push down the current pointer when we find a new node. Element newElement = bufferDoc.createElement(eventName); currentElement.appendChild(newElement); currentElement = newElement; } // If we aren't in a PC-Compound tree, we just let the elements pass by. break; case XMLStreamConstants.CHARACTERS: if (currentElement == null) { // Ignore this event if we're not in a PC-Compound tree. continue; } Characters chars = event.asCharacters(); // Ignore only whitespace strings, which just inflate the size of the DOM. Text coalescing makes this safe. if (chars.isWhiteSpace()) { continue; } // Rely on the XMLEventStream to coalesce consecutive text events. Text textNode = bufferDoc.createTextNode(chars.getData()); currentElement.appendChild(textNode); break; case XMLStreamConstants.END_ELEMENT: if (currentElement == null) { // Ignore this event if we're not in a PC-Compound tree. continue; } eventName = event.asEndElement().getName().getLocalPart(); Node parentNode = currentElement.getParentNode(); if (parentNode instanceof Element) { currentElement = (Element) parentNode; } else if (parentNode instanceof Document && eventName.equals(COMPOUND_DOC_TAG)) { // We're back at the top of the node stack! Convert the buffered document into a Chemical. PubchemEntry entry = extractPCCompoundFeatures(bufferDoc); if (entry != null) { return entry.asChemical(); } else { // Skip this entry if we can't process it correctly by resetting the world and continuing on. bufferDoc = null; currentElement = null; } } else { // This should not happen, but is here as a sanity check. throw new RuntimeException(String.format("Parent of XML element %s is of type %d, not Element", currentElement.getTagName(), parentNode.getNodeType())); } break; // TODO: do we care about attributes or other XML structures? } } // Return null when we run out of chemicals, just like readLine(). return null; }