List of usage examples for org.jdom2 Element getChild
public Element getChild(final String cname, final Namespace ns)
From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutConverter.java
License:Open Source License
/** * Converts the layout of a YAWL task from container element * /*from w w w . j a v a 2 s. co m*/ * @param netLayout * @param yawlContainer * may be NULL if the task has no labels and decorators * @param yawlVertex * bounds of the vertex element inside the container */ private void convertTaskLayout(final NetLayout netLayout, final Element yawlContainer, final Element yawlVertex) { Element yawlVertexBounds = yawlVertex.getChild("attributes", yawlNamespace).getChild("bounds", yawlNamespace); NetElementLayout layoutInformation = new NetElementLayout(false); // Task has to be adjusted to Oryx coordinates, // as the JOIN/SPLIT decorator is part of the BasicShape in Oryx layoutInformation.setBounds(convertToOryxBounds(yawlVertexBounds, 24.0, 24.0)); layoutInformation.setIconPath(convertIconPath(yawlVertex)); if (yawlContainer != null) { convertDecorator(yawlContainer, layoutInformation); netLayout.putVertexLayout(yawlContainer.getAttributeValue("id"), layoutInformation); } else { netLayout.putVertexLayout(yawlVertex.getAttributeValue("id"), layoutInformation); } }
From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutConverter.java
License:Open Source License
/** * Extracts the information about the iconPath. * /* w w w . ja v a 2s. co m*/ * @param yawlVertex * @return IconPath as String or Empty String */ private String convertIconPath(final Element yawlVertex) { if (yawlVertex.getChild("iconpath", yawlNamespace) != null) { return yawlVertex.getChildText("iconpath", yawlNamespace); } return ""; }
From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutConverter.java
License:Open Source License
private DecoratorType convertDecoratorType(final Element yawlDecorator) { Element decoratorPosition = yawlDecorator.getChild("position", yawlNamespace); if (decoratorPosition != null) { return YAWLMapping.DECORATOR_TYPE_MAP.get(Integer.parseInt(decoratorPosition.getText())); }//from w w w . ja v a2 s. c o m return DecoratorType.NONE; }
From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutConverter.java
License:Open Source License
private int convertFlowLineStyle(final Element yawlFlow) { if (yawlFlow.getChild("attributes", yawlNamespace) != null) { Element attributes = yawlFlow.getChild("attributes", yawlNamespace); if (attributes.getChild("lineStyle", yawlNamespace) != null) { return Integer.parseInt(attributes.getChild("lineStyle", yawlNamespace).getValue()); }/*from ww w . java 2s . co m*/ } return 11; }
From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutConverter.java
License:Open Source License
private String convertFlowLabel(final Element yawlFlow) { if (yawlFlow.getChild("label", yawlNamespace) != null) { Element labelElement = yawlFlow.getChild("label", yawlNamespace); // TODO why is the label text urlencoded in YAWL? try {/*from w w w .jav a 2s . c om*/ return URLDecoder.decode(JDOMUtil.decodeEscapes(labelElement.getText()), "UTF-8"); } catch (UnsupportedEncodingException e) { return ""; } } return ""; }
From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutConverter.java
License:Open Source License
/** * @param netLayout// w w w .j av a2 s . c o m * @param yawlFlow * @return */ private ArrayList<Point> convertFlowDockers(final NetLayout netLayout, final Element yawlFlow) { Element flowPorts = yawlFlow.getChild("ports", yawlNamespace); Integer inPort = Integer.valueOf(flowPorts.getAttributeValue("in")); Integer outPort = Integer.valueOf(flowPorts.getAttributeValue("out")); Point inDocker; Point outDocker; String targetId = yawlFlow.getAttributeValue("target"); String sourceId = yawlFlow.getAttributeValue("source"); // Source may have a SPLIT decorator or may be a condition if (netLayout.getVertexLayout(sourceId).isCondition()) { inDocker = YAWLMapping.CONDITION_PORT_MAP.get(inPort); } else { inDocker = convertTaskDocker(netLayout.getVertexLayout(sourceId).getSplitDecorator(), inPort); } // Target may have a JOIN decorator or may be a condition if (netLayout.getVertexLayout(targetId).isCondition()) { outDocker = YAWLMapping.CONDITION_PORT_MAP.get(outPort); } else { outDocker = convertTaskDocker(netLayout.getVertexLayout(targetId).getJoinDecorator(), outPort); } // Fallback in case the values in XML are wrong if (outDocker == null) { outDocker = YAWLMapping.TASK_PORT_MAP.get(14); } if (inDocker == null) { inDocker = YAWLMapping.TASK_PORT_MAP.get(14); } ArrayList<Point> dockers = new ArrayList<Point>(); // Important to add as first Docker with source BasicShape coordinates dockers.add(inDocker); // Add bends from YAWL with coordinates of Diagram Element pointElement = yawlFlow.getChild("attributes", yawlNamespace).getChild("points", yawlNamespace); // points may be omitted in YAWL if (pointElement != null) { @SuppressWarnings("rawtypes") List pointList = pointElement.getChildren(); if (pointList.size() > 2) { // Skip the first and last element, // as those will be added according to the port information for (int i = 1; i < pointList.size() - 1; i++) { if (pointList.get(i) instanceof Element) { Element point = (Element) pointList.get(i); String x = point.getAttributeValue("x"); String y = point.getAttributeValue("y"); dockers.add(new Point(parseDouble(x), parseDouble(y))); } } } } // Important to add as last Docker with target BasicShape coordinates dockers.add(outDocker); return dockers; }
From source file:de.huberlin.german.korpling.laudatioteitool.SplitTEI.java
License:Apache License
private TEIValidator.Errors extractMainCorpusHeader(Document doc) throws LaudatioException, IOException, SAXException { TEIValidator validator = corpusSchemeURL == null ? new TEICorpusValidator() : new FromURLValidator(corpusSchemeURL); Element corpusHeader = doc.getRootElement().getChild("teiHeader", null); if (corpusHeader != null) { File corpusDir = new File(outputDirectory, "CorpusHeader"); if (!corpusDir.exists() && !corpusDir.mkdir()) { throw new LaudatioException( messages.getString("COULD NOT CREATE DIRECTORY") + corpusDir.getAbsolutePath()); }//from w w w . ja v a 2s .c om // create the subtree for the global corpus header Namespace teiNS = Namespace.getNamespace("http://www.tei-c.org/ns/1.0"); Element newRootForCorpus = new Element("TEI", teiNS); newRootForCorpus.addContent(corpusHeader.clone()); Document corpusDoc = new Document(newRootForCorpus); if (corpusSchemeURL == null) { corpusDoc.addContent(0, new ProcessingInstruction("xml-model", "href=\"" + TEICorpusValidator.DEFAULT_SCHEME_URL + "\"")); } else { corpusDoc.addContent(0, new ProcessingInstruction("xml-model", "href=\"" + corpusSchemeURL + "\"")); } // we need to append an empty "text" element after the header Element text = new Element("text", teiNS); text.setText(""); newRootForCorpus.addContent(text); // we work with the copy from now corpusHeader = newRootForCorpus.getChild("teiHeader", null); Preconditions.checkNotNull(corpusHeader, messages.getString("ERROR NO CORPUS TITLE GIVEN")); Preconditions.checkState("CorpusHeader".equals(corpusHeader.getAttributeValue("type"))); Preconditions.checkNotNull(corpusHeader.getChild("fileDesc", null), messages.getString("ERROR NO CORPUS TITLE GIVEN")); Preconditions.checkNotNull(corpusHeader.getChild("fileDesc", null).getChild("titleStmt", null), messages.getString("ERROR NO CORPUS TITLE GIVEN")); String title = corpusHeader.getChild("fileDesc", null).getChild("titleStmt", null) .getChildTextNormalize("title", null); Preconditions.checkNotNull(title, messages.getString("ERROR NO CORPUS TITLE GIVEN")); // save the file with the title as file name File outputFile = new File(corpusDir, title + ".xml"); XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); xmlOut.output(corpusDoc, new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")); log.info(messages.getString("WRITTEN CORPUS HEADER"), outputFile.getPath()); validator.validate(outputFile); } return validator.getErrors(); }
From source file:de.huberlin.german.korpling.laudatioteitool.SplitTEI.java
License:Apache License
private TEIValidator.Errors extractDocumentHeaders(Document doc) throws LaudatioException, IOException, SAXException { TEIValidator validator = documentSchemeURL == null ? new TEIDocumentValidator() : new FromURLValidator(documentSchemeURL); File documentDir = new File(outputDirectory, "DocumentHeader"); if (!documentDir.exists() && !documentDir.mkdir()) { throw new LaudatioException( messages.getString("COULD NOT CREATE DIRECTORY") + documentDir.getAbsolutePath()); }//from ww w .ja va 2 s. c om Element documentRoot = Preconditions.checkNotNull(doc.getRootElement().getChild("teiCorpus", null)); for (Element docHeader : documentRoot.getChildren("teiHeader", null)) { Preconditions.checkState("DocumentHeader".equals(docHeader.getAttributeValue("type"))); // create the subtree for the global corpus header Namespace teiNS = Namespace.getNamespace("http://www.tei-c.org/ns/1.0"); Element tei = new Element("TEI", teiNS); tei.addContent(docHeader.clone()); Document newDoc = new Document(tei); if (documentSchemeURL == null) { newDoc.addContent(0, new ProcessingInstruction("xml-model", "href=\"" + TEIDocumentValidator.DEFAULT_SCHEME_URL + "\"")); } else { newDoc.addContent(0, new ProcessingInstruction("xml-model", "href=\"" + documentSchemeURL + "\"")); } // we need to append an empty "text" element after the header Element text = new Element("text", teiNS); text.setText(""); tei.addContent(text); Element fileDesc = Preconditions .checkNotNull(tei.getChild("teiHeader", null).getChild("fileDesc", null)); String outName = UUID.randomUUID().toString(); String id = fileDesc.getAttributeValue("id", Namespace.XML_NAMESPACE); if (id != null) { outName = id; } else { Element titleStmt = Preconditions.checkNotNull(fileDesc.getChild("titleStmt", null)); String title = titleStmt.getChildText("title", null); if (title != null) { outName = title; } } File outputFile = new File(documentDir, outName + ".xml"); XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); xmlOut.output(newDoc, new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")); log.info(messages.getString("WRITTEN DOCUMENT HEADER"), outputFile.getPath()); validator.validate(outputFile); } return validator.getErrors(); }
From source file:de.huberlin.german.korpling.laudatioteitool.SplitTEI.java
License:Apache License
private TEIValidator.Errors extractPreparationSteps(Document doc) throws LaudatioException, IOException, SAXException { TEIValidator validator = preparationSchemeURL == null ? new TEIPreparationValidator() : new FromURLValidator(preparationSchemeURL); Multiset<String> knownPreparationTitles = HashMultiset.create(); File documentDir = new File(outputDirectory, "PreparationHeader"); if (!documentDir.exists() && !documentDir.mkdir()) { throw new LaudatioException( messages.getString("COULD NOT CREATE DIRECTORY") + documentDir.getAbsolutePath()); }//from www. j ava 2 s. co m Preconditions.checkNotNull(doc.getRootElement().getChild("teiCorpus", null)); Element preparationRoot = Preconditions .checkNotNull(doc.getRootElement().getChild("teiCorpus", null).getChild("teiCorpus", null)); for (Element preparationHeader : preparationRoot.getChildren("teiHeader", null)) { Preconditions.checkState("PreparationHeader".equals(preparationHeader.getAttributeValue("type"))); // create the subtree for the global corpus header Namespace teiNS = Namespace.getNamespace("http://www.tei-c.org/ns/1.0"); Element tei = new Element("TEI", teiNS); tei.addContent(preparationHeader.clone()); Document newDoc = new Document(tei); if (preparationSchemeURL == null) { newDoc.addContent(0, new ProcessingInstruction("xml-model", "href=\"" + TEIPreparationValidator.DEFAULT_SCHEME_URL + "\"")); } else { newDoc.addContent(0, new ProcessingInstruction("xml-model", "href=\"" + preparationSchemeURL + "\"")); } // we need to append an empty "text" element after the header Element text = new Element("text", teiNS); text.setText(""); tei.addContent(text); Element fileDesc = Preconditions .checkNotNull(tei.getChild("teiHeader", null).getChild("fileDesc", null)); String outName = UUID.randomUUID().toString(); Element titleStmt = Preconditions.checkNotNull(fileDesc.getChild("titleStmt", null)); Element title = Preconditions.checkNotNull(titleStmt.getChild("title", null)); String corresp = title.getAttributeValue("corresp"); if (corresp != null) { if (knownPreparationTitles.contains(corresp)) { knownPreparationTitles.add(corresp); outName = corresp + "_" + knownPreparationTitles.count(corresp); log.warn(messages.getString("MORE THAN ONE PREPARATION HEADER"), corresp); } else { outName = corresp; knownPreparationTitles.add(corresp); } } File outputFile = new File(documentDir, outName + ".xml"); XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); xmlOut.output(newDoc, new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")); log.info(messages.getString("WRITTEN PREPARATION HEADER"), outputFile.getPath()); validator.validate(outputFile); } return validator.getErrors(); }
From source file:de.intranda.goobi.plugins.sru.SRUHelper.java
License:Open Source License
public static Element getRecordWithoutSruHeader(Document document) { Element root = document.getRootElement(); // <srw:records> Element srw_records = root.getChild("records", SRW); // <srw:record> if (srw_records == null) { return null; }// w w w . jav a 2 s. com List<Element> srw_recordList = srw_records.getChildren("record", SRW); // <srw:recordData> if (srw_recordList == null || srw_recordList.isEmpty()) { return null; } Element recordData = srw_recordList.get(0).getChild("recordData", SRW); Element record = recordData.getChild("record", MARC); return record; }