Search in sources :

Example 1 with SAXReader

use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.

the class PublishedItem method getPayload.

/**
     * Returns the payload included when publishing the item. A published item may or may not
     * have a payload. Transient nodes that are configured to not broadcast payloads may allow
     * published items to have no payload.
     *
     * @return the payload included when publishing the item or <tt>null</tt> if none was found.
     */
public Element getPayload() {
    if (payload == null && payloadXML != null) {
        synchronized (this) {
            if (payload == null) {
                // payload initialized as XML string from DB
                SAXReader xmlReader = null;
                try {
                    xmlReader = xmlReaders.take();
                    payload = xmlReader.read(new StringReader(payloadXML)).getRootElement();
                } catch (Exception ex) {
                    log.error("Failed to parse payload XML", ex);
                } finally {
                    if (xmlReader != null) {
                        xmlReaders.add(xmlReader);
                    }
                }
            }
        }
    }
    return payload;
}
Also used : SAXReader(org.dom4j.io.SAXReader) StringReader(java.io.StringReader)

Example 2 with SAXReader

use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.

the class AdminConsole method addModel.

/**
     * Adds XML stream to the tabs/sidebar model.
     *
     * @param name the name.
     * @param in the XML input stream.
     * @throws Exception if an error occurs when parsing the XML or adding it to the model.
     */
public static void addModel(String name, InputStream in) throws Exception {
    SAXReader saxReader = new SAXReader();
    Document doc = saxReader.read(in);
    addModel(name, (Element) doc.selectSingleNode("/adminconsole"));
}
Also used : SAXReader(org.dom4j.io.SAXReader) Document(org.dom4j.Document)

Example 3 with SAXReader

use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.

the class OfflineMessageStore method start.

@Override
public void start() throws IllegalStateException {
    super.start();
    // Initialize the pool of sax readers
    for (int i = 0; i < POOL_SIZE; i++) {
        SAXReader xmlReader = new SAXReader();
        xmlReader.setEncoding("UTF-8");
        xmlReaders.add(xmlReader);
    }
    // Add this module as a user event listener so we can delete
    // all offline messages when a user is deleted
    UserEventDispatcher.addListener(this);
}
Also used : SAXReader(org.dom4j.io.SAXReader)

Example 4 with SAXReader

use of org.dom4j.io.SAXReader 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 5 with SAXReader

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

the class HTMLDocGenerator method parseXml2HtmlPdf.

private List<URL> parseXml2HtmlPdf(String tempFolderPath, String jobName, String xslFilePath) throws Exception {
    // clear the cache, maybe need improve it latter.
    HTMLHandler.clearExternalNodeFileCache();
    String htmlFilePath = tempFolderPath + File.separatorChar + jobName + IHTMLDocConstants.HTML_FILE_SUFFIX;
    String xmlFilePath = tempFolderPath + File.separatorChar + jobName + IHTMLDocConstants.XML_FILE_SUFFIX;
    HTMLHandler.generateHTMLFile(tempFolderPath, xslFilePath, xmlFilePath, htmlFilePath, this.externalNodeHTMLMap);
    // for pdf
    File originalXmlFile = new File(xmlFilePath);
    if (originalXmlFile.exists()) {
        //$NON-NLS-1$
        String pdfXmlPath = tempFolderPath + File.separatorChar + "pdf_" + jobName + IHTMLDocConstants.XML_FILE_SUFFIX;
        File pdfXmlFile = new File(pdfXmlPath);
        if (pdfXmlFile.exists()) {
            pdfXmlFile.delete();
        }
        FilesUtils.copyFile(originalXmlFile, pdfXmlFile);
        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read(pdfXmlPath);
        //$NON-NLS-1$
        Attribute attri = (Attribute) document.selectNodes("/project/job/preview/@picture").get(0);
        //$NON-NLS-1$
        attri.setValue(IHTMLDocConstants.PICTUREFOLDERPATH + "pdf_" + jobName + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX);
        //$NON-NLS-1$
        List attributeList = document.selectNodes("/project/job/externalNodeComponents/component/@preview");
        for (int i = 0; i < attributeList.size(); i++) {
            Attribute at = (Attribute) attributeList.get(i);
            //$NON-NLS-1$
            String externalValue = at.getValue().substring(at.getValue().indexOf("/") + 1);
            //$NON-NLS-1$
            String value = IHTMLDocConstants.PICTUREFOLDERPATH + "pdf_" + externalValue;
            at.setValue(value);
        }
        XMLHandler.generateXMLFile(tempFolderPath, pdfXmlPath, document);
        HTMLHandler.clearExternalNodeFileCache();
        //$NON-NLS-1$
        String htmlPdfPath = tempFolderPath + File.separatorChar + "pdf_" + jobName + IHTMLDocConstants.HTML_FILE_SUFFIX;
        HTMLHandler.generateHTMLFile(tempFolderPath, xslFilePath, pdfXmlPath, htmlPdfPath, this.externalNodeHTMLMap);
    }
    return getParsedUrl(tempFolderPath);
}
Also used : Attribute(org.dom4j.Attribute) SAXReader(org.dom4j.io.SAXReader) 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) Document(org.dom4j.Document) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

SAXReader (org.dom4j.io.SAXReader)322 Document (org.dom4j.Document)256 Element (org.dom4j.Element)195 StringReader (java.io.StringReader)120 DocumentException (org.dom4j.DocumentException)74 Test (org.junit.jupiter.api.Test)74 File (java.io.File)54 List (java.util.List)49 IOException (java.io.IOException)48 InputStream (java.io.InputStream)48 ArrayList (java.util.ArrayList)47 Node (org.dom4j.Node)28 FileInputStream (java.io.FileInputStream)25 HashMap (java.util.HashMap)24 XMLWriter (org.dom4j.io.XMLWriter)22 ByteArrayInputStream (java.io.ByteArrayInputStream)20 URL (java.net.URL)18 OutputFormat (org.dom4j.io.OutputFormat)18 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)17 Test (org.junit.Test)14