Search in sources :

Example 1 with Builder

use of com.qcadoo.plugin.internal.DefaultPlugin.Builder in project qcadoo by qcadoo.

the class DefaultPluginDescriptorParser method parsePluginNode.

private Builder parsePluginNode(final Node pluginNode, final boolean ignoreModules) {
    Preconditions.checkState("plugin".equals(pluginNode.getNodeName()), "Wrong plugin description root tag");
    String pluginIdentifier = getStringAttribute(pluginNode, "plugin");
    checkNotNull(pluginIdentifier, "No plugin identifier");
    LOG.info("Parsing plugin " + pluginIdentifier);
    Builder pluginBuilder = new Builder(pluginIdentifier, moduleFactoryAccessor.getModuleFactories());
    String pluginVersionStr = getStringAttribute(pluginNode, "version");
    checkNotNull(pluginVersionStr, "No plugin version");
    pluginBuilder.withVersion(pluginVersionStr);
    String isSystemPluginStr = getStringAttribute(pluginNode, "system");
    if (isSystemPluginStr != null && Boolean.parseBoolean(isSystemPluginStr)) {
        pluginBuilder.asSystem();
    }
    String pluginGroup = getStringAttribute(pluginNode, "group");
    pluginBuilder.withGroup(pluginGroup);
    for (Node child : getChildNodes(pluginNode)) {
        if ("information".equals(child.getNodeName())) {
            addPluginInformation(child, pluginBuilder);
        } else if ("dependencies".equals(child.getNodeName())) {
            addDependenciesInformation(child, pluginBuilder);
        } else if ("modules".equals(child.getNodeName())) {
            if (!ignoreModules) {
                addModules(child, pluginBuilder, pluginIdentifier);
            }
        } else if ("features".equals(child.getNodeName())) {
            addFeturesInformation(child, pluginBuilder);
        } else {
            throw new IllegalStateException("Wrong plugin tag: " + child.getNodeName());
        }
    }
    return pluginBuilder;
}
Also used : Builder(com.qcadoo.plugin.internal.DefaultPlugin.Builder) DOMBuilder(org.jdom.input.DOMBuilder) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Node(org.w3c.dom.Node)

Example 2 with Builder

use of com.qcadoo.plugin.internal.DefaultPlugin.Builder in project qcadoo by qcadoo.

the class DefaultPluginDescriptorParser method parse.

private InternalPlugin parse(final InputStream inputStream, final boolean ignoreModules, final String fileName) throws IOException {
    try {
        Document document = documentBuilder.parse(inputStream);
        Node root = document.getDocumentElement();
        Builder pluginBuilder = parsePluginNode(root, ignoreModules);
        InternalPlugin plugin = pluginBuilder.withFileName(fileName).build();
        LOG.info("Parse complete");
        return plugin;
    } catch (SAXException e) {
        throw new PluginException(e.getMessage(), e);
    }
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Node(org.w3c.dom.Node) Builder(com.qcadoo.plugin.internal.DefaultPlugin.Builder) DOMBuilder(org.jdom.input.DOMBuilder) DocumentBuilder(javax.xml.parsers.DocumentBuilder) PluginException(com.qcadoo.plugin.internal.PluginException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Aggregations

Builder (com.qcadoo.plugin.internal.DefaultPlugin.Builder)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DOMBuilder (org.jdom.input.DOMBuilder)2 Node (org.w3c.dom.Node)2 PluginException (com.qcadoo.plugin.internal.PluginException)1 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)1 Document (org.w3c.dom.Document)1 SAXException (org.xml.sax.SAXException)1