Java Code Examples for org.dom4j.Element#getName()
The following examples show how to use
org.dom4j.Element#getName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QTI_and_test.java From olat with Apache License 2.0 | 6 votes |
@Override public boolean eval(final Element boolElement, final float score) { final List elems = boolElement.elements(); final int size = elems.size(); boolean ev = true; for (int i = 0; i < size; i++) { final Element child = (Element) elems.get(i); final String name = child.getName(); final ScoreBooleanEvaluable bev = QTIHelper.getSectionBooleanEvaluableInstance(name); final boolean res = bev.eval(child, score); ev = ev && res; if (!ev) { return false; } } return true; }
Example 2
Source File: AndroidNativePageSourceHandler.java From agent with MIT License | 6 votes |
/** * 由于appium pageSource返回的xml不是规范的xml,需要把除了hierarchy节点以外的节点替换成node,否则xml转json会出问题 * * @param element */ @Override public void handleElement(Element element) { if (element == null) { return; } String elementName = element.getName(); if (StringUtils.isEmpty(elementName)) { return; } if (!"hierarchy".equals(elementName)) { element.setName("node"); } List<Element> elements = element.elements(); elements.forEach(e -> handleElement(e)); }
Example 3
Source File: ScriptDecisionTableParser.java From urule with Apache License 2.0 | 6 votes |
public ScriptDecisionTable parse(Element element) { ScriptDecisionTable table =new ScriptDecisionTable(); for(Object obj:element.elements()){ if(obj==null || !(obj instanceof Element)){ continue; } Element ele=(Element)obj; String name=ele.getName(); if(rowParser.support(name)){ table.addRow(rowParser.parse(ele)); }else if(columnParser.support(name)){ table.addColumn(columnParser.parse(ele)); }else if(scriptCellParser.support(name)){ table.addCell(scriptCellParser.parse(ele)); }if(name.equals("import-variable-library")){ table.addLibrary(new Library(ele.attributeValue("path"),null,LibraryType.Variable)); }else if(name.equals("import-constant-library")){ table.addLibrary(new Library(ele.attributeValue("path"),null,LibraryType.Constant)); }else if(name.equals("import-action-library")){ table.addLibrary(new Library(ele.attributeValue("path"),null,LibraryType.Action)); }else if(name.equals("import-parameter-library")){ table.addLibrary(new Library(ele.attributeValue("path"),null,LibraryType.Parameter)); } } return table; }
Example 4
Source File: CriteriaParser.java From urule with Apache License 2.0 | 6 votes |
public Criterion parse(Element element) { Criteria criteria=new Criteria(); Op op=Op.valueOf(element.attributeValue("op")); criteria.setOp(op); for(Object obj:element.elements()){ if(obj==null || !(obj instanceof Element)){ continue; } Element ele=(Element)obj; String name=ele.getName(); if(name.equals("value")){ criteria.setValue(valueParser.parse(ele)); }else if(name.equals("left")){ criteria.setLeft(leftParser.parse(ele)); } } return criteria; }
Example 5
Source File: VariableCategoryParser.java From urule with Apache License 2.0 | 6 votes |
public VariableCategory parse(Element element) { VariableCategory category=new VariableCategory(); category.setName(element.attributeValue("name")); category.setClazz(element.attributeValue("clazz")); category.setType(CategoryType.valueOf(element.attributeValue("type"))); for(Object obj:element.elements()){ if(obj==null || !(obj instanceof Element)){ continue; } Element ele=(Element)obj; String name=ele.getName(); if(variableParser.support(name)){ category.addVariable(variableParser.parse(ele)); } } return category; }
Example 6
Source File: FormParserUtils.java From ureport with Apache License 2.0 | 6 votes |
public static List<Component> parse(Element element){ List<Component> list=new ArrayList<Component>(); for(Object obj:element.elements()){ if(obj==null || !(obj instanceof Element)){ continue; } Element ele=(Element)obj; String name=ele.getName(); FormParser<?> targetParser=null; for(FormParser<?> parser:parsers){ if(parser.support(name)){ targetParser=parser; break; } } if(targetParser==null){ continue; } list.add((Component)targetParser.parse(ele)); } return list; }
Example 7
Source File: FlowDefinitionReferenceUpdater.java From urule with Apache License 2.0 | 5 votes |
public boolean contain(String path, String xml) { try{ Document doc=DocumentHelper.parseText(xml); Element element=doc.getRootElement(); for(Object obj:element.elements()){ if(!(obj instanceof Element)){ continue; } Element ele=(Element)obj; String name=ele.getName(); boolean match=false; if(name.equals("import-variable-library")){ match=true; }else if(name.equals("import-constant-library")){ match=true; }else if(name.equals("import-action-library")){ match=true; }else if(name.equals("import-parameter-library")){ match=true; } if(!match){ continue; } String filePath=ele.attributeValue("path"); if(filePath.endsWith(path)){ return true; } } return false; }catch(Exception ex){ throw new RuleException(ex); } }
Example 8
Source File: GetXMLData.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public void prepareNSMap( Element l ) { @SuppressWarnings( "unchecked" ) List<Namespace> namespacesList = l.declaredNamespaces(); for ( Namespace ns : namespacesList ) { if ( ns.getPrefix().trim().length() == 0 ) { data.NAMESPACE.put( "pre" + data.NSPath.size(), ns.getURI() ); String path = ""; Element element = l; while ( element != null ) { if ( element.getNamespacePrefix() != null && element.getNamespacePrefix().length() > 0 ) { path = GetXMLDataMeta.N0DE_SEPARATOR + element.getNamespacePrefix() + ":" + element.getName() + path; } else { path = GetXMLDataMeta.N0DE_SEPARATOR + element.getName() + path; } element = element.getParent(); } data.NSPath.add( path ); } else { data.NAMESPACE.put( ns.getPrefix(), ns.getURI() ); } } @SuppressWarnings( "unchecked" ) List<Element> elementsList = l.elements(); for ( Element e : elementsList ) { prepareNSMap( e ); } }
Example 9
Source File: OperationStats.java From mts with GNU General Public License v3.0 | 5 votes |
private void handleText(Runner runner, Element root) throws Exception { // read attributes String name = root.attributeValue("name"); // create the corresponding template StatKey statKeyValue = new StatKey(StatPool.PREFIX_USER, "value", name, "_value"); CounterReportTemplate template = new CounterReportTemplate("<text>", statKeyValue, null, root); // read and check the attributes checkStoreTemplate(new StatKey(StatPool.PREFIX_USER), template); // Now execute the action. List<Element> actionElements = (List<Element>) root.elements(); for (Element actionElement : actionElements) { String actionElementName = actionElement.getName(); if (actionElementName.equals("newValue")) { String value = (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value") : actionElement.getText()); long timestamp = getTimestamp(actionElement); if (-1 != timestamp) { StatPool.getInstance().addValue(statKeyValue, value, timestamp); } else { StatPool.getInstance().addValue(statKeyValue, value); } GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic TEXT : ", name, "/_value +=", value); } } }
Example 10
Source File: LoopRuleParser.java From urule with Apache License 2.0 | 5 votes |
public LoopRule parse(Element element) { LoopRule rule=new LoopRule(); parseRule(rule, element); LoopStart loopStart=new LoopStart(); rule.setLoopStart(loopStart); LoopEnd loopEnd=new LoopEnd(); rule.setLoopEnd(loopEnd); for(Object obj:element.elements()){ if(obj==null || !(obj instanceof Element)){ continue; } Element ele=(Element)obj; String name=ele.getName(); if(name.equals("loop-start")){ loopStart.setActions(rhsParser.parseActions(ele)); }else if(name.equals("loop-end")){ loopEnd.setActions(rhsParser.parseActions(ele)); }else if(name.equals("loop-target")){ LoopTarget loopTarget=new LoopTarget(); rule.setLoopTarget(loopTarget); for(Object eleObj:ele.elements()){ if(eleObj==null || !(eleObj instanceof Element)){ continue; } Element e=(Element)eleObj; if(valueParser.support(e.getName())){ loopTarget.setValue(valueParser.parse(e)); break; } } } } return rule; }
Example 11
Source File: AssessmentContext.java From olat with Apache License 2.0 | 5 votes |
/** * Method calcFeedBack. */ private void calcFeedBack() { if (feedbacktesting) { List<?> el_ofts = el_assessment.selectNodes("outcomes_processing/outcomes_feedback_test"); feedbackavailable = false; for (Iterator<?> it_oft = el_ofts.iterator(); it_oft.hasNext();) { Element el_oft = (Element) it_oft.next(); // <!ELEMENT outcomes_feedback_test (test_variable , displayfeedback+)> Element el_testvar = (Element) el_oft.selectSingleNode("test_variable"); // must exist: dtd // <!ELEMENT test_variable (variable_test | and_test | or_test | // not_test)> Element el_varandornot = (Element) el_testvar.selectSingleNode("variable_test|and_test|or_test|not_test"); String elname = el_varandornot.getName(); ScoreBooleanEvaluable sbe = QTIHelper.getSectionBooleanEvaluableInstance(elname); float totalscore = getScore(); boolean fulfilled = sbe.eval(el_varandornot, totalscore); if (fulfilled) { // get feedback Element el_displayfeedback = (Element) el_oft.selectSingleNode("displayfeedback"); String linkRefId = el_displayfeedback.attributeValue("linkrefid"); // must exist (dtd) // ignore feedbacktype, since we section or assess feedback only // accepts material, no hints or solutions Element el_resolved = (Element) el_assessment.selectSingleNode(".//assessfeedback[@ident='" + linkRefId + "']"); getOutput().setEl_response(new AssessFeedback(el_resolved)); // give the whole assessmentfeedback to render feedbackavailable = true; } } } }
Example 12
Source File: CompositeComponentLayoutLoader.java From cuba with Apache License 2.0 | 5 votes |
protected ComponentLoader getLoader(Element element) { if (COMPOSITE_COMPONENT_ELEMENT_NAME.equals(element.getName())) { List<Element> elements = element.elements(); Preconditions.checkArgument(elements.size() == 1, "%s must contain a single root element", COMPOSITE_COMPONENT_ELEMENT_NAME); element = elements.get(0); } Class<? extends ComponentLoader> loaderClass = config.getLoader(element.getName()); if (loaderClass == null) { throw new GuiDevelopmentException("Unknown component: " + element.getName(), context); } return initLoader(element, loaderClass); }
Example 13
Source File: Parser.java From bulbasaur with Apache License 2.0 | 5 votes |
public Definition parser0(String name, int version, Document processXML, boolean status) { Element root = processXML.getRootElement(); String innerName = root.attributeValue("name"); require(innerName != null, "attribute name in process is required"); require(name.equals(innerName), String.format("name in process not equals given one\n" + "Inner: %s \n Given: %s", innerName, name)); String alias = root.attributeValue("alias"); // 模板 Definition definition = new Definition(name, "start", version, status, alias); // 解析xml for (Iterator i = root.elementIterator(); i.hasNext(); ) { Element tmp = (Element)i.next(); StateLike state; try { state = StateFactory.newInstance(tmp.getName(), tmp); } catch (RuntimeException re) { logger.error(String.format("实例节点类型时候出错,节点类型为:%s , 异常为:%s", tmp.getName(), re.toString())); throw re; } catch (Throwable e) { logger.error(String.format("实例节点类型时候出错,节点类型为:%s , 异常为:", tmp.getName(), e.toString())); throw new UndeclaredThrowableException(e, "error happened when newInstance class:" + tmp.getName()); } if (!state.isRunnable()) { definition.addExtNode(state); } else { definition.addState(state); if (!StringUtils.isBlank(tmp.getName()) && (tmp.getName()).contains("start")) { definition.setFirst(state.getStateName()); } } } return definition; }
Example 14
Source File: StreamManager.java From Openfire with Apache License 2.0 | 5 votes |
/** * Processes a stream management element. * * @param element The stream management element to be processed. */ public void process( Element element ) { switch(element.getName()) { case "enable": String resumeString = element.attributeValue("resume"); boolean resume = false; if (resumeString != null) { if (resumeString.equalsIgnoreCase("true") || resumeString.equalsIgnoreCase("yes") || resumeString.equals("1")) { resume = true; } } enable( element.getNamespace().getStringValue(), resume ); break; case "resume": long h = new Long(element.attributeValue("h")); String previd = element.attributeValue("previd"); startResume( element.getNamespaceURI(), previd, h); break; case "r": sendServerAcknowledgement(); break; case "a": processClientAcknowledgement( element); break; default: sendUnexpectedError(); } }
Example 15
Source File: FlowDefinitionReferenceUpdater.java From urule with Apache License 2.0 | 5 votes |
public String update(String oldPath, String newPath, String xml) { try{ boolean modify=false; Document doc=DocumentHelper.parseText(xml); Element element=doc.getRootElement(); for(Object obj:element.elements()){ if(!(obj instanceof Element)){ continue; } Element ele=(Element)obj; String name=ele.getName(); boolean match=false; if(name.equals("import-variable-library")){ match=true; }else if(name.equals("import-constant-library")){ match=true; }else if(name.equals("import-action-library")){ match=true; }else if(name.equals("import-parameter-library")){ match=true; } if(!match){ continue; } String path=ele.attributeValue("path"); if(path.endsWith(oldPath)){ ele.addAttribute("path", newPath); modify=true; } } if(modify){ return xmlToString(doc); } return null; }catch(Exception ex){ throw new RuleException(ex); } }
Example 16
Source File: DecisionTableReferenceUpdater.java From urule with Apache License 2.0 | 5 votes |
public String update(String oldPath, String newPath, String xml) { try{ boolean modify=false; Document doc=DocumentHelper.parseText(xml); Element element=doc.getRootElement(); for(Object obj:element.elements()){ if(!(obj instanceof Element)){ continue; } Element ele=(Element)obj; String name=ele.getName(); boolean match=false; if(name.equals("import-variable-library")){ match=true; }else if(name.equals("import-constant-library")){ match=true; }else if(name.equals("import-action-library")){ match=true; }else if(name.equals("import-parameter-library")){ match=true; } if(!match){ continue; } String path=ele.attributeValue("path"); if(path.endsWith(oldPath)){ ele.addAttribute("path", newPath); modify=true; } } if(modify){ return xmlToString(doc); } return null; }catch(Exception ex){ throw new RuleException(ex); } }
Example 17
Source File: SectionContext.java From olat with Apache License 2.0 | 5 votes |
/** * Method calcFeedBack. */ private void calcFeedBack() { List el_ofts = el_section.selectNodes("outcomes_processing/outcomes_feedback_test"); feedbackavailable = false; for (Iterator it_oft = el_ofts.iterator(); it_oft.hasNext();) { Element el_oft = (Element) it_oft.next(); // <!ELEMENT outcomes_feedback_test (test_variable , displayfeedback+)> Element el_testvar = (Element) el_oft.selectSingleNode("test_variable"); // must exist: dtd // <!ELEMENT test_variable (variable_test | and_test | or_test | // not_test)> Element el_varandornot = (Element) el_testvar.selectSingleNode("variable_test|and_test|or_test|not_test"); String elname = el_varandornot.getName(); ScoreBooleanEvaluable sbe = QTIHelper.getSectionBooleanEvaluableInstance(elname); float totalscore = getScore(); boolean fulfilled = sbe.eval(el_varandornot, totalscore); if (fulfilled) { // get feedback Element el_displayfeedback = (Element) el_oft.selectSingleNode("displayfeedback"); String linkRefId = el_displayfeedback.attributeValue("linkrefid"); // must exist (dtd) // ignore feedbacktype, since we section or assess feedback only accepts // material, no hints or solutions Element el_resolved = (Element) el_section.selectSingleNode(".//sectionfeedback[@ident='" + linkRefId + "']"); getOutput().setEl_response(new SectionFeedback(el_resolved)); // give the whole sectionfeedback to render feedbackavailable = true; } } }
Example 18
Source File: StanzaHandler.java From Openfire with Apache License 2.0 | 4 votes |
public void process(String stanza, XMPPPacketReader reader) throws Exception { boolean initialStream = stanza.startsWith("<stream:stream") || stanza.startsWith("<flash:stream"); if (!sessionCreated || initialStream) { if (!initialStream) { // Allow requests for flash socket policy files directly on the client listener port if (stanza.startsWith("<policy-file-request/>")) { String crossDomainText = FlashCrossDomainServlet.CROSS_DOMAIN_TEXT + XMPPServer.getInstance().getConnectionManager().getClientListenerPort() + FlashCrossDomainServlet.CROSS_DOMAIN_END_TEXT + '\0'; connection.deliverRawText(crossDomainText); return; } else { // Ignore <?xml version="1.0"?> return; } } // Found an stream:stream tag... if (!sessionCreated) { sessionCreated = true; MXParser parser = reader.getXPPParser(); parser.setInput(new StringReader(stanza)); createSession(parser); } else if (startedTLS) { startedTLS = false; tlsNegotiated(); } else if (startedSASL && saslStatus == SASLAuthentication.Status.authenticated) { startedSASL = false; saslSuccessful(); } else if (waitingCompressionACK) { waitingCompressionACK = false; compressionSuccessful(); } return; } // Verify if end of stream was requested if (stanza.equals("</stream:stream>")) { if (session != null) { session.getStreamManager().formalClose(); Log.debug( "Closing session as an end-of-stream was received: {}", session ); session.close(); } return; } // Ignore <?xml version="1.0"?> stanzas sent by clients if (stanza.startsWith("<?xml")) { return; } // Create DOM object from received stanza Element doc = reader.read(new StringReader(stanza)).getRootElement(); if (doc == null) { // No document found. return; } String tag = doc.getName(); if ("starttls".equals(tag)) { // Negotiate TLS if (negotiateTLS()) { startedTLS = true; } else { connection.close(); session = null; } } else if ("auth".equals(tag)) { // User is trying to authenticate using SASL startedSASL = true; // Process authentication stanza saslStatus = SASLAuthentication.handle(session, doc); } else if (startedSASL && "response".equals(tag) || "abort".equals(tag)) { // User is responding to SASL challenge. Process response saslStatus = SASLAuthentication.handle(session, doc); } else if ("compress".equals(tag)) { // Client is trying to initiate compression if (compressClient(doc)) { // Compression was successful so open a new stream and offer // resource binding and session establishment (to client sessions only) waitingCompressionACK = true; } } else if (isStreamManagementStanza(doc)) { session.getStreamManager().process( doc ); } else { process(doc); } }
Example 19
Source File: FIBQuestion.java From olat with Apache License 2.0 | 4 votes |
/** * Called by ItemParser * * @param item * @return */ public static FIBQuestion getInstance(final Element item) { final FIBQuestion instance = new FIBQuestion(); final Element presentationXML = item.element("presentation"); final List elementsXML = presentationXML.element("flow").elements(); final List responses = instance.getResponses(); final Element el_resprocessing = item.element("resprocessing"); for (final Iterator i = elementsXML.iterator(); i.hasNext();) { final Element content = (Element) i.next(); final FIBResponse fibresponse = new FIBResponse(); final String name = content.getName(); if (name.equalsIgnoreCase("material")) { final Material mat = (Material) parserManager.parse(content); if (mat != null) { fibresponse.setContent(mat); } fibresponse.setType(FIBResponse.TYPE_CONTENT); responses.add(fibresponse); } else if (name.equalsIgnoreCase("response_str")) { final String ident = content.attribute("ident").getValue(); final Element render_fib = content.element("render_fib"); content.element("render_fib").element("flow_label"); fibresponse.setType(FIBResponse.TYPE_BLANK); fibresponse.setIdent(ident); fibresponse.setSizeFromColumns(render_fib.attribute("columns")); fibresponse.setMaxLengthFromMaxChar(render_fib.attribute("maxchars")); final List el_varequals = el_resprocessing.selectNodes(".//varequal[@respident='" + ident + "']"); final List processedSolutions = new ArrayList(); // list of already process strings if (el_varequals != null) { String correctBlank = ""; String correctBlankCaseAttribute = "No"; for (final Iterator iter = el_varequals.iterator(); iter.hasNext();) { final Element el_varequal = (Element) iter.next(); final String solution = el_varequal.getTextTrim(); if (!processedSolutions.contains(solution)) { // Solutions are there twice because of the mastery feedback. // Only process solutions once. correctBlank = correctBlank + solution; if (iter.hasNext()) { correctBlank = correctBlank + ";"; } correctBlankCaseAttribute = el_varequal.attributeValue("case"); processedSolutions.add(solution); } } if (correctBlank.endsWith(";")) { correctBlank = correctBlank.substring(0, correctBlank.length() - 1); } fibresponse.setCorrectBlank(correctBlank); fibresponse.setCaseSensitive(correctBlankCaseAttribute); } responses.add(fibresponse); } } final Element resprocessingXML = item.element("resprocessing"); if (resprocessingXML != null) { List respconditions = resprocessingXML.elements("respcondition"); Map<String, Float> points = QTIEditHelperEBL.fetchPoints(respconditions, instance.getType()); // postprocessing choices for (final Iterator i = responses.iterator(); i.hasNext();) { final FIBResponse fibResp = (FIBResponse) i.next(); final Float fPoints = (Float) points.get(fibResp.getIdent()); if (fPoints != null) { fibResp.setPoints(fPoints.floatValue()); fibResp.setCorrect(true); } } // if does not contain any ANDs, assume only one combination // of answers is possible (which sets points by a setvar action="Set") if (resprocessingXML.selectNodes(".//setvar[@action='Add']").size() == 0) { instance.setSingleCorrect(true); final Collection values = points.values(); if (values.size() > 0) { instance.setSingleCorrectScore(((Float) (values.iterator().next())).floatValue()); } } else { instance.setSingleCorrect(false); } // set min/max score QTIEditHelperEBL.configureMinMaxScore(instance, (Element) resprocessingXML.selectSingleNode(".//decvar")); } return instance; }
Example 20
Source File: Host.java From big-c with Apache License 2.0 | 3 votes |
public synchronized void Parse(Element node){ if(node.getName() != "CLUSTER"){ } List<Attribute> arrtibuteList = node.attributes(); //first initialize or update attributes for(Attribute attribute : arrtibuteList){ if(attribute.getName() == "NAME"){ this.setName(attribute.getValue()); } if(attribute.getName()=="IP"){ this.setIp(attribute.getValue()); } } //then parse the child nodes for (Iterator iterator = node.elementIterator( "METRIC" ); iterator.hasNext(); ) { Element element = (Element) iterator.next(); String name = element.attribute("NAME").getValue(); Metric metric= new Metric(); metric.Parse(element); this.nameToMetrics.put(name, metric); } }