List of usage examples for org.dom4j Node selectSingleNode
Node selectSingleNode(String xpathExpression);
selectSingleNode
evaluates an XPath expression and returns the result as a single Node
instance.
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
private List<CollaborationParticipant> deserializeXMLToListOfCollaborationParticipant(InputStream xmlStream) throws ParseException, DocumentException { List<CollaborationParticipant> result = new ArrayList<CollaborationParticipant>(); SAXReader reader = new SAXReader(); Document doc = reader.read(xmlStream); String lElem = "//loi:ArrayOfCollaborationParticipant"; 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:CollaborationParticipant"); for (Node node : nodes) { CollaborationParticipant collaborationParticipant = new CollaborationParticipant(); Node n = node.selectSingleNode("loi:FirstName"); if (n.hasContent()) { collaborationParticipant.setFirstName(n.getStringValue()); }//w w w . java 2s. co m n = node.selectSingleNode("loi:LastName"); if (n.hasContent()) { collaborationParticipant.setFirstName(n.getStringValue()); } n = node.selectSingleNode("loi:CollaborationId"); if (n.hasContent()) { collaborationParticipant.setUserId(Integer.parseInt(n.getStringValue())); } n = node.selectSingleNode("loi:UserId"); if (n.hasContent()) { collaborationParticipant.setUserId(Integer.parseInt(n.getStringValue())); } result.add(collaborationParticipant); } return result; }
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
private List<LearningObjectiveAssessmentStatus> getLearningObjectiveAssessmentStatusesFromXml( List<Node> nodes) { List<LearningObjectiveAssessmentStatus> result = new ArrayList<LearningObjectiveAssessmentStatus>(); for (Node n : nodes) { LearningObjectiveAssessmentStatus status = new LearningObjectiveAssessmentStatus(); Node node = n.selectSingleNode("loi:LearningObjectiveAssessmentStatusId"); if (node.hasContent()) { status.setLearningObjectiveAssessmentStatusId(Integer.parseInt(node.getStringValue())); }/*from ww w . java 2 s . co m*/ node = n.selectSingleNode("loi:Enabled"); if (node.hasContent()) { status.setEnabled(Boolean.parseBoolean(node.getStringValue())); } node = n.selectSingleNode("loi:StartsAtPercentage"); if (node.hasContent()) { status.setStartsAtPercentage(Integer.parseInt(node.getStringValue())); } node = n.selectSingleNode("loi:Label"); if (node.hasContent()) { status.setLabel(node.getStringValue()); } node = n.selectSingleNode("loi:Type"); if (node.hasContent()) { try { status.setType(LearningObjectiveAssessmentStatusType.valueOf(node.getStringValue())); } catch (IllegalArgumentException iea) { status.setType(LearningObjectiveAssessmentStatusType.NotAssessed); } } node = n.selectSingleNode("loi:MasteryThreshold"); if (node.hasContent()) { status.setMasteryThreshold(Boolean.parseBoolean(node.getStringValue())); } result.add(status); } return result; }
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
private HashMap<Integer, LearningObjectiveMasteryClientSettings> getClientMasterySettingsHashMapFromXml( List<Node> nodes) { HashMap<Integer, LearningObjectiveMasteryClientSettings> result = new HashMap<Integer, LearningObjectiveMasteryClientSettings>(); for (Node n : nodes) { Node node = n.selectSingleNode("loi:LearningObjectiveId"); if (node.hasContent()) { Integer learningObjectiveId = Integer.parseInt(node.getStringValue()); node = n.selectSingleNode("loi:LearningObjectiveMasterySettings"); if (node.hasContent()) { result.put(learningObjectiveId, getClientMasterySettingsFromXml(node)); }/*w ww. j av a2 s .co m*/ } } return result; }
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
private LearningObjectiveMasteryClientSettings getClientMasterySettingsFromXml(Node n) { LearningObjectiveMasteryClientSettings masterySettings = new LearningObjectiveMasteryClientSettings(); Node node = n.selectSingleNode("loi:AffectsByLevel"); if (node.hasContent()) { masterySettings.setAffectsByLevel(Boolean.parseBoolean(node.getStringValue())); }/*ww w. java2 s .c o m*/ node = n.selectSingleNode("loi:AffectsByResettingMastery"); if (node.hasContent()) { masterySettings.setAffectsByResettingMastery(Boolean.parseBoolean(node.getStringValue())); } node = n.selectSingleNode("loi:MasteredWithoutOverride"); if (node.hasContent()) { masterySettings.setMasteredWithoutOverride(Boolean.parseBoolean(node.getStringValue())); } node = n.selectSingleNode("loi:BreaksRecurrence"); if (node.hasContent()) { masterySettings.setBreaksRecurrence(Boolean.parseBoolean(node.getStringValue())); } node = n.selectSingleNode("loi:IsReportMastered"); if (node.hasContent()) { masterySettings.setIsReportMastered(Boolean.parseBoolean(node.getStringValue())); } return masterySettings; }
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
private List<LearningObjectiveAssessment> deserializeXMLToListOfLearningObjectiveAssessment( InputStream xmlStream) throws ParseException, DocumentException { List<LearningObjectiveAssessment> result = new ArrayList<LearningObjectiveAssessment>(); SAXReader reader = new SAXReader(); Document doc = reader.read(xmlStream); String lElem = "//loi:ArrayOfLearningObjectiveAssessment"; 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:LearningObjectiveAssessment"); for (Node node : nodes) { LearningObjectiveAssessment learningObjectiveAssessment = new LearningObjectiveAssessment(); Node n = node.selectSingleNode("loi:LearningObjectiveId"); if (n.hasContent()) { learningObjectiveAssessment.setLearningObjectiveId(Integer.parseInt(n.getStringValue())); }/* w w w . ja v a 2 s . c om*/ n = node.selectSingleNode("loi:UserId"); if (n.hasContent()) { learningObjectiveAssessment.setUserId(Integer.parseInt(n.getStringValue())); } n = node.selectSingleNode("loi:RubricCriteriaItemId"); if (n.hasContent()) { learningObjectiveAssessment.setRubricCriteriaItemId(Integer.parseInt(n.getStringValue())); } n = node.selectSingleNode("loi:PercentScore"); if (n.hasContent()) { learningObjectiveAssessment.setPercentScore(Double.parseDouble(n.getStringValue())); } n = node.selectSingleNode("loi:Comment"); if (n.hasContent()) { learningObjectiveAssessment.setComment(n.getStringValue()); } n = node.selectSingleNode("loi:Mastery"); if (n.hasContent()) { learningObjectiveAssessment.setMastery(Boolean.parseBoolean(n.getStringValue())); } n = node.selectSingleNode("loi:Override"); if (n.hasContent()) { learningObjectiveAssessment.setOverride(Boolean.parseBoolean(n.getStringValue())); } n = node.selectSingleNode("loi:AssessedAchievementLevelId"); if (n.hasContent()) { learningObjectiveAssessment.setAssessedAchievementLevelId(Integer.parseInt(n.getStringValue())); } n = node.selectSingleNode("loi:Reportable"); if (n.hasContent()) { learningObjectiveAssessment.setReportable(Boolean.parseBoolean(n.getStringValue())); } result.add(learningObjectiveAssessment); } return result; }
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 .java 2s .co 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 w w . ja va2 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:log4JToXml.xmlToProperties.XmlToLog4jConverterImpl.java
private void processRoot() { //root node parsing, root element is optional Node rootNode = doc.selectSingleNode("/log4j:configuration/root"); if (rootNode != null) { String rootContent = ""; Node priority = rootNode.selectSingleNode("./priority | ./level"); rootContent += priority.valueOf("@value").toUpperCase(); //appenders refernces List<Node> appendersRefs = rootNode.selectNodes("./appender-ref"); for (Node appender : appendersRefs) { rootContent += ", " + appender.valueOf("@ref"); }// ww w . ja v a 2 s. co m String rootName = "log4j.rootLogger"; log4jProperties.setProperty(rootName, rootContent); //root params List<Node> rootParams = rootNode.selectNodes("./param"); if (!rootParams.isEmpty()) { for (Node param : rootParams) { log4jProperties.setProperty(rootName + "." + param.valueOf("@name"), param.valueOf("@value")); } } } }
From source file:log4JToXml.xmlToProperties.XmlToLog4jConverterImpl.java
private void processAppenders() { //appender nodes, optional List<Node> appenderNodes = doc.selectNodes("/log4j:configuration/appender"); if (!appenderNodes.isEmpty()) { String appenderName = null; for (Node appender : appenderNodes) { appenderName = "log4j.appender." + appender.valueOf("@name"); log4jProperties.setProperty(appenderName, appender.valueOf("@class")); //errorHandler, optional 0-1 Node errorHandler = appender.selectSingleNode("./errorHandler"); if (errorHandler != null) { String errorHandlerName = appenderName + ".errorhandler"; log4jProperties.setProperty(errorHandlerName, errorHandler.valueOf("@class")); //EH params, optional List<Node> eHParams = errorHandler.selectNodes("./param"); if (!eHParams.isEmpty()) { for (Node param : eHParams) { log4jProperties.setProperty(errorHandlerName + "." + param.valueOf("@name"), param.valueOf("@value")); }/*from w w w . j a v a 2s . c om*/ } //EH root-ref, 0-1 Node rootRef = errorHandler.selectSingleNode("./root-ref"); if (rootRef != null) { log4jProperties.setProperty(errorHandlerName + ".root-ref", "true"); } //EH logger-ref, optional List<Node> eHLoggerRefs = errorHandler.selectNodes("./logger-ref"); if (!eHLoggerRefs.isEmpty()) { String loggersRefValue = eHLoggerRefs.get(0).valueOf("@ref"); for (int i = 1; i < eHLoggerRefs.size(); i++) { loggersRefValue += ", " + eHLoggerRefs.get(i).valueOf("@ref"); } log4jProperties.setProperty(errorHandlerName + ".logger-ref", loggersRefValue); } //EH appender-ref, 0-1 Node appenderRef = errorHandler.selectSingleNode("./appender-ref"); if (appenderRef != null) { log4jProperties.setProperty(errorHandlerName + ".appender-ref", appenderRef.valueOf("@ref")); } } //appender params, optional List<Node> appenderParams = appender.selectNodes("./param"); if (!appenderParams.isEmpty()) { for (Node param : appenderParams) { log4jProperties.setProperty(appenderName + "." + param.valueOf("@name"), param.valueOf("@value")); } } //appender layout, 0-1 Node appenderLayout = appender.selectSingleNode("./layout"); if (appenderLayout != null) { String appenderLayoutName = appenderName + ".layout"; log4jProperties.setProperty(appenderLayoutName, appenderLayout.valueOf("@class")); //AL params, optional List<Node> appenderLayoutParams = appenderLayout.selectNodes("./param"); if (!appenderLayoutParams.isEmpty()) { for (Node param : appenderLayoutParams) { log4jProperties.setProperty(appenderLayoutName + "." + param.valueOf("@name"), param.valueOf("@value")); } } } //appender filter, optional List<Node> appenderFilters = appender.selectNodes("./filter"); if (!appenderFilters.isEmpty()) { String appenderFilterName = ""; int filterCount = 0; for (Node filter : appenderFilters) { filterCount++; appenderFilterName = appenderName + ".filter." + filterCount; log4jProperties.setProperty(appenderFilterName, filter.valueOf("@class")); //filter params, optional List<Node> filterParams = filter.selectNodes("./param"); if (!filterParams.isEmpty()) { for (Node param : filterParams) { log4jProperties.setProperty(appenderFilterName + "." + param.valueOf("@name"), param.valueOf("@value")); } } } } //appender appender-refs, optional List<Node> appenderAppenderRefs = appender.selectNodes("./appender-ref"); if (!appenderAppenderRefs.isEmpty()) { String appenderRefsValue = appenderAppenderRefs.get(0).valueOf("@ref"); for (int i = 1; i < appenderAppenderRefs.size(); i++) { appenderRefsValue += ", " + appenderAppenderRefs.get(i).valueOf("@ref"); } log4jProperties.setProperty(appenderName + ".appender-ref", appenderRefsValue); } } } }
From source file:log4JToXml.xmlToProperties.XmlToLog4jConverterImpl.java
private void processCategories() { //category, optional List<Node> categoryNodes = doc.selectNodes("/log4j:configuration/category"); if (!categoryNodes.isEmpty()) { for (Node category : categoryNodes) { String categoryContent = ""; //(priority | level)? Node categoryPriority = category.selectSingleNode("./priority"); Node categoryLevel = category.selectSingleNode("./level"); if (categoryPriority != null) { categoryContent += categoryPriority.valueOf("@value").toUpperCase(); } else if (categoryLevel != null) { categoryContent += categoryLevel.valueOf("@value").toUpperCase(); }//from w ww . j av a 2 s . c om //appender-refs, optional List<Node> categoryAppenderRefs = category.selectNodes("./appender-ref"); if (!categoryAppenderRefs.isEmpty()) { for (Node appenderRef : categoryAppenderRefs) { categoryContent += ", " + appenderRef.valueOf("@ref"); } } String categoryName = "log4j.category." + category.valueOf("@name"); log4jProperties.setProperty(categoryName, categoryContent); //params, optional List<Node> categoryParams = category.selectNodes("./param"); if (!categoryParams.isEmpty()) { for (Node param : categoryParams) { log4jProperties.setProperty(categoryName + "." + param.valueOf("@name"), param.valueOf("@value")); } } //category additivity if (category.valueOf("@additivity").equals("false")) { log4jProperties.setProperty("log4j.additivity." + category.valueOf("@name"), "false"); } } } }