List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
From source file:com.cn.controller.CommonController.java
/** * ?????json/*from w ww.j a v a 2 s.c o m*/ * * @param element * @param roleRightList * @return */ public String hasRight(Element element, ArrayList<String> roleRightList) { String menuJson = ""; String roleCode = element.attributeValue("id"); if (roleRightList.contains(roleCode)) { if (element.elementIterator().hasNext()) { menuJson += "\"" + element.attributeValue("text") + "\":{"; Iterator<Element> iterator = element.elementIterator(); while (iterator.hasNext()) { menuJson += hasRight(iterator.next(), roleRightList); } menuJson = menuJson.substring(0, menuJson.length() - 1); menuJson += "},"; } else { menuJson += "\"" + element.attributeValue("text") + "\":"; menuJson += "\"" + element.attributeValue("hypelnk") + "," + element.attributeValue("url") + "," + element.attributeValue("id") + "," + element.attributeValue("icon") + "\","; } } return menuJson; }
From source file:com.cn.controller.CommonController.java
public String hasAppRight(Element element, ArrayList<String> roleRightList) { String menuJson = ""; String roleCode = element.attributeValue("id"); if (roleRightList.contains(roleCode) && roleCode.startsWith("80")) { if (element.elementIterator().hasNext()) { menuJson += "\"" + element.attributeValue("text") + "\":{"; Iterator<Element> iterator = element.elementIterator(); while (iterator.hasNext()) { menuJson += hasAppRight(iterator.next(), roleRightList); }//from www. j ava 2 s.com menuJson = menuJson.substring(0, menuJson.length() - 1); menuJson += "},"; } else { menuJson += "\"" + element.attributeValue("text") + "\":"; menuJson += "\"" + element.attributeValue("hypelnk") + "," + element.attributeValue("url") + "," + element.attributeValue("id") + "," + element.attributeValue("icon") + "\","; } } return menuJson; }
From source file:com.collabnet.ccf.core.ga.GenericArtifactHelper.java
License:Open Source License
/** * Converts native Java types to the XML format * /*from w w w . jav a 2 s .com*/ * @param field * XML element for the field * @param fieldValue * Java object for the field's value * @param fieldValueType * CCF data type that should be used * @throws GenericArtifactParsingException * Will be thrown if attribute values were not set appropriately */ private static void setFieldValue(Element field, Object fieldValue, FieldValueTypeValue fieldValueType) throws GenericArtifactParsingException { // TODO Carefully specify conversion for every single type if (fieldValueType == null) { throw new GenericArtifactParsingException( "Non valid value for field-attribute " + field.attributeValue(FIELD_NAME) + " specified."); } switch (fieldValueType) { case BASE64STRING: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_BASE64STRING); break; } case BOOLEAN: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_BOOLEAN); break; } case DATE: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_DATE); break; } case DATETIME: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_DATETIME); break; } case DOUBLE: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_DOUBLE); break; } case HTMLSTRING: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_HTML_STRING); break; } case INTEGER: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_INTEGER); break; } case STRING: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_STRING); break; } case USER: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_USER); break; } // case LIST: { // addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_LIST); // break; // } // case MULTI_SELECT_LIST: { // addAttribute(field, FIELD_VALUE_TYPE, // FIELD_VALUE_TYPE_MULTI_SELECT_LIST); // break; // } // case UNKNOWN: { // addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_UNKNOWN); // break; // } default: { throw new GenericArtifactParsingException( "Non valid value for field-attribute " + FIELD_VALUE_TYPE + " specified."); } } if (fieldValue == null) { addAttribute(field, FIELD_VALUE_IS_NULL, FIELD_VALUE_IS_NULL_TRUE); } else { addAttribute(field, FIELD_VALUE_IS_NULL, FIELD_VALUE_IS_NULL_FALSE); if (fieldValue instanceof Date) synchronized (df) { setValue(field, df.format((Date) fieldValue), false); } else if (fieldValue instanceof Calendar) synchronized (df) { setValue(field, df.format(((Calendar) fieldValue).getTime()), false); } else if (fieldValue instanceof XMLGregorianCalendar) synchronized (df) { setValue(field, df.format(((XMLGregorianCalendar) fieldValue).toGregorianCalendar().getTime()), false); } else setValue(field, fieldValue.toString(), false); } }
From source file:com.collabnet.ccf.core.GenericArtifactHelper.java
License:Apache License
/** * Converts native Java types to the XML format * // www.ja v a 2s. c o m * @param field * XML element for the field * @param fieldValue * Java object for the field's value * @param fieldValueType * CCF data type that should be used * @throws GenericArtifactParsingException * Will be thrown if attribute values were not set appropriately */ private static void setFieldValue(Element field, Object fieldValue, FieldValueTypeValue fieldValueType) throws GenericArtifactParsingException { // TODO Carefully specify conversion for every single type if (fieldValueType == null) { throw new GenericArtifactParsingException( "Non valid value for field-attribute " + field.attributeValue(FIELD_NAME) + " specified."); } switch (fieldValueType) { case BASE64STRING: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_BASE64STRING); break; } case BOOLEAN: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_BOOLEAN); break; } case DATE: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_DATE); break; } case DATETIME: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_DATETIME); break; } case DOUBLE: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_DOUBLE); break; } case HTMLSTRING: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_HTML_STRING); break; } case INTEGER: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_INTEGER); break; } case STRING: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_STRING); break; } case USER: { addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_USER); break; } // case LIST: { // addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_LIST); // break; // } // case MULTI_SELECT_LIST: { // addAttribute(field, FIELD_VALUE_TYPE, // FIELD_VALUE_TYPE_MULTI_SELECT_LIST); // break; // } // case UNKNOWN: { // addAttribute(field, FIELD_VALUE_TYPE, FIELD_VALUE_TYPE_UNKNOWN); // break; // } default: { throw new GenericArtifactParsingException( "Non valid value for field-attribute " + FIELD_VALUE_TYPE + " specified."); } } if (fieldValue == null || (fieldValue != null && fieldValue.equals("0"))) { addAttribute(field, FIELD_VALUE_IS_NULL, FIELD_VALUE_IS_NULL_TRUE); } else { addAttribute(field, FIELD_VALUE_IS_NULL, FIELD_VALUE_IS_NULL_FALSE); if (fieldValue instanceof Date) synchronized (df) { setValue(field, df.format((Date) fieldValue), false); } else if (fieldValue instanceof Calendar) synchronized (df) { setValue(field, df.format(((Calendar) fieldValue).getTime()), false); } else if (fieldValue instanceof XMLGregorianCalendar) synchronized (df) { setValue(field, df.format(((XMLGregorianCalendar) fieldValue).toGregorianCalendar().getTime()), false); } else setValue(field, fieldValue.toString(), false); } }
From source file:com.ctvit.vdp.product.baseconfig.service.SystemConfigService.java
public ArrayList<String[]> getOrgTypes() throws Exception { String[] typeBean = null;/* w w w. ja v a 2 s. c om*/ 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.ctvit.vdp.services.sysconfiguration.user.UserService.java
/** * ?????XML//from ww w . ja v a 2 s .com **/ public Map<String, String> getXML(Map xmlRightIds, Map thirdRightIds) throws DocumentException { String baseXML = systemConfigDao.selectByPrimaryKey("Rights").getValue();//??XML Document doc = DocumentHelper.parseText(baseXML); Document topDoc = DocumentHelper.createDocument(); Element baseElement = doc.getRootElement(); Element topEl = topDoc.addElement("Rights");//?XML List<Element> secMenuList = new ArrayList<Element>(); String topIdFlag = ""; Iterator elementIter = baseElement.elementIterator(); while (elementIter.hasNext()) {//?? Element element01 = (Element) elementIter.next(); Iterator elementIter01 = element01.elementIterator(); while (elementIter01.hasNext()) {//?? Element element02 = (Element) elementIter01.next(); Iterator elementIter02 = element02.elementIterator(); String idFlag = ""; if (xmlRightIds.get(element02.attributeValue("id")) != null) {//??ID?ID Element tempEl = element02.getParent();//? if (topEl.nodeCount() > 0 && !topIdFlag.equals(tempEl.attributeValue("id"))) { topEl.addElement(tempEl.getName()).addAttribute("id", element01.attributeValue("id")) .addAttribute("name", element01.attributeValue("name")); } if (topEl.nodeCount() == 0) { topEl.addElement(tempEl.getName()).addAttribute("id", element01.attributeValue("id")) .addAttribute("name", element01.attributeValue("name")); } topIdFlag = tempEl.attributeValue("id"); secMenuList.add(element02); } } } StringBuffer secXML = new StringBuffer(); secXML.append("<Rights>"); Element tempTopEl = topEl.createCopy(); // System.out.println("tempTopEl: "+tempTopEl.asXML()); Iterator secIt = tempTopEl.elementIterator();//???? String flag = ""; while (secIt.hasNext()) { Element op = (Element) secIt.next(); for (Element eo : secMenuList) {//eo?? if (eo.attributeValue("id").substring(0, 2).equals(op.attributeValue("id")) && !flag.equals(eo.attributeValue("id"))) { flag = eo.attributeValue("id"); Document secDoc = DocumentHelper.createDocument(); Element secEle = secDoc.addElement("SecMenu"); secEle.addAttribute("id", eo.attributeValue("id")); secEle.addAttribute("name", eo.attributeValue("name")); secEle.addAttribute("source", eo.attributeValue("source")); Iterator eoIter = eo.elementIterator(); while (eoIter.hasNext()) {//?? Element thirdEl = (Element) eoIter.next(); if (thirdRightIds.get(thirdEl.attributeValue("id")) != null) { Document document = DocumentHelper.createDocument(); Element tempEle = document.addElement("ThirdMenu"); tempEle.addAttribute("id", thirdEl.attributeValue("id")); tempEle.addAttribute("name", thirdEl.attributeValue("name")); tempEle.addAttribute("source", thirdEl.attributeValue("source")); secEle.add(tempEle);// } } op.add(secEle);// } //System.out.println("************ op: "+op.asXML()); } secXML.append(op.asXML()); } secXML.append("</Rights>"); Map<String, String> xmlMap = new HashMap<String, String>(); xmlMap.put("topMenu", topEl.asXML()); xmlMap.put("treeMenu", secXML.toString()); xmlMap.put("baseXML", baseElement.asXML()); // this.getElementList(baseElement,xmlRightIds); return xmlMap; }
From source file:com.ctvit.vdp.services.sysconfiguration.user.UserService.java
public String getRightXML(Map rightIds) throws DocumentException { String baseXML = systemConfigDao.selectByPrimaryKey("Rights").getValue();//??XML Document doc = DocumentHelper.parseText(baseXML); Element baseElement = doc.getRootElement(); Iterator elementIter = baseElement.elementIterator(); //?// w w w .jav a2 s . co m while (elementIter.hasNext()) {//?? Element el01 = (Element) elementIter.next(); if (rightIds.get(el01.attributeValue("id")) == null) { baseElement.remove(el01); } Iterator elIter01 = el01.elementIterator(); while (elIter01.hasNext()) {//?? Element el02 = (Element) elIter01.next(); if (rightIds.get(el02.attributeValue("id")) == null) { el01.remove(el02); } Iterator elIter02 = el02.elementIterator(); while (elIter02.hasNext()) {//??(?) Element el03 = (Element) elIter02.next(); if (rightIds.get(el03.attributeValue("id")) == null) { el02.remove(el03); } Iterator elIter03 = el03.elementIterator(); while (elIter03.hasNext()) {//??() Element el04 = (Element) elIter03.next(); if (rightIds.get(el04.attributeValue("id")) == null) { el03.remove(el04); } Iterator elIter04 = el04.elementIterator(); while (elIter04.hasNext()) {//??() Element el05 = (Element) elIter04.next(); System.out.println(el05.attributeValue("id")); if (rightIds.get(el05.attributeValue("id")) == null) { el04.remove(el05); } } } } } } return baseElement.asXML(); }
From source file:com.cwctravel.hudson.plugins.suitegroupedtests.junit.CaseResult.java
License:Open Source License
private static float parseTime(Element testCase) { String time = testCase.attributeValue("time"); if (time != null) { time = time.replace(",", ""); try {//from ww w . ja va 2 s . c o m return Float.parseFloat(time); } catch (NumberFormatException e) { try { return new DecimalFormat().parse(time).floatValue(); } catch (ParseException x) { // hmm, don't know what this format is. } } } return 0.0f; }
From source file:com.cwctravel.hudson.plugins.suitegroupedtests.junit.CaseResult.java
License:Open Source License
CaseResult(SuiteResult parent, Element testCase, String testClassName, boolean keepLongStdio) { // schema for JUnit report XML format is not available in Ant, // so I don't know for sure what means what. // reports in http://www.nabble.com/difference-in-junit-publisher-and-ant-junitreport-tf4308604.html#a12265700 // indicates that maybe I shouldn't use @classname altogether. // String cn = testCase.attributeValue("classname"); // if(cn==null) // // Maven seems to skip classname, and that shows up in testSuite/@name // cn = parent.getName(); /*/* w ww .j a v a 2 s.c o m*/ According to http://www.nabble.com/NPE-(Fatal%3A-Null)-in-recording-junit-test-results-td23562964.html there's some odd-ball cases where testClassName is null but @name contains fully qualified name. */ String nameAttr = testCase.attributeValue("name"); if (testClassName == null && nameAttr.contains(".")) { testClassName = nameAttr.substring(0, nameAttr.lastIndexOf('.')); nameAttr = nameAttr.substring(nameAttr.lastIndexOf('.') + 1); } className = testClassName; testName = nameAttr; errorStackTrace = getError(testCase); errorDetails = getErrorMessage(testCase); this.parent = parent; duration = parseTime(testCase); skipped = isMarkedAsSkipped(testCase); @SuppressWarnings("LeakingThisInConstructor") Collection<CaseResult> _this = Collections.singleton(this); stdout = possiblyTrimStdio(_this, keepLongStdio, testCase.elementText("system-out")); stderr = possiblyTrimStdio(_this, keepLongStdio, testCase.elementText("system-err")); }
From source file:com.cwctravel.hudson.plugins.suitegroupedtests.junit.CaseResult.java
License:Open Source License
private static String getErrorMessage(Element testCase) { Element msg = testCase.element("error"); if (msg == null) { msg = testCase.element("failure"); }//from w w w .j av a 2s .co m if (msg == null) { return null; // no error or failure elements! damn! } return msg.attributeValue("message"); }