List of usage examples for org.dom4j Element addElement
Element addElement(String name);
Element
node with the given name to this branch and returns a reference to the new node. From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void storeCommonTable(String strTableName, String strPath, HmDomain oDomain, Connection conTable) { XMLWriter output = null;/* w ww.ja v a 2 s .c o m*/ ResultSet rsTable = null; Statement stTable = null; try { stTable = conTable.createStatement(); boolean bOwnerFlag = false; String strSql = "select * from " + strTableName + " limit 1"; rsTable = stTable.executeQuery(strSql); rsTable.next(); ResultSetMetaData rsmd = rsTable.getMetaData(); int iColumnCount = rsmd.getColumnCount(); for (int i = 1; i <= iColumnCount; ++i) { if (rsmd.getColumnName(i).equalsIgnoreCase("owner")) { bOwnerFlag = true; break; } } rsTable.close(); // if (!bOwnerFlag) { // strSql = "select count(*) from " + strTableName; // } else { // strSql = "select count(*) from " + strTableName // + ", hm_domain where " + strTableName // + ".owner=hm_domain.id and (" + strTableName // + ".owner=" + oDomain.getId().toString() // + " or hm_domain.domainname='global')"; // } // rsTable = stTable.executeQuery(strSql); // rsTable.next(); // int iRowCount = rsTable.getInt(1); // rsTable.close(); int intFileCount = 0; int intRecordNum; strSql = "select id from hm_domain where domainname='global'"; rsTable = stTable.executeQuery(strSql); long global_id = 0; if (rsTable.next()) global_id = rsTable.getLong(1); String strId = String.valueOf(global_id); while (true) { intRecordNum = 0; //for (int i = 0; i < iRowCount || i == 0; i = i + 5000) { // if (!bOwnerFlag) { // strSql = "select * from " + strTableName + " limit " + 5000 // + " offset " + i; // } else { // strSql = "select " + strTableName + ".* from " // + strTableName + ", hm_domain where " // + strTableName + ".owner=hm_domain.id and (" // + strTableName + ".owner=" // + oDomain.getId().toString() // + " or hm_domain.domainname='global')" + " limit " // + 5000 + " offset " + i; // } if (!bOwnerFlag) { strSql = "select * from " + strTableName + " limit " + 5000 + " offset " + intFileCount * 5000; } else { strSql = "select * from " + strTableName + " where owner=" + oDomain.getId().toString() + " or owner=" + strId + " limit " + 5000 + " offset " + intFileCount * 5000; } rsTable = stTable.executeQuery(strSql); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strTableName); rsmd = rsTable.getMetaData(); int iCount = rsmd.getColumnCount(); while (rsTable.next()) { intRecordNum++; Element row = table.addElement("row"); for (int icol = 1; icol <= iCount; icol++) { String newStr; if (rsTable.getString(icol) == null) { newStr = "NULL"; } else if ("null".equalsIgnoreCase(rsTable.getString(icol))) { newStr = "_" + rsTable.getString(icol) + "_"; } else { newStr = rsTable.getString(icol); } // row.addElement("field").addAttribute("name", // rsmd.getColumnName(icol)).addAttribute("value", // newStr); if (1 == intRecordNum) { row.addElement("field").addAttribute("name", rsmd.getColumnName(icol)) .addAttribute("value", newStr); } else { row.addElement("field").addAttribute("value", newStr); } } } if (intRecordNum <= 0 && 0 != intFileCount) break; File file; if (intFileCount == 0) { file = new File(strPath + strTableName.toLowerCase() + ".xml"); } else { file = new File(strPath + strTableName.toLowerCase() + "_" + intFileCount + ".xml"); } intFileCount++; output = new XMLWriter(new FileOutputStream(file)); output.write(document); output.close(); if (5000 > intRecordNum) break; } rsTable.close(); stTable.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } if (null != rsTable) { try { rsTable.close(); } catch (Exception rsex) { BeLogTools.restoreLog(BeLogTools.ERROR, rsex.getMessage()); } } if (null != stTable) { try { stTable.close(); } catch (Exception stex) { BeLogTools.restoreLog(BeLogTools.ERROR, stex.getMessage()); } } } }
From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void storeSpecialTable(String strTableName, String strPath, HmDomain oDomain, Connection conTable) { XMLWriter output = null;//from ww w . j av a 2 s. com ResultSet rsTable = null; Statement stTable = null; try { if (!(strPath.substring(strPath.length() - 1).equals(File.separator) || strPath.substring(strPath.length() - 1).equals("/"))) { strPath = strPath + File.separatorChar; } stTable = conTable.createStatement(); // String strSql = "select count(*) from " + strTableName // + ", hm_domain where " + strTableName // + ".owner=hm_domain.id and (" + strTableName + ".owner=" // + oDomain.getId().toString() // + " or hm_domain.domainname='global')"; // // begin = System.currentTimeMillis(); // // rsTable = stTable.executeQuery(strSql); // // dbtime += System.currentTimeMillis() - begin; // // rsTable.next(); // // int iRowCount = rsTable.getInt(1); // // rsTable.close(); String strSql = "select id from " + strTableName + " where owner=" + oDomain.getId().toString() + " order by id asc limit 1"; rsTable = stTable.executeQuery(strSql); long id = 0; if (rsTable.next()) id = rsTable.getLong(1) - 1; // else // return; rsTable.close(); int intFileCount = 0; String strId = String.valueOf(id); int intRecordNum; while (true) { intRecordNum = 0; // strSql = "select * from " + strTableName // + " where owner=" + oDomain.getId().toString() // + " and id>" + strId +" order by id asc "+ " limit " + 5000; strSql = "select * from " + strTableName + " where id > " + strId + " and owner=" + oDomain.getId().toString() + " order by id asc " + " limit " + 5000; rsTable = stTable.executeQuery(strSql); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strTableName); ResultSetMetaData rsmd = rsTable.getMetaData(); int iCount = rsmd.getColumnCount(); while (rsTable.next()) { intRecordNum++; Element row = table.addElement("row"); for (int icol = 1; icol <= iCount; icol++) { String newStr; if (rsTable.getString(icol) == null) { newStr = "NULL"; } else if ("null".equalsIgnoreCase(rsTable.getString(icol))) { newStr = "_" + rsTable.getString(icol) + "_"; } else { newStr = rsTable.getString(icol); } if ("id".equalsIgnoreCase(rsmd.getColumnName(icol))) { strId = newStr; } if (1 == intRecordNum) { row.addElement("field").addAttribute("name", rsmd.getColumnName(icol)) .addAttribute("value", newStr); } else { row.addElement("field").addAttribute("value", newStr); } } } if (intRecordNum <= 0 && 0 != intFileCount) break; File file; if (intFileCount == 0) { file = new File(strPath + strTableName.toLowerCase() + ".xml"); } else { file = new File(strPath + strTableName.toLowerCase() + "_" + intFileCount + ".xml"); } intFileCount++; output = new XMLWriter(new FileOutputStream(file)); output.write(document); output.close(); if (5000 > intRecordNum) break; } rsTable.close(); stTable.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } if (null != rsTable) { try { rsTable.close(); } catch (Exception rsex) { BeLogTools.restoreLog(BeLogTools.ERROR, rsex.getMessage()); } } if (null != stTable) { try { stTable.close(); } catch (Exception stex) { BeLogTools.restoreLog(BeLogTools.ERROR, stex.getMessage()); } } } }
From source file:com.ah.ui.actions.config.USBModemAction.java
private Document generateExportDoc() { List<USBModem> usbModemLst = QueryUtil.executeQuery(USBModem.class, null, null, null, this); if (usbModemLst.isEmpty()) { return null; }//from w ww . ja va2 s . c om Document document = DocumentHelper.createDocument(); Element modems = document.addElement("hiveos-modem-support-list").addElement("modems"); for (USBModem usbModem : usbModemLst) { Element modem = modems.addElement("modem").addAttribute("id", usbModem.getModemName()); modem.addElement("display").addAttribute("name", usbModem.getDisplayName()).addAttribute("type", usbModem.getDisplayType()); modem.addElement("usb-info").addAttribute("vendor-id", usbModem.getUsbVendorId()) .addAttribute("product-id", usbModem.getUsbProductId()) .addAttribute("module", usbModem.getUsbModule()); modem.addElement("hiveos-version").addAttribute("min", usbModem.getHiveOSVersionMin()); //Element strengthCheck = modem.addElement("signal-strength-check"); //if (usbModem.getUsbSignalStrengthCheckList() != null && usbModem.getUsbSignalStrengthCheckList().size()> 0) { // strengthCheck.addAttribute("type", usbModem.getUsbSignalStrengthCheckList().get(0).getType()); // strengthCheck.addElement("serial-port").addAttribute("value", usbModem.getUsbSignalStrengthCheckList().get(0).getSerialPort()); // strengthCheck.addElement("check-cmd").addAttribute("value", usbModem.getUsbSignalStrengthCheckList().get(0).getCheckCmd()); //} Element connect = modem.addElement("connect").addAttribute("type", usbModem.getConnectType()); connect.addElement("serial-port").addAttribute("value", usbModem.getSerialPort()); connect.addElement("dialstring").addAttribute("value", usbModem.getDailupNumber()); connect.addElement("apn").addAttribute("value", usbModem.getApn()); Element userAuth = connect.addElement("user-auth").addAttribute("type", usbModem.getAuthType()); if ("password".equals(usbModem.getAuthType())) { userAuth.addElement("username").addAttribute("value", usbModem.getUserId()); userAuth.addElement("password").addAttribute("value", usbModem.getPassword()); } //modem.addElement("usepeerdns").addAttribute("value", usbModem.isUsePeerDns()?"true":"false"); } return document; }
From source file:com.alibaba.citrus.springext.support.SchemaUtil.java
License:Open Source License
/** contributionsschema?schema */ public static Document createConfigurationPointSchema(ConfigurationPoint configurationPoint, String version) { Document doc = createDocument(); // <xsd:schema> Element schemaRoot = doc.addElement("xsd:schema", W3C_XML_SCHEMA_NS_URI); schemaRoot.addNamespace("xsd", W3C_XML_SCHEMA_NS_URI); schemaRoot.addNamespace("beans", BEANS_NAMESPACE_URI); schemaRoot.addNamespace("springext", SPRINGEXT_BASE_URI); schemaRoot.addNamespace("", configurationPoint.getNamespaceUri()); schemaRoot.addAttribute("targetNamespace", configurationPoint.getNamespaceUri()); // <xsd:include schemaLocation="contribution schema" /> Set<String> includings = createTreeSet(); for (Contribution contrib : configurationPoint.getContributions()) { Schema contribSchema = contrib.getSchemas().getVersionedSchema(version); if (contribSchema == null) { contribSchema = contrib.getSchemas().getMainSchema(); }/*from ww w.ja va 2s. c o m*/ if (contribSchema != null) { includings.add(contribSchema.getName()); } } for (String including : includings) { Element includeElement = schemaRoot.addElement("xsd:include"); includeElement.addAttribute("schemaLocation", including); } if (configurationPoint.getDefaultElementName() != null) { // <xsd:import namespace="http://www.springframework.org/schema/beans" // schemaLocation="http://www.springframework.org/schema/beans/spring-beans.xsd" /> Element importBeans = schemaRoot.addElement("xsd:import"); importBeans.addAttribute("namespace", BEANS_NAMESPACE_URI); importBeans.addAttribute("schemaLocation", BEANS_NAMESPACE_URI + "/spring-beans.xsd"); // <xsd:import namespace="http://www.alibaba.com/schema/springext/base" // schemaLocation="http://www.alibaba.com/schema/springext/springext-base.xsd" /> Element importSpringextBase = schemaRoot.addElement("xsd:import"); importSpringextBase.addAttribute("namespace", SPRINGEXT_BASE_URI); importSpringextBase.addAttribute("schemaLocation", SPRINGEXT_BASE_XSD); // <xsd:element name="defaultElementName" type="springext:referenceableBeanType" /> Element element = schemaRoot.addElement("xsd:element"); element.addAttribute("name", configurationPoint.getDefaultElementName()); element.addAttribute("type", "springext:referenceableBeanType"); } return doc; }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
public Element getParentElement(TreeObject treeObj) { if (!(treeObj instanceof TreeParent)) { return null; }/* www .j av a2 s . c o m*/ if (treeObj.getServerRoot() == null) { return null; } Element elemFolder = null; String xpath = getXPathForTreeObject(treeObj); if (credentials.get(UnifyUrl(treeObj.getServerRoot().getWsKey().toString())) == null) { return null; } Document doc = credentials.get(UnifyUrl(treeObj.getServerRoot().getWsKey().toString())).doc; if (doc.selectNodes(xpath).isEmpty()) { xpath = xpath.replaceAll("\\[.*\\]", "");//$NON-NLS-1$//$NON-NLS-2$ if (doc.selectNodes(xpath).isEmpty()) { xpath = getXPathForTreeObject( treeObj.getParent() != null ? treeObj.getParent() : treeObj.getServerRoot()); } if (xpath != null) { Element elemTop = null; if (doc.selectNodes(xpath).isEmpty()) { elemTop = getTopElementWithUser(treeObj.getServerRoot().getUser().getUsername(), UnifyUrl(treeObj.getServerRoot().getWsKey().toString())); } else { // process and trigger is in special, as they are located in EventManagement which is in the same // level as data container and data model if (treeObj.getType() == TreeObject.TRANSFORMER && treeObj.getParent() == null) { xpath += "/EventManagement[text() = '33']";//$NON-NLS-1$ } elemTop = (Element) doc.selectNodes(xpath).get(0); } String selPath = "./" + filterOutBlank(treeObj.getDisplayName()) + "[text() = '" + treeObj.getType() //$NON-NLS-1$//$NON-NLS-2$ + "']";//$NON-NLS-1$ if (elemTop.selectNodes(selPath).isEmpty()) { elemFolder = elemTop.addElement(filterOutBlank(treeObj.getDisplayName())); elemFolder.setText(treeObj.getType() + "");//$NON-NLS-1$ } else { elemFolder = (Element) elemTop.selectNodes(selPath).get(0); } } } else { elemFolder = (Element) doc.selectNodes(xpath).get(0); } return elemFolder; }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private void addChild(TreeObject parent, TreeObject child) { if (parent.getParent() == null && parent.getDisplayName().equals("INVISIBLE ROOT")) { return;// www .ja v a 2 s . co m } if (parent.getServerRoot() == null) { return; } String xpath = getXPathForTreeObject(child); Document doc = credentials.get(UnifyUrl(parent.getServerRoot().getWsKey().toString())).doc; List<Element> models = doc.selectNodes(xpath); if (!models.isEmpty() && child instanceof TreeParent) { Element model = models.get(0); if (isAEXtentisObjects(model, child) == MODEL_LEVEL) { checkUpAllCategoryForModel((TreeParent) child); } } String catalog = synchronizeWithElem(child, (TreeParent) parent, true); Element elemFolder = getParentElement(parent); if (elemFolder != null) { String xpathTail = "";//$NON-NLS-1$ String xpathTailOther = "']";//$NON-NLS-1$ xpath = "child::*[name()='" + filterOutBlank(child.getDisplayName()) + "' and text()='" //$NON-NLS-1$//$NON-NLS-2$ + child.getType(); if (child.getType() == TreeObject.CATEGORY_FOLDER) { xpathTail = "' and @Url='" + getURLFromTreeObject(child);//$NON-NLS-1$ } List<Element> list = elemFolder.selectNodes(xpath + xpathTail + xpathTailOther); if (list.isEmpty() && (catalog.equals("") || catalog == null)) {//$NON-NLS-1$ Element childElem = elemFolder.addElement(filterOutBlank(child.getDisplayName())); childElem.setText(child.getType() + "");//$NON-NLS-1$ if (child.getType() == TreeObject.CATEGORY_FOLDER) { childElem.addAttribute(URL, getURLFromTreeObject(child)); childElem.addAttribute(REALNAME, child.getDisplayName()); } } } saveDocument(parent); }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private String synchronizeWithElem(TreeObject theObj, TreeParent folder, boolean fireEvent) { internalCheck = fireEvent;//from w ww . j ava2 s . co m String catalogPath = "";//$NON-NLS-1$ ArrayList<String> catalogs = checkUpCatalogRepositoryForTreeObject(theObj, folder); if (catalogs != null && folder.getType() != TreeObject.CATEGORY_FOLDER) { // create a catalog folder and insert the theObj into it TreeParent subFolder = folder; TreeParent category = null; for (String catalogName : catalogs) { // if (catalogName.equals(filterOutBlank(folder.getDisplayName()))) // continue; category = null; for (TreeObject child : subFolder.getChildren()) { if (child.getDisplayName().equals(catalogName) && child.getType() == TreeObject.CATEGORY_FOLDER && child instanceof TreeParent) { category = (TreeParent) child; subFolder = category; break; } } if (category == null) { category = new TreeParent(catalogName, folder.getServerRoot(), TreeObject.CATEGORY_FOLDER, null, null); subFolder.addChild(category); category.setServerRoot(folder.getServerRoot()); addAttributeToCategoryElem(category, URL, getURLFromTreeObject(folder)); saveDocument(folder); subFolder = category; } } boolean exist = false; for (TreeObject obj : category.getChildren()) { if (obj.getDisplayName().equals(theObj.getDisplayName()) && obj.getType() == theObj.getType()) { exist = true; break; } } if (!exist) { folder.removeChild(theObj); category.addChild(theObj); } catalogPath = catalogs.isEmpty() ? "" : catalogs.get(0);//$NON-NLS-1$ } else { // check up the system catalog, create it and all system tree objects // into it if these objects are not categorized if (XSystemObjects.isExist(theObj.getType(), theObj.getDisplayName())) { TreeParent systemCatalog = null; for (TreeObject xobj : folder.getChildren()) { if (DEFAULT_CATALOG.equals(filterOutBlank(xobj.getDisplayName())) && xobj.getType() == TreeObject.CATEGORY_FOLDER) { systemCatalog = (TreeParent) xobj; break; } } if (folder.getDisplayName().equals("System") && folder.getType() == TreeObject.CATEGORY_FOLDER) { return DEFAULT_CATALOG; } if (theObj.getParent() == null) { internalCheck = !fireEvent; return DEFAULT_CATALOG; } if (theObj.getServerRoot() != null) { String xpath = "//" + theObj.getServerRoot().getUser().getUsername() + "/"//$NON-NLS-1$//$NON-NLS-2$ + filterOutBlank(folder.getDisplayName()) + "//child::*[name() = 'System'"//$NON-NLS-1$ + " and @Url='" + getURLFromTreeObject(theObj) + "']";//$NON-NLS-1$//$NON-NLS-2$ Document doc = credentials.get(UnifyUrl(folder.getServerRoot().getWsKey().toString())).doc; if (systemCatalog == null) { List<Element> elems = doc.selectNodes(xpath); if (elems.isEmpty()) { systemCatalog = new TreeParent(DEFAULT_CATALOG, folder.getServerRoot(), TreeObject.CATEGORY_FOLDER, null, null); folder.addChild(systemCatalog); folder.removeChild(theObj); systemCatalog.addChild(theObj); systemCatalog.setServerRoot(folder.getServerRoot()); Element elemFolder = getParentElement(folder); Element elemSystem = elemFolder.addElement(systemCatalog.getDisplayName()); elemSystem.setText(TreeObject.CATEGORY_FOLDER + "");//$NON-NLS-1$ elemSystem.addAttribute(URL, getURLFromTreeObject(folder)); Element childElem = elemSystem.addElement(filterOutBlank(theObj.getDisplayName())); childElem.setText(theObj.getType() + "");//$NON-NLS-1$ saveDocument(folder); } } else { boolean exist = false; for (TreeObject xbj : systemCatalog.getChildren()) { if (xbj.getDisplayName().equals(theObj.getDisplayName()) && xbj.getType() == theObj.getType()) { exist = true; break; } } if (!exist) { folder.removeChild(theObj); systemCatalog.addChild(theObj); List<Element> elems = doc.selectNodes(xpath); if (!elems.isEmpty()) { elems.get(0).addElement(filterOutBlank(theObj.getDisplayName())) .setText(theObj.getType() + "");//$NON-NLS-1$ saveDocument(folder); } } } } catalogPath = DEFAULT_CATALOG; } } // check up the catalog with none children checkUpCatalogHavingNoChildren(theObj, folder); if (theObj instanceof TreeParent) { TreeParent subParent = (TreeParent) theObj; for (TreeObject obj : subParent.getChildren()) { synchronizeWithElem(obj, subParent, fireEvent); } } internalCheck = !fireEvent; return catalogPath; }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private void createCategoryForOrgDoc(String categoryToCreate, Element srcElem, Element tgtElem, TreeParent serverRoot) {/*ww w .java2 s.c om*/ String[] xpathSnippetsToCreate = categoryToCreate.split("/");//$NON-NLS-1$ int categoryBeginPos = 3; if (xpathSnippetsToCreate[3].equals("EventManagement")) {//$NON-NLS-1$ categoryBeginPos = 4; } int pos = categoryToCreate.indexOf("/" + xpathSnippetsToCreate[categoryBeginPos]);//$NON-NLS-1$ String categoryXpath = categoryToCreate.substring(0, pos + xpathSnippetsToCreate[categoryBeginPos].length() + 1); Element subParentElem = pingElement(categoryXpath, tgtElem); for (int i = categoryBeginPos + 1; i < xpathSnippetsToCreate.length; i++) { String categoryXpathSnippet = "child::" + xpathSnippetsToCreate[i] + "[text()='" //$NON-NLS-1$//$NON-NLS-2$ + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$ Element newCategory = pingElement(categoryXpathSnippet, subParentElem); if (newCategory == null) { Element existedCategory = pingElement(categoryXpath + "/" + categoryXpathSnippet, srcElem);//$NON-NLS-1$ newCategory = subParentElem.addElement(xpathSnippetsToCreate[i]); newCategory.setText(TreeObject.CATEGORY_FOLDER + "");//$NON-NLS-1$ newCategory.addAttribute(URL, getURLFromTreeObject(serverRoot)); newCategory.addAttribute(REALNAME, existedCategory.attributeValue(REALNAME)); } categoryXpath += "/" + xpathSnippetsToCreate[i];//$NON-NLS-1$ subParentElem = newCategory; } transferElementsWithCategoryPath(categoryToCreate, srcElem, tgtElem); }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private void transferElementsWithCategoryPath(String categoryXpath, Element srcElemRoot, Element targtElemRoot) {/*w ww. j a v a 2 s .co m*/ categoryXpath += "[text()='" + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$//$NON-NLS-2$ // clear up the context of targtElemRoot firstly Element elemCategoryInTagt = pingElement(categoryXpath, targtElemRoot); List elems = elemCategoryInTagt.content(); List xobjects = new ArrayList(); for (Object obj : elems) { if (obj instanceof Element) { Element elem = (Element) obj; if (!elem.getTextTrim().equals(TreeObject.CATEGORY_FOLDER + "")) {//$NON-NLS-1$ Element division = drillUpForDevisionElement(elem); division.addElement(elem.getName()).setText(elem.getTextTrim()); xobjects.add(elem); } } } elemCategoryInTagt.content().removeAll(xobjects); Element elemCategoryInSrc = pingElement(categoryXpath, srcElemRoot); elems = elemCategoryInSrc.content(); for (Object obj : elems) { if (obj instanceof Element) { Element elem = (Element) obj; if (!elem.getTextTrim().equals(TreeObject.CATEGORY_FOLDER + "")) {//$NON-NLS-1$ String xpath = ".//descendant::" + elem.getName() + "[text()='" + elem.getTextTrim() + "']";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ List<Element> es = targtElemRoot.selectNodes(xpath); Element newElem = null; for (Element elemExist : es) { if (elemExist.getParent() != null && elemExist.getParent().getTextTrim().equals(TreeObject.EVENT_MANAGEMENT + "")) { continue; } if (elemExist != null) { Element parentExist = elemExist.getParent(); parentExist.remove(elemExist); } elemExist = pingElement(categoryXpath, targtElemRoot); newElem = elemExist.addElement(elem.getName()); newElem.setText(elem.getTextTrim()); } if (es.size() == 0 || (es.size() > 0 && newElem == null)) { Element elemExist = pingElement(categoryXpath, targtElemRoot); newElem = elemExist.addElement(elem.getName()); newElem.setText(elem.getTextTrim()); } } } } }
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 . jav a2s .c o m 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()); } }