List of usage examples for org.dom4j QName QName
public QName(String name, Namespace namespace)
From source file:ie.cmrc.smtx.base.serialisation.rdfxml.RDFXMLSerialiser.java
License:Apache License
/** * Creates an RDF document containing the XML representation of the provided * resources/*from ww w .j a va 2 s .c o m*/ * @param resources A collection of {@link RDFXMLisable} instances * @param elementSet Specifies the level of information to serialise * (see {@link ElementSetName} for more details) * @param language Language code. Only annotations in this language will * be included in the XML. * @return XML document */ public static Document makeRDFXMLDocument(Collection<? extends RDFXMLisable> resources, ElementSetName elementSet, String language) { Element rdfElt = DocumentHelper.createElement(new QName("RDF", Namespaces.RDF)); rdfElt.add(Namespaces.RDF); rdfElt.add(Namespaces.RDFS); rdfElt.add(Namespaces.OWL); rdfElt.add(Namespaces.SKOS); rdfElt.add(Namespaces.XSD); if (resources != null) { for (RDFXMLisable resource : resources) { if (resource != null) { Element xmlElement = resource.toXMLElement(elementSet, language); if (xmlElement != null) rdfElt.add(xmlElement); } } } Document doc = DocumentHelper.createDocument(rdfElt); return doc; }
From source file:ie.cmrc.smtx.base.serialisation.rdfxml.RDFXMLSerialiser.java
License:Apache License
/** * Creates an RDF document containing the XML representation of the provided * resources//from w w w . ja v a 2 s. c o m * @param resources An iterator over {@link RDFXMLisable} instances * @param elementSet Specifies the level of information to serialise * (see {@link ElementSetName} for more details) * @param language Language code. Only annotations in this language will * be included in the XML. * @return XML document */ public static Document makeRDFXMLDocument(Iterator<? extends RDFXMLisable> resources, ElementSetName elementSet, String language) { Element rdfElt = DocumentHelper.createElement(new QName("RDF", Namespaces.RDF)); rdfElt.add(Namespaces.RDF); rdfElt.add(Namespaces.RDFS); rdfElt.add(Namespaces.OWL); rdfElt.add(Namespaces.SKOS); rdfElt.add(Namespaces.XSD); if (resources != null) { while (resources.hasNext()) { RDFXMLisable resource = resources.next(); if (resource != null) { Element xmlElement = resource.toXMLElement(elementSet, language); if (xmlElement != null) rdfElt.add(xmlElement); } } } Document doc = DocumentHelper.createDocument(rdfElt); return doc; }
From source file:ie.cmrc.smtx.skos.index.lucene.DocSemanticEntityWrapper.java
License:Apache License
/** * {@inheritDoc}/*from w w w. j ava 2 s . c o m*/ * @param elementSet {@inheritDoc} * @param language {@inheritDoc} * @return {@inheritDoc} */ @Override public Element toXMLElement(ElementSetName elementSet, String language) { ElementSetName esn = elementSet; if (esn == null) esn = ElementSetName.BRIEF; if (this.getURI() != null && !this.getURI().isEmpty()) { Element resourceElt; resourceElt = DocumentHelper.createElement(new QName(CONCEPT, Namespaces.SKOS)); QName aboutQN = new QName("about", Namespaces.RDF); QName resourceQN = new QName("resource", Namespaces.RDF); resourceElt.addAttribute(aboutQN, this.getURI()); if (esn.compareTo(ElementSetName.BRIEF) >= 0) { QName xmlLang = new QName("lang", Namespaces.XML); List<Element> prefLabelElts = this.getXMLPrefLabels(language); for (Element prefLabelElt : prefLabelElts) resourceElt.add(prefLabelElt); } return resourceElt; } else return null; }
From source file:ie.cmrc.smtx.skos.index.lucene.DocSemanticEntityWrapper.java
License:Apache License
private List<Element> getXMLPrefLabels(String language) { QName xmlLang = new QName("lang", Namespaces.XML); List<Element> xmlAnnotations = new ArrayList<Element>(); if (language != null) { String prefLabel = this.getPrefLabel(language); if (prefLabel != null) { Element element = DocumentHelper.createElement(new QName(PREF_LABEL, Namespaces.SKOS)) .addText(prefLabel); element.addAttribute(xmlLang, language); xmlAnnotations.add(element); }//from w w w .j a va 2s.co m } else { List<String> languages = this.getPrefLabelLanguages(); for (String lang : languages) { String annotation = this.getPrefLabel(lang); if (annotation != null) { Element element = DocumentHelper.createElement(new QName(PREF_LABEL, Namespaces.SKOS)) .addText(annotation); if (lang != null && !lang.isEmpty()) element.addAttribute(xmlLang, language); xmlAnnotations.add(element); } } } return xmlAnnotations; }
From source file:ie.cmrc.smtx.skos.model.AbstractSKOSResource.java
License:Apache License
/** * {@inheritDoc}//from ww w . j av a 2 s . c o m * @param elementSet {@inheritDoc} * @param language {@inheritDoc} * @return {@inheritDoc} */ @Override public Element toXMLElement(ElementSetName elementSet, String language) { ElementSetName esn = elementSet; if (esn == null) esn = ElementSetName.BRIEF; if (this.getURI() != null && !this.getURI().isEmpty()) { Element resourceElt; resourceElt = DocumentHelper.createElement(new QName(this.getSkosType().name(), Namespaces.SKOS)); QName aboutQN = new QName("about", Namespaces.RDF); QName resourceQN = new QName("resource", Namespaces.RDF); resourceElt.addAttribute(aboutQN, this.getURI()); if (esn.compareTo(ElementSetName.BRIEF) >= 0) { QName xmlLang = new QName("lang", Namespaces.XML); List<Element> prefLabelElts = this.getXMLAnnotations(SKOSAnnotationProperty.prefLabel, language); for (Element prefLabelElt : prefLabelElts) resourceElt.add(prefLabelElt); if (esn.compareTo(ElementSetName.SUMMARY) >= 0) { QName inSchemeQN = new QName(SKOSElementProperty.inScheme.name(), Namespaces.SKOS); QName conceptSchemeQN = new QName(SKOSType.ConceptScheme.name(), Namespaces.SKOS); CloseableIterator<SKOSResource> inSchemeIter = this.listRelations(SKOSElementProperty.inScheme); while (inSchemeIter.hasNext()) { SKOSResource cs = inSchemeIter.next(); //resourceElt.addElement(inSchemeQN).addAttribute(resourceQN, cs.getURI()); resourceElt.addElement(inSchemeQN).addElement(conceptSchemeQN).addAttribute(aboutQN, cs.getURI()); } inSchemeIter.close(); List<Element> defElts = this.getXMLAnnotations(SKOSAnnotationProperty.definition, language); for (Element defElt : defElts) resourceElt.add(defElt); if (esn.compareTo(ElementSetName.FULL) >= 0) { List<Element> altLabelElts = this.getXMLAnnotations(SKOSAnnotationProperty.altLabel, language); for (Element altLabelElt : altLabelElts) resourceElt.add(altLabelElt); if (esn.compareTo(ElementSetName.EXTENDED) >= 0) { QName topConceptOfQN = new QName(SKOSElementProperty.topConceptOf.name(), Namespaces.SKOS); CloseableIterator<SKOSResource> topConceptOf = this .listRelations(SKOSElementProperty.topConceptOf); while (topConceptOf.hasNext()) { SKOSResource cs = topConceptOf.next(); //resourceElt.addElement(inSchemeQN).addAttribute(resourceQN, cs.getURI()); resourceElt.addElement(topConceptOfQN).addElement(conceptSchemeQN) .addAttribute(aboutQN, cs.getURI()); } topConceptOf.close(); for (SKOSAnnotationProperty property : SKOSAnnotationProperty.values()) { if (property != SKOSAnnotationProperty.prefLabel && property != SKOSAnnotationProperty.altLabel && property != SKOSAnnotationProperty.definition) { List<Element> annotationElts = this.getXMLAnnotations(property, language); for (Element annotationElt : annotationElts) resourceElt.add(annotationElt); } } } } } } return resourceElt; } else return null; }
From source file:ie.cmrc.smtx.skos.model.AbstractSKOSResource.java
License:Apache License
private List<Element> getXMLAnnotations(SKOSAnnotationProperty property, String language) { QName xmlLang = new QName("lang", Namespaces.XML); List<Element> xmlAnnotations = new ArrayList<Element>(); if (language != null) { List<String> annotations = this.getAnnotations(property, language); for (String annotation : annotations) { Element element = DocumentHelper.createElement(new QName(property.name(), Namespaces.SKOS)) .addText(annotation); element.addAttribute(xmlLang, language); xmlAnnotations.add(element); }//from w w w. ja v a2 s. com } else { List<Term> annotationTerms = this.getAnnotations(property); for (Term annotationTerm : annotationTerms) { String annotation = annotationTerm.getString(); String lang = annotationTerm.getLanguage(); Element element = DocumentHelper.createElement(new QName(property.name(), Namespaces.SKOS)) .addText(annotation); if (lang != null && !lang.isEmpty()) element.addAttribute(xmlLang, language); xmlAnnotations.add(element); } } return xmlAnnotations; }
From source file:ie.cmrc.smtx.skos.model.hierarchy.DefaultSKOSConceptNode.java
License:Apache License
/** * {@inheritDoc}//from www . java 2 s .c o m * @param elementSet {@inheritDoc} * @param language {@inheritDoc} * @return {@inheritDoc} */ @Override public Element toXMLElement(ElementSetName elementSet, String language) { if (this.concept != null) { Element elt = this.concept.toXMLElement(elementSet, language); if (elt != null && this.hasChildren()) { for (SKOSConceptNode child : this.children) { if (child != null) { Element childNodeElt = child.toXMLElement(elementSet, language); if (childNodeElt != null) { Element narrower = elt .addElement(new QName(SKOSSemanticProperty.narrower.name(), Namespaces.SKOS)); narrower.add(childNodeElt); } } } } return elt; } return null; }
From source file:ie.cmrc.smtx.sws.exceptions.SWSExceptionReport.java
License:Apache License
public Document getXML() { if (!this.isEmpty()) { Namespace sws = new Namespace("sws", swsURI); Namespace xml = new Namespace("xml", xmlURI); //Namespace xsi = new Namespace("xsi", xsiURI); QName exReportQN = new QName("ExceptionReport", sws); Element exceptionReport = DocumentHelper.createElement(exReportQN); exceptionReport.add(xml);/*from w ww . j av a2s . c o m*/ exceptionReport.add(sws); //exceptionReport.add(xsi); //QName schemaLocQN = new QName ("schemaLocation", xsi); //exceptionReport.addAttribute(schemaLocQN, this.xsiSchameLocation); //Language if (this.language != null) { if (!this.language.trim().equals("")) { QName langQN = new QName("lang", xml); exceptionReport.addAttribute(langQN, this.language.trim()); } } //Version exceptionReport.addAttribute("version", this.version); QName exceptionQN = new QName("Exception", sws); for (SWSException e : this.exceptions) { if (e != null) { Element exception = exceptionReport.addElement(exceptionQN).addAttribute("code", e.getCode()); if (e.getLocator() != null) { if (!e.getLocator().trim().equals("")) { exception.addAttribute("locator", e.getLocator().trim()); } } if (e.getMessage() != null) { QName messageQN = new QName("Message", sws); exception.addElement(messageQN).addText(e.getMessage()); } } } Document exceptionReportDoc = DocumentHelper.createDocument(exceptionReport); return exceptionReportDoc; } else { //Raise Empty exceptionReport exception return null; } }
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
private List<AssessmentStatusItem> deserializeXMLToListOfAssessmentStatusItems(InputStream xmlStream) throws ParseException, DocumentException { List<AssessmentStatusItem> result = new ArrayList<AssessmentStatusItem>(); SAXReader reader = new SAXReader(); Document doc = reader.read(xmlStream); String lElem = "//loi:ArrayOfAssessmentStatusItem"; doc.getRootElement().setQName(new QName(doc.getRootElement().getQName().getName(), new Namespace("loi", doc.getRootElement().getNamespaceURI()))); Element root = doc.getRootElement(); List<Node> nodes = root.selectNodes(lElem + "/loi:AssessmentStatusItem"); for (Node node : nodes) { AssessmentStatusItem assessmentStatusItem = new AssessmentStatusItem(); Node n = node.selectSingleNode("loi:AssessmentStatusId"); if (n.hasContent()) { assessmentStatusItem.setAssessmentStatusId(Integer.parseInt(n.getStringValue())); }/*from w w w. java 2 s .c o m*/ n = node.selectSingleNode("loi:AssessmentStatusItemId"); if (n.hasContent()) { assessmentStatusItem.setAssessmentStatusItemId(Integer.parseInt(n.getStringValue())); } n = node.selectSingleNode("loi:Title"); if (n.hasContent()) { assessmentStatusItem.setTitle(n.getStringValue()); } result.add(assessmentStatusItem); } return result; }
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
/** * xml looks like this/* w w w . j a v a 2 s . c om*/ <EntityList xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <CurrentPageIndex>0</CurrentPageIndex> <EntityArray> <Organization> <HierarchyId>1</HierarchyId> <LegalId>FK</LegalId> <Title>Fylkeskommune</Title> <Type>Site</Type> </Organization> <Organization> <HierarchyId>6</HierarchyId> <LegalId>S-B</LegalId> <Title>School B</Title> <Type>School</Type> </Organization> </EntityArray> <PageSize>2</PageSize> <Total>2</Total> </EntityList> * * @param responseBodyAsStream * @return */ private List<Organisation> deserializeXMLToOrganisations(InputStream xmlStream) throws DocumentException { List<Organisation> result = new ArrayList<Organisation>(); SAXReader reader = new SAXReader(); Document doc = reader.read(xmlStream); String lElem = "//org:ArrayOfOrganization"; doc.getRootElement().setQName(new QName(doc.getRootElement().getQName().getName(), new Namespace("org", doc.getRootElement().getNamespaceURI()))); Element root = doc.getRootElement(); List<Node> nodes = root.selectNodes(lElem + "/org:Organization"); for (Node n : nodes) { Organisation organisation = new Organisation(); Node node = n.selectSingleNode("org:HierarchyId"); if (node.hasContent()) { organisation.setHierarchyId(Integer.parseInt(node.getStringValue())); } node = n.selectSingleNode("org:SyncLocationId"); if (node.hasContent()) { organisation.setSyncLocationId(node.getStringValue()); } node = n.selectSingleNode("org:LegalId"); if (node.hasContent()) { organisation.setLegalId(node.getStringValue()); } node = n.selectSingleNode("org:Title"); if (node.hasContent()) { organisation.setTitle(node.getStringValue()); } node = n.selectSingleNode("org:Type"); if (node.hasContent()) { try { organisation.setType(OrganisationType.valueOf(node.getStringValue())); } catch (IllegalArgumentException iea) { organisation.setType(OrganisationType.Unknown); } } result.add(organisation); } return result; }