List of usage examples for org.dom4j Element elements
List<Element> elements(QName qName);
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * Return the child elements with the given name. The elements must be in * the same name space as the parent element. * /*from www. j a v a 2 s .c o m*/ * @param element * The parent element * @param name * The child element name * @return The child elements */ public static List<Element> children(Element element, String name) { return element.elements(new QName(name, element.getNamespace())); }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * // ww w . j av a 2s .com * * * * @param element * * @param name * * * * * @param optional * * @return * @throws XMLDocException * @throws BaseException */ public static Element getFirstChild(Element element, String name, boolean optional) throws BaseException { List list = element.elements(new QName(name, element.getNamespace())); // 0 if (list.size() > 0) { return (Element) list.get(0); } else { if (!optional) { throw new BaseException("UTIL-0001", name + " element expected as first child of " + element.getName() + "."); } else { return null; } } }
From source file:com.bluexml.side.framework.alfresco.sharePortalExtension.PresetsManagerExtension.java
License:Open Source License
/** * Construct the model objects for a given preset. * Objects persist to the default store for the appropriate object type. * /* w w w . jav a 2 s. c om*/ * @param id * Preset ID to use * @param tokens * Name value pair tokens to replace in preset definition */ public void constructPreset(String id, Map<String, String> tokens) { if (id == null) { throw new IllegalArgumentException("Preset ID is mandatory."); } // perform one time init - this cannot be perform in an app handler or by the // framework init - as it requires the Alfresco server to be started... synchronized (this) { if (this.documents == null) { init(); } } for (Document doc : this.documents) { for (Element preset : (List<Element>) doc.getRootElement().elements("preset")) { // found preset with matching id? if (id.equals(preset.attributeValue("id"))) { // any components in the preset? Element components = preset.element("components"); if (components != null) { for (Element c : (List<Element>) components.elements("component")) { // apply token replacement to each value as it is retrieved String title = replace(c.elementTextTrim(Component.PROP_TITLE), tokens); String titleId = replace(c.elementTextTrim(Component.PROP_TITLE_ID), tokens); String description = replace(c.elementTextTrim(Component.PROP_DESCRIPTION), tokens); String descriptionId = replace(c.elementTextTrim(Component.PROP_DESCRIPTION_ID), tokens); String typeId = replace(c.elementTextTrim(Component.PROP_COMPONENT_TYPE_ID), tokens); String scope = replace(c.elementTextTrim(Component.PROP_SCOPE), tokens); String regionId = replace(c.elementTextTrim(Component.PROP_REGION_ID), tokens); String sourceId = replace(c.elementTextTrim(Component.PROP_SOURCE_ID), tokens); String url = replace(c.elementTextTrim(Component.PROP_URL), tokens); String chrome = replace(c.elementTextTrim(Component.PROP_CHROME), tokens); // validate mandatory values if (scope == null || scope.length() == 0) { throw new IllegalArgumentException( "Scope is a mandatory property for a component preset."); } if (regionId == null || regionId.length() == 0) { throw new IllegalArgumentException( "RegionID is a mandatory property for a component preset."); } if (sourceId == null || sourceId.length() == 0) { throw new IllegalArgumentException( "SourceID is a mandatory property for a component preset."); } // generate component Component component = modelObjectService.newComponent(scope, regionId, sourceId); component.setComponentTypeId(typeId); component.setTitle(title); component.setTitleId(titleId); component.setDescription(description); component.setDescriptionId(descriptionId); component.setURL(url); component.setChrome(chrome); // apply arbituary custom properties if (c.element("properties") != null) { for (Element prop : (List<Element>) c.element("properties").elements()) { String propName = replace(prop.getName(), tokens); String propValue = replace(prop.getTextTrim(), tokens); component.setCustomProperty(propName, propValue); } } // persist the object modelObjectService.saveObject(component); } } // any pages in the preset? Element pages = preset.element("pages"); if (pages != null) { for (Element p : (List<Element>) pages.elements("page")) { // apply token replacement to each value as it is retrieved String pageId = replace(p.attributeValue(Page.PROP_ID), tokens); String title = replace(p.elementTextTrim(Page.PROP_TITLE), tokens); String titleId = replace(p.elementTextTrim(Page.PROP_TITLE_ID), tokens); String description = replace(p.elementTextTrim(Page.PROP_DESCRIPTION), tokens); String descriptionId = replace(p.elementTextTrim(Page.PROP_DESCRIPTION_ID), tokens); String typeId = replace(p.elementTextTrim(Page.PROP_PAGE_TYPE_ID), tokens); String auth = replace(p.elementTextTrim(Page.PROP_AUTHENTICATION), tokens); String template = replace(p.elementTextTrim(Page.PROP_TEMPLATE_INSTANCE), tokens); // validate mandatory values if (pageId == null || pageId.length() == 0) { throw new IllegalArgumentException( "ID is a mandatory attribute for a page preset."); } if (template == null || template.length() == 0) { throw new IllegalArgumentException( "Template is a mandatory property for a page preset."); } // generate page Page page = modelObjectService.newPage(pageId); page.setPageTypeId(typeId); page.setTitle(title); page.setTitleId(titleId); page.setDescription(description); page.setDescriptionId(descriptionId); page.setAuthentication(auth); page.setTemplateId(template); // apply arbituary custom properties if (p.element("properties") != null) { for (Element prop : (List<Element>) p.element("properties").elements()) { String propName = replace(prop.getName(), tokens); String propValue = replace(prop.getTextTrim(), tokens); page.setCustomProperty(propName, propValue); } } // persist the object modelObjectService.saveObject(page); } } // any template instances in the preset? Element templates = preset.element("template-instances"); if (templates != null) { for (Element t : (List<Element>) templates.elements("template-instance")) { // apply token replacement to each value as it is retrieved String templateId = replace(t.attributeValue(TemplateInstance.PROP_ID), tokens); String title = replace(t.elementTextTrim(TemplateInstance.PROP_TITLE), tokens); String titleId = replace(t.elementTextTrim(TemplateInstance.PROP_TITLE_ID), tokens); String description = replace(t.elementTextTrim(TemplateInstance.PROP_DESCRIPTION), tokens); String descriptionId = replace(t.elementTextTrim(TemplateInstance.PROP_DESCRIPTION_ID), tokens); String templateType = replace(t.elementTextTrim(TemplateInstance.PROP_TEMPLATE_TYPE), tokens); // validate mandatory values if (templateId == null || templateId.length() == 0) { throw new IllegalArgumentException( "ID is a mandatory attribute for a template-instance preset."); } if (templateType == null || templateType.length() == 0) { throw new IllegalArgumentException( "Template is a mandatory property for a page preset."); } // generate template-instance TemplateInstance template = modelObjectService.newTemplate(templateId); template.setTitle(title); template.setTitleId(titleId); template.setDescription(description); template.setDescriptionId(descriptionId); template.setTemplateTypeId(templateType); // apply arbituary custom properties if (t.element("properties") != null) { for (Element prop : (List<Element>) t.element("properties").elements()) { String propName = replace(prop.getName(), tokens); String propValue = replace(prop.getTextTrim(), tokens); template.setCustomProperty(propName, propValue); } } // persist the object modelObjectService.saveObject(template); } } // TODO: any chrome, associations, types, themes etc. in the preset... // found our preset - no need to process further break; } } } }
From source file:com.brick.util.nciic.NciicUtil.java
/** * ?XML// ww w .jav a 2 s. com * @param text * @return * @throws Exception */ public static List<NciicEntity> readResult(String text) throws Exception { List<NciicEntity> resultList = new ArrayList<NciicEntity>(); NciicEntity result = null; Document d; XMLWriter writer = null; try { //SAXReader reader = new SAXReader(); //d = reader.read(new File("d:/test/testxml.xml")); d = DocumentHelper.parseText(text); String dateStr = DateUtil.dateToString(new Date(), "[yyyy-MM-dd][HH-mm]"); File xmlPath = new File(XML_PATH); if (!xmlPath.exists()) { xmlPath.mkdirs(); } File xpPath = new File(XP_PATH); if (!xpPath.exists()) { xpPath.mkdirs(); } writer = new XMLWriter(new FileOutputStream(new File(xmlPath, dateStr + ".xml"))); writer.write(d); writer.flush(); writer.close(); writer = null; Element root = d.getRootElement(); List<Element> allResult = root.elements("ROW"); Element input = null; List<Element> output = null; String result_msg = null; for (Element element : allResult) { result = new NciicEntity(); result_msg = null; input = element.element("INPUT"); result.setGmsfhm(input.element("gmsfhm").getText()); result.setXm(input.element("xm").getText()); output = element.element("OUTPUT").elements("ITEM"); for (Element out_element : output) { if (out_element.element("result_gmsfhm") != null) { result.setResult_gmsfhm(out_element.element("result_gmsfhm").getText()); } if (out_element.element("result_xm") != null) { result.setResult_xm(out_element.element("result_xm").getText()); } if (out_element.element("errormesage") != null) { result.setError_msg(out_element.element("errormesage").getText()); } if (out_element.element("errormesagecol") != null) { result.setError_msg_col(out_element.element("errormesagecol").getText()); } if (out_element.element("xp") != null) { result.setXp(out_element.element("xp").getText()); } if (!StringUtils.isEmpty(result.getXp())) { try { File f = new File(xpPath, result.getGmsfhm() + "-" + result.getXm() + ".jpg"); BufferedImage img = ImageIO.read( new ByteArrayInputStream(new BASE64Decoder().decodeBuffer(result.getXp()))); ImageIO.write(img, "jpg", f); result.setXp_file(f.getPath()); } catch (IOException e) { e.printStackTrace(); } } } if ("".equals(result.getResult_gmsfhm()) && "".equals(result.getResult_xm())) { result_msg = ""; } else { if ("?".equals(result.getResult_gmsfhm())) { result_msg = "???"; } else if ("?".equals(result.getResult_xm())) { result_msg = "???"; } else if (!StringUtils.isEmpty(result.getError_msg())) { result_msg = result.getError_msg(); if (!StringUtils.isEmpty(result.getError_msg_col())) { result_msg += "(" + result.getError_msg_col() + ")"; } } } result.setResult_msg(result_msg); resultList.add(result); } return resultList; } catch (Exception e) { throw e; } finally { if (writer != null) { writer.flush(); writer.close(); writer = null; } } }
From source file:com.buddycloud.channeldirectory.search.utils.FeatureUtils.java
License:Apache License
/** * Parses options features from an IQ request * Returns an empty map if there is no <options> tag * //from www . j av a 2 s.c om * @param request * @return */ @SuppressWarnings("unchecked") public static Set<String> parseOptions(Element queryElement) { Element optionsElement = queryElement.element("options"); Set<String> options = new HashSet<String>(); if (optionsElement == null) { return options; } List<Element> features = optionsElement.elements("feature"); for (Element element : features) { options.add(element.attributeValue("var")); } return options; }
From source file:com.bullx.heartbeat.Command.java
License:Open Source License
@SuppressWarnings("unchecked") public static List<Command> parse(Element e) { if (null == e) { return Collections.emptyList(); }//from ww w . ja v a 2s . c o m List<Element> commandNodeList = e.elements("command"); List<Command> retList = new ArrayList<Command>(); for (Element cmNode : commandNodeList) { Command c = new Command(); c.objid = cmNode.attributeValue("objid"); c.commandType = CommandType.valueOf(cmNode.attributeValue("type")); List<Element> actionNodeList = cmNode.elements(); for (Element a : actionNodeList) { c.action.put(a.attributeValue("name"), a.attributeValue("value")); } retList.add(c); } return retList; }
From source file:com.ctvit.vdp.product.baseconfig.service.SystemConfigService.java
public ArrayList<String[]> getOrgTypes() throws Exception { String[] typeBean = null;//from ww w . ja va2s .c o m ArrayList<String[]> resultList = new ArrayList<String[]>(); Document doc = XMLUtil.transforXml(getSystemConfig("EnumDefines")); Element root = doc.getRootElement(); List<Element> selectedNodes = root.selectNodes("Enum"); for (Element element : selectedNodes) { if ("".equals(element.attributeValue("enumid"))) { List<Element> el = element.elements("EnumNode"); for (Element element1 : el) { typeBean = new String[2]; typeBean[0] = element1.attributeValue("label"); typeBean[1] = element1.attributeValue("value"); resultList.add(typeBean); } break; } } return resultList; }
From source file:com.cwctravel.hudson.plugins.suitegroupedtests.junit.SuiteResult.java
License:Open Source License
/** * Parses the JUnit XML file into {@link SuiteResult}s. This method returns a collection, as a single XML may have multiple <testsuite> * elements wrapped into the top-level <testsuites>. */// w w w.j a va 2s . co m static List<SuiteResult> parse(File xmlReport, boolean keepLongStdio) throws DocumentException, IOException { List<SuiteResult> r = new ArrayList<SuiteResult>(); // parse into DOM SAXReader saxReader = new SAXReader(); // install EntityResolver for resolving DTDs, which are in files created by TestNG. // (see https://hudson.dev.java.net/servlets/ReadMsg?listName=users&msgNo=5530) XMLEntityResolver resolver = new XMLEntityResolver(); saxReader.setEntityResolver(resolver); Document result = saxReader.read(xmlReport); Element root = result.getRootElement(); if (root.getName().equals("testsuites")) { // multi-suite file for (Element suite : (List<Element>) root.elements("testsuite")) r.add(new SuiteResult(xmlReport, suite, keepLongStdio)); } else { // single suite file r.add(new SuiteResult(xmlReport, root, keepLongStdio)); } return r; }
From source file:com.cwctravel.hudson.plugins.suitegroupedtests.junit.SuiteResult.java
License:Open Source License
/** * @param xmlReport/* w w w.j a v a 2 s. c o m*/ * A JUnit XML report file whose top level element is 'testsuite'. * @param suite * The parsed result of {@code xmlReport} */ private SuiteResult(File xmlReport, Element suite, boolean keepLongStdio) throws DocumentException, IOException { this.file = xmlReport.getAbsolutePath(); String name = suite.attributeValue("name"); if (name == null) // some user reported that name is null in their environment. // see http://www.nabble.com/Unexpected-Null-Pointer-Exception-in-Hudson-1.131-tf4314802.html name = '(' + xmlReport.getName() + ')'; else { String pkg = suite.attributeValue("package"); if (pkg != null && pkg.length() > 0) name = pkg + '.' + name; } this.name = TestObject.safe(name); this.timestamp = suite.attributeValue("timestamp"); Element ex = suite.element("error"); if (ex != null) { // according to junit-noframes.xsl l.229, this happens when the test class failed to load addCase(new CaseResult(this, suite, "<init>", keepLongStdio)); } for (Element e : (List<Element>) suite.elements("testcase")) { // https://hudson.dev.java.net/issues/show_bug.cgi?id=1233 indicates that // when <testsuites> is present, we are better off using @classname on the // individual testcase class. // https://hudson.dev.java.net/issues/show_bug.cgi?id=1463 indicates that // @classname may not exist in individual testcase elements. We now // also test if the testsuite element has a package name that can be used // as the class name instead of the file name which is default. String classname = e.attributeValue("classname"); if (classname == null) { classname = suite.attributeValue("name"); } // https://hudson.dev.java.net/issues/show_bug.cgi?id=1233 and // http://www.nabble.com/difference-in-junit-publisher-and-ant-junitreport-tf4308604.html#a12265700 // are at odds with each other --- when both are present, // one wants to use @name from <testsuite>, // the other wants to use @classname from <testcase>. addCase(new CaseResult(this, e, classname, keepLongStdio)); } String stdout = suite.elementText("system-out"); String stderr = suite.elementText("system-err"); if (stdout == null && stderr == null) { // Surefire never puts stdout/stderr in the XML. Instead, it goes to a separate file Matcher m = SUREFIRE_FILENAME.matcher(xmlReport.getName()); if (m.matches()) { // look for ***-output.txt from TEST-***.xml File mavenOutputFile = new File(xmlReport.getParentFile(), m.group(1) + "-output.txt"); if (mavenOutputFile.exists()) { try { stdout = FileUtils.readFileToString(mavenOutputFile); } catch (IOException e) { throw new IOException2("Failed to read " + mavenOutputFile, e); } } } } this.stdout = CaseResult.possiblyTrimStdio(cases, keepLongStdio, stdout); this.stderr = CaseResult.possiblyTrimStdio(cases, keepLongStdio, stderr); }
From source file:com.denimgroup.threadfix.service.SurveyServiceImpl.java
License:Mozilla Public License
private Survey constructSurvey(Element element) { Survey survey = new Survey(); survey.setName(element.elementText("name")); for (Object levelElement : element.elements("level")) { survey.getSurveyLevels().add(constructLevel((Element) levelElement)); }//from w ww . jav a2 s. c om for (Object sectionElement : element.elements("section")) { survey.getSurveySections().add(constructSection((Element) sectionElement)); } // Link Back for (SurveyLevel l : survey.getSurveyLevels()) { l.setSurvey(survey); } for (SurveySection s : survey.getSurveySections()) { s.setSurvey(survey); } return survey; }