Java Code Examples for org.dom4j.Document#selectNodes()
The following examples show how to use
org.dom4j.Document#selectNodes() .
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: UnittypeXML.java From freeacs with MIT License | 6 votes |
@SuppressWarnings("rawtypes") public void load(String file_input) throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setXIncludeAware(true); factory.setNamespaceAware(false); factory.setValidating(false); SAXParser parser = factory.newSAXParser(); SAXReader reader = new SAXReader(parser.getXMLReader()); Document document = reader.read(file_input); info = new Info(); info.load(document.selectSingleNode("//unittype/info")); Enums enums = new Enums(); enums.load(document.selectSingleNode("//unittype/parameters/enums")); parameters = new Parameters(); List parameters_nodes = document.selectNodes("//unittype/parameters"); for (Object parameters_node : parameters_nodes) { Node parameter_node = (Node) parameters_node; parameters.load(parameter_node, enums); } }
Example 2
Source File: GridDataDecoder.java From boubei-tss with Apache License 2.0 | 6 votes |
/** * 将Grid数据dataXml中各个<row ...>节点的属性值设置到实体中,并将各个实体放入List返回 * * @param dataXml XML数据 * @param entityClass 实体的class名称 * @return */ public static List<Object> decode(String dataXml, Class<?> entityClass){ Document doc = XMLDocUtil.dataXml2Doc(dataXml); List<Map<String, String>> mapList = new ArrayList<Map<String, String>>(); @SuppressWarnings("unchecked") List<Element> nodeList = doc.selectNodes("//row"); for(Element node : nodeList){ mapList.add(XMLDocUtil.dataNode2Map(node)); } List<Object> list = new ArrayList<Object>(); for(Map<String, String> map : mapList){ Object bean = BeanUtil.newInstance(entityClass); BeanUtil.setDataToBean(bean, map); list.add(bean); } return list; }
Example 3
Source File: SurveyFileResourceValidator.java From olat with Apache License 2.0 | 6 votes |
@Override public boolean validate(final File unzippedDir) { // with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if no longer needed. final VFSContainer vfsUnzippedRoot = new LocalFolderImpl(unzippedDir); final VFSItem vfsQTI = vfsUnzippedRoot.resolve("qti.xml"); // getDocument(..) ensures that InputStream is closed in every case. final Document doc = QTIHelper.getDocument((LocalFileImpl) vfsQTI); // if doc is null an error loading the document occured if (doc == null) { return false; } final List metas = doc.selectNodes("questestinterop/assessment/qtimetadata/qtimetadatafield"); for (final Iterator iter = metas.iterator(); iter.hasNext();) { final Element el_metafield = (Element) iter.next(); final Element el_label = (Element) el_metafield.selectSingleNode("fieldlabel"); final String label = el_label.getText(); if (label.equals(AssessmentInstance.QMD_LABEL_TYPE)) { // type meta final Element el_entry = (Element) el_metafield.selectSingleNode("fieldentry"); final String entry = el_entry.getText(); return entry.equals(AssessmentInstance.QMD_ENTRY_TYPE_SURVEY); } } return false; }
Example 4
Source File: Tools.java From testing_platform with Apache License 2.0 | 6 votes |
public static void updateJmx(String jmxFilePath,String csvFilePath,String csvDataXpath) throws IOException, DocumentException { SAXReader reader = new SAXReader(); Document documentNew = reader.read(new File(jmxFilePath)); List<Element> list = documentNew.selectNodes(csvDataXpath); if( list.size()>1 ){ System.out.println("报错"); }else{ Element e = list.get(0); List<Element> eList = e.elements("stringProp"); for(Element eStringProp:eList){ if( "filename".equals( eStringProp.attributeValue("name") ) ){ System.out.println("=========="); System.out.println( eStringProp.getText() ); eStringProp.setText(csvFilePath); break; } } } XMLWriter writer = new XMLWriter(new FileWriter(new File( jmxFilePath ))); writer.write(documentNew); writer.close(); }
Example 5
Source File: LilithDataStore.java From CardFantasy with BSD 2-Clause "Simplified" License | 6 votes |
public static LilithDataStore loadDefault() { LilithDataStore store = new LilithDataStore(); URL url = LilithDataStore.class.getClassLoader().getResource("cfvbaibai/cardfantasy/game/LilithData.xml"); SAXReader reader = new SAXReader(); try { Document doc = reader.read(url); @SuppressWarnings("unchecked") List<Node> lilithNodes = doc.selectNodes("/Liliths/Lilith"); for (Node lilithNode : lilithNodes) { int adjAT = Integer.parseInt(lilithNode.valueOf("@adjAT")); int adjHP = Integer.parseInt(lilithNode.valueOf("@adjHP")); String id = lilithNode.valueOf("@id"); String deckDescs = lilithNode.getText(); LilithStartupInfo lsi = new LilithStartupInfo(id, deckDescs, adjAT, adjHP); store.add(lsi); } return store; } catch (DocumentException e) { throw new CardFantasyRuntimeException("Cannot load card info XML.", e); } }
Example 6
Source File: AlipaySubmit.java From roncoo-pay with Apache License 2.0 | 6 votes |
/** * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数 * 注意:远程解析XML出错,与服务器是否支持SSL等配置有关 * @return 时间戳字符串 * @throws IOException * @throws DocumentException * @throws MalformedURLException */ public static String query_timestamp() throws MalformedURLException, DocumentException, IOException { //构造访问query_timestamp接口的URL串 String strUrl = ALIPAY_GATEWAY_NEW + "service=query_timestamp&partner=" + AlipayConfigUtil.partner + "&_input_charset" + AlipayConfigUtil.input_charset; StringBuffer result = new StringBuffer(); SAXReader reader = new SAXReader(); Document doc = reader.read(new URL(strUrl).openStream()); List<Node> nodeList = doc.selectNodes("//alipay/*"); for (Node node : nodeList) { // 截取部分不需要解析的信息 if (node.getName().equals("is_success") && node.getText().equals("T")) { // 判断是否有成功标示 List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*"); for (Node node1 : nodeList1) { result.append(node1.getText()); } } } return result.toString(); }
Example 7
Source File: AlipaySubmit.java From xmu-2016-MrCode with GNU General Public License v2.0 | 6 votes |
/** * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数 * 注意:远程解析XML出错,与服务器是否支持SSL等配置有关 * @return 时间戳字符串 * @throws IOException * @throws DocumentException * @throws MalformedURLException */ public static String query_timestamp() throws MalformedURLException, DocumentException, IOException { //构造访问query_timestamp接口的URL串 String strUrl = ALIPAY_GATEWAY_NEW + "service=query_timestamp&partner=" + AlipayConfig.partner + "&_input_charset" +AlipayConfig.input_charset; StringBuffer result = new StringBuffer(); SAXReader reader = new SAXReader(); Document doc = reader.read(new URL(strUrl).openStream()); List<Node> nodeList = doc.selectNodes("//alipay/*"); for (Node node : nodeList) { // 截取部分不需要解析的信息 if (node.getName().equals("is_success") && node.getText().equals("T")) { // 判断是否有成功标示 List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*"); for (Node node1 : nodeList1) { result.append(node1.getText()); } } } return result.toString(); }
Example 8
Source File: ConversionUtil.java From pentaho-aggdesigner with GNU General Public License v2.0 | 5 votes |
public static List<Document> generateMondrianDocsFromSSASSchema( final InputStream input ) throws DocumentException, IOException, AggDesignerException { Document ssasDocument = parseAssl( input ); // issue: if we have multi-line text, there is a problem with identing names / etc // solution: clean up the dom before traversal List allElements = ssasDocument.selectNodes( "//*" ); for ( int i = 0; i < allElements.size(); i++ ) { Element element = (Element) allElements.get( i ); element.setText( element.getText().replaceAll( "[\\s]+", " " ).trim() ); } List ssasDatabases = ssasDocument.selectNodes( "//assl:Database" ); List<Document> mondrianDocs = new ArrayList<Document>( ssasDatabases.size() ); for ( int i = 0; i < ssasDatabases.size(); i++ ) { Document mondrianDoc = DocumentFactory.getInstance().createDocument(); Element mondrianSchema = DocumentFactory.getInstance().createElement( "Schema" ); mondrianDoc.add( mondrianSchema ); Element ssasDatabase = (Element) ssasDatabases.get( i ); mondrianSchema.add( DocumentFactory.getInstance() .createAttribute( mondrianSchema, "name", getXPathNodeText( ssasDatabase, "assl:Name" ) ) ); populateCubes( mondrianSchema, ssasDatabase ); mondrianDocs.add( mondrianDoc ); } return mondrianDocs; }
Example 9
Source File: PluginCacheConfigurator.java From Openfire with Apache License 2.0 | 5 votes |
public void configure(String pluginName) { try { SAXReader saxReader = new SAXReader(); saxReader.setEncoding("UTF-8"); Document cacheXml = saxReader.read(configDataStream); List<Node> mappings = cacheXml.selectNodes("/cache-config/cache-mapping"); for (Node mapping: mappings) { registerCache(pluginName, mapping); } } catch (DocumentException e) { Log.error(e.getMessage(), e); } }
Example 10
Source File: PluginManager.java From Spark with Apache License 2.0 | 5 votes |
private boolean hasDependencies( File pluginFile ) { SAXReader saxReader = new SAXReader(); try { final Document pluginXML = saxReader.read( pluginFile ); final List dependencies = pluginXML.selectNodes( "plugin/depends/plugin" ); return dependencies != null && dependencies.size() > 0; } catch ( DocumentException e ) { Log.error( "Unable to read plugin dependencies from " + pluginFile, e ); return false; } }
Example 11
Source File: ComponentAction.java From boubei-tss with Apache License 2.0 | 5 votes |
/** * 获取组件的XML结构数据,用于单个组件预览。 * @return * @throws IOException * @throws TemplateException */ @RequestMapping("/preview/{id}") public void previewComponent(HttpServletResponse response, @PathVariable("id") Long id) throws IOException, TemplateException { Component component = service.getComponent(id); String componentType = component.getComponentType(); Document doc = XMLDocUtil.dataXml2Doc(component.getDefinition()); String html = doc.selectSingleNode("/" + componentType + "/html").getText(); String script = doc.selectSingleNode("/" + componentType + "/script").getText(); String style = doc.selectSingleNode("/" + componentType + "/style").getText(); Map<String, String> events = new HashMap<String, String>(); List<?> eventNodes = doc.selectNodes("/" + componentType + "/events/attach"); for(Iterator<?> it = eventNodes.iterator(); it.hasNext();) { Element eventNode = (Element) it.next(); events.put(eventNode.attributeValue("event"), eventNode.attributeValue("onevent")); } Map<String, String> parameters = new HashMap<String, String>(); List<?> paramNodes = doc.selectNodes("/" + componentType + "/parameters/param"); for(Iterator<?> it = paramNodes.iterator(); it.hasNext();) { Element paramNode = (Element) it.next(); parameters.put("#{" + paramNode.attributeValue("name") + "}", paramNode.attributeValue("defaultValue")); } parameters.put("${id}", componentType.substring(0, 1) + component.getId()); parameters.put("${content}", ""); parameters.put("${basepath}", Environment.getContextPath() + "/" + component.getResourcePath() + "/"); // 直接预览门户组件 for(int i = 0; i < 12; i++) { parameters.put("${port" + i + "}", "port" + i); } String data = toHTML(html, script, style, events, parameters); printHTML(data); }
Example 12
Source File: RssLoader.java From android-opensource-library-56 with Apache License 2.0 | 5 votes |
@Override public RssList loadInBackground() { try { SAXReader reader = new SAXReader(); Document document = reader.read(this.mFeed.url); List<Element> list = document.selectNodes("/rss/channel/item"); if (list != null) { for (Element element : list) { Item item = new Item(); Element title = element.element("title"); if (title != null) { item.title = title.getStringValue(); } Element link = element.element("link"); if (link != null) { item.url = link.getStringValue(); } if (mList == null) { mList = new RssList(); } mList.addItem(item); } } else { Log.d(TAG, "not found"); } } catch (Exception e) { e.printStackTrace(); } return mList; }
Example 13
Source File: XmlUtils.java From nbp with Apache License 2.0 | 5 votes |
public List<AuthInfo> xmlReadAuthInfo(Document document, String local) { Document doc = document; List<Node> list = doc.selectNodes("/ROOT/AuthId"); Iterator<Node> it = list.iterator(); List<AuthInfo> authInfoList = new ArrayList<AuthInfo>(); while (it.hasNext()) { AuthInfo authInfo = new AuthInfo(); Element taskElement = (Element) it.next(); Node authName = taskElement.selectSingleNode("authName"); Node authNaLabelKey = taskElement.selectSingleNode("authNaLabelKey"); Node authNaLabelValue = taskElement.selectSingleNode("authNaLabelValue"); Node authNaSummaryKey = taskElement.selectSingleNode("authNaSummaryKey"); Node authNaSummaryValue = taskElement.selectSingleNode("authNaSummaryValue"); Node authId = taskElement.selectSingleNode("authId"); Node authIdLabelKey = taskElement.selectSingleNode("authIdLabelKey"); Node authIdLabelValue = taskElement.selectSingleNode("authIdLabelValue"); Node authIdSummaryKey = taskElement.selectSingleNode("authIdSummaryKey"); Node authIdSummaryValue = taskElement.selectSingleNode("authIdSummaryValue"); authInfo.setAuthName(authName.getText()); authInfo.setAuthNaLabel(authNaLabelKey.getText()); authInfo.setAuthNaLabelValue(authNaLabelValue.getText()); authInfo.setAuthNaSummary(authNaSummaryKey.getText()); authInfo.setAuthNaSummaryValue(authNaSummaryValue.getText()); authInfo.setAuthId(authId.getText()); authInfo.setAuthIdLabel(authIdLabelKey.getText()); authInfo.setAuthIdLabelValue(authIdLabelValue.getText()); authInfo.setAuthIdSummary(authIdSummaryKey.getText()); authInfo.setAuthIdSummaryValue(authIdSummaryValue.getText()); authInfo.setAuthLocal(local); authInfoList.add(authInfo); } return authInfoList; }
Example 14
Source File: Dom4JParser.java From tutorials with MIT License | 5 votes |
public Node getElementsListByTitle(String name) { try { SAXReader reader = new SAXReader(); Document document = reader.read(file); List<Node> elements = document.selectNodes("//tutorial[descendant::title[text()=" + "'" + name + "'" + "]]"); return elements.get(0); } catch (DocumentException e) { e.printStackTrace(); return null; } }
Example 15
Source File: XMLInputFieldsImportProgressDialog.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@SuppressWarnings( "unchecked" ) private RowMetaAndData[] doScan( IProgressMonitor monitor ) throws Exception { monitor.beginTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.ScanningFile", filename ), 1 ); SAXReader reader = XMLParserFactoryProducer.getSAXReader( null ); monitor.worked( 1 ); if ( monitor.isCanceled() ) { return null; } // Validate XML against specified schema? if ( meta.isValidating() ) { reader.setValidation( true ); reader.setFeature( "http://apache.org/xml/features/validation/schema", true ); } else { // Ignore DTD reader.setEntityResolver( new IgnoreDTDEntityResolver() ); } monitor.worked( 1 ); monitor .beginTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.ReadingDocument" ), 1 ); if ( monitor.isCanceled() ) { return null; } InputStream is = null; try { Document document = null; if ( !Utils.isEmpty( filename ) ) { is = KettleVFS.getInputStream( filename ); document = reader.read( is, encoding ); } else { if ( !Utils.isEmpty( xml ) ) { document = reader.read( new StringReader( xml ) ); } else { document = reader.read( new URL( url ) ); } } monitor.worked( 1 ); monitor.beginTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.DocumentOpened" ), 1 ); monitor.worked( 1 ); monitor.beginTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.ReadingNode" ), 1 ); if ( monitor.isCanceled() ) { return null; } List<Node> nodes = document.selectNodes( this.loopXPath ); monitor.worked( 1 ); monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes" ) ); if ( monitor.isCanceled() ) { return null; } for ( Node node : nodes ) { if ( monitor.isCanceled() ) { return null; } nr++; monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes", String .valueOf( nr ) ) ); monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes", node .getPath() ) ); setNodeField( node, monitor ); childNode( node, monitor ); } monitor.worked( 1 ); } finally { try { if ( is != null ) { is.close(); } } catch ( Exception e ) { /* Ignore */ } } RowMetaAndData[] listFields = fieldsList.toArray( new RowMetaAndData[fieldsList.size()] ); monitor.setTaskName( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.NodesReturned" ) ); monitor.done(); return listFields; }
Example 16
Source File: FilterUtil.java From CEC-Automatic-Annotation with Apache License 2.0 | 4 votes |
public static void parseXML(String filePath) { // InputStream is = null; // try { // is = new InputStreamReader(new FileInputStream(new File(filePath))); // } catch (FileNotFoundException e1) { // e1.printStackTrace(); // MyLogger.logger.error(e1.getMessage()); // } SAXReader saxReader = new SAXReader(); Document document = null; try { document = saxReader.read(new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)), EncodingUtil.CHARSET_UTF8))); } catch (DocumentException | UnsupportedEncodingException | FileNotFoundException e1) { e1.printStackTrace(); MyLogger.logger.error(e1.getMessage()); } // Element rootElement = document.getRootElement(); // System.out.println("根节点名称:" + rootElement.getName()); // System.out.println("根节点的属性个数:" + rootElement.attributeCount()); // System.out.println("根节点id属性的值:" + rootElement.attributeValue("id")); // System.out.println("根节点内文本:" + rootElement.getText()); // System.out.println("根节点内去掉换行tab键等字符:" + rootElement.getTextTrim()); // System.out.println("根节点子节点文本内容:" + rootElement.getStringValue()); // Element content = rootElement.element("Content"); // Element paragraph = content.element("Paragraph"); // Element sentence = paragraph.element("Sentence"); // Element event = sentence.element("Event"); // Element event = paragraph.element("Event"); @SuppressWarnings("unchecked") List<Element> event_list = document.selectNodes("//Sentence/Event"); @SuppressWarnings("unchecked") List<Element> denoter_list = document.selectNodes("//Sentence/Event/Denoter"); Iterator<Element> denoterIter = denoter_list.iterator(); Iterator<Element> eventIter = event_list.iterator(); // Element para = doc.element("para"); // Element sent = para.element("sent"); while (denoterIter.hasNext()) { Element denoter = denoterIter.next(); Element event = eventIter.next(); String denoterValue = denoter.getTextTrim(); for (int i = 0; i < treeSetsList.size(); i++) { if (treeSetsList.get(i).contains(denoterValue)) { String typeValue = type_value.get(i);// 获取denoter的type值 if (0 == i) { // 说明是意念事件,那么这时候拿到的typeValue是Event的属性值 event.addAttribute("type", typeValue); denoter.addAttribute("type", "statement");// 默认意念事件触发词的类型都是statement // 注意如果是意念事件的话,event的type是thoughtEvent,denoter的属性是statement // 只要发现了一个意念事件,那个根据原则,就应该将意念事件的关系加到文档末尾 document.getRootElement().addElement(Annotation.THOUGHTEVENT_RELATION); } else { // 为event添加属性和值 denoter.addAttribute("type", typeValue); } } } } // 这部分用来实现判断Time是不是绝对时间 @SuppressWarnings("unchecked") List<Element> time_list = document.selectNodes("//Sentence/Event/Time"); Iterator<Element> timeIter = time_list.iterator(); while (timeIter.hasNext()) { Element time = timeIter.next(); String timeValue = time.getTextTrim(); if (isAbsTime(timeValue)) { time.addAttribute("type", "absTime"); } } try { // 使用XMLWriter写入,可以控制格式,经过调试,发现这种方式会出现乱码,主要是因为Eclipse中xml文件和JFrame中文件编码不一致造成的 OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(EncodingUtil.CHARSET_UTF8); // format.setSuppressDeclaration(true);//这句话会压制xml文件的声明,如果为true,就不打印出声明语句 format.setIndent(true);// 设置缩进 format.setIndent(" ");// 空行方式缩进 format.setNewlines(true);// 设置换行 XMLWriter writer = new XMLWriter(new FileWriterWithEncoding(new File(filePath), EncodingUtil.CHARSET_UTF8), format); writer.write(document); writer.close(); // 使用common的Util包写入 // FileWriterWithEncoding out = new FileWriterWithEncoding(new File(filePath), "UTF-8"); // document.write(out); // out.flush(); // out.close(); } catch (IOException e) { e.printStackTrace(); } }
Example 17
Source File: TestFileResourceValidator.java From olat with Apache License 2.0 | 4 votes |
@Override public boolean validate(final File unzippedDir) { // with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if // no longer needed. final VFSContainer vfsUnzippedRoot = new LocalFolderImpl(unzippedDir); final VFSItem vfsQTI = vfsUnzippedRoot.resolve("qti.xml"); // getDocument(..) ensures that InputStream is closed in every case. final Document doc = QTIHelper.getDocument((LocalFileImpl) vfsQTI); // if doc is null an error loading the document occured if (doc == null) { return false; } // check if this is marked as test final List metas = doc.selectNodes("questestinterop/assessment/qtimetadata/qtimetadatafield"); for (final Iterator iter = metas.iterator(); iter.hasNext();) { final Element el_metafield = (Element) iter.next(); final Element el_label = (Element) el_metafield.selectSingleNode("fieldlabel"); final String label = el_label.getText(); if (label.equals(AssessmentInstance.QMD_LABEL_TYPE)) { // type meta final Element el_entry = (Element) el_metafield.selectSingleNode("fieldentry"); final String entry = el_entry.getText(); if (!(entry.equals(AssessmentInstance.QMD_ENTRY_TYPE_SELF) || entry.equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS))) { return false; } } } // check if at least one section with one item final List sectionItems = doc.selectNodes("questestinterop/assessment/section/item"); if (sectionItems.size() == 0) { return false; } for (final Iterator iter = sectionItems.iterator(); iter.hasNext();) { final Element it = (Element) iter.next(); final List sv = it.selectNodes("resprocessing/outcomes/decvar[@varname='SCORE']"); // the QTIv1.2 system relies on the SCORE variable of items if (sv.size() != 1) { return false; } } return true; }
Example 18
Source File: TestFileResourceValidator.java From olat with Apache License 2.0 | 4 votes |
@Override public boolean validate(final File unzippedDir) { // with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if // no longer needed. final VFSContainer vfsUnzippedRoot = new LocalFolderImpl(unzippedDir); final VFSItem vfsQTI = vfsUnzippedRoot.resolve("qti.xml"); // getDocument(..) ensures that InputStream is closed in every case. final Document doc = QTIHelper.getDocument((LocalFileImpl) vfsQTI); // if doc is null an error loading the document occured if (doc == null) { return false; } // check if this is marked as test final List metas = doc.selectNodes("questestinterop/assessment/qtimetadata/qtimetadatafield"); for (final Iterator iter = metas.iterator(); iter.hasNext();) { final Element el_metafield = (Element) iter.next(); final Element el_label = (Element) el_metafield.selectSingleNode("fieldlabel"); final String label = el_label.getText(); if (label.equals(AssessmentInstance.QMD_LABEL_TYPE)) { // type meta final Element el_entry = (Element) el_metafield.selectSingleNode("fieldentry"); final String entry = el_entry.getText(); if (!(entry.equals(AssessmentInstance.QMD_ENTRY_TYPE_SELF) || entry.equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS))) { return false; } } } // check if at least one section with one item final List sectionItems = doc.selectNodes("questestinterop/assessment/section/item"); if (sectionItems.size() == 0) { return false; } for (final Iterator iter = sectionItems.iterator(); iter.hasNext();) { final Element it = (Element) iter.next(); final List sv = it.selectNodes("resprocessing/outcomes/decvar[@varname='SCORE']"); // the QTIv1.2 system relies on the SCORE variable of items if (sv.size() != 1) { return false; } } return true; }
Example 19
Source File: LoopNodesImportProgressDialog.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@SuppressWarnings( "unchecked" ) private String[] doScan( IProgressMonitor monitor ) throws Exception { monitor.beginTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.ScanningFile", filename ), 1 ); SAXReader reader = XMLParserFactoryProducer.getSAXReader( null ); monitor.worked( 1 ); if ( monitor.isCanceled() ) { return null; } // Validate XML against specified schema? if ( meta.isValidating() ) { reader.setValidation( true ); reader.setFeature( "http://apache.org/xml/features/validation/schema", true ); } else { // Ignore DTD reader.setEntityResolver( new IgnoreDTDEntityResolver() ); } monitor.worked( 1 ); monitor .beginTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.ReadingDocument" ), 1 ); if ( monitor.isCanceled() ) { return null; } InputStream is = null; try { Document document = null; if ( !Utils.isEmpty( filename ) ) { is = KettleVFS.getInputStream( filename ); document = reader.read( is, encoding ); } else { if ( !Utils.isEmpty( xml ) ) { document = reader.read( new StringReader( xml ) ); } else { document = reader.read( new URL( url ) ); } } monitor.worked( 1 ); monitor.beginTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.DocumentOpened" ), 1 ); monitor.worked( 1 ); monitor.beginTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.ReadingNode" ), 1 ); if ( monitor.isCanceled() ) { return null; } List<Node> nodes = document.selectNodes( document.getRootElement().getName() ); monitor.worked( 1 ); monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes" ) ); if ( monitor.isCanceled() ) { return null; } for ( Node node : nodes ) { if ( monitor.isCanceled() ) { return null; } if ( !listpath.contains( node.getPath() ) ) { nr++; monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes", String.valueOf( nr ) ) ); monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.AddingNode", node .getPath() ) ); listpath.add( node.getPath() ); addLoopXPath( node, monitor ); } } monitor.worked( 1 ); } finally { try { if ( is != null ) { is.close(); } } catch ( Exception e ) { /* Ignore */ } } String[] list_xpath = listpath.toArray( new String[listpath.size()] ); monitor.setTaskName( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.NodesReturned" ) ); monitor.done(); return list_xpath; }
Example 20
Source File: FullPatch.java From titan-hotfix with Apache License 2.0 | 4 votes |
private static boolean fillComponentsInfoFromManifestFile(File manifestFile, Map<String, List<String>> components) { try { SAXReader saxReader = new SAXReader(); Document document = saxReader.read(manifestFile); // read activity class names List<Node> activityNodes = document.selectNodes("/manifest/application/activity"); if (activityNodes != null) { List<String> activityTypes = activityNodes.stream() .map(node -> ((Element)node).attribute("name").getValue()) .map(className -> classNameToTypeDesc(className)) .collect(Collectors.toList()); components.put(InstrumentMain.Argument.COMPONENT_ACTIVITY, activityTypes); } // read service class names List<Node> serviceNodes = document.selectNodes("/manifest/application/service"); if (serviceNodes != null) { List<String> serviceTypes = serviceNodes.stream() .map(node -> ((Element)node).attribute("name").getValue()) .map(className -> classNameToTypeDesc(className)) .collect(Collectors.toList()); components.put(InstrumentMain.Argument.COMPONENT_SERVICE, serviceTypes); } // read provider class names List<Node> providerNodes = document.selectNodes("/manifest/application/provider"); if (providerNodes != null) { List<String> providerTypes = providerNodes.stream() .map(node -> ((Element)node).attribute("name").getValue()) .map(className -> classNameToTypeDesc(className)) .collect(Collectors.toList()); components.put(InstrumentMain.Argument.COMPONENT_PROVIDER, providerTypes); } // read receiver class names List<Node> receiverNodes = document.selectNodes("/manifest/application/receiver"); if (receiverNodes != null) { List<String> receiverTypes = receiverNodes.stream() .map(node -> ((Element)node).attribute("name").getValue()) .map(className -> classNameToTypeDesc(className)) .collect(Collectors.toList()); components.put(InstrumentMain.Argument.COMPONENT_RECEIVER, receiverTypes); } return true; } catch (Exception e) { e.printStackTrace(); return false; } }