List of usage examples for org.dom4j Element add
void add(Namespace namespace);
Namespace
to this element. From source file:com.ah.be.ls.stat.StatManager.java
public Document stat() throws DocumentException, IOException, Exception { log.info("StatManager", "stats.size=" + stats.size()); if (stats == null || stats.isEmpty()) { throw new Exception("no stat config"); }//from w ww.jav a2s . co m boolean isHMOL = NmsUtil.isProduction(); boolean isHM = !NmsUtil.isHostedHMApplication(); if (!isHMOL && !isHM) { log.warn("StatManager", "the server is not production HMOL or Stand alone HM, do not do data mining."); return null; } Document document = generateDocumentTemplate(); Map<String, List<Element>> entity = new HashMap<String, List<Element>>(); getTargetedHiveApVhmMapping(); if (isHMOL) {// HMOL vhms = getHmolVhmList(); if (vhms.isEmpty()) { log.warn("StatManager", "the server do not have any HMOL customer, do not do data mining."); return null; } } for (StatConfig stat : stats) { Map<String, Element> featureElements = buildOfDocumentFragment(stat, isHMOL); if (null == featureElements) { continue; } // store all document fragment for (String key : featureElements.keySet()) { List<Element> elements = entity.get(key); if (null == elements) { elements = new ArrayList<Element>(); entity.put(key, elements); } elements.add(featureElements.get(key)); } } // generate document if (isHMOL) { // create document root element Element root = document.addElement("stats"); root.addAttribute("version", VERSION); for (String vhmId : entity.keySet()) { Element vhmRoot = createVhmStatElement(vhmId); List<Element> elements = entity.get(vhmId); for (Element element : elements) { vhmRoot.add(element); } root.add(vhmRoot); } } else { // fetch system id String systemId = ""; LicenseInfo licenseInfo = HmBeLicenseUtil.getLicenseInfo(); if (licenseInfo != null && null != licenseInfo.getSystemId()) { systemId = licenseInfo.getSystemId(); } // create document root element Element root = document.addElement("stat"); root.addAttribute("version", VERSION); root.addAttribute("system-id", systemId); List<Element> elements = entity.get("HM"); if (null != elements) { for (Element element : elements) { root.add(element); } } } return document; }
From source file:com.ah.be.ls.stat.StatManager.java
private Map<String, Element> buildCvgAndActiveTunnel(StatConfig stat, boolean isHMOL) { Map<String, Element> elems = new HashMap<String, Element>(); if (isHMOL) { Map<Long, List<String>> totalCvgs = new HashMap<Long, List<String>>(); Map<Long, Map<String, Integer>> totalCvgTunnelCounts = new HashMap<Long, Map<String, Integer>>(); String query = "select macAddress, owner.id from " + HiveAp.class.getCanonicalName(); FilterParams filter = HiveApUtils.getCvgModeFilter(true, true); List<?> list = QueryUtil.executeQuery(query, null, filter); for (Object object : list) { Object[] objects = (Object[]) object; String macAddress = (String) objects[0]; Long vhmId = (Long) objects[1]; List<String> vhmCvgs = totalCvgs.get(vhmId); if (null == vhmCvgs) { vhmCvgs = new ArrayList<String>(); totalCvgs.put(vhmId, vhmCvgs); }//from ww w . j av a2 s . c om vhmCvgs.add(macAddress); } query = "select vpn.serverid, count(1), vpn.owner from hm_vpnstatus as vpn left join hive_ap as ap on vpn.serverid = ap.macaddress where vpn.clientid is not null and ap.hiveApModel in (" + HiveAp.HIVEAP_MODEL_VPN_GATEWAY_VA + "," + HiveAp.HIVEAP_MODEL_VPN_GATEWAY + ")" + " and ap.id is not null group by vpn.serverid, vpn.owner"; list = QueryUtil.executeNativeQuery(query); for (Object object : list) { Object[] objects = (Object[]) object; String mac = objects[0].toString(); int count = ((BigInteger) objects[1]).intValue(); long owner = ((BigInteger) objects[2]).longValue(); Map<String, Integer> vhmResult = totalCvgTunnelCounts.get(owner); if (null == vhmResult) { vhmResult = new HashMap<String, Integer>(); totalCvgTunnelCounts.put(owner, vhmResult); } vhmResult.put(mac, count); } // create document fragment for (Long id : vhms.keySet()) { String vhmId = vhms.get(id); // Integer vhmCvgCount = totalCounts.get(id); List<String> vhmCvgs = totalCvgs.get(id); Map<String, Integer> vhmCvgTunnelCounts = totalCvgTunnelCounts.get(id); Element elem = createFeatureElement(stat.getFeatureId(), stat.getFeatureName()); Element ele = createCvgsElement(vhmCvgs == null ? 0 : vhmCvgs.size()); if (null != vhmCvgs) { for (String mac : vhmCvgs) { boolean isL2 = isL2CvgTunnel(mac); Integer cvgTunnelCount = null; if (null != vhmCvgTunnelCounts) { cvgTunnelCount = vhmCvgTunnelCounts.get(mac); } ele.add(createCvgsTunnelElement(mac, null == cvgTunnelCount ? 0 : cvgTunnelCount, isL2)); } } elem.add(ele); elems.put(vhmId, elem); } } else { List<String> totalCvgs = new ArrayList<String>(); Map<String, Integer> cvgTunnelCounts = new HashMap<String, Integer>(); String query = "select macAddress from " + HiveAp.class.getCanonicalName(); FilterParams filter = HiveApUtils.getCvgModeFilter(true, true); List<?> list = QueryUtil.executeQuery(query, null, filter); for (Object object : list) { totalCvgs.add((String) object); } query = "select vpn.serverid, count(1) from hm_vpnstatus as vpn left join hive_ap as ap on vpn.serverid = ap.macaddress where vpn.clientid is not null and ap.hiveApModel in (" + HiveAp.HIVEAP_MODEL_VPN_GATEWAY_VA + "," + HiveAp.HIVEAP_MODEL_VPN_GATEWAY + ")" + " and ap.id is not null group by vpn.serverid"; list = QueryUtil.executeNativeQuery(query); for (Object object : list) { Object[] objects = (Object[]) object; String mac = objects[0].toString(); int count = ((BigInteger) objects[1]).intValue(); cvgTunnelCounts.put(mac, count); } // create document fragment Element elem = createFeatureElement(stat.getFeatureId(), stat.getFeatureName()); Element ele = createCvgsElement(totalCvgs.size()); for (String mac : totalCvgs) { boolean isL2 = isL2CvgTunnel(mac); Integer tunnelCount = cvgTunnelCounts.get(mac); ele.add(createCvgsTunnelElement(mac, tunnelCount == null ? 0 : tunnelCount, isL2)); } elem.add(ele); elems.put("HM", elem); } return elems; }
From source file:com.ah.be.ls.stat.StatManager.java
private Map<String, Element> buildDeviceNumberAndPercentagePerModel(StatConfig stat, boolean isHMOL, Set<Long> apIds) { Map<String, Element> elems = new HashMap<String, Element>(); if (isHMOL) { Map<Long, Map<Integer, Integer>> total = new HashMap<Long, Map<Integer, Integer>>(); Map<Long, Map<Integer, Integer>> selected = new HashMap<Long, Map<Integer, Integer>>(); String query = "select hiveApModel, count(id), owner from hive_ap where managestatus=" + HiveAp.STATUS_MANAGED + " and simulated = false group by hiveApModel, owner"; List<?> totalList = QueryUtil.executeNativeQuery(query); for (Object object : totalList) { Object[] objects = (Object[]) object; int apModel = ((Short) objects[0]).intValue(); int count = ((BigInteger) objects[1]).intValue(); long owner = ((BigInteger) objects[2]).longValue(); Map<Integer, Integer> vhmTotal = total.get(owner); if (null == vhmTotal) { vhmTotal = new HashMap<Integer, Integer>(); total.put(owner, vhmTotal); }/* ww w . jav a 2 s . c o m*/ vhmTotal.put(apModel, count); } if (!apIds.isEmpty()) { query = "select hiveApModel, count(id), owner from hive_ap where managestatus=" + HiveAp.STATUS_MANAGED + " and simulated = false and id in (" + getSqlParameters(apIds) + ") group by hiveApModel, owner"; List<?> selectedList = QueryUtil.executeNativeQuery(query); for (Object object : selectedList) { Object[] objects = (Object[]) object; int apModel = ((Short) objects[0]).intValue(); int count = ((BigInteger) objects[1]).intValue(); long owner = ((BigInteger) objects[2]).longValue(); Map<Integer, Integer> vhmSelected = selected.get(owner); if (null == vhmSelected) { vhmSelected = new HashMap<Integer, Integer>(); selected.put(owner, vhmSelected); } vhmSelected.put(apModel, count); } } // create document fragment for (Long id : vhms.keySet()) { String vhmId = vhms.get(id); Map<Integer, Integer> vhmSelected = selected.get(id); Map<Integer, Integer> vhmTotal = total.get(id); Element elem = createFeatureElement(stat.getFeatureId(), stat.getFeatureName()); if (null != vhmTotal) { for (Integer apModel : vhmTotal.keySet()) { Integer totalCount = vhmTotal.get(apModel); Integer selectedCount = null; if (null != vhmSelected) { selectedCount = vhmSelected.get(apModel); } elem.add(createPlatformElement(String.valueOf(apModel), (totalCount == null ? 0 : totalCount), (selectedCount == null ? 0 : selectedCount))); } } elems.put(vhmId, elem); } } else { Map<Integer, Integer> total = new HashMap<Integer, Integer>(); Map<Integer, Integer> selected = new HashMap<Integer, Integer>(); String query = "select hiveApModel, count(id) from hive_ap where managestatus=" + HiveAp.STATUS_MANAGED + " and simulated = false group by hiveApModel"; List<?> totalList = QueryUtil.executeNativeQuery(query); for (Object object : totalList) { Object[] objects = (Object[]) object; int apModel = ((Short) objects[0]).intValue(); int count = ((BigInteger) objects[1]).intValue(); total.put(apModel, count); } if (!apIds.isEmpty()) { query = "select hiveApModel, count(id) from hive_ap where managestatus=" + HiveAp.STATUS_MANAGED + " and simulated = false and id in (" + getSqlParameters(apIds) + ") group by hiveApModel"; List<?> selectedList = QueryUtil.executeNativeQuery(query); for (Object object : selectedList) { Object[] objects = (Object[]) object; int apModel = ((Short) objects[0]).intValue(); int count = ((BigInteger) objects[1]).intValue(); selected.put(apModel, count); } } // create document fragment Element elem = createFeatureElement(stat.getFeatureId(), stat.getFeatureName()); for (Integer apModel : total.keySet()) { Integer totalCount = total.get(apModel); Integer selectedCount = selected.get(apModel); elem.add(createPlatformElement(String.valueOf(apModel), (totalCount == null ? 0 : totalCount), (selectedCount == null ? 0 : selectedCount))); } elems.put("HM", elem); } return elems; }
From source file:com.ah.be.ls.stat.StatManager.java
private void buildApAndRouteElement(Map<String, Map<Integer, Integer>> result, Element elem) { for (String apModel : result.keySet()) { Map<Integer, Integer> types = result.get(apModel); Element ele = createPlatformElement(apModel); if (String.valueOf(HiveAp.HIVEAP_MODEL_VPN_GATEWAY_VA).equals(apModel) || String.valueOf(HiveAp.HIVEAP_MODEL_VPN_GATEWAY).equals(apModel)) { // CVG always counted as CVG mode Integer count = 0;/* ww w . ja v a2 s. c o m*/ for (Integer type : types.keySet()) { count = count + types.get(type); } ele.add(createCvgElement(count)); } else { for (Integer type : types.keySet()) { Integer count = types.get(type); switch (type) { case (int) HiveAp.Device_TYPE_HIVEAP: ele.add(createL2Element(count)); break; case (int) HiveAp.Device_TYPE_BRANCH_ROUTER: case (int) HiveAp.Device_TYPE_VPN_BR: ele.add(createL3Element(count)); break; case (int) HiveAp.Device_TYPE_VPN_GATEWAY: ele.add(createCvgElement(count)); break; case (int) HiveAp.Device_TYPE_SWITCH: ele.add(createSwitchElement(count)); break; } } } elem.add(ele); } }
From source file:com.alkacon.opencms.feeder.CmsFeedXmlContentHandler.java
License:Open Source License
/** * @see org.opencms.xml.content.CmsDefaultXmlContentHandler#validateAppinfoElement(org.dom4j.Element) *//*from ww w .j a v a2 s. c om*/ protected void validateAppinfoElement(Element appinfoElement) throws CmsXmlException { // create a document to validate Document doc = DocumentHelper.createDocument(); Element root = doc.addElement(APPINFO_APPINFO); // attach the default appinfo schema root.add(I_CmsXmlSchemaType.XSI_NAMESPACE); root.addAttribute(I_CmsXmlSchemaType.XSI_NAMESPACE_ATTRIBUTE_NO_SCHEMA_LOCATION, FEED_APPINFO_SCHEMA_SYSTEM_ID); // append the content from the appinfo node in the content definition root.appendContent(appinfoElement); // now validate the document with the default appinfo schema CmsXmlUtils.validateXmlStructure(doc, CmsEncoder.ENCODING_UTF_8, new CmsXmlEntityResolver(null)); }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
public void makeUpDocWithImportCategory(String[] schemas, TreeParent serverRoot) { if (serverRoot.getServerRoot() == null) { return;/*from w w w .ja v a 2 s .c om*/ } Document orgDoc = credentials.get(UnifyUrl(serverRoot.getServerRoot().getWsKey().toString())).doc; // spareDoc is meant to show the category when import digloag is launched spareDoc = (Document) orgDoc.clone(); if (schemas != null) { for (String schema : schemas) { Element subRoot = parseElements(schema); String subRootXquery = "descendant::" + subRoot.getName() + "[text()='" + subRoot.getTextTrim() //$NON-NLS-1$//$NON-NLS-2$ + "']";//$NON-NLS-1$ Element division = pingElement(subRootXquery, spareDoc.getRootElement()); if (division == null || division.getParent() == null) { return; } Element divisionParent = division.getParent(); divisionParent.remove(division); divisionParent.add((Element) subRoot.clone()); } String url = getURLFromTreeObject(serverRoot); String urlXquery = "descendant::*[@Url != '" + url + "']";//$NON-NLS-1$//$NON-NLS-2$ List<Element> elems = spareDoc.selectNodes(urlXquery); for (Element elem : elems) { elem.addAttribute("Url", url);//$NON-NLS-1$ } } credentials.get(UnifyUrl(serverRoot.getServerRoot().getWsKey().toString())).doc = spareDoc; spareDoc = orgDoc; importCategories = schemas; }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
public void parseElementForOutput(TreeObject[] xobjs) { for (TreeObject xobj : xobjs) { TreeObject subParent = xobj;/*from ww w . j a v a 2s. c om*/ while (subParent.getParent().getType() != 0) { subParent = subParent.getParent(); } Element modelElem = getParentElement(subParent); if (!outPutSchemas.containsKey(modelElem.getName())) { Element copyElem = (Element) modelElem.clone(); copyElem.clearContent(); copyElem.setText(modelElem.getTextTrim()); outPutSchemas.put(modelElem.getName(), copyElem); } subParent = xobj; TreeObject categorySubRoot = null; while (subParent.getParent().getType() == TreeObject.CATEGORY_FOLDER) { categorySubRoot = subParent.getParent(); subParent = subParent.getParent(); } Element divisionElem = null; Element copyModelElem = outPutSchemas.get(modelElem.getName()); Document doc = credentials.get(UnifyUrl(xobj.getServerRoot().getWsKey().toString())).doc; String division = xobj.getType() == TreeObject.TRANSFORMER ? "Process" : "Trigger";//$NON-NLS-1$//$NON-NLS-2$ String xpathForDivision = ".//child::" + division + "[text()='" + xobj.getType() + "']";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ if (categorySubRoot != null) { Element categoryElem = getParentElement(categorySubRoot); if (categoryElem.getParent() != modelElem) { divisionElem = pingElement(xpathForDivision, copyModelElem); if (divisionElem == null) { divisionElem = copyModelElem.addElement(categoryElem.getParent().getName()); divisionElem.setText(categoryElem.getParent().getTextTrim()); } } else { divisionElem = copyModelElem; } Element categoryElementClone = (Element) categoryElem.clone(); String xpath = "./child::" + categoryElem.getName() + "[text()='" + TreeObject.CATEGORY_FOLDER //$NON-NLS-1$//$NON-NLS-2$ + "']";//$NON-NLS-1$ if (divisionElem.selectNodes(xpath).size() == 0) { divisionElem.add(categoryElementClone); } } else { // individual xobject Element xobjElem = pingElement(getXPathForTreeObject(xobj), doc.getRootElement()); Element parentElem = xobjElem.getParent(); if (parentElem == modelElem) { parentElem = copyModelElem; } else { divisionElem = pingElement(xpathForDivision, copyModelElem); if (divisionElem == null) { divisionElem = copyModelElem.addElement(parentElem.getName()); divisionElem.setText(parentElem.getTextTrim()); } } String xpath = ".//child::" + xobjElem.getName() + "[text()='" + xobjElem.getTextTrim() + "']";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ if (divisionElem != null && pingElement(xpath, divisionElem) == null) { divisionElem.add((Element) xobjElem.clone()); } } } // filter those excluded from xobjects out of categorys String xpath = ".//descendant::*[text() ='" + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$//$NON-NLS-2$ Iterator<Element> iter = outPutSchemas.values().iterator(); while (iter.hasNext()) { Element divisionElement = iter.next(); List<Element> categorys = divisionElement.selectNodes(xpath); if (categorys != null) { for (Element categoryElems : categorys) { List objs = categoryElems.content(); List<Element> elemToDel = new ArrayList<Element>(); for (Object obj : objs) { if (obj instanceof Element) { Element categoryElement = (Element) obj; if (categoryElement.getTextTrim().equals(TreeObject.CATEGORY_FOLDER + "")) { continue; } boolean match = false; for (TreeObject xobj : xobjs) { if (filterOutBlank(xobj.getDisplayName()).equals(categoryElement.getName()) && categoryElement.getTextTrim().equals(xobj.getType() + "")) {//$NON-NLS-1$ match = true; break; } } if (!match) { elemToDel.add(categoryElement); } } } for (Element del : elemToDel) { categoryElems.remove(del); } } } } ArrayList<String> schemas = new ArrayList<String>(); Iterator<Element> iterd = outPutSchemas.values().iterator(); while (iterd.hasNext()) { schemas.add(iterd.next().asXML()); } }
From source file:com.anite.maven.plugin.hivedoc.Dom4JRegistrySerializer.java
License:Apache License
private void processModuleDescriptorProvider(Element registry, ModuleDescriptorProvider provider) { for (Iterator j = provider.getModuleDescriptors(_handler).iterator(); j.hasNext();) { _md = (ModuleDescriptor) j.next(); Element module = getModuleElement(_md); registry.add(module); }//from w w w .j a v a2 s.c om }
From source file:com.anite.maven.plugin.hivedoc.Dom4JRegistrySerializer.java
License:Apache License
private void addDependencies(Element module) { List dependencies = _md.getDependencies(); if (dependencies != null) { for (Iterator i = dependencies.iterator(); i.hasNext();) { DependencyDescriptor dd = (DependencyDescriptor) i.next(); Element dependency = getDependencyElement(dd); module.add(dependency); }/*from www. jav a2 s .c o m*/ } }
From source file:com.anite.maven.plugin.hivedoc.Dom4JRegistrySerializer.java
License:Apache License
private void addServicePoints(Element module) { List servicePoints = _md.getServicePoints(); if (servicePoints != null) { for (Iterator i = servicePoints.iterator(); i.hasNext();) { ServicePointDescriptor spd = (ServicePointDescriptor) i.next(); Element servicePoint = getServicePointElement(spd); module.add(servicePoint); SchemaImpl s = (SchemaImpl) spd.getParametersSchema(); if (s != null && s.getId() != null) addSchema(module, s, "schema"); }//from w ww . j av a 2s .c o m } }