Search in sources :

Example 71 with Document

use of org.dom4j.Document in project Openfire by igniterealtime.

the class PresenceManagerImpl method getLastPresenceStatus.

@Override
public String getLastPresenceStatus(User user) {
    String username = user.getUsername();
    String presenceStatus = null;
    String presenceXML = offlinePresenceCache.get(username);
    if (presenceXML == null) {
        loadOfflinePresence(username);
    }
    presenceXML = offlinePresenceCache.get(username);
    if (presenceXML != null) {
        // If the cached answer is no data, return null.
        if (presenceXML.equals(NULL_STRING)) {
            return null;
        }
        // Otherwise, parse out the status from the XML.
        try {
            // Parse the element
            Document element = DocumentHelper.parseText(presenceXML);
            presenceStatus = element.getRootElement().elementTextTrim("status");
        } catch (DocumentException e) {
            Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
        }
    }
    return presenceStatus;
}
Also used : DocumentException(org.dom4j.DocumentException) Document(org.dom4j.Document)

Example 72 with Document

use of org.dom4j.Document in project atlas by alibaba.

the class ManifestFileUtils method updatePreProcessManifestFile.

/**
     * 更新libManifest文件
     *
     * @param libManifestFile
     * @param mainManifestFileObject param updateSdkVersion
     */
public static void updatePreProcessManifestFile(File libManifestFile, ManifestFileObject mainManifestFileObject, boolean updateSdkVersion) throws IOException, DocumentException {
    if (!libManifestFile.exists()) {
        return;
    }
    File orgManifestFile = new File(libManifestFile.getParentFile(), "AndroidManifest-org.xml");
    if (orgManifestFile.exists()) {
        return;
    }
    libManifestFile.renameTo(orgManifestFile);
    SAXReader reader = new SAXReader();
    OutputFormat format = OutputFormat.createPrettyPrint();
    // 设置XML文件的编码格式
    format.setEncoding("UTF-8");
    // 读取XML文件
    Document document = reader.read(orgManifestFile);
    // 得到根节点
    Element root = document.getRootElement();
    if (updateSdkVersion) {
        Element useSdkElement = root.element("uses-sdk");
        if (null == useSdkElement) {
            useSdkElement = root.addElement("uses-sdk");
        }
        if (null != useSdkElement) {
            updateElement(useSdkElement, mainManifestFileObject.getUseSdkProperties());
        }
    }
    // 先人工处理一下tools:remove和tools:replace规则,发现有些通过ManifestMerge不一定可以
    Element applicationElement = root.element("application");
    Map<String, String> replaceAttrs = mainManifestFileObject.getReplaceApplicationAttribute();
    List<String> removeAttrs = mainManifestFileObject.getRemoveApplicationAttribute();
    if (null != applicationElement) {
        // 去除lib项目里的tools属性
        List<Attribute> toRomoved = new ArrayList<Attribute>();
        for (Attribute attribute : applicationElement.attributes()) {
            if (attribute.getName().equals("replace") || attribute.getName().equals("remove")) {
                // applicationElement.remove(attribute);
                // applicationElement.attributes().remove(attribute);
                toRomoved.add(attribute);
            }
        }
        if (toRomoved.size() > 0) {
            for (Attribute attribute : toRomoved) {
                applicationElement.remove(attribute);
            }
        }
        updateApplicationElement(applicationElement, replaceAttrs, removeAttrs);
    }
    //处理packageName TODO
    String packageName = root.attributeValue("package");
    if (StringUtils.isEmpty(packageName)) {
        packageName = ManifestFileUtils.getPackage(orgManifestFile);
    }
    List<? extends Node> applicatNodes = root.selectNodes("//application");
    for (Node node : applicatNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        if (attribute != null) {
            if (!attribute.getValue().startsWith(packageName)) {
                attribute.setValue(packageName + attribute.getValue());
            }
        }
    }
    fillFullClazzName(root, packageName, "activity");
    fillFullClazzName(root, packageName, "provider");
    fillFullClazzName(root, packageName, "receiver");
    fillFullClazzName(root, packageName, "service");
    saveFile(document, format, libManifestFile);
}
Also used : Attribute(org.dom4j.Attribute) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) Node(org.dom4j.Node) OutputFormat(org.dom4j.io.OutputFormat) ArrayList(java.util.ArrayList) Document(org.dom4j.Document) File(java.io.File)

Example 73 with Document

use of org.dom4j.Document in project atlas by alibaba.

the class ManifestFileUtils method removeProvider.

public static void removeProvider(File androidManifestFile) throws IOException, DocumentException {
    File backupFile = new File(androidManifestFile.getParentFile(), "AndroidManifest-backup.xml");
    FileUtils.deleteQuietly(backupFile);
    FileUtils.moveFile(androidManifestFile, backupFile);
    // 声明写XML的对象
    XMLWriter writer = null;
    SAXReader reader = new SAXReader();
    OutputFormat format = OutputFormat.createPrettyPrint();
    // 设置XML文件的编码格式
    format.setEncoding("UTF-8");
    FileOutputStream fos = new FileOutputStream(androidManifestFile);
    if (androidManifestFile.exists()) {
        try {
            // 读取XML文件
            Document document = reader.read(backupFile);
            // 得到根节点
            Element root = document.getRootElement();
            List<? extends Node> nodes = root.selectNodes("//provider");
            for (Node node : nodes) {
                Element element = (Element) node;
                String name = element.attributeValue("name");
                logger.info("[Remove Provider]" + name);
                element.getParent().remove(element);
            }
            writer = new XMLWriter(fos, format);
            writer.write(document);
        } finally {
            if (null != writer) {
                writer.close();
            }
            IOUtils.closeQuietly(fos);
        }
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) FileOutputStream(java.io.FileOutputStream) Element(org.dom4j.Element) Node(org.dom4j.Node) OutputFormat(org.dom4j.io.OutputFormat) Document(org.dom4j.Document) File(java.io.File) XMLWriter(org.dom4j.io.XMLWriter)

Example 74 with Document

use of org.dom4j.Document in project atlas by alibaba.

the class ManifestFileUtils method postProcessManifests.

/**
     * 对manifest做后续处理
     *
     * @param mainManifest
     * @param libManifestMap
     * @param baseBunfleInfoFile
     * @param manifestOptions
     */
public static void postProcessManifests(File mainManifest, Map<String, File> libManifestMap, Multimap<String, File> libDependenciesMaps, File baseBunfleInfoFile, ManifestOptions manifestOptions, boolean addMultiDex, Set<String> remoteBundles) throws IOException, DocumentException {
    File backupFile = new File(mainManifest.getParentFile(), "AndroidManifest-backup.xml");
    FileUtils.deleteQuietly(backupFile);
    FileUtils.moveFile(mainManifest, backupFile);
    // 声明写XML的对象
    XMLWriter writer = null;
    SAXReader reader = new SAXReader();
    OutputFormat format = OutputFormat.createPrettyPrint();
    // 设置XML文件的编码格式
    format.setEncoding("UTF-8");
    FileOutputStream fos = new FileOutputStream(mainManifest);
    if (mainManifest.exists()) {
        try {
            // 读取XML文件
            Document document = reader.read(backupFile);
            if (null != baseBunfleInfoFile && baseBunfleInfoFile.exists()) {
                addApplicationMetaData(document, libManifestMap, baseBunfleInfoFile, manifestOptions, remoteBundles);
            }
            if (null != manifestOptions && manifestOptions.isAddBundleLocation()) {
                addBundleLocationToDestManifest(document, libManifestMap, libDependenciesMaps, manifestOptions);
            }
            if (null != manifestOptions && manifestOptions.isReplaceApplication()) {
                replaceManifestApplicationName(document);
            }
            if ((null != manifestOptions && manifestOptions.isAddMultiDexMetaData()) || addMultiDex) {
                addMultiDexMetaData(document);
            }
            if (null != manifestOptions && manifestOptions.isRemoveProvider()) {
                removeProvider(document);
            }
            removeCustomLaunches(document, manifestOptions);
            updatePermission(document, manifestOptions);
            removeComments(document);
            writer = new XMLWriter(fos, format);
            writer.write(document);
        } finally {
            if (null != writer) {
                writer.close();
            }
            IOUtils.closeQuietly(fos);
        }
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) FileOutputStream(java.io.FileOutputStream) OutputFormat(org.dom4j.io.OutputFormat) Document(org.dom4j.Document) File(java.io.File) XMLWriter(org.dom4j.io.XMLWriter)

Example 75 with Document

use of org.dom4j.Document in project tdi-studio-se by Talend.

the class HTMLDocGenerator method handleXMLFile.

/**
     * Generates the xml file base on an instance of <code>ExportFileResource</code> and the temporary folder path.
     * 
     * @param resource
     * @param tempFolderPath
     * @param version
     */
private void handleXMLFile(ExportFileResource resource, String tempFolderPath, String... version) throws Exception {
    Item item = resource.getItem();
    // Check if generate Job Extra / Stats&Logs Setting Info
    if (item instanceof ProcessItem) {
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IMRProcessService.class)) {
            IMRProcessService mrProcessService = (IMRProcessService) GlobalServiceRegister.getDefault().getService(IMRProcessService.class);
            generateExtraSetting = !mrProcessService.isMapReduceItem(item);
            generateStatsLogsSetting = generateExtraSetting;
        } else if (isRouteProcess(item)) {
            generateStatsLogsSetting = generateExtraSetting = !isRouteProcess(item);
        }
    } else if (item instanceof JobletProcessItem) {
        generateStatsLogsSetting = false;
    }
    targetConnectionMap = new HashMap<String, List>();
    sourceConnectionMap = new HashMap<String, List>();
    getSourceAndTargetConnection(item);
    Document document = DocumentHelper.createDocument();
    Element projectElement = generateProjectInfo(document);
    Element jobElement = generateJobInfo(item, projectElement, version);
    // This two element see feature 4162
    generateContextInfo(item, jobElement);
    generateJobSettingInfo(item, jobElement);
    List<List> allList = seperateNodes(item);
    if (allList == null || allList.size() != 3) {
        return;
    }
    List<INode> allComponentsList = allList.get(0);
    List<INode> internalNodeComponentsList = allList.get(1);
    List<INode> externalNodeComponentsList = allList.get(2);
    if (allComponentsList.size() > 0) {
        // Generates information for 'Component List' part in exported HTML file.
        generateAllComponentsSummaryInfo(item, jobElement, allComponentsList);
    }
    //$NON-NLS-1$
    Element internalNodeElement = jobElement.addElement("internalNodeComponents");
    //$NON-NLS-1$
    Element externalNodeElement = jobElement.addElement("externalNodeComponents");
    if (internalNodeComponentsList.size() > 0) {
        InternalNodeComponentHandler internalNodeComponentHandler = new InternalNodeComponentHandler(this.picFilePathMap, internalNodeElement, internalNodeComponentsList, this.sourceConnectionMap, this.targetConnectionMap, this.designerCoreService, this.repositoryConnectionItemMap, this.repositoryDBIdAndNameMap, externalNodeHTMLMap);
        // Generates internal node components information.
        internalNodeComponentHandler.generateComponentInfo();
    }
    if (externalNodeComponentsList.size() > 0) {
        ExternalNodeComponentHandler externalNodeComponentHandler = new ExternalNodeComponentHandler(this.picFilePathMap, externalNodeElement, externalNodeComponentsList, this.sourceConnectionMap, this.targetConnectionMap, this.designerCoreService, this.repositoryConnectionItemMap, this.repositoryDBIdAndNameMap, externalNodeHTMLMap);
        // Generates external node components(tMap etc.) information.
        externalNodeComponentHandler.generateComponentInfo();
    }
    // Generates all connection information(include internal node and external node).
    EList connectionList = null;
    if (item instanceof ProcessItem) {
        connectionList = ((ProcessItem) item).getProcess().getConnection();
    } else if (item instanceof JobletProcessItem) {
        connectionList = (((JobletProcessItem) item).getJobletProcess().getConnection());
    }
    if (connectionList != null && connectionList.size() != 0) {
        generateConnectionsInfo(jobElement, connectionList);
    }
    //$NON-NLS-1$
    String versionPath = "_";
    if (version != null && version.length == 1) {
        versionPath = versionPath + version[0];
    } else {
        versionPath = versionPath + item.getProperty().getVersion();
    }
    String filePath = tempFolderPath + File.separatorChar + item.getProperty().getLabel() + versionPath + IHTMLDocConstants.XML_FILE_SUFFIX;
    // This element see feature 4382
    if (item instanceof ProcessItem) {
        generateSourceCodeInfo((ProcessItem) item, jobElement);
    }
    XMLHandler.generateXMLFile(tempFolderPath, filePath, document);
}
Also used : INode(org.talend.core.model.process.INode) InternalNodeComponentHandler(org.talend.core.ui.documentation.generation.InternalNodeComponentHandler) IMRProcessService(org.talend.core.service.IMRProcessService) Element(org.dom4j.Element) Document(org.dom4j.Document) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ExternalNodeComponentHandler(org.talend.core.ui.documentation.generation.ExternalNodeComponentHandler) CSSRuleList(org.w3c.dom.css.CSSRuleList) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(org.w3c.dom.NodeList) EList(org.eclipse.emf.common.util.EList)

Aggregations

Document (org.dom4j.Document)288 Element (org.dom4j.Element)192 SAXReader (org.dom4j.io.SAXReader)143 Test (org.junit.Test)102 StringReader (java.io.StringReader)88 File (java.io.File)57 ArrayList (java.util.ArrayList)47 List (java.util.List)40 IOException (java.io.IOException)27 DocumentException (org.dom4j.DocumentException)25 XMLWriter (org.dom4j.io.XMLWriter)22 HashMap (java.util.HashMap)19 Map (java.util.Map)18 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)17 LinkedList (java.util.LinkedList)16 Attribute (org.dom4j.Attribute)15 Node (org.dom4j.Node)14 FileOutputStream (java.io.FileOutputStream)11 DavException (com.zimbra.cs.dav.DavException)10 OutputFormat (org.dom4j.io.OutputFormat)9