List of usage examples for org.dom4j QName QName
public QName(String name, Namespace namespace)
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
private List<Assessment> deserializeXMLToListOfAssessments(InputStream xmlStream) throws ParseException, DocumentException { List<Assessment> result = new ArrayList<Assessment>(); SAXReader reader = new SAXReader(); Document doc = reader.read(xmlStream); String lElem = "//loi:ArrayOfAssessment"; 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:Assessment"); for (Node node : nodes) { Assessment assessment = new Assessment(); Node n = node.selectSingleNode("loi:AssessmentId"); if (n.hasContent()) { assessment.setAssessmentId(Integer.parseInt(n.getStringValue())); }//from www. j av a2 s. c o m n = node.selectSingleNode("loi:Description"); if (n.hasContent()) { assessment.setDescription(n.getStringValue()); } n = node.selectSingleNode("loi:Title"); if (n.hasContent()) { assessment.setTitle(n.getStringValue()); } result.add(assessment); } return result; }
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
private LearningObjectInstance deserializeXMLToLearningObjectInstance(InputStream xmlStream) throws ParseException, DocumentException { LearningObjectInstance loi = null;// www .j a va2 s.c om SAXReader reader = new SAXReader(); Document doc = reader.read(xmlStream); String lElem = "//loi:LearningObjectInstance"; doc.getRootElement().setQName(new QName(doc.getRootElement().getQName().getName(), new Namespace("loi", doc.getRootElement().getNamespaceURI()))); Element root = doc.getRootElement(); if (root.getName().equals("LearningObjectInstance")) { loi = new LearningObjectInstance(); Node node = root.selectSingleNode(lElem + "/loi:ActiveToUtc"); if (node != null && node.hasContent()) { loi.setActiveToUTC(sdf.parse(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:DeadlineUtc"); if (node != null && node.hasContent()) { loi.setDeadLineUTC(sdf.parse(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:ActiveFromUtc"); if (node != null && node.hasContent()) { loi.setActiveFromUTC(sdf.parse(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:CreatedUtc"); if (node != null && node.hasContent()) { loi.setCreatedUTC(sdf.parse(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:ModifiedUtc"); if (node != null && node.hasContent()) { loi.setModifiedUTC(sdf.parse(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:Title"); if (node != null && node.hasContent()) { loi.setTitle(node.getStringValue()); } node = root.selectSingleNode(lElem + "/loi:LearningObjectInstanceId"); if (node != null && node.hasContent()) { loi.setLearningObjectInstanceId(Integer.parseInt(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:LearningObjectId"); if (node != null && node.hasContent()) { loi.setLearningObjectId(Integer.parseInt(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:ModifiedUtc"); if (node != null && node.hasContent()) { loi.setModifiedUTC(sdf.parse(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:CreatedUtc"); if (node != null && node.hasContent()) { loi.setCreatedUTC(sdf.parse(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:CreatedByUserId"); if (node != null && node.hasContent()) { loi.setCreatedByUserId(Integer.parseInt(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:IsObligatory"); if (node != null && node.hasContent()) { loi.setIsObligatory(Boolean.parseBoolean(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:AssessmentId"); if (node != null && node.hasContent()) { loi.setAssessmentId(Integer.parseInt(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:AssessmentStatusId"); if (node != null && node.hasContent()) { loi.setAssessmentStatusId(Integer.parseInt(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:IsAssessmentVisible"); if (node != null && node.hasContent()) { loi.setIsAssessmentVisible(Boolean.parseBoolean(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:CourseCode"); if (node != null && node.hasContent()) { loi.setCourseCode(node.getStringValue()); } node = root.selectSingleNode(lElem + "/loi:CourseId"); if (node != null && node.hasContent()) { loi.setCourseId(node.getStringValue()); } node = root.selectSingleNode(lElem + "/loi:CourseSyncKey"); if (node != null && node.hasContent()) { loi.setCourseSyncKey(node.getStringValue()); } node = root.selectSingleNode(lElem + "/loi:CourseOrganisationId"); if (node != null && node.hasContent()) { loi.setCourseOrganisationId(Integer.parseInt(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:CourseOrganisationSyncKey"); if (node != null && node.hasContent()) { loi.setCourseOrganisationSyncKey(node.getStringValue()); } node = root.selectSingleNode(lElem + "/loi:MaxScore"); if (node != null && node.hasContent()) { loi.setMaxScore(Double.parseDouble(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:SubmissionType"); if (node != null && node.hasContent()) { try { loi.setSubmissionType(SubmissionType.valueOf(node.getStringValue())); } catch (IllegalArgumentException iea) { loi.setSubmissionType(SubmissionType.NotInUse); } } node = root.selectSingleNode(lElem + "/loi:UsePlagiarism"); if (node != null && node.hasContent()) { loi.setUsePlagiarism(Boolean.parseBoolean(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:UseAnonymousSubmission"); if (node != null && node.hasContent()) { loi.setUseAnonymousSubmission(Boolean.parseBoolean(node.getStringValue())); } node = root.selectSingleNode(lElem + "/loi:HasLearningObjectiveAssessmentCriteria"); if (node != null && node.hasContent()) { loi.setHasLearningObjectiveAssessmentCriteria(Boolean.parseBoolean(node.getStringValue())); } } return loi; }
From source file:net.sf.saxon.option.dom4j.DOM4JWriter.java
License:Mozilla Public License
/** * Start of an element.//from w w w.j av a 2 s. c o m */ public void startElement(NodeName nameCode, SchemaType typeCode, int locationId, int properties) throws XPathException { flush(); String local = nameCode.getLocalPart(); String uri = nameCode.getURI(); String prefix = nameCode.getPrefix(); Element element; if (ancestors.isEmpty()) { startDocument(0); implicitDocumentNode = true; } QName name = new QName(local, new Namespace(prefix, uri)); if (ancestors.size() == 1) { element = new DefaultElement(name); document.setRootElement(element); } else { element = ((Element) ancestors.peek()).addElement(name); } ancestors.push(element); }
From source file:net.yrom.builder.util.ManifestParser.java
License:Apache License
public ManifestParser(String manifestPath) throws DocumentException { manifestFile = new File(manifestPath); try {// ww w . j av a 2 s .c o m FileUtils.copyFile(manifestFile, new File(manifestPath + ".bak")); } catch (IOException e) { } doc = parseManifest(manifestPath); manifest = doc.getRootElement(); xmlns = manifest.getNamespaceForPrefix(ANDROID); qVersionCode = new QName("versionCode", xmlns); qVersionName = new QName("versionName", xmlns); androidName = new QName("name", xmlns); androidValue = new QName("value", xmlns); application = manifest.element("application"); }
From source file:nz.govt.natlib.ndha.common.dublincore.DublinCore.java
License:Open Source License
/** * Add a DC element using the enum <code>DCElementSet</code> * <p/>// w ww. j a va2s. c om * Added by @author Nicolai Moles-Benfell * * @param element * @param value */ public void addElement(DCElementSet element, String value) { QName qname = new QName(element.getName(), element.getNameSpace()); Element elem = m_record.addElement(qname); elem.setText(value); }
From source file:nz.govt.natlib.ndha.common.dublincore.DublinCore.java
License:Open Source License
public void addElement(int namespace, String key, String xsiType, String value) { QName qname = null;// w w w. j av a 2 s.c om if (namespace == DC_NAMESPACE) { qname = new QName(key, dcNamespace); } else if (namespace == DCTERMS_NAMESPACE) { qname = new QName(key, dctermsNamespace); } else { return; } Element elem = m_record.addElement(qname); elem.setText(value); if (xsiType != null) { elem.addAttribute(XsiQName, xsiType); } }
From source file:org.apache.poi.openxml4j.opc.internal.ContentTypeManager.java
License:Apache License
/** * Save the contents type part./*from w w w . j a va 2 s. c o m*/ * * @param outStream * The output stream use to save the XML content of the content * types part. * @return <b>true</b> if the operation success, else <b>false</b>. */ public boolean save(OutputStream outStream) { Document xmlOutDoc = DocumentHelper.createDocument(); // Building namespace Namespace dfNs = Namespace.get("", TYPES_NAMESPACE_URI); Element typesElem = xmlOutDoc.addElement(new QName(TYPES_TAG_NAME, dfNs)); // Adding default types for (Entry<String, String> entry : defaultContentType.entrySet()) { appendDefaultType(typesElem, entry); } // Adding specific types if any exist if (overrideContentType != null) { for (Entry<PackagePartName, String> entry : overrideContentType.entrySet()) { appendSpecificTypes(typesElem, entry); } } xmlOutDoc.normalize(); // Save content in the specified output stream return this.saveImpl(xmlOutDoc, outStream); }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
/** * Marshall package core properties to an XML document. Always return * <code>true</code>.// w w w.j a va 2 s . c o m */ public boolean marshall(PackagePart part, OutputStream out) throws OpenXML4JException { if (!(part instanceof PackagePropertiesPart)) throw new IllegalArgumentException("'part' must be a PackagePropertiesPart instance."); propsPart = (PackagePropertiesPart) part; // Configure the document xmlDoc = DocumentHelper.createDocument(); Element rootElem = xmlDoc.addElement(new QName("coreProperties", namespaceCoreProperties)); rootElem.addNamespace("cp", PackagePropertiesPart.NAMESPACE_CP_URI); rootElem.addNamespace("dc", PackagePropertiesPart.NAMESPACE_DC_URI); rootElem.addNamespace("dcterms", PackagePropertiesPart.NAMESPACE_DCTERMS_URI); rootElem.addNamespace("xsi", PackagePropertiesPart.NAMESPACE_XSI_URI); addCategory(); addContentStatus(); addContentType(); addCreated(); addCreator(); addDescription(); addIdentifier(); addKeywords(); addLanguage(); addLastModifiedBy(); addLastPrinted(); addModified(); addRevision(); addSubject(); addTitle(); addVersion(); return true; }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
/** * Add category property element if needed. *///from w ww .j av a 2 s . c o m private void addCategory() { if (!propsPart.getCategoryProperty().hasValue()) return; Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_CATEGORY, namespaceCoreProperties)); if (elem == null) { // Missing, we add it elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_CATEGORY, namespaceCoreProperties)); } else { elem.clearContent();// clear the old value } elem.addText(propsPart.getCategoryProperty().getValue()); }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
/** * Add content status property element if needed. *///w ww .ja v a 2 s. c o m private void addContentStatus() { if (!propsPart.getContentStatusProperty().hasValue()) return; Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_CONTENT_STATUS, namespaceCoreProperties)); if (elem == null) { // Missing, we add it elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_CONTENT_STATUS, namespaceCoreProperties)); } else { elem.clearContent();// clear the old value } elem.addText(propsPart.getContentStatusProperty().getValue()); }