Search in sources :

Example 61 with DocumentException

use of org.dom4j.DocumentException in project pentaho-platform by pentaho.

the class PentahoSystemPluginManager method registerSettings.

private void registerSettings(IPlatformPlugin plugin, ClassLoader loader) {
    IPluginResourceLoader resLoader = PentahoSystem.get(IPluginResourceLoader.class, null);
    InputStream stream = resLoader.getResourceAsStream(loader, "settings.xml");
    if (stream == null) {
        // No settings.xml is fine
        return;
    }
    Properties properties = new Properties();
    try {
        Document docFromStream = XmlDom4JHelper.getDocFromStream(stream);
        for (Object element : docFromStream.getRootElement().elements()) {
            Element ele = (Element) element;
            String name = ele.getName();
            String value = ele.getText();
            properties.put("settings/" + name, value);
        }
    } catch (DocumentException | IOException e) {
        logger.error("Error parsing settings.xml for plugin: " + plugin.getId(), e);
    }
    try {
        systemConfig.registerConfiguration(new PropertiesFileConfiguration(plugin.getId(), properties));
    } catch (IOException e) {
        logger.error("Error registering settings.xml for plugin: " + plugin.getId(), e);
    }
}
Also used : PropertiesFileConfiguration(org.pentaho.platform.config.PropertiesFileConfiguration) InputStream(java.io.InputStream) Element(org.dom4j.Element) DocumentException(org.dom4j.DocumentException) IOException(java.io.IOException) Properties(java.util.Properties) Document(org.dom4j.Document) IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader)

Example 62 with DocumentException

use of org.dom4j.DocumentException in project pentaho-platform by pentaho.

the class PentahoObjectsConfig method setDocument.

public void setDocument(Document doc) throws DocumentException {
    Element rootElement = doc.getRootElement();
    if ((rootElement != null) && !doc.getRootElement().getName().equals(ROOT)) {
        throw new DocumentException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "PentahoObjectsConfig.ERROR_0001_INVALID_ROOT_ELEMENT"));
    }
    document = doc;
}
Also used : Element(org.dom4j.Element) DocumentException(org.dom4j.DocumentException)

Example 63 with DocumentException

use of org.dom4j.DocumentException in project pentaho-platform by pentaho.

the class EmailConfigurationXml method loadFromConfigurationDocument.

private void loadFromConfigurationDocument(final Document doc) throws DocumentException {
    final Element rootElement = doc.getRootElement();
    if ((rootElement != null) && !doc.getRootElement().getName().equals(ROOT_ELEMENT)) {
        // $NON-NLS-1$
        throw new DocumentException(messages.getErrorString("EmailConfigurationXml.ERROR_0002_INVALID_ROOT_ELEMENT"));
    }
    setSmtpHost(getStringValue(doc, SMTP_HOST_XPATH));
    setSmtpPort(getIntegerPortValue(doc, SMTP_PORT_XPATH));
    setSmtpProtocol(getStringValue(doc, SMTP_PROTOCOL_XPATH));
    setUseStartTls(getBooleanValue(doc, USE_START_TLS_XPATH));
    setAuthenticate(getBooleanValue(doc, AUTHENTICATE_XPATH));
    setUseSsl(getBooleanValue(doc, USE_SSL_XPATH));
    setDebug(getBooleanValue(doc, DEBUG_XPATH));
    setSmtpQuitWait(getBooleanValue(doc, SMTP_QUIT_WAIT_XPATH));
    setDefaultFrom(getStringValue(doc, DEFAULT_FROM_XPATH));
    setFromName(getStringValue(doc, FROM_NAME_XPATH));
    setUserId(getStringValue(doc, USER_ID_XPATH));
    setPassword(Encr.decryptPasswordOptionallyEncrypted(getStringValue(doc, PASSWORD_XPATH)));
}
Also used : XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Element(org.dom4j.Element) DocumentException(org.dom4j.DocumentException)

Example 64 with DocumentException

use of org.dom4j.DocumentException in project alfresco-repository by Alfresco.

the class QueryRegisterComponentImpl method loadQueryCollection.

public void loadQueryCollection(String location) {
    try {
        InputStream is = this.getClass().getClassLoader().getResourceAsStream(location);
        SAXReader reader = SAXReader.createDefault();
        Document document = reader.read(is);
        is.close();
        QueryCollection collection = QueryCollectionImpl.createQueryCollection(document.getRootElement(), dictionaryService, namespaceService);
        collections.put(location, collection);
    } catch (DocumentException de) {
        throw new AlfrescoRuntimeException("Error reading XML", de);
    } catch (IOException e) {
        throw new AlfrescoRuntimeException("IO Error reading XML", e);
    }
}
Also used : InputStream(java.io.InputStream) SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) IOException(java.io.IOException) Document(org.dom4j.Document)

Example 65 with DocumentException

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

the class ChatTranscriptManager method formatTranscript.

/**
     * Formats a given XML Chat Transcript.
     *
     * @param transcript the XMP ChatTranscript.
     * @return the pretty-version of a transcript.
     */
public static String formatTranscript(String transcript) {
    if (transcript == null || "".equals(transcript)) {
        return "";
    }
    final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat(XMPPDateTimeFormat.XMPP_DELAY_DATETIME_FORMAT);
    UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
    final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
    Document element = null;
    try {
        element = DocumentHelper.parseText(transcript);
    } catch (DocumentException e) {
        Log.error(e.getMessage(), e);
    }
    StringBuilder buf = new StringBuilder();
    String conv1 = null;
    // Add the Messages and Presences contained in the retrieved transcript element
    for (Iterator<Element> it = element.getRootElement().elementIterator(); it.hasNext(); ) {
        Element packet = it.next();
        String name = packet.getName();
        String message = "";
        String from = "";
        if ("presence".equals(name)) {
            String type = packet.attributeValue("type");
            from = new JID(packet.attributeValue("from")).getResource();
            if (type == null) {
                message = from + " has joined the room";
            } else {
                message = from + " has left the room";
            }
        } else if ("message".equals(name)) {
            from = new JID(packet.attributeValue("from")).getResource();
            message = packet.elementText("body");
            message = StringUtils.escapeHTMLTags(message);
            if (conv1 == null) {
                conv1 = from;
            }
        }
        List<Element> el = packet.elements("x");
        for (Element ele : el) {
            if ("jabber:x:delay".equals(ele.getNamespaceURI())) {
                String stamp = ele.attributeValue("stamp");
                try {
                    String formattedDate;
                    synchronized (UTC_FORMAT) {
                        Date d = UTC_FORMAT.parse(stamp);
                        formattedDate = formatter.format(d);
                    }
                    if ("presence".equals(name)) {
                        buf.append("<tr valign=\"top\"><td class=\"notification-label\" colspan=2 nowrap>[").append(formattedDate).append("] ").append(message).append("</td></tr>");
                    } else {
                        String cssClass = conv1.equals(from) ? "conversation-label1" : "conversation-label2";
                        buf.append("<tr valign=\"top\"><td width=1% class=\"" + cssClass + "\" nowrap>[").append(formattedDate).append("] ").append(from).append(":</td><td class=\"conversation-body\">").append(message).append("</td></tr>");
                    }
                } catch (ParseException e) {
                    Log.error(e.getMessage(), e);
                }
            }
        }
    }
    return buf.toString();
}
Also used : JID(org.xmpp.packet.JID) DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) ParseException(java.text.ParseException) Document(org.dom4j.Document) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

DocumentException (org.dom4j.DocumentException)123 Document (org.dom4j.Document)80 SAXReader (org.dom4j.io.SAXReader)73 Element (org.dom4j.Element)51 IOException (java.io.IOException)45 File (java.io.File)27 InputStream (java.io.InputStream)21 StringReader (java.io.StringReader)15 InputStreamReader (java.io.InputStreamReader)11 ArrayList (java.util.ArrayList)10 XMLWriter (org.dom4j.io.XMLWriter)9 InputSource (org.xml.sax.InputSource)9 FileInputStream (java.io.FileInputStream)7 URL (java.net.URL)7 List (java.util.List)7 Node (org.dom4j.Node)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 FileNotFoundException (java.io.FileNotFoundException)5 Reader (java.io.Reader)5