public HashMap<String, String> parseXml(InputStream inStream) throws Exception { HashMap<String, String> hashMap = new HashMap<String, String>(); // 实例化一个文档构建器工厂 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // 通过文档构建器工厂获取一个文档构建器 DocumentBuilder builder = factory.newDocumentBuilder(); // 通过文档通过文档构建器构建一个文档实例 Document document = builder.parse(inStream); // 获取XML文件根节点 Element root = document.getDocumentElement(); // 获得所有子节点 NodeList childNodes = root.getChildNodes(); for (int j = 0; j < childNodes.getLength(); j++) { // 遍历子节点 Node childNode = (Node) childNodes.item(j); if (childNode.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) childNode; // 版本号 if ("version".equals(childElement.getNodeName())) { hashMap.put("version", childElement.getFirstChild().getNodeValue()); } // 软件名称 else if (("name".equals(childElement.getNodeName()))) { hashMap.put("name", childElement.getFirstChild().getNodeValue()); } // 下载地址 else if (("url".equals(childElement.getNodeName()))) { hashMap.put("url", childElement.getFirstChild().getNodeValue()); } } } return hashMap; }
public VOMSWarningMessage[] warningMessages() { NodeList nodes = xmlResponse.getElementsByTagName("item"); if (nodes.getLength() == 0) return null; List<VOMSWarningMessage> warningList = new ArrayList<VOMSWarningMessage>(); for (int i = 0; i < nodes.getLength(); i++) { Element itemElement = (Element) nodes.item(i); Element numberElement = (Element) itemElement.getElementsByTagName("number").item(0); Element messageElement = (Element) itemElement.getElementsByTagName("message").item(0); int number = Integer.parseInt(numberElement.getFirstChild().getNodeValue()); if (number < ERROR_OFFSET) warningList.add( new VOMSWarningMessage(number, messageElement.getFirstChild().getNodeValue())); } if (warningList.isEmpty()) return null; return warningList.toArray(new VOMSWarningMessage[warningList.size()]); }
public void testCreateInstance() throws Exception { // create musteri schema manager... POSchemaManager musteriSchemaManager = MusteriSchemaManager.getInstance(); // create an example musteri... Musteri musteri = createExampleMusteri(); // create xml instance of example musteri... Document musteriInstance = musteriSchemaManager.createInstanceXML(musteri); // assert that musteriInstance is not null... assertNotNull(musteriInstance); // get Musteri element... Element musteriElement = musteriInstance.getDocumentElement(); // get adSoyad element from Musteri element... Element adSoyadElement = (Element) musteriElement.getElementsByTagName("adSoyad").item(0); // check "adSoyad"... assertEquals("adim soyadim", adSoyadElement.getFirstChild().getNodeValue()); // get kullaniciAdi element from Musteri element... Element kullaniciElement = (Element) musteriElement.getElementsByTagName("kullaniciAdi").item(0); // check "kullaniciAdi"... assertEquals("kullaniciAdim", kullaniciElement.getFirstChild().getNodeValue()); // check the number of elements of musteri... NodeList nodeList = musteriElement.getChildNodes(); assertEquals(4, nodeList.getLength()); }
private ArrayList<Forecast> buildForecasts(String raw) throws Exception { ArrayList<Forecast> forecasts = new ArrayList<Forecast>(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(new InputSource(new StringReader(raw))); NodeList times = doc.getElementsByTagName("start-valid-time"); for (int i = 0; i < times.getLength(); i++) { Element time = (Element) times.item(i); Forecast forecast = new Forecast(); forecasts.add(forecast); forecast.setTime(time.getFirstChild().getNodeValue()); } NodeList temps = doc.getElementsByTagName("value"); for (int i = 0; i < temps.getLength(); i++) { Element temp = (Element) temps.item(i); Forecast forecast = forecasts.get(i); forecast.setTemp(new Integer(temp.getFirstChild().getNodeValue())); } NodeList icons = doc.getElementsByTagName("icon-link"); for (int i = 0; i < icons.getLength(); i++) { Element icon = (Element) icons.item(i); Forecast forecast = forecasts.get(i); forecast.setIcon(icon.getFirstChild().getNodeValue()); } return (forecasts); }
/** * returns fetch a Pair. iterates into the next one. * * @return PairXMLData * @throws RawFormatReaderException */ public PairXMLData nextPair() throws RawFormatReaderException { // open up pairNodes(current) Element pair = (Element) pairNodes.item(current); NodeList tl = pair.getElementsByTagName("t"); NodeList hl = pair.getElementsByTagName("h"); if (tl.getLength() == 0 || hl.getLength() == 0) throw new RawFormatReaderException( "A pair with missing T or H tag (Pair id: " + pair.getAttribute("id") + ")"); // get text, get hypothesis, as string Element t = (Element) tl.item(0); String text = t.getFirstChild().getNodeValue(); Element h = (Element) hl.item(0); String hypothesis = h.getFirstChild().getNodeValue(); // get attributes String id = pair.getAttribute("id"); String goldAnswer = pair.getAttribute("entailment"); String task = pair.getAttribute("task"); // throw exception if missing task or id if (task.length() == 0 || id.length() == 0) throw new RawFormatReaderException("A pair with missing task or id"); // generate return data structure and return it PairXMLData pairData = new PairXMLData(text, hypothesis, id, goldAnswer, task); current++; return pairData; }
private void processLocalisations(final Entity entity, final NodeList localisations) throws EntityListParserException { boolean foundDefault = false; for (int i = 0; i < localisations.getLength(); i++) { Element localisationElement = (Element) localisations.item(i); String locale = localisationElement.getAttribute(EntityListParser.LOCALISATION_LOCALE); EntityLocalistation localisation = new EntityLocalistation(); localisation.setLocale(locale); localisation.setName(localisationElement.getAttribute(EntityListParser.LOCALISATION_NAME)); localisation.setShortname( localisationElement.getAttribute(EntityListParser.LOCALISATION_SHORTNAME)); localisation.setDefaultLocalisation( Boolean.valueOf(localisationElement.getAttribute(EntityListParser.LOCALISATION_DEFAULT))); if (localisationElement.getFirstChild() != null) { localisation.setUrl(localisationElement.getFirstChild().getNodeValue()); } String appLocale = localisationElement.getAttribute(EntityListParser.LOCALISATION_APP_LOCALE); if (appLocale != null && appLocale.trim().length() > 0) { localisation.setAppLocale(appLocale); } else { localisation.setAppLocale(locale); } entity.addLocalisation(localisation); foundDefault = foundDefault || localisation.isDefaultLocalisation(); } if (!foundDefault) { throw new EntityListParserException( String.format("Entity %s does not have a default localistation", entity.getId())); } }
void parsePhase() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // Now use the factory to create a DOM parser (a.k.a. a DocumentBuilder) DocumentBuilder parser; try { parser = factory.newDocumentBuilder(); // Parse the file and build a Document tree to represent its content Document document = parser.parse(new StringBufferInputStream("<root>" + conf.get("phases") + "</root>")); // Ask the document for a list of all phases NodeList rows = document.getElementsByTagName(AnalysisProcessorConfiguration.phase); int phasenumber = rows.getLength(); for (int i = 0; i < phasenumber; i++) { Node phase = rows.item(i); NodeList fields = phase.getChildNodes(); String phasename = null; String stacks = null; String funcs = null; List<String> functionlist = new ArrayList<String>(); for (int j = 0; j < fields.getLength(); j++) { Node fieldNode = fields.item(j); if (!(fieldNode instanceof Element)) continue; Element field = (Element) fieldNode; if ("phasename".equals(field.getTagName()) && field.hasChildNodes()) phasename = ((org.w3c.dom.Text) field.getFirstChild()).getData().trim(); else if ("stack".equals(field.getTagName()) && field.hasChildNodes()) stacks = ((org.w3c.dom.Text) field.getFirstChild()).getData(); else if ("functions".equals(field.getTagName()) && field.hasChildNodes()) funcs = ((org.w3c.dom.Text) field.getFirstChild()).getData(); } if (stacks != null && stacks.length() != 0) stacks = stacks.replace(" ", ""); else stacks = ""; phasealias.put(stacks, phasename); if (funcs == null) { continue; } for (String func : funcs.split(SEPERATOR_COMMA)) { functionlist.add(func); } this.phases.put(stacks, functionlist); } } catch (ParserConfigurationException e) { // TODO Auto-generated catch block log.warn(e); e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block log.warn(e); e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block log.warn(e); e.printStackTrace(); } }
public Map<String, Object> grid() throws Exception { Element gridElement = ReaderUtils.getChildElement(coverage, "grid"); if (gridElement == null) { return null; } HashMap<String, Object> grid = new HashMap<String, Object>(); grid.put( "dimension", Integer.parseInt(ReaderUtils.getAttribute(gridElement, "dimension", true))); Element lowElement = ReaderUtils.getChildElement(gridElement, "low"); String[] lows = lowElement.getFirstChild().getTextContent().trim().split(" "); int[] low = new int[lows.length]; for (int i = 0; i < low.length; i++) { low[i] = Integer.parseInt(lows[i]); } grid.put("low", low); Element highElement = ReaderUtils.getChildElement(gridElement, "high"); String[] highs = highElement.getFirstChild().getTextContent().trim().split(" "); int[] high = new int[highs.length]; for (int i = 0; i < high.length; i++) { high[i] = Integer.parseInt(highs[i]); } grid.put("high", high); Element[] axisNameElements = ReaderUtils.getChildElements(gridElement, "axisName"); String[] axisName = new String[axisNameElements.length]; for (int i = 0; i < axisName.length; i++) { axisName[i] = axisNameElements[i].getFirstChild().getTextContent(); } grid.put("axisName", axisName); Element geoTransformElement = ReaderUtils.getChildElement(gridElement, "geoTransform"); if (geoTransformElement != null) { Map<String, Double> geoTransform = new HashMap<String, Double>(); String scaleX = ReaderUtils.getChildText(geoTransformElement, "scaleX"); String scaleY = ReaderUtils.getChildText(geoTransformElement, "scaleY"); String shearX = ReaderUtils.getChildText(geoTransformElement, "shearX"); String shearY = ReaderUtils.getChildText(geoTransformElement, "shearY"); String translateX = ReaderUtils.getChildText(geoTransformElement, "translateX"); String translateY = ReaderUtils.getChildText(geoTransformElement, "translateY"); geoTransform.put("scaleX", scaleX != null ? new Double(scaleX) : null); geoTransform.put("scaleY", scaleY != null ? new Double(scaleY) : null); geoTransform.put("shearX", shearX != null ? new Double(shearX) : null); geoTransform.put("shearY", shearY != null ? new Double(shearY) : null); geoTransform.put("translateX", translateX != null ? new Double(translateX) : null); geoTransform.put("translateY", translateY != null ? new Double(translateY) : null); grid.put("geoTransform", geoTransform); } return grid; }
/** * Carries out preprocessing that makes JEuclid handle the document better. * * @param doc Document */ static void preprocessForJEuclid(Document doc) { // underbrace and overbrace NodeList list = doc.getElementsByTagName("mo"); for (int i = 0; i < list.getLength(); i++) { Element mo = (Element) list.item(i); String parentName = ((Element) mo.getParentNode()).getTagName(); if (parentName == null) { continue; } if (parentName.equals("munder") && isTextChild(mo, "\ufe38")) { mo.setAttribute("stretchy", "true"); mo.removeChild(mo.getFirstChild()); mo.appendChild(doc.createTextNode("\u23df")); } else if (parentName.equals("mover") && isTextChild(mo, "\ufe37")) { mo.setAttribute("stretchy", "true"); mo.removeChild(mo.getFirstChild()); mo.appendChild(doc.createTextNode("\u23de")); } } // menclose for long division doesn't allow enough top padding. Oh, and // <mpadded> isn't implemented. And there isn't enough padding to left of // the bar either. Solve by adding an <mover> with just an <mspace> over# // the longdiv, contained within an mrow that adds a <mspace> before it. list = doc.getElementsByTagName("menclose"); for (int i = 0; i < list.getLength(); i++) { Element menclose = (Element) list.item(i); // Only for longdiv if (!"longdiv".equals(menclose.getAttribute("notation"))) { continue; } Element mrow = doc.createElementNS(WebMathsService.NS, "mrow"); Element mover = doc.createElementNS(WebMathsService.NS, "mover"); Element mspace = doc.createElementNS(WebMathsService.NS, "mspace"); Element mspaceW = doc.createElementNS(WebMathsService.NS, "mspace"); boolean previousElement = false; for (Node previous = menclose.getPreviousSibling(); previous != null; previous = previous.getPreviousSibling()) { if (previous.getNodeType() == Node.ELEMENT_NODE) { previousElement = true; break; } } if (previousElement) { mspaceW.setAttribute("width", "4px"); } menclose.getParentNode().insertBefore(mrow, menclose); menclose.getParentNode().removeChild(menclose); mrow.appendChild(mspaceW); mrow.appendChild(mover); mover.appendChild(menclose); mover.appendChild(mspace); } }
/** * Locate the linux fonts based on the XML configuration file * * @param file The location of the XML file */ private static void locateLinuxFonts(File file) { if (!file.exists()) { System.err.println("Unable to open: " + file.getAbsolutePath()); return; } try { InputStream in = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); ByteArrayOutputStream temp = new ByteArrayOutputStream(); PrintStream pout = new PrintStream(temp); while (reader.ready()) { String line = reader.readLine(); if (line.indexOf("DOCTYPE") == -1) { pout.println(line); } } in = new ByteArrayInputStream(temp.toByteArray()); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(in); NodeList dirs = document.getElementsByTagName("dir"); for (int i = 0; i < dirs.getLength(); i++) { Element element = (Element) dirs.item(i); String dir = element.getFirstChild().getNodeValue(); if (dir.startsWith("~")) { dir = dir.substring(1); dir = userhome + dir; } addFontDirectory(new File(dir)); } NodeList includes = document.getElementsByTagName("include"); for (int i = 0; i < includes.getLength(); i++) { Element element = (Element) dirs.item(i); String inc = element.getFirstChild().getNodeValue(); if (inc.startsWith("~")) { inc = inc.substring(1); inc = userhome + inc; } locateLinuxFonts(new File(inc)); } } catch (Exception e) { e.printStackTrace(); System.err.println("Unable to process: " + file.getAbsolutePath()); } }
public Object convertAttributeValue(Element a) { String type = a.getAttributeNS(XSI_NS, "type"); if ((type == null) || ("".equals(type))) { System.out.println( "----> convertAttributeValue " + type + " " + a.getFirstChild().getNodeValue()); return a.getFirstChild().getNodeValue(); } else { System.out.println("----> convertAttributeValue " + type); return c.convertTypedLiteral(type, "\"" + a.getFirstChild().getNodeValue() + "\""); } }
/* * (non-Javadoc) * * @see org.glite.voms.contact.VOMSResponseIF#getAC() */ public byte[] getAC() { Element acElement = (Element) xmlResponse.getElementsByTagName("ac").item(0); byte[] ac = VOMSBase64Decoder.decode(acElement.getFirstChild().getNodeValue()); if (ac == null) ac = new GoodACDecodingStrategy().decode(acElement.getFirstChild().getNodeValue()); return ac; }
private String getTextValue(Element ele, String tagName, int pos) { String textVal = null; NodeList nl = ele.getElementsByTagName(tagName); if (nl != null && nl.getLength() > pos) { Element el = (Element) nl.item(pos); if (el != null & el.getFirstChild() != null) { textVal = el.getFirstChild().getNodeValue(); } } return textVal; }
// firstchild, lastchild, nextsibling, previoussibling, parent @Test public void testNavigate() throws Exception { String xml = "<?xml version=\"1.0\"?>" + "<root>" + "<a/>" + "<b/>" + "<c/>" + "</root>"; DocumentBuilder builder = builderFactory.newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes())); Element root = doc.getDocumentElement(); Assert.assertEquals("a", ((Element) root.getFirstChild()).getTagName()); Assert.assertEquals("c", ((Element) root.getLastChild()).getTagName()); Assert.assertEquals("b", ((Element) root.getFirstChild().getNextSibling()).getTagName()); Assert.assertEquals("b", ((Element) root.getLastChild().getPreviousSibling()).getTagName()); Assert.assertEquals("root", ((Element) root.getFirstChild().getParentNode()).getTagName()); }
/** Add a list item */ public Document nextListItem(String format) { // <list-block> // <list-item> // <list-item-label end-indent="label-end()"><block>•</block></list-item-label> // <list-item-body start-indent="body-start()"> // <block/> // </list-item-body> // </list-item> // check containing list-block Element list = peek("list-block", "nextListItem() is not applicable outside list block"); // a list with only one item containing an empty block? if (list.getChildNodes().getLength() == 1 && cursor.getFirstChild() == null && cursor.getPreviousSibling() == null && cursor.getParentNode().getLocalName().equals("list-item-body")) { // delete list-item and start over list.removeChild(list.getFirstChild()); } // continue with list cursor = list; // find out what 'bullet' to use String label = attribute("genj:label", format); if (label != null) { // check provisional-distance-between-starts - we assume a certain 'em' per label character String dist = list.getAttribute("provisional-distance-between-starts"); if (dist.endsWith("em")) { float len = label.length() * 0.6F; if (Float.parseFloat(dist.substring(0, dist.length() - 2)) < len) list.setAttribute("provisional-distance-between-starts", len + "em"); } } else { label = "\u2219"; // • /u2219 works in JEditPane, • \u2022 doesn't } // add new item push("list-item"); push("list-item-label", "end-indent=label-end()"); push("block"); text(label, ""); pop(); pop(); push("list-item-body", "start-indent=body-start()"); push("block"); return this; }
/** * adds a tag to the existing word. Only adds the current tag and not its children * * @param tag */ public void addTag(Element tag) { Element e = XMLParser.xmlDocument.createElement(tag.getNodeName()); NamedNodeMap attributes = tag.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attribute = (Attr) attributes.item(i); e.setAttribute(attribute.getNodeName(), attribute.getNodeValue()); } tags.add(e); if (tag.hasChildNodes()) { if (tag.getFirstChild().getNodeType() == Element.ELEMENT_NODE) { addTag((Element) tag.getFirstChild()); } } }
public HttpNfcLeaseState getState() throws Exception { Object stateProp = _context.getVimClient().getDynamicProperty(_mor, "state"); // Due to some issue in JAX-WS De-serialization getting the information // from the nodes assert (stateProp.toString().contains("val: null")); String stateVal = null; Element stateElement = (Element) stateProp; if (stateElement != null && stateElement.getFirstChild() != null) { stateVal = stateElement.getFirstChild().getTextContent(); } if (stateVal != null) { return HttpNfcLeaseState.fromValue(stateVal); } return HttpNfcLeaseState.ERROR; }
private static String compareElements(String path, Element e1, Element e2) { if (!e1.getNamespaceURI().equals(e2.getNamespaceURI())) return "Namespaces differ at " + path + ": " + e1.getNamespaceURI() + "/" + e2.getNamespaceURI(); if (!e1.getLocalName().equals(e2.getLocalName())) return "Names differ at " + path + ": " + e1.getLocalName() + "/" + e2.getLocalName(); path = path + "/" + e1.getLocalName(); String s = compareAttributes(path, e1.getAttributes(), e2.getAttributes()); if (!Utilities.noString(s)) return s; s = compareAttributes(path, e2.getAttributes(), e1.getAttributes()); if (!Utilities.noString(s)) return s; Node c1 = e1.getFirstChild(); Node c2 = e2.getFirstChild(); c1 = skipBlankText(c1); c2 = skipBlankText(c2); while (c1 != null && c2 != null) { if (c1.getNodeType() != c2.getNodeType()) return "node type mismatch in children of " + path + ": " + Integer.toString(e1.getNodeType()) + "/" + Integer.toString(e2.getNodeType()); if (c1.getNodeType() == Node.TEXT_NODE) { if (!normalise(c1.getTextContent()).equals(normalise(c2.getTextContent()))) return "Text differs at " + path + ": " + normalise(c1.getTextContent()) + "/" + normalise(c2.getTextContent()); } else if (c1.getNodeType() == Node.ELEMENT_NODE) { s = compareElements(path, (Element) c1, (Element) c2); if (!Utilities.noString(s)) return s; } c1 = skipBlankText(c1.getNextSibling()); c2 = skipBlankText(c2.getNextSibling()); } if (c1 != null) return "node mismatch - more nodes in source in children of " + path; if (c2 != null) return "node mismatch - more nodes in target in children of " + path; return null; }
private Tree getTreeFromXML(Node root) { final Element eRoot = (Element) root; if (isWordNode(eRoot)) { return buildWordNode(eRoot); } else if (isEllipticNode(eRoot)) { return buildEllipticNode(eRoot); } else { List<Tree> kids = new ArrayList<>(); for (Node childNode = eRoot.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) { if (childNode.getNodeType() != Node.ELEMENT_NODE) continue; Tree t = getTreeFromXML(childNode); if (t == null) { System.err.printf( "%s: Discarding empty tree (root: %s)%n", this.getClass().getName(), childNode.getNodeName()); } else { kids.add(t); } } return (kids.size() == 0) ? null : buildConstituentNode(eRoot, kids); } }
public static String RecogniseFromXml(byte[] bin) { String tranCode = ""; String xmlStr = new String(bin); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Element theTranCode = null, root = null; try { factory.setIgnoringElementContentWhitespace(true); DocumentBuilder db = factory.newDocumentBuilder(); final byte[] bytes = xmlStr.getBytes(); final ByteArrayInputStream is = new ByteArrayInputStream(bytes); final InputSource source = new InputSource(is); Document xmldoc = db.parse(source); root = xmldoc.getDocumentElement(); theTranCode = (Element) selectSingleNode("/root/head/transid", root); // Element nameNode = (Element) theTranCode.getElementsByTagName("price").item(0); if (theTranCode != null) { tranCode = theTranCode.getFirstChild().getNodeValue(); } else { System.out.println("获取 /root/head/transid 失败!"); } // System.out.println(tranCode); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return tranCode; }
// the xml is different for these protected ArrayList<BGCOffenseSupplementBean> parseSupplements(Element e) { // XXX get right element first // e = offense // supp = offense/recordDetails/recordDetail/supplements (then each /supplement) Element eRecordDetails = (Element) e.getElementsByTagName("recordDetails").item(0); Element eRecordDetail = (Element) eRecordDetails.getElementsByTagName("recordDetail").item(0); Element eSupplements = (Element) eRecordDetail.getElementsByTagName("supplements").item(0); // HashMap<String,String> map = new HashMap<String,String>(); ArrayList<BGCOffenseSupplementBean> list = new ArrayList<BGCOffenseSupplementBean>(); NodeList nl = eSupplements.getElementsByTagName("supplement"); for (int i = 0; i < nl.getLength(); i++) { Element eSupp = (Element) nl.item(i); Node eTitle = eSupp.getFirstChild(); Node eValue = eSupp.getLastChild(); if (eTitle.getNodeName().equals("displayTitle") && eValue.getNodeName().equals("displayValue")) { String sTitle = eTitle.getFirstChild().getNodeValue(); // getTextContent(); String sValue = eValue.getFirstChild().getNodeValue(); // getTextContent(); BGCOffenseSupplementBean bean = new BGCOffenseSupplementBean(); bean.setDisplayTitle(sTitle); bean.setDisplayValue(sValue); // map.put(sTitle, sValue); list.add(bean); } } // return map; return list; }
@SuppressWarnings("unchecked") protected void handleForEachNode( final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException { super.handleNode(node, element, uri, localName, parser); ForEachNode forEachNode = (ForEachNode) node; org.w3c.dom.Node xmlNode = element.getFirstChild(); while (xmlNode != null) { String nodeName = xmlNode.getNodeName(); if ("ioSpecification".equals(nodeName)) { readIoSpecification(xmlNode, dataInputs, dataOutputs); } else if ("dataInputAssociation".equals(nodeName)) { readDataInputAssociation(xmlNode, forEachNode); } else if ("multiInstanceLoopCharacteristics".equals(nodeName)) { readMultiInstanceLoopCharacteristics(xmlNode, forEachNode, parser); } xmlNode = xmlNode.getNextSibling(); } List<SequenceFlow> connections = (List<SequenceFlow>) forEachNode.getMetaData(ProcessHandler.CONNECTIONS); ProcessHandler.linkConnections(forEachNode, connections); ProcessHandler.linkBoundaryEvents(forEachNode); }
private void emitMenu(SourceWriter writer, Element el) throws UnableToCompleteException { for (Node n = el.getFirstChild(); n != null; n = n.getNextSibling()) { if (n.getNodeType() != Node.ELEMENT_NODE) continue; Element child = (Element) n; if (child.getTagName().equals("cmd")) { String cmdId = child.getAttribute("refid"); writer.print("callback.addCommand("); writer.print("\"" + Generator.escape(cmdId) + "\", "); writer.println("this.cmds." + cmdId + "());"); } else if (child.getTagName().equals("separator")) { writer.println("callback.addSeparator();"); } else if (child.getTagName().equals("menu")) { String label = child.getAttribute("label"); writer.println("callback.beginMenu(\"" + Generator.escape(label) + "\");"); emitMenu(writer, child); writer.println("callback.endMenu();"); } else if (child.getTagName().equals("dynamic")) { String dynamicClass = child.getAttribute("class"); writer.println("new " + dynamicClass + "().execute(callback);"); } else { logger_.log(TreeLogger.Type.ERROR, "Unexpected tag " + el.getTagName() + " in menu"); throw new UnableToCompleteException(); } } }
/** * ct. * * @param param der XML-Knoten mit den Daten. */ private Param(Element param) { Node content = param.getFirstChild(); this.path = content != null ? content.getNodeValue() : null; this.type = param.getAttribute("type"); this.conditionName = param.getAttribute("condition-name"); this.conditionValue = param.getAttribute("condition-value"); }
private Element addLinkpool(Element topic, boolean prepend, String linkpoolType, Document doc) { Element relatedLinks = DITAUtil.findChildByClass(topic, "topic/related-links"); if (relatedLinks == null) { relatedLinks = doc.createElementNS(null, "related-links"); relatedLinks.setAttributeNS(null, "class", "- topic/related-links "); topic.insertBefore(relatedLinks, DITAUtil.findChildByClass(topic, "topic/topic")); } Element linkpool = doc.createElementNS(null, "linkpool"); linkpool.setAttributeNS(null, "class", "- topic/linkpool "); if (mapHref != null && linkpoolType != null) { // mapkeyref is a standard DITA 1.2 attribute meant for this use. linkpool.setAttributeNS(null, "mapkeyref", mapHref + " type=" + linkpoolType); } Node before = null; if (prepend) { before = relatedLinks.getFirstChild(); } relatedLinks.insertBefore(linkpool, before); return linkpool; }
private void processColumn( Element reltable, int column, LoadedDocuments loadedDocs, List<Entry> entryList, List<Entry[]> cellList) { Node child = reltable.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) child; if (DITAUtil.hasClass(childElement, "map/relrow")) { Element relcell = DOMUtil.getNthChildElement(childElement, column); if (relcell != null && DITAUtil.hasClass(relcell, "map/relcell")) { entryList.clear(); processCell(relcell, loadedDocs, entryList); Entry[] entries = new Entry[entryList.size()]; entryList.toArray(entries); cellList.add(entries); } } } child = child.getNextSibling(); } }
private void processHierarchy( Element topicrefOrMap, LoadedDocuments loadedDocs, List<Entry> childList) { CollectionType collectionType = null; String type = DITAUtil.getNonEmptyAttribute(topicrefOrMap, null, "collection-type"); if (type != null) { collectionType = CollectionType.fromString(type); } if (collectionType == null) { collectionType = CollectionType.UNORDERED; } processCollection(topicrefOrMap, collectionType, loadedDocs, childList); // Recurse --- // LIMITATION: @collection-type is ignored inside reltables. Node child = topicrefOrMap.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) child; if (DITAUtil.hasClass(childElement, "map/topicref") && // Does not make sense inside frontmatter/backmatter. // For example, inside a glossary. !DITAUtil.hasClass(childElement, "bookmap/frontmatter", "bookmap/backmatter")) { processHierarchy(childElement, loadedDocs, childList); } } child = child.getNextSibling(); } }
public ArrayList<Entity> getEntitiesFromFile(String filePath) { ArrayList<Entity> entities = new ArrayList<>(); try { d = db.parse(filePath); NodeList entityMentions = d.getElementsByTagName("entity_mention"); for (int i = 0; i < entityMentions.getLength(); i++) { Element entityMention = (Element) entityMentions.item(i); NodeList heads = entityMention.getElementsByTagName("head"); Element head = (Element) heads.item(0); NodeList charseqs = head.getElementsByTagName("charseq"); Element charseq = (Element) charseqs.item(0); int start = Integer.parseInt(charseq.getAttribute("START")); int end = Integer.parseInt(charseq.getAttribute("END")); String value = charseq.getFirstChild().getNodeValue(); // value = value.replaceAll("\n", ""); String id = entityMention.getAttribute("ID"); Element entityParent = (Element) entityMention.getParentNode(); String type = entityParent.getAttribute("TYPE"); // String subType = entityParent.getAttribute("SUBTYPE"); Entity entity = new Entity(value, start, end, type, id); entities.add(entity); } } catch (Exception e) { e.printStackTrace(); } return entities; }
/** * Returns a list of Filter objects that represents the feMergeNode of the specified feMerge * filter element. * * @param filterElement the feMerge filter element * @param filteredElement the filtered element * @param filteredNode the filtered graphics node * @param inputFilter the <tt>Filter</tt> that represents the current filter input if the filter * chain. * @param filterMap the filter map that contains named filter primitives * @param ctx the bridge context */ protected static List extractFeMergeNode( Element filterElement, Element filteredElement, GraphicsNode filteredNode, Filter inputFilter, Map filterMap, BridgeContext ctx) { List srcs = null; for (Node n = filterElement.getFirstChild(); n != null; n = n.getNextSibling()) { if (n.getNodeType() != Node.ELEMENT_NODE) { continue; } Element e = (Element) n; Bridge bridge = ctx.getBridge(e); if (bridge == null || !(bridge instanceof SVGFeMergeNodeElementBridge)) { continue; } Filter filter = ((SVGFeMergeNodeElementBridge) bridge) .createFilter(ctx, e, filteredElement, filteredNode, inputFilter, filterMap); if (filter != null) { if (srcs == null) { srcs = new LinkedList(); } srcs.add(filter); } } return srcs; }
public Document nextTableRow(String atts) { // peek at current cell - stay with it IF // + it's the first cell in the row // + the current cursor points at the first child (a block) // + the block pointed by cursor is empty Element cell = peek("table-cell", "nextTableRow() is not applicable outside enclosing table"); if (cell.getPreviousSibling() == null && cursor == cell.getFirstChild() && !cursor.hasChildNodes()) { attributes((Element) cell.getParentNode(), atts); return this; } // pop to table pop("table", "nextTableRow() is not applicable outside enclosing table"); Element table = cursor; // last child is already table-body? if (table.getLastChild().getNodeName().equals("table-body")) { cursor = (Element) table.getLastChild(); } else { push("table-body"); } // add row push("table-row", atts); // add cell push("table-cell", "border=" + table.getAttribute("border")); push("block"); // done return this; }