/** * This will take a DSML <code>Element</code> containing an entry of type <dsml:entry * name="name"/> and convert it to an LDAP entry. * * @param entryElement <code>Element</code> of DSML content * @return <code>LdapEntry</code> */ protected LdapEntry createSearchResult(final Element entryElement) { final LdapEntry ldapEntry = new LdapEntry(); ldapEntry.setDn(""); if (entryElement != null) { final String name = entryElement.attributeValue("dn"); if (name != null) { ldapEntry.setDn(name); } if (entryElement.hasContent()) { final Iterator<?> ocIterator = entryElement.elementIterator("objectclass"); while (ocIterator.hasNext()) { final Element ocElement = (Element) ocIterator.next(); if (ocElement != null && ocElement.hasContent()) { final String ocName = "objectClass"; final LdapAttribute ldapAttribute = new LdapAttribute(ocName); final Iterator<?> valueIterator = ocElement.elementIterator("oc-value"); while (valueIterator.hasNext()) { final Element valueElement = (Element) valueIterator.next(); if (valueElement != null) { final String value = valueElement.getText(); if (value != null) { final String encoding = valueElement.attributeValue("encoding"); if (encoding != null && encoding.equals("base64")) { ldapAttribute.getValues().add(LdapUtil.base64Decode(value)); } else { ldapAttribute.getValues().add(value); } } } } ldapEntry.getLdapAttributes().addAttribute(ldapAttribute); } } ldapEntry .getLdapAttributes() .addAttributes( super.createSearchResult(entryElement).getLdapAttributes().getAttributes()); } } return ldapEntry; }
/** * 初始化数据 * * @param args * @throws Exception * @throws DocumentException */ @SuppressWarnings("rawtypes") public static void init(String[] args) throws Exception { try { // 读取配置文件 Element root = getConfiguration(args); // 初始化 config = getNameMap(root.element("config")); // 任务 Element jobssElement = root.element("jobs"); if (jobssElement != null && jobssElement.hasContent()) { List<?> jobList = jobssElement.elements("job"); if (jobList != null && jobList.size() > 0) { for (Object element : jobList) { Element jobElement = (Element) element; // 任务属性 if (!Boolean.parseBoolean(jobElement.attributeValue("enable"))) continue; JobInfo jobInfo = new JobInfo(); JobDetail jobDetail = new JobDetail(); jobDetail.setName(jobElement.attributeValue("name")); jobDetail.setGroup(jobElement.attributeValue("group")); jobDetail.setDescription(jobElement.attributeValue("description")); String classStr = jobElement.elementTextTrim("class"); Class clazz = Class.forName(classStr); jobDetail.setJobClass(clazz); jobInfo.setJobDetail(jobDetail); CronTrigger cronTrigger = new CronTrigger(); cronTrigger.setName(jobElement.attributeValue("name")); cronTrigger.setJobGroup(jobElement.attributeValue("group")); cronTrigger.setCronExpression(jobElement.elementTextTrim("cron")); jobInfo.setCronTrigger(cronTrigger); jobs.add(jobInfo); } } } } catch (Exception e1) { log.error("初始化数据异常:" + e1.getMessage(), e1); throw new Exception("初始化数据异常! Init Error!"); } }
/** * @方法功能描述:判断节点是否还有子节点 @方法名:hasChild * * @param e @返回类型:boolean */ public static boolean hasChild(Element e) { if (e == null) return false; return e.hasContent(); }
private void loadDatatablesXml() { String xmlPath = AliceHelper.getInstance().getJoddProps().getValue("datatables.xml.path"); SAXReader reader = new SAXReader(); Document document; try { InputStream in = this.getClass().getResourceAsStream(xmlPath); document = reader.read(in); } catch (Exception e) { LOGGER.error("**** DatatablesHelper -> loadDatatablesXml fail! ****", e); return; } /* reset */ datatablesMap = new HashMap<String, Datatable>(); globalValueMap = new HashMap<String, String>(); languageMap = new HashMap<String, Object>(); Element root = document.getRootElement(); for (Iterator iterA = root.elementIterator(); iterA.hasNext(); ) { // 获取节点 version/globalValue/datatables Element elementA = (Element) iterA.next(); if (elementA != null && elementA.hasContent()) { if ("datatables".equals(elementA.getName())) { // 获取节点 datatable for (Iterator iterB = elementA.elementIterator(); iterB.hasNext(); ) { Element elementB = (Element) iterB.next(); if (elementB != null && "datatable".equals(elementB.getName())) { Attribute attrB_id = elementB.attribute("id"); Attribute attrB_name = elementB.attribute("name"); // create datatable Datatable datatable = new Datatable(attrB_id.getText(), attrB_name.getText()); if (elementB.hasContent()) { // 获取节点 property for (Iterator iterC = elementB.elementIterator(); iterC.hasNext(); ) { Element elementC = (Element) iterC.next(); if (elementC != null && "property".equals(elementC.getName())) { Attribute attrC_name = elementC.attribute("name"); Attribute attrC_value = elementC.attribute("value"); Attribute attrC_url = elementC.attribute("isURL"); if (attrC_url != null && "true".equals(attrC_url.getText())) { datatable.setProperty( attrC_name.getText(), BaseFunctions.getBasePath() + attrC_value.getText()); } else { datatable.setProperty(attrC_name.getText(), attrC_value.getText()); } } } // property end } datatablesMap.put(datatable.getId(), datatable); } } // datatable end } // datatables end else if ("language".equals(elementA.getName())) { // 获取节点 item for (Iterator iterB = elementA.elementIterator(); iterB.hasNext(); ) { Element elementB = (Element) iterB.next(); if (elementB != null) { if ("item".equals(elementB.getName())) { addItemElementForMap(elementB, languageMap); } else if ("paginate".equals(elementB.getName())) { Map<String, Item> paginateMap = new HashMap<String, Item>(); for (Iterator iterC = elementB.elementIterator(); iterC.hasNext(); ) { Element elementC = (Element) iterC.next(); if (elementC != null && "item".equals(elementC.getName())) { addItemElementForMap(elementC, paginateMap); } } languageMap.put("paginateHM", paginateMap); } } } // item end } } else { if (elementA != null) { if ("version".equals(elementA.getName())) { this.version = elementA.attribute("value").getText(); } else if ("globalValue".equals(elementA.getName())) { addGlobalValueForMap(elementA, globalValueMap); } } } } }