List of usage examples for org.dom4j Node getStringValue
String getStringValue();
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
private List<AssessmentItem> deserializeXMLToListOfAssessmentItems(InputStream xmlStream) throws ParseException, DocumentException { List<AssessmentItem> result = new ArrayList<AssessmentItem>(); SAXReader reader = new SAXReader(); Document doc = reader.read(xmlStream); String lElem = "//loi:ArrayOfAssessmentItem"; 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:AssessmentItem"); for (Node node : nodes) { AssessmentItem assessmentItem = new AssessmentItem(); Node n = node.selectSingleNode("loi:AssessmentId"); if (n.hasContent()) { assessmentItem.setAssessmentId(Integer.parseInt(n.getStringValue())); }//from w w w .j a va 2 s . c o m n = node.selectSingleNode("loi:AssessmentItemId"); if (n.hasContent()) { assessmentItem.setAssessmentItemId(Integer.parseInt(n.getStringValue())); } n = node.selectSingleNode("loi:Description"); if (n.hasContent()) { assessmentItem.setDescription(n.getStringValue()); } n = node.selectSingleNode("loi:PercentFromAndIncl"); if (n.hasContent()) { assessmentItem.setPercentFromAndIncl(Double.parseDouble(n.getStringValue())); } n = node.selectSingleNode("loi:PercentTo"); if (n.hasContent()) { assessmentItem.setPercentTo(Double.parseDouble(n.getStringValue())); } n = node.selectSingleNode("loi:Title"); if (n.hasContent()) { assessmentItem.setTitle(n.getStringValue()); } result.add(assessmentItem); } return result; }
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 w ww . jav a2 s. co 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;//from ww w . j ava 2 s . c o m 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:org.apache.commons.jelly.tags.jsl.JellyStylesheet.java
License:Apache License
public JellyStylesheet() { setValueOfAction(new Action() { public void run(Node node) throws Exception { String text = node.getStringValue(); if (text != null && text.length() > 0) { getOutput().write(text); }//w ww. ja va2 s . c om } }); }
From source file:org.apache.commons.jelly.xpath.XPathComparator.java
License:Apache License
/** * Turns the XPath result value into a Comparable object. */// w w w . j a v a 2 s.c o m protected Comparable getComparableValue(Object value) { if (value instanceof List) { List list = (List) value; if (list.isEmpty()) { value = ""; } value = list.get(0); if (value == null) { value = ""; } } if (value instanceof Comparable) { return (Comparable) value; } else if (value instanceof Node) { Node node = (Node) value; return node.getStringValue(); } return value.toString(); }
From source file:org.apache.taglibs.xtags.xpath.JspValueOfAction.java
License:Apache License
public void run(Node node) throws Exception { String text = node.getStringValue(); if (text != null && text.length() > 0) { text = ValueOfTag.encode(text);/*from ww w.j a v a 2s.co m*/ pageContext.getOut().print(text); } }
From source file:org.apache.taglibs.xtags.xpath.StylesheetValueOfAction.java
License:Apache License
public void run(Node node) throws Exception { String text = node.getStringValue(); if (text != null && text.length() > 0) { text = ValueOfTag.encode(text);//from www.j a v a2 s . com this.stylesheetTag.addOutput(text); } }
From source file:org.apache.taverna.activities.xpath.XPathActivity.java
License:Apache License
/** * This method executes pre-configured instance of XPath activity. *///from www .j a va 2 s . com @Override public void executeAsynch(final Map<String, T2Reference> inputs, final AsynchronousActivityCallback callback) { // Don't execute service directly now, request to be run asynchronously callback.requestRun(new Runnable() { @Override @SuppressWarnings("unchecked") public void run() { InvocationContext context = callback.getContext(); ReferenceService referenceService = context.getReferenceService(); // ---- RESOLVE INPUT ---- String xmlInput = (String) referenceService.renderIdentifier(inputs.get(IN_XML), String.class, context); // ---- DO THE ACTUAL SERVICE INVOCATION ---- List<Node> matchingNodes = new ArrayList<Node>(); // only attempt to execute XPath expression if there is some input data if (xmlInput != null && xmlInput.length() > 0) { // XPath configuration is taken from the config bean try { XPath expr = DocumentHelper.createXPath(json.get("xpathExpression").textValue()); Map<String, String> xpathNamespaceMap = new HashMap<>(); for (JsonNode namespaceMapping : json.get("xpathNamespaceMap")) { xpathNamespaceMap.put(namespaceMapping.get("prefix").textValue(), namespaceMapping.get("uri").textValue()); } expr.setNamespaceURIs(xpathNamespaceMap); Document doc = DocumentHelper.parseText(xmlInput); matchingNodes = expr.selectNodes(doc); } catch (InvalidXPathException e) { callback.fail("Incorrect XPath Expression -- XPath processing library " + "reported the following error: " + e.getMessage(), e); // make sure we don't call callback.receiveResult later return; } catch (DocumentException e) { callback.fail("XML document was not valid -- XPath processing library " + "reported the following error: " + e.getMessage(), e); // make sure we don't call callback.receiveResult later return; } catch (XPathException e) { callback.fail("Unexpected error has occurred while executing the XPath expression. " + "-- XPath processing library reported the following error:\n" + e.getMessage(), e); // make sure we don't call callback.receiveResult later return; } } // --- PREPARE OUTPUTS --- List<String> outNodesText = new ArrayList<String>(); List<String> outNodesXML = new ArrayList<String>(); Object textValue = null; Object xmlValue = null; for (Object o : matchingNodes) { if (o instanceof Node) { Node n = (Node) o; if (n.getStringValue() != null && n.getStringValue().length() > 0) { outNodesText.add(n.getStringValue()); if (textValue == null) textValue = n.getStringValue(); } outNodesXML.add(n.asXML()); if (xmlValue == null) xmlValue = n.asXML(); } else { outNodesText.add(o.toString()); if (textValue == null) textValue = o.toString(); } } // ---- REGISTER OUTPUTS ---- Map<String, T2Reference> outputs = new HashMap<String, T2Reference>(); if (textValue == null) { ErrorDocumentService errorDocService = referenceService.getErrorDocumentService(); textValue = errorDocService.registerError("No value produced", 0, callback.getContext()); } if (xmlValue == null) { ErrorDocumentService errorDocService = referenceService.getErrorDocumentService(); xmlValue = errorDocService.registerError("No value produced", 0, callback.getContext()); } T2Reference firstNodeAsText = referenceService.register(textValue, 0, true, context); outputs.put(SINGLE_VALUE_TEXT, firstNodeAsText); T2Reference firstNodeAsXml = referenceService.register(xmlValue, 0, true, context); outputs.put(SINGLE_VALUE_XML, firstNodeAsXml); T2Reference outNodesAsText = referenceService.register(outNodesText, 1, true, context); outputs.put(OUT_TEXT, outNodesAsText); T2Reference outNodesAsXML = referenceService.register(outNodesXML, 1, true, context); outputs.put(OUT_XML, outNodesAsXML); // return map of output data, with empty index array as this is // the only and final result (this index parameter is used if // pipelining output) callback.receiveResult(outputs, new int[0]); } }); }
From source file:org.craftercms.studio.impl.v1.service.cmis.CmisServiceImpl.java
License:Open Source License
private String getPropertyValue(Node repositoryNode, String property) { Node propertyNode = repositoryNode.selectSingleNode(property); if (propertyNode != null) { return propertyNode.getStringValue(); }/* w w w .ja va 2s . c o m*/ return StringUtils.EMPTY; }
From source file:org.esupportail.lecture.domain.model.ChannelConfig.java
/** * @param channel/*from w ww .j av a2 s. c o m*/ */ @SuppressWarnings("unchecked") public static void loadContextsAndCategoryprofiles(final Channel channel) { if (LOG.isDebugEnabled()) { LOG.debug("loadContextsAndCategoryprofiles()"); } String categoryProfileId = ""; Node channelConfig = xmlFile.getRootElement(); List<Node> contexts = channelConfig.selectNodes("context"); for (Node context : contexts) { Context c = new Context(); c.setId(context.valueOf("@id")); c.setName(context.valueOf("@name")); //treeVisible String treeVisible = context.valueOf("@treeVisible"); if (treeVisible.equals("no")) { c.setTreeVisible(TreeDisplayMode.NOTVISIBLE); } else if (treeVisible.equals("forceNo")) { c.setTreeVisible(TreeDisplayMode.NEVERVISIBLE); } else { c.setTreeVisible(TreeDisplayMode.VISIBLE); } if (LOG.isDebugEnabled()) { LOG.debug("loadContextsAndCategoryprofiles() : contextId " + c.getId()); } Node description = context.selectSingleNode("description"); c.setDescription(description.getStringValue()); List<Node> refCategoryProfiles = context.selectNodes("refCategoryProfile"); // Lire les refCategoryProfilesUrl puis : // - les transformer en refCategoryProfile ds le context // - ajouter les categoryProfile // A faire dans checkXmlFile ? Map<String, Integer> orderedCategoryIDs = Collections.synchronizedMap(new HashMap<String, Integer>()); int xmlOrder = 1; // On parcours les refCategoryProfile de context for (Node refCategoryProfile : refCategoryProfiles) { String refId; // Ajout mcp refId = refCategoryProfile.valueOf("@refId"); if (LOG.isDebugEnabled()) { LOG.debug("loadContextsAndCategoryprofiles() : refCategoryProfileId " + refId); } List<Node> categoryProfiles = channelConfig.selectNodes("categoryProfile"); // On parcours les categoryProfile de root for (Node categoryProfile : categoryProfiles) { categoryProfileId = categoryProfile.valueOf("@id"); if (LOG.isDebugEnabled()) { LOG.debug("loadContextsAndCategoryprofiles() : is categoryProfileId " + categoryProfileId + " matching ?"); } if (categoryProfileId.compareTo(refId) == 0) { if (LOG.isDebugEnabled()) { LOG.debug("loadContextsAndCategoryprofiles() : categoryProfileId " + refId + " matches... create mcp"); } ManagedCategoryProfile mcp = new ManagedCategoryProfile(); // Id = long Id String mcpProfileID = categoryProfileId; mcp.setFileId(c.getId(), mcpProfileID); if (LOG.isDebugEnabled()) { LOG.debug("loadContextsAndCategoryprofiles() : categoryProfileId " + mcp.getId() + " matches... create mcp"); } mcp.setName(categoryProfile.valueOf("@name")); mcp.setCategoryURL(categoryProfile.valueOf("@urlCategory")); mcp.setTrustCategory(getBoolean(categoryProfile.valueOf("@trustCategory"), false)); mcp.setUserCanMarkRead(getBoolean(categoryProfile.valueOf("@userCanMarkRead"), true)); String specificUserContentValue = categoryProfile.valueOf("@specificUserContent"); if (specificUserContentValue.equals("yes")) { mcp.setSpecificUserContent(true); } else { mcp.setSpecificUserContent(false); } String ttl = categoryProfile.valueOf("@ttl"); mcp.setTtl(Integer.parseInt(ttl)); String timeout = categoryProfile.valueOf("@timeout"); mcp.setTimeOut(Integer.parseInt(timeout)); mcp.setName(categoryProfile.valueOf("@name")); // Accessibility String access = categoryProfile.valueOf("@access"); if (access.equalsIgnoreCase("public")) { mcp.setAccess(Accessibility.PUBLIC); } else if (access.equalsIgnoreCase("cas")) { mcp.setAccess(Accessibility.CAS); } // Visibility VisibilitySets visibilitySets = new VisibilitySets(); // foreach (allowed / autoSubscribed / Obliged visibilitySets.setAllowed(loadDefAndContentSets("allowed", categoryProfile)); visibilitySets.setAutoSubscribed(loadDefAndContentSets("autoSubscribed", categoryProfile)); visibilitySets.setObliged(loadDefAndContentSets("obliged", categoryProfile)); mcp.setVisibility(visibilitySets); channel.addManagedCategoryProfile(mcp); c.addRefIdManagedCategoryProfile(mcp.getId()); orderedCategoryIDs.put(mcp.getId(), xmlOrder); break; } } xmlOrder += 1; } c.setOrderedCategoryIDs(orderedCategoryIDs); channel.addContext(c); } }