Search in sources :

Example 56 with Node

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

the class PentahoOFC4JChartHelper method generateChartJson.

@SuppressWarnings("unchecked")
public static String generateChartJson(Node chartNode, IPentahoResultSet data, boolean byRow, Log log) {
    String chartType = null;
    String factoryClassString = null;
    try {
        Node temp = chartNode.selectSingleNode(CHART_TYPE_NODE_LOC);
        if (AbstractChartFactory.getValue(temp) != null) {
            chartType = AbstractChartFactory.getValue(temp);
        } else {
            // This should NEVER happen.
            chartType = CHART_TYPE_DEFAULT;
        }
        factoryClassString = (String) getChartFactories().get(chartType);
        if (factoryClassString == null) {
            throw new RuntimeException(Messages.getInstance().getErrorString("PentahoOFC4JChartHelper.ERROR_0001_FACTORY_INIT", chartType, // $NON-NLS-1$
            factoryClassString));
        } else {
            Class factoryClass = Class.forName(factoryClassString);
            // throw exception if factoryClass not found
            IChartFactory factory = (IChartFactory) factoryClass.getConstructor(new Class[0]).newInstance(new Object[0]);
            factory.setChartNode(chartNode);
            factory.setLog(log);
            if (byRow) {
                factory.setData(PentahoDataTransmuter.pivot(data));
            } else {
                factory.setData(data);
            }
            return factory.convertToJson();
        }
    } catch (Exception e) {
        logger.error(Messages.getInstance().getErrorString("PentahoOFC4JChartHelper.ERROR_0001_FACTORY_INIT", chartType, factoryClassString), // $NON-NLS-1$
        e);
        throw new RuntimeException(e);
    }
}
Also used : Node(org.dom4j.Node) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 57 with Node

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

the class PieChartFactory method setupStyles.

@Override
protected void setupStyles() {
    super.setupStyles();
    Node temp = chartNode.selectSingleNode(ANIMATE_NODE_LOC);
    if (getValue(temp) != null) {
        // $NON-NLS-1$
        animate = "true".equals(getValue(temp));
    }
    temp = chartNode.selectSingleNode(START_ANGLE_NODE_LOC);
    if (getValue(temp) != null) {
        startAngle = Integer.parseInt(getValue(temp));
    }
}
Also used : Node(org.dom4j.Node)

Example 58 with Node

use of org.dom4j.Node in project xwiki-platform by xwiki.

the class AbstractDocumentMojo method loadFromXML.

/**
 * Loads a XWikiDocument from a XML file
 *
 * @param file the xml file to load
 * @return the XWiki document loaded from XML
 * @throws MojoExecutionException
 */
protected XWikiDocument loadFromXML(File file) throws MojoExecutionException {
    XWikiDocument doc = new XWikiDocument(new DocumentReference("xwiki", "XWiki", "WebHome"));
    FileInputStream fis;
    try {
        // Load the document as a XWikiDocument from XML
        fis = new FileInputStream(file);
        doc.fromXML(fis);
        // get XML tree
        FileReader fr = new FileReader(file);
        SAXReader reader = new SAXReader();
        Document domdoc;
        domdoc = reader.read(fr);
        Element root = domdoc.getRootElement();
        // Lookup all class nodes, and add them to our xwiki context as BaseClass definitions
        List<Node> classNodes = root.selectNodes("//xwikidoc/object/class");
        for (Iterator<Node> it = classNodes.iterator(); it.hasNext(); ) {
            BaseClass bClass = new BaseClass();
            bClass.fromXML((Element) it.next());
            context.addBaseClass(bClass);
        }
        fis.close();
        return doc;
    } catch (Exception e) {
        throw new MojoExecutionException("Error loading XWikiDocument [" + file + "]", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) Node(org.dom4j.Node) Document(org.dom4j.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) FileInputStream(java.io.FileInputStream) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ExecutionContextException(org.xwiki.context.ExecutionContextException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) FileReader(java.io.FileReader) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 59 with Node

use of org.dom4j.Node in project Spark by igniterealtime.

the class EmoticonManager method addEmoticonPack.

/**
 * Loads an emoticon set.
 *
 * @param packName
 *            the name of the pack.
 */
public void addEmoticonPack(String packName) {
    File emoticonSet = new File(EMOTICON_DIRECTORY, packName + ".adiumemoticonset");
    if (!emoticonSet.exists()) {
        emoticonSet = new File(EMOTICON_DIRECTORY, packName + ".AdiumEmoticonset");
    }
    if (!emoticonSet.exists()) {
        emoticonSet = new File(EMOTICON_DIRECTORY, "Default.adiumemoticonset");
        packName = "Default";
        setActivePack("Default");
    }
    Map<String, Emoticon> emoticons = new LinkedHashMap<>();
    final File plist = new File(emoticonSet, "Emoticons.plist");
    // Create SaxReader and set to non-validating parser.
    // This will allow for non-http problems to not break spark :)
    final SAXReader saxParser = new SAXReader();
    saxParser.setValidation(false);
    try {
        saxParser.setFeature("http://xml.org/sax/features/validation", false);
        saxParser.setFeature("http://xml.org/sax/features/namespaces", false);
        saxParser.setFeature("http://apache.org/xml/features/validation/schema", false);
        saxParser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", false);
        saxParser.setFeature("http://apache.org/xml/features/validation/dynamic", false);
        saxParser.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
        saxParser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
        saxParser.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
        saxParser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    } catch (SAXException e) {
        e.printStackTrace();
    }
    Document emoticonFile;
    try {
        emoticonFile = saxParser.read(plist);
    } catch (DocumentException e) {
        Log.error(e);
        return;
    }
    Node root = emoticonFile.selectSingleNode("/plist/dict/dict");
    List<?> keyList = root.selectNodes("key");
    List<?> dictonaryList = root.selectNodes("dict");
    Iterator<?> keys = keyList.iterator();
    Iterator<?> dicts = dictonaryList.iterator();
    while (keys.hasNext()) {
        Element keyEntry = (Element) keys.next();
        String key = keyEntry.getText();
        Element dict = (Element) dicts.next();
        String name = dict.selectSingleNode("string").getText();
        // Load equivilants
        final List<String> equivs = new ArrayList<>();
        final List<?> equivilants = dict.selectNodes("array/string");
        for (Object equivilant1 : equivilants) {
            Element equivilant = (Element) equivilant1;
            String equivilantString = equivilant.getText();
            equivs.add(equivilantString);
        }
        final Emoticon emoticon = new Emoticon(key, name, equivs, emoticonSet);
        for (String equivalent : emoticon.getEquivalants()) {
            emoticons.put(equivalent, emoticon);
        }
    }
    emoticonMap.put(packName, emoticons);
}
Also used : SAXReader(org.dom4j.io.SAXReader) Node(org.dom4j.Node) Element(org.dom4j.Element) Document(org.dom4j.Document) SAXException(org.xml.sax.SAXException) DocumentException(org.dom4j.DocumentException) JarFile(java.util.jar.JarFile) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 60 with Node

use of org.dom4j.Node in project Spark by igniterealtime.

the class PluginViewer method getPluginList.

public Collection<PublicPlugin> getPluginList(InputStream response) {
    final List<PublicPlugin> pluginList = new ArrayList<>();
    SAXReader saxReader = new SAXReader();
    Document pluginXML = null;
    try {
        pluginXML = saxReader.read(response);
    } catch (DocumentException e) {
        Log.error(e);
    }
    List<? extends Node> plugins = pluginXML.selectNodes("/plugins/plugin");
    for (Node plugin1 : plugins) {
        PublicPlugin publicPlugin = new PublicPlugin();
        String clazz;
        String name = null;
        try {
            Element plugin = (Element) plugin1;
            try {
                String version = plugin.selectSingleNode("minSparkVersion").getText();
                if (!isGreaterOrEqual(JiveInfo.getVersion(), version)) {
                    Log.error("Unable to load plugin " + name + " due to min version incompatibility.");
                    continue;
                }
            } catch (Exception e) {
                Log.error("Unable to load plugin " + name + " due to no minSparkVersion.");
                continue;
            }
            name = plugin.selectSingleNode("name").getText();
            clazz = plugin.selectSingleNode("class").getText();
            publicPlugin.setPluginClass(clazz);
            publicPlugin.setName(name);
            try {
                String version = plugin.selectSingleNode("version").getText();
                publicPlugin.setVersion(version);
                String author = plugin.selectSingleNode("author").getText();
                publicPlugin.setAuthor(author);
                Node emailNode = plugin.selectSingleNode("email");
                if (emailNode != null) {
                    publicPlugin.setEmail(emailNode.getText());
                }
                Node descriptionNode = plugin.selectSingleNode("description");
                if (descriptionNode != null) {
                    publicPlugin.setDescription(descriptionNode.getText());
                }
                Node homePageNode = plugin.selectSingleNode("homePage");
                if (homePageNode != null) {
                    publicPlugin.setHomePage(homePageNode.getText());
                }
                Node downloadNode = plugin.selectSingleNode("downloadURL");
                if (downloadNode != null) {
                    String downloadURL = downloadNode.getText();
                    publicPlugin.setDownloadURL(downloadURL);
                }
                Node changeLogNode = plugin.selectSingleNode("changeLog");
                if (changeLogNode != null) {
                    publicPlugin.setChangeLogURL(changeLogNode.getText());
                }
                Node readMeNode = plugin.selectSingleNode("readme");
                if (readMeNode != null) {
                    publicPlugin.setReadMeURL(readMeNode.getText());
                }
                Node smallIcon = plugin.selectSingleNode("smallIcon");
                if (smallIcon != null) {
                    publicPlugin.setSmallIconAvailable(true);
                }
                Node largeIcon = plugin.selectSingleNode("largeIcon");
                if (largeIcon != null) {
                    publicPlugin.setLargeIconAvailable(true);
                }
            } catch (Exception e) {
                Log.error("Error retrieving PluginInformation from xml.", e);
            }
            pluginList.add(publicPlugin);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return pluginList;
}
Also used : SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Node(org.dom4j.Node) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) PublicPlugin(org.jivesoftware.spark.plugin.PublicPlugin) Document(org.dom4j.Document) DocumentException(org.dom4j.DocumentException)

Aggregations

Node (org.dom4j.Node)253 Document (org.dom4j.Document)83 Element (org.dom4j.Element)61 ArrayList (java.util.ArrayList)56 List (java.util.List)54 Test (org.junit.Test)40 SAXReader (org.dom4j.io.SAXReader)28 File (java.io.File)25 Iterator (java.util.Iterator)18 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)18 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)18 HashMap (java.util.HashMap)16 URL (java.net.URL)15 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)15 InputStream (java.io.InputStream)14 Attribute (org.dom4j.Attribute)14 Image (java.awt.Image)12 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)11 VFSItem (org.olat.core.util.vfs.VFSItem)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)10