private Element prepareDocumentationElement(Namespace rootns) { Element documentationOf = new Element("documentationOf", rootns); Element serviceEvent = new Element("serviceEvent", rootns); Element performer = new Element("performer", rootns); Element assignedEntity = new Element("assignedEntity", rootns); Element nationalProviderIdentifier = new Element("id", rootns) .setAttribute("root", "2.16.840.1.113883.4.6") .setAttribute("extension", "2567891421"); Element representedOrganization = prepareRepOrgWithTaxPayerId(rootns); assignedEntity.addContent(representedOrganization); assignedEntity.addContent(nationalProviderIdentifier); performer.addContent(assignedEntity); serviceEvent.addContent(performer); documentationOf.addContent(serviceEvent); return documentationOf; }
@Test void testInternalDecode() throws Exception { Namespace rootNs = Namespace.getNamespace("urn:hl7-org:v3"); Namespace ns = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Context context = new Context(); Element element = new Element("observation", rootNs); element.addContent(new Element("templateId", rootNs).setAttribute("root", TemplateId.ACI_AGGREGATE_COUNT.getTemplateId(context))); element.addContent(new Element("value", rootNs).setAttribute("value", "450").setAttribute("type", "INT", ns)); element.addNamespaceDeclaration(ns); Node thisNode = new Node(); AggregateCountDecoder instance = new AggregateCountDecoder(context); instance.setNamespace(element, instance); instance.internalDecode(element, thisNode); assertThat(thisNode.getValue("aggregateCount")) .isEqualTo("450"); }
/** * for the server request ?verb=ListIdentifiers this method build the xml section * * @param handler * @param firstRow * @param numRows * @return * @throws SolrServerException */ public Element createListIdentifiers(RequestHandler handler, int firstRow, int numRows) throws SolrServerException { Map<String, String> datestamp = filterDatestampFromRequest(handler); SolrDocumentList listIdentifiers = solr.getListIdentifiers(datestamp, firstRow, numRows, false); if (listIdentifiers == null || listIdentifiers.isEmpty()) { return new ErrorCode().getNoRecordsMatch(); } Namespace xmlns = DataManager.getInstance().getConfiguration().getStandardNameSpace(); Element xmlListIdentifiers = new Element("ListIdentifiers", xmlns); long totalHits = listIdentifiers.getNumFound(); for (int i = 0; i < listIdentifiers.size(); i++) { SolrDocument doc = listIdentifiers.get(i); Element header = getHeader(doc, null, handler); xmlListIdentifiers.addContent(header); } // Create resumption token if (totalHits > firstRow + numRows) { Element resumption = createResumptionTokenAndElement(totalHits, firstRow + numRows, xmlns, handler); xmlListIdentifiers.addContent(resumption); } return xmlListIdentifiers; }
/** * for the server request ?verb=ListMetadataFormats this method build the xml section * * @return */ public Element createMetadataFormats() { Namespace xmlns = DataManager.getInstance().getConfiguration().getStandardNameSpace(); if (Metadata.values().length == 0) { return new ErrorCode().getNoMetadataFormats(); } Element listMetadataFormats = new Element("ListMetadataFormats", xmlns); for (Metadata m : Metadata.values()) { // logger.trace("{}: {}", m.getMetadataPrefix(), DataManager.getInstance().getConfiguration().isMetadataFormatEnabled(m.name())); if (m.isOaiSet() && DataManager.getInstance().getConfiguration().isMetadataFormatEnabled(m.name())) { Element metadataFormat = new Element("metadataFormat", xmlns); Element metadataPrefix = new Element("metadataPrefix", xmlns); metadataPrefix.setText(m.getMetadataPrefix()); Element schema = new Element("schema", xmlns); schema.setText(m.getSchema()); Element metadataNamespace = new Element("metadataNamespace", xmlns); metadataNamespace.setText(m.getMetadataNamespace()); metadataFormat.addContent(metadataPrefix); metadataFormat.addContent(schema); metadataFormat.addContent(metadataNamespace); listMetadataFormats.addContent(metadataFormat); } } return listMetadataFormats; }
/** * * @param totalHits * @param cursor * @param xmlns * @param handler * @return */ private Element createResumptionTokenAndElement(long totalHits, int cursor, Namespace xmlns, RequestHandler handler) { long now = System.currentTimeMillis(); long time = now + expiration; ResumptionToken token = new ResumptionToken("oai_" + System.currentTimeMillis(), totalHits, cursor, time, handler); try { saveToken(token); } catch (IOException e) { // do nothing } Element eleResumptionToken = new Element("resumptionToken", xmlns); eleResumptionToken.setAttribute("expirationDate", Utils.convertDate(time)); eleResumptionToken.setAttribute("completeListSize", String.valueOf(totalHits)); eleResumptionToken.setAttribute("cursor", String.valueOf(cursor)); eleResumptionToken.setText(token.getTokenName()); return eleResumptionToken; }
/** * Adds relevant XML namespaces to the list of available namespace objects. * * @should add custom namespaces correctly */ public void initNamespaces() { namespaces.clear(); namespaces.put("xml", Namespace.getNamespace("xml", "http://www.w3.org/XML/1998/namespace")); namespaces.put("mets", Namespace.getNamespace("mets", "http://www.loc.gov/METS/")); namespaces.put("mods", Namespace.getNamespace("mods", "http://www.loc.gov/mods/v3")); namespaces.put("gdz", Namespace.getNamespace("gdz", "http://gdz.sub.uni-goettingen.de/")); namespaces.put("xlink", Namespace.getNamespace("xlink", "http://www.w3.org/1999/xlink")); namespaces.put("dv", Namespace.getNamespace("dv", "http://dfg-viewer.de/")); namespaces.put("lido", Namespace.getNamespace("lido", "http://www.lido-schema.org")); namespaces.put("mix", Namespace.getNamespace("mix", "http://www.loc.gov/mix/v20")); namespaces.put("mm", Namespace.getNamespace("mm", "http://www.mycore.de/metsmaker/v1")); namespaces.put("tei", Namespace.getNamespace("tei", "http://www.tei-c.org/ns/1.0")); Map<String, String> additionalNamespaces = getListConfiguration("init.namespaces"); if (additionalNamespaces != null) { for (String key : additionalNamespaces.keySet()) { namespaces.put(key, Namespace.getNamespace(key, additionalNamespaces.get(key))); logger.info("Added custom namespace '{}'.", key); } } }
protected static String getPreferredRubricLabel(Element classElement, String lang) { Iterator<Element> it = classElement.getChildren(ClamlConstants.RUBRIC_ELEMENT).iterator(); String label = null; while (it.hasNext() && label == null) { Element rubric = it.next(); if (ClamlConstants.RUBRIC_KIND_PREFFERD_ATTR.equals(rubric.getAttributeValue(ClamlConstants.KIND_ATTR))) { Element labelElement = rubric.getChild(ClamlConstants.LABEL_ELEMENT); if (labelElement != null) { if (CommonUtil.isEmptyString(lang) || lang.equals(labelElement.getAttributeValue(ClamlConstants.XML_LANG, Namespace.XML_NAMESPACE))) { label = labelElement.getTextTrim(); } } else { throw new IllegalArgumentException(getKind(classElement) + " " + getCode(classElement) + ": " + ClamlConstants.RUBRIC_ELEMENT + " without " + ClamlConstants.LABEL_ELEMENT); } } } return label; }
/** * Returns a List of NamespaceURIs used in the subtree of node * @param element * {@link Element} * @return {@link java.util.List}<{@link String}> * @author sholzer (14.04.2015) */ private List<String> getNameSpaces(Element element) { List<String> namespaces = new LinkedList<>(); for (Namespace ns : element.getNamespacesInScope()) { boolean flag = true; for (String s : namespaces) { if (ns.getURI().equals(s)) { flag = false; break; } } if (flag) { namespaces.add(ns.getURI()); } } return namespaces; }
/** * Simple Spring Beans test case. * @throws Exception * when something somewhere goes wrong * @author sholzer (31.03.2015) */ @Test public void ThirdBeanTest() throws Exception { String mergeSchemaLocation = resources + "mergeschemas"; String bean = "http://www.springframework.org/schema/beans"; String aop = "http://www.springframework.org/schema/aop"; Document base = JDom2Util.getInstance().getDocument(resources + "bases/Beans3.xml"); Document patch = JDom2Util.getInstance().getDocument(resources + "patches/Beans3.xml"); LeXeMerger testMerger = new LeXeMerger(mergeSchemaLocation); Element result = testMerger.merge(base.getRootElement(), patch.getRootElement(), ConflictHandlingType.PATCHOVERWRITE); assertEquals("Not as much bean as expected", result.getChildren("bean", Namespace.getNamespace(bean)) .size(), 2); assertTrue("no aop:config found", result.getChildren("config", Namespace.getNamespace(aop)).size() == 1); Element config = result.getChild("config", Namespace.getNamespace(aop)); assertEquals("Not as much pointcut as expected", 2, config.getChildren("pointcut", Namespace.getNamespace(aop)).size()); assertEquals("Not as much advisor as expected", 2, config.getChildren("advisor", Namespace.getNamespace(aop)).size()); }
/** * Test case as in {@link FirstWorkingBuild#SecondTest()}. Patch uses another prefix for its namespace. * The prefix used in the result should be the same as in the base * @throws Exception * when something somewhere goes wrong * @author sholzer (31.03.2015) */ @Test public void SecondTestWithDifferentPrefixes() throws Exception { String mergeSchemaLocation = resources + "mergeschemas/SecondMergeSchema.xml"; String uri = "http://www.example.org/SecondSchema"; Document base = JDom2Util.getInstance().getDocument(resources + "bases/SecondBase.xml"); Document patch = JDom2Util.getInstance().getDocument(resources + "patches/SecondPatchWithOtherPrefixes.xml"); LeXeMerger testMerger = new LeXeMerger(mergeSchemaLocation); Element result = testMerger.merge(base.getRootElement(), patch.getRootElement(), ConflictHandlingType.PATCHATTACHOROVERWRITE); assertTrue("No B Element found", result.getChildren("B", Namespace.getNamespace(uri)).size() == 1); Element b = result.getChildren("B", Namespace.getNamespace(uri)).get(0); assertTrue("Wrong id at B element", b.getAttribute("id").getValue().equals("abc;def")); assertTrue("No B Element found", (result.getChildren("C", Namespace.getNamespace(uri))).size() == 1); Element c = result.getChildren("C", Namespace.getNamespace(uri)).get(0); assertTrue("Wrong number of Ca elements", (c.getChildren("Ca", Namespace.getNamespace(uri))).size() == 1); assertTrue("Wrong content of Ca", JDom2Util.getInstance().getTextNodes(c.getChildren("Ca", Namespace.getNamespace(uri)).get(0)) .get(0).getText().equals("0")); int numberOfCb = (c.getChildren("Cb", Namespace.getNamespace(uri))).size(); assertTrue("Wrong number of Cb elements. Found " + numberOfCb, numberOfCb == 3); }
/** * Simple Spring Beans test case * @throws Exception * when something somewhere goes wrong * @author sholzer (31.03.2015) */ @Test public void SecondBeanTest() throws Exception { String mergeSchemaLocation = resources + "mergeschemas/BeansMergeSchema.xml"; String namespaceUri = "http://www.springframework.org/schema/beans"; Document base = JDom2Util.getInstance().getDocument(resources + "bases/Beans2.xml"); Document patch = JDom2Util.getInstance().getDocument(resources + "patches/Beans2.xml"); LeXeMerger testMerger = new LeXeMerger(mergeSchemaLocation); Element result = testMerger.merge(base.getRootElement(), patch.getRootElement(), ConflictHandlingType.PATCHOVERWRITE); assertEquals("Not all bean elements found", 2, result.getChildren("bean", Namespace.getNamespace("http://www.springframework.org/schema/beans")) .size()); List<Element> beanNodeList = result.getChildren("bean", Namespace.getNamespace(namespaceUri)); Element bean1 = beanNodeList.get(0); assertEquals("wrong parent for bean1", "bean2", bean1.getAttribute("parent").getValue()); assertEquals("No properties found", 1, bean1.getChildren("property", Namespace.getNamespace(namespaceUri)).size()); }
/** * Tests the merge process if the merge schema has multiple namespace definitions. The setup of * {@link FirstWorkingBuild#FirstTest()} is used with a modified MergeSchema * @throws Exception * when something unexpected happens * @author sholzer (Jul 30, 2015) */ @Test public void testAdditionalNamespaceDefinition() throws Exception { final String mergeSchemaLocation = pathRoot + "mergeschemas/CobiGenIntegration/"; final String uri = "http://www.example.org/FirstXMLSchema"; Document base = JDom2Util.getInstance().getDocument(pathRoot + "bases/FirstBase.xml"); Document patch = JDom2Util.getInstance().getDocument(pathRoot + "patches/FirstPatch.xml"); LeXeMerger testObject = LeXeMeFactory.build(mergeSchemaLocation); Element result = testObject.merge(base.getRootElement(), patch.getRootElement(), ConflictHandlingType.PATCHATTACHOROVERWRITE); List<Element> bList = result.getChildren("B", Namespace.getNamespace(uri)); assertTrue("Wrong number of B elements found. Excpected 2, found " + bList.size(), bList.size() == 2); assertTrue("Wrong id attribute at first B element", bList.get(0).getAttribute("id").getValue() .equals("abc")); assertTrue("Wrong id attribute at first B element", bList.get(1).getAttribute("id").getValue() .equals("def")); List<Element> cList = result.getChildren("C", Namespace.getNamespace(uri)); assertTrue("Wrong number of C elements found. Excpected 1, found " + cList.size(), cList.size() == 1); assertTrue("Wrong id attribute at first C element", cList.get(0).getAttribute("id").getValue() .equals("def")); }
/** * Output xml * @param eRoot - the root element * @param lang - the language which should be filtered or null for no filter * @return a string representation of the XML * @throws IOException */ private static String writeXML(Element eRoot, String lang) throws IOException { StringWriter sw = new StringWriter(); if (lang != null) { // <label xml:lang="en" text="part" /> XPathExpression<Element> xpE = XPathFactory.instance().compile("//label[@xml:lang!='" + lang + "']", Filters.element(), null, Namespace.XML_NAMESPACE); for (Element e : xpE.evaluate(eRoot)) { e.getParentElement().removeContent(e); } } XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); Document docOut = new Document(eRoot.detach()); xout.output(docOut, sw); return sw.toString(); }
/** * output children in JSON format used as input for Dijit Checkbox Tree * * @param eParent - the parent xml element * @param writer - the JSON writer * @param lang - the language to be filtered or null if all languages should be displayed * * @throws IOException */ private static void writeChildrenAsJSONCBTree(Element eParent, JsonWriter writer, String lang, boolean checked) throws IOException { writer.beginArray(); for (Element e : eParent.getChildren("category")) { writer.beginObject(); writer.name("ID").value(e.getAttributeValue("ID")); for (Element eLabel : e.getChildren("label")) { if (lang == null || lang.equals(eLabel.getAttributeValue("lang", Namespace.XML_NAMESPACE))) { writer.name("text").value(eLabel.getAttributeValue("text")); } } writer.name("checked").value(checked); if (e.getChildren("category").size() > 0) { writer.name("children"); writeChildrenAsJSONCBTree(e, writer, lang, checked); } writer.endObject(); } writer.endArray(); }
/** * Sets a label for this node * * @param lang * the xml:lang language ID * @param label * the label in this language */ public void setLabel(String lang, String label) throws IOException { data.getChildren(LABEL_ELEMENT) .stream() .filter(child -> lang.equals( child.getAttributeValue(LANG_ATT, Namespace.XML_NAMESPACE))) .findAny() .orElseGet(() -> { Element newLabel = new Element(LABEL_ELEMENT).setAttribute(LANG_ATT, lang, Namespace.XML_NAMESPACE); data.addContent(newLabel); return newLabel; }) .setText(label); getRoot().saveAdditionalData(); }
/** * Build an CoordAxis2D from a JDOM representation of element name. * * @param name * the name of the Element. * @param parent * the parent Element. * @param namespace * of the document. * @param required * is the element expected to be found. * @return an CoordAxis2D, or null if the document doesn't contain element * called name. * @throws ObservationParsingException */ protected CoordAxis2D getCoordAxis2D(String name, Element parent, Namespace namespace, boolean required) throws ObservationParsingException { Element element = getChildElement(name, parent, namespace, required); if (element == null || element.getContentSize() == 0) { return null; } Axis axis1 = getAxis("axis1", element, namespace, true); Axis axis2 = getAxis("axis2", element, namespace, true); CoordAxis2D axis = new CoordAxis2D(axis1, axis2); axis.error1 = getCoordError("error1", element, namespace, false); axis.error2 = getCoordError("error2", element, namespace, false); axis.range = getCoordRange2D("range", element, namespace, false); axis.bounds = getCoordBounds2D("bounds", element, namespace, false); axis.function = getCoordFunction2D("function", element, namespace, false); return axis; }
/** * This method creates a XML stream for all data in this class, defined by * the MyCoRe XML MCRMetaHistoryDate definition for the given subtag. * * @exception MCRException * if the content of this class is not valid * @return a JDOM Element with the XML MCRMetaHistoryDate part */ @Override public org.jdom2.Element createXML() throws MCRException { Element elm = super.createXML(); for (MCRMetaHistoryDateText text : texts) { Element elmt = new Element("text"); elmt.addContent(text.getText()); elmt.setAttribute("lang", text.getLang(), Namespace.XML_NAMESPACE); elm.addContent(elmt); } elm.addContent(new org.jdom2.Element("calendar").addContent(calendar)); elm.addContent(new org.jdom2.Element("ivon").addContent(Integer.toString(ivon))); elm.addContent(new org.jdom2.Element("von").addContent(getVonToString())); elm.addContent(new org.jdom2.Element("ibis").addContent(Integer.toString(ibis))); elm.addContent(new org.jdom2.Element("bis").addContent(getBisToString())); return elm; }
/** * This abstract method create a XML stream for all data in this class, * defined by the MyCoRe XML MCRMeta... definition for the given subtag. * * @exception MCRException * if the content of this class is not valid * @return a JDOM Element with the XML MCRMeta... part */ public Element createXML() throws MCRException { try { validate(); } catch (MCRException exc) { debug(); throw exc; } Element elm = new Element(subtag); if (getLang() != null && getLang().length() > 0) elm.setAttribute("lang", getLang(), Namespace.XML_NAMESPACE); if (getType() != null && getType().length() > 0) { elm.setAttribute("type", getType()); } elm.setAttribute("inherited", Integer.toString(getInherited())); return elm; }
@SuppressWarnings("unchecked") private Object buildNameStep(NameStep nameStep, String value, Parent parent) throws JaxenException { String name = nameStep.getLocalName(); String prefix = nameStep.getPrefix(); Namespace ns = prefix.isEmpty() ? Namespace.NO_NAMESPACE : MCRConstants.getStandardNamespace(prefix); if (nameStep.getAxis() == Axis.CHILD) { if (parent instanceof Document) return buildPredicates(nameStep.getPredicates(), ((Document) parent).getRootElement()); else return buildPredicates(nameStep.getPredicates(), buildElement(ns, name, value, (Element) parent)); } else if (nameStep.getAxis() == Axis.ATTRIBUTE) { return buildAttribute(ns, name, value, (Element) parent); } else { if (LOGGER.isDebugEnabled()) LOGGER.debug("ignoring axis, can not be built: {} {}{}", nameStep.getAxis(), prefix.isEmpty() ? "" : prefix + ":", name); return null; } }
protected void addKeywordsToList(Collection<String> list, Element element, Namespace ns) throws ObservationParsingException { Element kwe = element.getChild("keywords", ns); log.debug("addKeywordsToList: " + kwe); if (kwe == null) { return; } List kws = kwe.getChildren("keyword", ns); log.debug("addKeywordsToList: " + kws.size()); Iterator it = kws.iterator(); while (it.hasNext()) { Element k = (Element) it.next(); String s = k.getTextTrim(); log.debug("addKeywordsToList: " + s); list.add(s); } }
/** * Build an CoordAxis1D from a JDOM representation of element name. * * @param name * the name of the Element. * @param parent * the parent Element. * @param namespace * of the document. * @param required * is the element expected to be found. * @return an CoordAxis1D, or null if the document doesn't contain element * called name. * @throws ObservationParsingException */ protected CoordAxis1D getCoordAxis1D(String name, Element parent, Namespace namespace, boolean required) throws ObservationParsingException { Element element = getChildElement(name, parent, namespace, required); if (element == null || element.getContentSize() == 0) { return null; } Axis axis = getAxis("axis", element, namespace, true); CoordAxis1D coordAxis1D = new CoordAxis1D(axis); coordAxis1D.error = getCoordError("error", element, namespace, false); coordAxis1D.range = getCoordRange1D("range", element, namespace, false); coordAxis1D.bounds = getCoordBounds1D("bounds", element, namespace, false); coordAxis1D.function = getCoordFunction1D("function", element, namespace, false); return coordAxis1D; }
private Element generateCategoryElement(final Category cat) { final Namespace namespace = getFeedNamespace(); final Element catElement = new Element("category", namespace); final String term = cat.getTerm(); if (term != null) { final Attribute termAttribute = new Attribute("term", term); catElement.setAttribute(termAttribute); } final String label = cat.getLabel(); if (label != null) { final Attribute labelAttribute = new Attribute("label", label); catElement.setAttribute(labelAttribute); } final String scheme = cat.getScheme(); if (scheme != null) { final Attribute schemeAttribute = new Attribute("scheme", scheme); catElement.setAttribute(schemeAttribute); } return catElement; }
/** * Build an Algorithm from a JDOM representation of an algorithm element. * * @param parent * the parent Element. * @param namespace * of the document. * @param rc * @return an Algorithm, or null if the document doesn't contain an * algorithm element. * @throws ObservationParsingException */ protected Environment getEnvironment(Element parent, Namespace namespace, ReadContext rc) throws ObservationParsingException { Element element = getChildElement("environment", parent, namespace, false); if (element == null || element.getContentSize() == 0) { return null; } Environment env = new Environment(); env.seeing = getChildTextAsDouble("seeing", element, namespace, false); env.humidity = getChildTextAsDouble("humidity", element, namespace, false); env.elevation = getChildTextAsDouble("elevation", element, namespace, false); env.tau = getChildTextAsDouble("tau", element, namespace, false); env.wavelengthTau = getChildTextAsDouble("wavelengthTau", element, namespace, false); env.ambientTemp = getChildTextAsDouble("ambientTemp", element, namespace, false); env.photometric = getChildTextAsBoolean("photometric", element, namespace, false); return env; }
/** * Build an Proposal from a JDOM representation of an proposal element. * * @param parent * the parent Element. * @param namespace * of the document. * @param rc * @return an Proposal, or null if the document doesn't contain an proposal * element. * @throws ObservationParsingException */ protected Proposal getProposal(Element parent, Namespace namespace, ReadContext rc) throws ObservationParsingException { Element element = getChildElement("proposal", parent, namespace, false); if (element == null || element.getContentSize() == 0) { return null; } String id = getChildText("id", element, namespace, true); // no check for null: Proposal will check and throw if illegal Proposal proposal = new Proposal(id); proposal.pi = getChildText("pi", element, namespace, false); proposal.project = getChildText("project", element, namespace, false); proposal.title = getChildText("title", element, namespace, false); if (rc.docVersion < 23) { addChildTextToStringList("keywords", proposal.getKeywords(), element, namespace, false); } else { addKeywordsToList(proposal.getKeywords(), element, namespace); } return proposal; }
/** * Build a TargetPosition from a JDOM representation of an targetPosition * element. * * @param parent * the parent Element. * @param namespace * of the document. * @param rc * @return a TargetPosition, or null if the document doesn't contain an * targetPosition element. * @throws ObservationParsingException */ protected TargetPosition getTargetPosition(Element parent, Namespace namespace, ReadContext rc) throws ObservationParsingException { Element element = getChildElement("targetPosition", parent, namespace, false); if (element == null || element.getContentSize() == 0) { return null; } String coordsys = getChildText("coordsys", element, namespace, true); Double equinox = getChildTextAsDouble("equinox", element, namespace, false); Element coords = getChildElement("coordinates", element, namespace, true); double cval1 = getChildTextAsDouble("cval1", coords, namespace, true); double cval2 = getChildTextAsDouble("cval2", coords, namespace, true); TargetPosition tpos = new TargetPosition(coordsys, new Point(cval1, cval2)); tpos.equinox = equinox; return tpos; }
/** * Build an Instrument from a JDOM representation of an instrument element. * * @param parent * the parent Element. * @param namespace * of the document. * @param rc * @return an Instrument, or null if the document doesn't contain an * instrument element. * @throws ObservationParsingException */ protected Instrument getInstrument(Element parent, Namespace namespace, ReadContext rc) throws ObservationParsingException { Element element = getChildElement("instrument", parent, namespace, false); if (element == null || element.getContentSize() == 0) { return null; } String name = getChildText("name", element, namespace, true); Instrument instrument = new Instrument(name); if (rc.docVersion < 23) { addChildTextToStringList("keywords", instrument.getKeywords(), element, namespace, false); } else { addKeywordsToList(instrument.getKeywords(), element, namespace); } return instrument; }
/** * Creates ObservationURI from the observationURI elements found in the * members element, and adds them to the given Set of ObservationURI's. * * @param members * Set of Member's from the Observation. * @param parent * the parent Element. * @param namespace * of the document. * @param rc * @throws ObservationParsingException */ protected void addMembers(Set<ObservationURI> members, Element parent, Namespace namespace, ReadContext rc) throws ObservationParsingException { Element element = getChildElement("members", parent, namespace, false); if (element != null) { List children = getChildrenElements("observationURI", element, namespace, false); Iterator it = children.iterator(); while (it.hasNext()) { Element child = (Element) it.next(); try { members.add(new ObservationURI(new URI(child.getText()))); } catch (URISyntaxException e) { String error = "Unable to parse observationURI " + child.getText() + " in to an ObservationURI in element " + element.getName() + " because " + e.getMessage(); throw new ObservationParsingException(error); } } } }
/** * Build an CoordFunction2D from a JDOM representation of an element named * name. * * @param name * the name of the Element. * @param parent * the parent Element. * @param namespace * of the document. * @param required * is the element expected to be found. * @return an CoordFunction2D, or null if the document doesn't contain * element named name. * @throws ObservationParsingException */ protected CoordFunction2D getCoordFunction2D(String name, Element parent, Namespace namespace, boolean required) throws ObservationParsingException { Element element = getChildElement(name, parent, namespace, false); if (element == null || element.getContentSize() == 0) { return null; } Dimension2D dimension = getDimension2D("dimension", element, namespace, true); Coord2D refCoord = getCoord2D("refCoord", element, namespace, true); double cd11 = getChildTextAsDouble("cd11", element, namespace, true); double cd12 = getChildTextAsDouble("cd12", element, namespace, true); double cd21 = getChildTextAsDouble("cd21", element, namespace, true); double cd22 = getChildTextAsDouble("cd22", element, namespace, true); return new CoordFunction2D(dimension, refCoord, cd11, cd12, cd21, cd22); }
/** * Creates PlaneURI's from the planeURI elements found in the inputs * element, and adds them to the given Set of PlaneURI's. * * @param inputs * the Set of PlaneURI from the Provenance. * @param parent * the parent Element. * @param namespace * of the document. * @param rc * @throws ObservationParsingException */ protected void addInputs(Set<PlaneURI> inputs, Element parent, Namespace namespace, ReadContext rc) throws ObservationParsingException { Element element = getChildElement("inputs", parent, namespace, false); if (element != null) { List children = getChildrenElements("planeURI", element, namespace, false); Iterator it = children.iterator(); while (it.hasNext()) { Element child = (Element) it.next(); try { inputs.add(new PlaneURI(new URI(child.getText()))); } catch (URISyntaxException e) { String error = "Unable to parse observationURI " + child.getText() + " in to an ObservationURI in element " + element.getName() + " because " + e.getMessage(); throw new ObservationParsingException(error); } } } }
protected void addChildTextToStringList(String name, Collection<String> list, Element element, Namespace ns, boolean required) throws ObservationParsingException { String child = getChildText(name, element, ns, required); if (child == null) { return; } String[] tokens = child.split("[\\s]+"); for (int i = 0; i < tokens.length; i++) { String token = tokens[i]; token = cleanWhitespace(token); if (!token.isEmpty()) { list.add(token); } } }
/** * Build an SpatialWCS from a JDOM representation of an position element. * * @param name * the name of the Element. * @param parent * the parent Element. * @param namespace * of the document. * @param required * is the element expected to be found. * @param rc * @return an SpatialWCS, or null if the document doesn't contain an * position element. * @throws ObservationParsingException */ protected SpatialWCS getSpatialWCS(String name, Element parent, Namespace namespace, boolean required, ReadContext rc) throws ObservationParsingException { Element element = getChildElement(name, parent, namespace, required); if (element == null || element.getContentSize() == 0) { return null; } CoordAxis2D axis = getCoordAxis2D("axis", element, namespace, true); SpatialWCS position = new SpatialWCS(axis); position.coordsys = getChildText("coordsys", element, namespace, false); position.equinox = getChildTextAsDouble("equinox", element, namespace, false); position.resolution = getChildTextAsDouble("resolution", element, namespace, false); return position; }
/** * Sets xml namespace * * @param element Element that hold the namespace * @param decoder Decoder to configure */ void setNamespace(Element element, XmlInputDecoder decoder) { decoder.defaultNs = element.getNamespace(); // this handles the case where there is no URI for a default namespace (test) String uri = decoder.defaultNs.getURI(); decoder.xpathNs = Strings.isNullOrEmpty(uri) ? Namespace.NO_NAMESPACE : Namespace.getNamespace("ns", decoder.defaultNs.getURI()); }
private Element makeClinicalDocument(String programName) { Namespace rootns = Namespace.getNamespace("urn:hl7-org:v3"); Namespace ns = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Element clinicalDocument = new Element("ClinicalDocument", rootns); clinicalDocument.addNamespaceDeclaration(ns); Element informationRecipient = prepareInfoRecipient(rootns, programName); Element documentationOf = prepareDocumentationElement(rootns); Element component = prepareComponentElement(rootns); clinicalDocument.addContent(informationRecipient); clinicalDocument.addContent(documentationOf); clinicalDocument.addContent(component); return clinicalDocument; }
private Element prepareInfoRecipient(Namespace rootns, String programName) { Element informationRecipient = new Element("informationRecipient", rootns); Element intendedRecipient = new Element("intendedRecipient", rootns); Element programNameEl = new Element("id", rootns) .setAttribute("root", "2.16.840.1.113883.3.249.7") .setAttribute("extension", programName); intendedRecipient.addContent(programNameEl); informationRecipient.addContent(intendedRecipient); return informationRecipient; }
private Element prepareParticipant(Namespace rootns) { Element participant = new Element("participant", rootns); Element associatedEntity = new Element("associatedEntity", rootns); Element entityId = new Element("id", rootns) .setAttribute("root", "2.16.840.1.113883.3.249.5.1") .setAttribute("extension", ENTITY_ID_VALUE) .setAttribute("assigningAuthorityName", "CMS-CMMI"); Element addr = new Element("addr", rootns) .setText("testing123"); associatedEntity.addContent(entityId); associatedEntity.addContent(addr); participant.addContent(associatedEntity); return participant; }
private Element prepareRepOrgWithTaxPayerId(Namespace rootns) { Element representedOrganization = new Element("representedOrganization", rootns); Element taxpayerIdentificationNumber = new Element("id", rootns) .setAttribute("root", "2.16.840.1.113883.4.2") .setAttribute("extension", "123456789"); representedOrganization.addContent(taxpayerIdentificationNumber); return representedOrganization; }
private Element prepareComponentElement(Namespace rootns) { Element component = new Element("component", rootns); Element structuredBody = new Element("structuredBody", rootns); Element componentTwo = new Element("component", rootns); Element aciSectionElement = new Element("templateId", rootns); aciSectionElement.setAttribute("root", TemplateId.ACI_SECTION.getRoot()); aciSectionElement.setAttribute("extension", TemplateId.ACI_SECTION.getExtension()); componentTwo.addContent(aciSectionElement); structuredBody.addContent(componentTwo); component.addContent(structuredBody); return component; }
@Test void testInternalDecode() throws Exception { //set-up Namespace rootns = Namespace.getNamespace("urn:hl7-org:v3"); Namespace ns = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Element element = new Element("organizer", rootns); Element templateIdElement = new Element("templateId", rootns) .setAttribute("root","2.16.840.1.113883.10.20.27.3.28"); Element referenceElement = new Element("reference", rootns); Element externalDocumentElement = new Element("externalDocument", rootns); Element idElement = new Element("id", rootns).setAttribute("extension", MEASURE_ID); externalDocumentElement.addContent(idElement); referenceElement.addContent(externalDocumentElement); element.addContent(templateIdElement); element.addContent(referenceElement); element.addNamespaceDeclaration(ns); Node thisNode = new Node(); AciNumeratorDenominatorDecoder objectUnderTest = new AciNumeratorDenominatorDecoder(new Context()); objectUnderTest.setNamespace(element, objectUnderTest); //execute objectUnderTest.internalDecode(element, thisNode); //assert assertThat(thisNode.getValue("measureId")) .isEqualTo(MEASURE_ID); }
@Test void internalDecodeReturnsTreeContinue() { //set-up AciMeasurePerformedRnRDecoder objectUnderTest = new AciMeasurePerformedRnRDecoder(new Context()); Namespace rootns = Namespace.getNamespace("urn:hl7-org:v3"); Namespace ns = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Element element = new Element("organizer", rootns); Element templateIdElement = new Element("templateId", rootns) .setAttribute("root","2.16.840.1.113883.10.20.27.3.28"); Element referenceElement = new Element("reference", rootns); Element externalDocumentElement = new Element("externalDocument", rootns); Element idElement = new Element("id", rootns).setAttribute("extension", MEASURE_ID); externalDocumentElement.addContent(idElement); referenceElement.addContent(externalDocumentElement); element.addContent(templateIdElement); element.addContent(referenceElement); element.addNamespaceDeclaration(ns); Node aciMeasurePerformedNode = new Node(); objectUnderTest.setNamespace(element, objectUnderTest); //execute DecodeResult decodeResult = objectUnderTest.internalDecode(element, aciMeasurePerformedNode); //assert assertThat(decodeResult) .isEqualTo(DecodeResult.TREE_CONTINUE); String actualMeasureId = aciMeasurePerformedNode.getValue("measureId"); assertThat(actualMeasureId) .isEqualTo(MEASURE_ID); }
/** * creates root element for oai protocol * * @param elementName * @return */ public Element getOaiPmhElement(String elementName) { Element oaiPmh = new Element(elementName); oaiPmh.setNamespace(Namespace.getNamespace("http://www.openarchives.org/OAI/2.0/")); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); oaiPmh.addNamespaceDeclaration(xsi); oaiPmh.setAttribute("schemaLocation", "http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd", xsi); return oaiPmh; }