Example usage for org.dom4j Document getRootElement

List of usage examples for org.dom4j Document getRootElement

Introduction

In this page you can find the example usage for org.dom4j Document getRootElement.

Prototype

Element getRootElement();

Source Link

Document

Returns the root Element for this document.

Usage

From source file:com.alibaba.citrus.springext.support.SchemaUtil.java

License:Open Source License

/** ?URI? */
public static Transformer getAddPrefixTransformer(final SchemaSet schemas, String prefix) {
    if (prefix != null) {
        if (!prefix.endsWith("/")) {
            prefix += "/";
        }//from   ww  w .j  a v  a  2s .  c om
    }

    final String normalizedPrefix = prefix;

    return new Transformer() {
        public void transform(Document document, String systemId) {
            if (normalizedPrefix != null) {
                Element root = document.getRootElement();

                // <xsd:schema>
                if (W3C_XML_SCHEMA_NS_URI.equals(root.getNamespaceURI()) && "schema".equals(root.getName())) {
                    Namespace xsd = DocumentHelper.createNamespace("xsd", W3C_XML_SCHEMA_NS_URI);
                    QName includeName = DocumentHelper.createQName("include", xsd);
                    QName importName = DocumentHelper.createQName("import", xsd);

                    // for each <xsd:include>
                    for (Iterator<?> i = root.elementIterator(includeName); i.hasNext();) {
                        Element includeElement = (Element) i.next();
                        String schemaLocation = trimToNull(includeElement.attributeValue("schemaLocation"));

                        if (schemaLocation != null) {
                            schemaLocation = getNewSchemaLocation(schemaLocation, null, systemId);

                            if (schemaLocation != null) {
                                includeElement.addAttribute("schemaLocation", schemaLocation);
                            }
                        }
                    }

                    // for each <xsd:import>
                    for (Iterator<?> i = root.elementIterator(importName); i.hasNext();) {
                        Element importElement = (Element) i.next();
                        String schemaLocation = importElement.attributeValue("schemaLocation");
                        String namespace = trimToNull(importElement.attributeValue("namespace"));

                        if (schemaLocation != null || namespace != null) {
                            schemaLocation = getNewSchemaLocation(schemaLocation, namespace, systemId);

                            if (schemaLocation != null) {
                                importElement.addAttribute("schemaLocation", schemaLocation);
                            }
                        }
                    }
                }
            }
        }

        private String getNewSchemaLocation(String schemaLocation, String namespace, String systemId) {
            // ?schemaLocation
            if (schemaLocation != null) {
                Schema schema = schemas.findSchema(schemaLocation);

                if (schema != null) {
                    return normalizedPrefix + schema.getName();
                } else {
                    return schemaLocation; // location??
                }
            }

            // ??namespace
            if (namespace != null) {
                Set<Schema> nsSchemas = schemas.getNamespaceMappings().get(namespace);

                if (nsSchemas != null && !nsSchemas.isEmpty()) {
                    // ?nsschema?schema
                    String versionedExtension = getVersionedExtension(systemId);

                    if (versionedExtension != null) {
                        for (Schema schema : nsSchemas) {
                            if (schema.getName().endsWith(versionedExtension)) {
                                return normalizedPrefix + schema.getName();
                            }
                        }
                    }

                    // schema?beans.xsd?beans-2.5.xsd?beans-2.0.xsd
                    return normalizedPrefix + nsSchemas.iterator().next().getName();
                }
            }

            return null;
        }

        /** spring-aop-2.5.xsd?-2.5.xsd */
        private String getVersionedExtension(String systemId) {
            if (systemId != null) {
                int dashIndex = systemId.lastIndexOf("-");
                int slashIndex = systemId.lastIndexOf("/");

                if (dashIndex > slashIndex) {
                    return systemId.substring(dashIndex);
                }
            }

            return null;
        }
    };
}

From source file:com.alibaba.citrus.springext.support.SchemaUtil.java

License:Open Source License

/** element/attribute??namespace */
public static Transformer getUnqualifiedStyleTransformer(ResourceResolver resourceResolver) {
    if (isUnqualifiedStyle(resourceResolver)) {
        return new Transformer() {
            public void transform(Document document, String systemId) {
                Element root = document.getRootElement();

                if (root.attribute("elementFormDefault") != null) {
                    root.remove(root.attribute("elementFormDefault"));
                }/*from ww  w  .  ja v  a  2 s. c o m*/

                if (root.attribute("attributeFormDefault") != null) {
                    root.remove(root.attribute("attributeFormDefault"));
                }
            }
        };
    } else {
        return getNoopTransformer();
    }
}

From source file:com.alibaba.citrus.springext.util.ConvertToUnqualifiedStyle.java

License:Open Source License

/** Root element?<code>&lt;beans:bean&gt;</code> */
private boolean isSpringConfigurationFile(Document doc) {
    Element root = doc.getRootElement();
    return "http://www.springframework.org/schema/beans".equals(root.getNamespaceURI())
            && "beans".equals(root.getName());
}

From source file:com.aliyun.odps.ogg.handler.datahub.ConfigureReader.java

License:Apache License

public static Configure reader(String configueFileName) throws DocumentException {
    logger.info("Begin read configure[" + configueFileName + "]");

    Configure configure = new Configure();
    SAXReader reader = new SAXReader();
    File file = new File(configueFileName);

    Document document = reader.read(file);
    Element root = document.getRootElement();

    String elementText = root.elementTextTrim("batchSize");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setBatchSize(Integer.parseInt(elementText));
    }/* www  . ja v a2 s  .  c  o m*/

    elementText = root.elementTextTrim("dirtyDataContinue");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setDirtyDataContinue(Boolean.parseBoolean(elementText));
    }

    elementText = root.elementTextTrim("dirtyDataFile");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setDirtyDataFile(elementText);
    }

    elementText = root.elementTextTrim("dirtyDataFileMaxSize");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setDirtyDataFileMaxSize(Integer.parseInt(elementText));
    }

    elementText = root.elementTextTrim("retryTimes");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setRetryTimes(Integer.parseInt(elementText));
    }

    elementText = root.elementTextTrim("retryInterval");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setRetryInterval(Integer.parseInt(elementText));
    }

    elementText = root.elementTextTrim("disableCheckPointFile");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setDisableCheckPointFile(Boolean.parseBoolean(elementText));
    }

    elementText = root.elementTextTrim("checkPointFileName");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setCheckPointFileName(elementText);
    }

    Element element = root.element("defaultOracleConfigure");
    if (element == null) {
        throw new RuntimeException("defaultOracleConfigure is null");
    }

    elementText = element.elementTextTrim("sid");
    if (StringUtils.isBlank(elementText)) {
        throw new RuntimeException("defaultOracleConfigure.sid is null");
    }
    configure.setSid(elementText);

    String defaultOracleSchema = element.elementTextTrim("schema");

    SimpleDateFormat defaultSimpleDateFormat;
    elementText = element.elementTextTrim("dateFormat");
    if (StringUtils.isNotBlank(elementText)) {
        defaultSimpleDateFormat = new SimpleDateFormat(elementText);
    } else {
        defaultSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }

    element = root.element("defalutDatahubConfigure");
    if (element == null) {
        throw new RuntimeException("defalutDatahubConfigure is null");
    }

    String endPoint = element.elementText("endPoint");
    if (StringUtils.isBlank(endPoint)) {
        throw new RuntimeException("defalutDatahubConfigure.endPoint is null");

    }

    String defaultDatahubProject = element.elementText("project");
    String defaultDatahubAccessID = element.elementText("accessId");
    String defaultDatahubAccessKey = element.elementText("accessKey");

    Field defaultCTypeField = null;
    String defaultCTypeColumn = element.elementText("ctypeColumn");
    if (StringUtils.isNotBlank(defaultCTypeColumn)) {
        defaultCTypeField = new Field(defaultCTypeColumn, FieldType.STRING);
    }
    Field defaultCTimeField = null;
    String defaultCTimeColumn = element.elementText("ctimeColumn");
    if (StringUtils.isNotBlank(defaultCTimeColumn)) {
        defaultCTimeField = new Field(defaultCTimeColumn, FieldType.STRING);
    }
    Field defaultCidField = null;
    String defaultCidColumn = element.elementText("cidColumn");
    if (StringUtils.isNotBlank(defaultCidColumn)) {
        defaultCidField = new Field(defaultCidColumn, FieldType.STRING);
    }

    String defaultConstColumnMapStr = element.elementText("constColumnMap");
    Map<String, String> defalutConstColumnMappings = Maps.newHashMap();
    Map<String, Field> defaultConstColumnFieldMappings = Maps.newHashMap();
    parseConstColumnMap(defaultConstColumnMapStr, defalutConstColumnMappings, defaultConstColumnFieldMappings);

    element = root.element("mappings");
    if (element == null) {
        throw new RuntimeException("mappings is null");
    }

    List<Element> mappingElements = element.elements("mapping");
    if (mappingElements == null || mappingElements.size() == 0) {
        throw new RuntimeException("mappings.mapping is null");
    }

    //init table mapping
    for (Element e : mappingElements) {
        String oracleSchema = e.elementTextTrim("oracleSchema");
        if (StringUtils.isNotBlank(oracleSchema)) {
            //nothing
        } else if (StringUtils.isNotBlank(defaultOracleSchema)) {
            oracleSchema = defaultOracleSchema;
        } else {
            throw new RuntimeException(
                    "both mappings.mapping.oracleSchema and defaultOracleConfigure.schema is null");
        }

        String oracleTable = e.elementTextTrim("oracleTable");
        if (StringUtils.isBlank(oracleTable)) {
            throw new RuntimeException("mappings.mapping.oracleTable is null");
        }

        String datahubProject = e.elementTextTrim("datahubProject");
        if (StringUtils.isNotBlank(datahubProject)) {
            //nothing
        } else if (StringUtils.isNotBlank(defaultOracleSchema)) {
            datahubProject = defaultDatahubProject;
        } else {
            throw new RuntimeException(
                    "both mappings.mapping.datahubProject and defalutDatahubConfigure.project is null");
        }

        String datahubAccessId = e.elementTextTrim("datahubAccessId");
        if (StringUtils.isNotBlank(datahubAccessId)) {
            //nothing
        } else if (StringUtils.isNotBlank(defaultDatahubAccessID)) {
            datahubAccessId = defaultDatahubAccessID;
        } else {
            throw new RuntimeException(
                    "both mappings.mapping.datahubAccessId and defalutDatahubConfigure.accessId is null");
        }

        String datahubAccessKey = e.elementTextTrim("datahubAccessKey");
        if (StringUtils.isNotBlank(datahubAccessKey)) {
            //nothing
        } else if (StringUtils.isNotBlank(defaultDatahubAccessKey)) {
            datahubAccessKey = defaultDatahubAccessKey;
        } else {
            throw new RuntimeException(
                    "both mappings.mapping.datahubAccessKey and defalutDatahubConfigure.accessKey is null");
        }

        String topicName = e.elementTextTrim("datahubTopic");
        if (topicName == null) {
            throw new RuntimeException("mappings.mapping.datahubTopic is null");
        }

        String ctypeColumn = e.elementText("ctypeColumn");
        String ctimeColumn = e.elementText("ctimeColumn");
        String cidColumn = e.elementText("cidColumn");

        DatahubConfiguration datahubConfiguration = new DatahubConfiguration(
                new AliyunAccount(datahubAccessId, datahubAccessKey), endPoint);
        Project project = Project.Builder.build(datahubProject, datahubConfiguration);
        Topic topic = project.getTopic(topicName);
        if (topic == null) {
            throw new RuntimeException("Can not find datahub topic[" + topicName + "]");
        } else {
            logger.info(
                    "topic name: " + topicName + ", topic schema: " + topic.getRecordSchema().toJsonString());
        }

        TableMapping tableMapping = new TableMapping();
        tableMapping.setTopic(topic);
        tableMapping.setOracleSchema(oracleSchema.toLowerCase());
        tableMapping.setOracleTableName(oracleTable.toLowerCase());
        tableMapping.setOracleFullTableName(
                tableMapping.getOracleSchema() + "." + tableMapping.getOracleTableName());
        tableMapping
                .setCtypeField(StringUtils.isNotBlank(ctypeColumn) ? new Field(ctypeColumn, FieldType.STRING)
                        : defaultCTypeField);
        tableMapping
                .setCtimeField(StringUtils.isNotBlank(ctimeColumn) ? new Field(ctimeColumn, FieldType.STRING)
                        : defaultCTimeField);
        tableMapping.setCidField(
                StringUtils.isNotBlank(cidColumn) ? new Field(cidColumn, FieldType.STRING) : defaultCidField);

        String constColumnMapStr = e.elementText("constColumnMap");
        Map<String, String> constColumnMappings = Maps.newHashMap();
        Map<String, Field> constColumnFieldMappings = Maps.newHashMap();
        parseConstColumnMap(constColumnMapStr, constColumnMappings, constColumnFieldMappings);

        tableMapping.setConstColumnMappings(
                constColumnMappings.isEmpty() ? defalutConstColumnMappings : constColumnMappings);
        tableMapping.setConstFieldMappings(constColumnFieldMappings.isEmpty() ? defaultConstColumnFieldMappings
                : constColumnFieldMappings);

        Map<String, ColumnMapping> columnMappings = Maps.newHashMap();
        tableMapping.setColumnMappings(columnMappings);

        elementText = e.elementTextTrim("shardId");
        if (StringUtils.isNotBlank(elementText)) {
            tableMapping.setShardId(elementText);
        }

        configure.addTableMapping(tableMapping);

        RecordSchema recordSchema = topic.getRecordSchema();

        Element columnMappingElement = e.element("columnMapping");
        List<Element> columns = columnMappingElement.elements("column");
        for (Element columnElement : columns) {
            String oracleColumnName = columnElement.attributeValue("src");
            if (StringUtils.isBlank(oracleColumnName)) {
                throw new RuntimeException("Topic[" + topicName + "] src attribute is null");
            }

            oracleColumnName = oracleColumnName.toLowerCase();
            ColumnMapping columnMapping = new ColumnMapping();
            columnMappings.put(oracleColumnName, columnMapping);
            columnMapping.setOracleColumnName(oracleColumnName);

            String datahubFieldName = columnElement.attributeValue("dest");
            if (datahubFieldName == null) {
                throw new RuntimeException("Topic[" + topicName + "] dest attribute is null");
            }

            Field field = recordSchema.getField(datahubFieldName.toLowerCase());
            if (field == null) {
                throw new RuntimeException(
                        "Topic[" + topicName + "] Field[" + datahubFieldName + "] is not exist");
            }

            columnMapping.setField(field);

            String datahubOldFieldName = columnElement.attributeValue("destOld");
            if (StringUtils.isNotBlank(datahubOldFieldName)) {
                Field oldField = recordSchema.getField(datahubOldFieldName);

                if (field == null) {
                    throw new RuntimeException(
                            "Topic[" + topicName + "] Field[" + datahubOldFieldName + "] is not exist");
                }
                columnMapping.setOldFiled(oldField);
            }

            String isShardColumn = columnElement.attributeValue("isShardColumn");
            if (StringUtils.isNotBlank(isShardColumn) && Boolean.TRUE.equals(Boolean.valueOf(isShardColumn))) {
                tableMapping.setIsShardHash(true);
                columnMapping.setIsShardColumn(true);
            } else {
                columnMapping.setIsShardColumn(false);
            }

            String isKeyColumn = columnElement.attributeValue("isKeyColumn");
            if (StringUtils.isNotBlank(isKeyColumn) && Boolean.TRUE.equals(Boolean.valueOf(isKeyColumn))) {
                columnMapping.setIsKeyColumn(true);
            } else {
                columnMapping.setIsKeyColumn(false);
            }

            String dateFormat = columnElement.attributeValue("dateFormat");

            if (StringUtils.isNotBlank(dateFormat)) {
                columnMapping.setSimpleDateFormat(new SimpleDateFormat(dateFormat));
            } else {
                columnMapping.setSimpleDateFormat(defaultSimpleDateFormat);
            }

            String isDateFormat = columnElement.attributeValue("isDateFormat");

            if (StringUtils.isNotBlank(isDateFormat) && Boolean.FALSE.equals(Boolean.valueOf(isDateFormat))) {
                columnMapping.setIsDateFormat(false);
            } else {
                columnMapping.setIsDateFormat(true);
            }
        }
    }

    logger.info("Read configure success: " + JsonHelper.beanToJson(configure));
    return configure;
}

From source file:com.allinfinance.common.grid.GridConfigUtil.java

License:Open Source License

/**
 * ??//from  ww  w  .ja v a2 s .  c o m
 * @param context
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public static void initGirdConfig(ServletContext context) throws Exception {
    SAXReader reader = new SAXReader();

    Document document = null;
    document = reader.read(context.getResourceAsStream(Constants.GRID_CONFIG_CONTEXTPATH));

    Element root = document.getRootElement();

    List<Element> gridInfoList = root.elements(GridConfigConstants.NODE_GRID);

    for (Element gridNode : gridInfoList) {
        String gridId = gridNode.attributeValue(GridConfigConstants.GRID_ID);
        String gridConfigType = gridNode.attributeValue(GridConfigConstants.GRID_TYPE);

        //?
        GridModel gridModel = new GridModel();
        gridModel.setId(gridId);
        gridModel.setType(gridConfigType);
        gridModel.setColumns(gridNode.elementText(GridConfigConstants.COLUMNS).trim());

        if (GridConfigConstants.TYPE_SQL.equals(gridConfigType)) {

            SqlMode sqlMode = new SqlMode();
            //SQL?
            Element sqlModeNode = gridNode.element(GridConfigConstants.TYPE_SQLMODE);
            //?
            Element wheresNode = sqlModeNode.element(GridConfigConstants.WHERES);

            List<Element> whereList = wheresNode.elements(GridConfigConstants.WHERE);

            sqlMode.setSql(sqlModeNode.elementText(GridConfigConstants.SQL).trim());
            sqlMode.setDao(sqlModeNode.elementText(GridConfigConstants.QUERY_DAO).trim());

            //?
            if (whereList != null && whereList.size() > 0) {
                WheresModel wheresModel = new WheresModel();
                List<WhereModel> whereModelList = new ArrayList<WhereModel>();
                for (Element whereNode : whereList) {
                    WhereModel whereModel = new WhereModel();
                    whereModel.setType(whereNode.attributeValue(GridConfigConstants.WHERE_TYPE));
                    whereModel.setOperator(whereNode.attributeValue(GridConfigConstants.WHERE_OPERATOR));
                    whereModel.setLogic(whereNode.attributeValue(GridConfigConstants.WHERE_LOGIC));
                    whereModel.setDataBaseColumn(
                            whereNode.elementText(GridConfigConstants.WHERE_DATABASE_COLUMN).trim());
                    whereModel.setQueryColumn(
                            whereNode.elementText(GridConfigConstants.WHERE_QUERY_COLUMN).trim());
                    whereModelList.add(whereModel);
                }
                wheresModel.setWhereModelList(whereModelList);
                sqlMode.setWheresModel(wheresModel);
            }

            // ???
            if (sqlModeNode.element(GridConfigConstants.ORDERS) != null) {
                OrdersModel ordersModel = new OrdersModel();
                Element orderModels = sqlModeNode.element(GridConfigConstants.ORDERS);
                ordersModel.setSort(orderModels.attributeValue("sort"));
                List<Element> orderList = orderModels.elements(GridConfigConstants.ORDER);
                for (Element element : orderList) {
                    ordersModel.getOrders().add(element.getText());
                }
                sqlMode.setOrdersModel(ordersModel);
            }

            gridModel.setSqlMode(sqlMode);
        } else if (GridConfigConstants.TYPE_SYNC.equals(gridConfigType)) {

            SyncMode syncMode = new SyncMode();

            Element syncModeNode = gridNode.element(GridConfigConstants.TYPE_SYNCMODE);

            Element methodNode = syncModeNode.element(GridConfigConstants.SYNC_METHOD);

            syncMode.setMethod(methodNode.attributeValue(GridConfigConstants.SYNC_METHOD_VALUE));

            gridModel.setSyncMode(syncMode);
        } else {
            throw new Exception("???[ id:" + gridId + " ]");
        }

        gridConfigMap.put(gridId, gridModel);
    }
}

From source file:com.amalto.workbench.export.ImportItemsWizard.java

License:Open Source License

private boolean isV2Transformer(String inputPath) throws DocumentException, FileNotFoundException {

    boolean isV2Transformer = false;
    Document document = XmlUtil.parse(new FileInputStream(inputPath));
    if (document != null && document.getRootElement() != null) {
        String rootElementName = document.getRootElement().getName();
        if (rootElementName.equals(WSTransformerV2.class.getSimpleName())) {
            isV2Transformer = true;
        }//from  w w  w. j  a v  a  2  s .co  m
    }
    return isV2Transformer;
}

From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java

License:Open Source License

private Element getTopElementWithUser(String user, String ip) {
    Document doc = credentials.get(ip).doc;
    List<Element> userRoots = doc.selectNodes(rootPath + "/" + user);//$NON-NLS-1$
    Element elementUser;/*from www.j  a va  2 s .  c o  m*/
    if (userRoots.isEmpty()) {
        elementUser = doc.getRootElement().addElement(user);
        elementUser.setText("0");//$NON-NLS-1$
    } else {
        elementUser = userRoots.get(0);
    }

    return elementUser;
}

From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java

License:Open Source License

private int isAEXtentisObjects(Element elemXobj, TreeObject treeObj) {
    if (elemXobj == null || treeObj.getServerRoot() == null) {
        return 0;
    }// w  w w  .j  a v a 2 s  .  co  m
    Document doc = credentials.get(UnifyUrl(treeObj.getServerRoot().getWsKey().toString())).doc;
    if (elemXobj == doc.getRootElement()) {
        return 1;
    }

    return 1 + isAEXtentisObjects(elemXobj.getParent(), treeObj);
}

From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java

License:Open Source License

private Element parseElements(String schema) {
    SAXReader saxReader = new SAXReader();
    try {// w  ww .j a  v a  2  s .c o  m
        Document doc = saxReader.read(new StringReader(schema));
        return doc.getRootElement();
    } catch (DocumentException e) {
        log.error(e.getMessage(), e);
    }

    return null;
}

From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java

License:Open Source License

private void mergeImportCategory(String[] schemas, TreeParent serverRoot, ArrayList<String> xpathsToDel) {
    if (serverRoot.getServerRoot() == null) {
        return;//w  ww .  j  a  va2  s  .com
    }
    Document orgDoc = spareDoc;
    String user = serverRoot.getServerRoot().getUser().getUsername();
    String xpathPrefix = "/category/" + user;//$NON-NLS-1$
    String xmlPrefix = "<category><" + user + ">*</" + user + "></category>";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
    if (schemas == null) // old version, skip the import
    {
        credentials.get(UnifyUrl(serverRoot.getServerRoot().getWsKey().toString())).doc = orgDoc;
        return;
    }
    for (String schema : schemas) {
        Element root = parseElements(xmlPrefix.replace("*", schema));//$NON-NLS-1$
        Element subRoot = parseElements(schema);

        // delete all unselected xobjects from orgDoc
        for (String xpathToDel : xpathsToDel) {
            Element elemToDel = pingElement(xpathToDel, root);
            if (elemToDel != null) {
                Element parent = elemToDel.getParent();
                if (parent != null) {
                    parent.remove(elemToDel);
                }
            }
        }
        // check out all categories having none child, and delete them if available
        String xpathForCategoriesWithNoneChild = "//child::*[count(child::*) = 0 and text()='" //$NON-NLS-1$
                + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$
        Element categoryToDel = pingElement(xpathForCategoriesWithNoneChild, root);
        while (categoryToDel != null) {
            Element categoryParent = categoryToDel.getParent();
            if (categoryParent != null) {
                categoryParent.remove(categoryToDel);
            }
            categoryToDel = pingElement(xpathForCategoriesWithNoneChild, root);
        }

        subRoot = this.pingElement(xpathPrefix + "/" + subRoot.getName(), root);//$NON-NLS-1$
        String xpathForCategory = "//descendant::*[text()='" + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$//$NON-NLS-2$
        List<Element> elementList = subRoot.selectNodes(xpathForCategory);
        List<String> categoryXpathForCurDoc = new ArrayList<String>();
        List<String> categoryXpathForOrgDoc = new ArrayList<String>();

        for (Element element : elementList) {
            List<String> categoryHierarchicals = parseXpathForElement(element, subRoot);
            String xpathForOrgCategory = xpathPrefix + "/" + subRoot.getName();//$NON-NLS-1$
            for (String categoryHierarchical : categoryHierarchicals) {
                xpathForOrgCategory += "/" + categoryHierarchical;//$NON-NLS-1$
            }
            if (!categoryXpathForOrgDoc.contains(xpathForOrgCategory)) {
                categoryXpathForOrgDoc.add(xpathForOrgCategory);
            }
        }
        xpathForCategory = xpathPrefix + "/" + subRoot.getName() + "//descendant::*[text()='" //$NON-NLS-1$//$NON-NLS-2$
                + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$
        // String xpathForOrgCategory = xpathPrefix + "/" + subRoot.getName() + "//descendant::" + element.getName()
        // + "[text()='" + element.getTextTrim() + "']";
        String topElemXpath = xpathPrefix + "/" + subRoot.getName();//$NON-NLS-1$
        Element topElem = pingElement(topElemXpath, orgDoc.getRootElement());
        elementList = orgDoc.getRootElement().selectNodes(xpathForCategory);
        for (Element elem : elementList) {
            List<String> categoryHierarchicals = parseXpathForElement(elem, topElem);
            String xpathForOrgCategory = xpathPrefix + "/" + subRoot.getName();//$NON-NLS-1$
            for (String categoryHierarchical : categoryHierarchicals) {
                xpathForOrgCategory += "/" + categoryHierarchical;//$NON-NLS-1$
            }
            if (!categoryXpathForCurDoc.contains(xpathForOrgCategory)) {
                categoryXpathForCurDoc.add(xpathForOrgCategory);
            }
        }

        for (String categoryHierarchical : categoryXpathForOrgDoc) {
            createOrReplaceCategory(categoryHierarchical, categoryXpathForCurDoc, root, orgDoc.getRootElement(),
                    serverRoot);
        }
    }
    // success
    credentials.get(UnifyUrl(serverRoot.getServerRoot().getWsKey().toString())).doc = orgDoc;
}