Search in sources :

Example 31 with DocumentException

use of org.dom4j.DocumentException in project zm-mailbox by Zimbra.

the class CrossServerNotification method getHandler.

@Override
public MessageHandler getHandler() {
    return new MessageHandler() {

        @Override
        public void handle(Message m, String clientId) {
            if (!(m instanceof CrossServerNotification)) {
                return;
            }
            CrossServerNotification message = (CrossServerNotification) m;
            Collection<Session> sessions = SessionCache.getSoapSessions(m.getRecipientAccountId());
            if (sessions == null) {
                log.warn("no active sessions for account %s", m.getRecipientAccountId());
                return;
            }
            RemoteNotifications soapNtfn = null, jsonNtfn = null;
            try {
                org.dom4j.Document dom = org.dom4j.DocumentHelper.parseText(message.getPayload());
                soapNtfn = new RemoteNotifications(Element.convertDOM(dom.getRootElement(), XMLElement.mFactory));
                jsonNtfn = new RemoteNotifications(Element.convertDOM(dom.getRootElement(), JSONElement.mFactory));
            } catch (DocumentException e) {
                log.warn("cannot parse notification from %s", clientId, e);
                return;
            }
            for (Session session : sessions) {
                log.debug("notifying session %s", session.toString());
                SoapSession ss = (SoapSession) session;
                SoapProtocol responseProtocol = ss.getResponseProtocol();
                if (responseProtocol == SoapProtocol.Soap11 || responseProtocol == SoapProtocol.Soap12) {
                    ss.addRemoteNotifications(soapNtfn);
                } else if (responseProtocol == SoapProtocol.SoapJS) {
                    ss.addRemoteNotifications(jsonNtfn);
                }
                ss.forcePush();
            }
        }
    };
}
Also used : SoapSession(com.zimbra.cs.session.SoapSession) RemoteNotifications(com.zimbra.cs.session.SoapSession.RemoteNotifications) DocumentException(org.dom4j.DocumentException) SoapProtocol(com.zimbra.common.soap.SoapProtocol) SoapSession(com.zimbra.cs.session.SoapSession) Session(com.zimbra.cs.session.Session)

Example 32 with DocumentException

use of org.dom4j.DocumentException in project zm-mailbox by Zimbra.

the class ElementTest method dom4jSAXReaderWhichUsesSecureProcessing.

@Test
public void dom4jSAXReaderWhichUsesSecureProcessing() throws XmlParseException, SAXException, DocumentException {
    org.dom4j.io.SAXReader dom4jSAXReader;
    org.dom4j.Document doc;
    dom4jSAXReader = W3cDomUtil.getDom4jSAXReaderWhichUsesSecureProcessing();
    doc = dom4jSAXReader.read(new ByteArrayInputStream(provisioningXMLWithNoEntityRefNoDocType.getBytes(StandardCharsets.UTF_8)));
    Assert.assertNotNull("org.dom4j.Document object should not be null", doc);
    Assert.assertEquals("Round tripped XML", provisioningXMLWithNoEntityRefNoDocType, doc.asXML());
    dom4jSAXReader = W3cDomUtil.getDom4jSAXReaderWhichUsesSecureProcessing();
    try {
        doc = dom4jSAXReader.read(new ByteArrayInputStream(provisioningXMLWithEntityRefButNoDecl.getBytes(StandardCharsets.UTF_8)));
        Assert.assertNotNull("org.dom4j.Document object should not be null", doc);
        Assert.fail("DocumentException should have been thrown");
    } catch (DocumentException de) {
        Assert.assertTrue(de.getMessage().contains("The entity \"xxe\" was referenced, but not declared."));
    }
    dom4jSAXReader = W3cDomUtil.getDom4jSAXReaderWhichUsesSecureProcessing();
    try {
        doc = dom4jSAXReader.read(new ByteArrayInputStream(provisioningXMLWithEntityRefAndDecl.getBytes(StandardCharsets.UTF_8)));
    } catch (DocumentException de) {
        Assert.assertTrue(de.getMessage().contains("DOCTYPE is disallowed when the feature " + "\"http://apache.org/xml/features/disallow-doctype-decl\" set to true"));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentException(org.dom4j.DocumentException) SAXReader(org.dom4j.io.SAXReader) Test(org.junit.Test)

Example 33 with DocumentException

use of org.dom4j.DocumentException in project zm-mailbox by Zimbra.

the class LocalConfigUpgrade method main.

public static void main(String[] args) throws ServiceException {
    CliUtil.toolSetup();
    CommandLine cl = null;
    try {
        CommandLineParser parser = new GnuParser();
        Options options = getAllOptions();
        cl = parser.parse(options, args);
        if (cl == null)
            throw new ParseException("");
    } catch (ParseException pe) {
        usage(pe.getMessage());
    }
    if (cl.hasOption(O_HELP)) {
        usage(null);
    }
    if (!cl.hasOption(O_BUG)) {
        usage("no bug specified");
    }
    if (!cl.hasOption(O_TAG)) {
        usage("no backup suffix tag specified");
    }
    LocalConfig lc = null;
    try {
        lc = new LocalConfig(cl.getOptionValue("c"));
        lc.backup(cl.getOptionValue("t"));
    } catch (DocumentException de) {
        ZimbraLog.misc.error("failed reading config file", de);
        System.exit(1);
    } catch (ConfigException ce) {
        ZimbraLog.misc.error("failed reading config file", ce);
        System.exit(2);
    } catch (IOException ioe) {
        ZimbraLog.misc.error("failed to backup config file", ioe);
        System.exit(3);
    }
    String[] bugs = cl.getOptionValues(O_BUG);
    for (String bug : bugs) {
        if (!sUpgrades.containsKey(bug)) {
            ZimbraLog.misc.warn("local config upgrade can't handle bug " + bug);
            continue;
        }
        LocalConfigUpgrade lcu = sUpgrades.get(bug);
        System.out.println("== Running local config upgrade for bug " + lcu.mBug + " (" + lcu.mShortName + ")");
        try {
            lcu.upgrade(lc);
            System.out.println("== Done local config upgrade for bug " + lcu.mBug + " (" + lcu.mShortName + ")");
        } catch (ConfigException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    try {
        lc.save();
    } catch (IOException ioe) {
        ZimbraLog.misc.error("failed writing config file", ioe);
        System.exit(1);
    } catch (ConfigException ce) {
        ZimbraLog.misc.error("failed writing config file", ce);
        System.exit(1);
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) DocumentException(org.dom4j.DocumentException) GnuParser(org.apache.commons.cli.GnuParser) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) IOException(java.io.IOException)

Example 34 with DocumentException

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

the class AlfrescoOutputModelManager method removeModel.

/**
     * Removes an Alfresco model definition file.
     * 
     * @param oldModelFilePath
     * @throws AlfrescoOutputException
     */
public void removeModel(String oldModelFilePath) throws AlfrescoOutputException {
    if (!this.availableModels.remove(oldModelFilePath)) {
        //$NON-NLS-1$
        throw new AlfrescoOutputException(Messages.getString("AlfrescoOutputModelManager.notYetAdded"));
    }
    // parsing the model
    org.dom4j.Document modelDoc = null;
    try {
        modelDoc = new SAXReader().read(new File(oldModelFilePath));
    } catch (DocumentException dex) {
        throw new AlfrescoOutputException(//$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("AlfrescoOutputModelManager.errorReadingModel") + " " + oldModelFilePath, dex);
    }
    Element modelElt = modelDoc.getRootElement();
    //$NON-NLS-1$
    Element namespacesElt = modelElt.element("namespaces");
    if (namespacesElt != null) {
        //$NON-NLS-1$
        List<Element> namespaces = (List<Element>) namespacesElt.elements("namespace");
        for (Element namespace : namespaces) {
            //$NON-NLS-1$
            String namespacePrefix = namespace.attributeValue("prefix");
            this.availablePrefixToNamespaceMap.remove(namespacePrefix);
        }
    }
    //$NON-NLS-1$
    Element typesElt = modelElt.element("types");
    if (typesElt != null) {
        //$NON-NLS-1$
        List<Element> types = (List<Element>) typesElt.elements("type");
        this.availableTypes.removeAllAlfrescoModelElement(types);
    }
    //$NON-NLS-1$
    Element aspectsElt = modelElt.element("aspects");
    if (aspectsElt != null) {
        //$NON-NLS-1$
        List<Element> aspects = (List<Element>) aspectsElt.elements("aspect");
        this.availableAspects.removeAllAlfrescoModelElement(aspects);
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) List(java.util.List) AlfrescoOutputException(org.talend.designer.alfrescooutput.util.AlfrescoOutputException) File(java.io.File)

Example 35 with DocumentException

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

the class ComponentFolderManager method writeXMLContent.

/**
     * DOC slanglois Comment method "writeXMLContent".
     * 
     * @param iFile
     * @param document
     * @param enCode
     * @throws CoreException
     */
private void writeXMLContent(IFile iFile, Document document, String enCode) throws CoreException {
    PrintWriter pw = null;
    XMLWriter writer = null;
    byte[] byteArray = null;
    // get xml content as inputstream
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = null;
    try {
        transformer = tf.newTransformer();
    } catch (TransformerConfigurationException e1) {
        // e1.printStackTrace();
        org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
    }
    DOMSource source = new DOMSource(document);
    transformer.setOutputProperty(OutputKeys.ENCODING, enCode);
    //$NON-NLS-1$
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    ByteArrayOutputStream sw = new ByteArrayOutputStream();
    pw = new PrintWriter(sw);
    StreamResult result = new StreamResult(pw);
    try {
        transformer.transform(source, result);
    } catch (TransformerException e1) {
        // e1.printStackTrace();
        org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
    }
    try {
        sw.flush();
    } catch (IOException e1) {
        // e1.printStackTrace();
        org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
    byteArray = sw.toByteArray();
    // format the xml content
    SAXReader saxReader = new SAXReader();
    org.dom4j.Document dom4jDocument = null;
    try {
        dom4jDocument = saxReader.read(new ByteArrayInputStream(byteArray));
    } catch (DocumentException e1) {
        // e1.printStackTrace();
        org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
    }
    /** format the output like the webBrowser */
    OutputFormat format = OutputFormat.createPrettyPrint();
    /** give the xml encoding */
    format.setEncoding(enCode);
    sw = new ByteArrayOutputStream();
    try {
        writer = new XMLWriter(sw, format);
    } catch (UnsupportedEncodingException e1) {
        // e1.printStackTrace();
        org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
    }
    try {
        writer.write(dom4jDocument);
        writer.flush();
    } catch (IOException e1) {
        // e1.printStackTrace();
        org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                // e.printStackTrace();
                org.talend.componentdesigner.exception.ExceptionHandler.process(e);
            }
        }
    }
    byteArray = sw.toByteArray();
    // write content
    iFile.setContents(new ByteArrayInputStream(byteArray), true, false, null);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) StreamResult(javax.xml.transform.stream.StreamResult) SAXReader(org.dom4j.io.SAXReader) OutputFormat(org.dom4j.io.OutputFormat) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) XMLWriter(org.dom4j.io.XMLWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentException(org.dom4j.DocumentException) TransformerException(javax.xml.transform.TransformerException) PrintWriter(java.io.PrintWriter)

Aggregations

DocumentException (org.dom4j.DocumentException)36 Document (org.dom4j.Document)20 SAXReader (org.dom4j.io.SAXReader)19 Element (org.dom4j.Element)13 IOException (java.io.IOException)8 StringReader (java.io.StringReader)8 File (java.io.File)7 ConfigException (com.zimbra.common.localconfig.ConfigException)4 ArrayList (java.util.ArrayList)4 LocalConfig (com.zimbra.common.localconfig.LocalConfig)3 ServiceException (com.zimbra.common.service.ServiceException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Server (com.zimbra.cs.account.Server)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 List (java.util.List)2 XMLWriter (org.dom4j.io.XMLWriter)2 LoginCms (afip.wsaa.wsdl.LoginCms)1 NonNull (com.android.annotations.NonNull)1 DirectoryInput (com.android.build.api.transform.DirectoryInput)1