Search in sources :

Example 1 with SolutionURIResolver

use of org.pentaho.platform.engine.services.SolutionURIResolver in project pentaho-platform by pentaho.

the class SystemPathXmlPluginProvider method processDirectory.

protected void processDirectory(List<IPlatformPlugin> plugins, File folder, IPentahoSession session) throws PlatformPluginRegistrationException {
    // see if there is a plugin.xml file
    // $NON-NLS-1$
    FilenameFilter filter = new NameFileFilter("plugin.xml", IOCase.SENSITIVE);
    File[] kids = folder.listFiles(filter);
    if (kids == null || kids.length == 0) {
        return;
    }
    boolean hasLib = false;
    // $NON-NLS-1$
    filter = new NameFileFilter("lib", IOCase.SENSITIVE);
    kids = folder.listFiles(filter);
    if (kids != null && kids.length > 0) {
        hasLib = kids[0].exists() && kids[0].isDirectory();
    }
    // we have found a plugin.xml file
    // get the file from the repository
    // $NON-NLS-1$ //$NON-NLS-2$
    String path = "system" + RepositoryFile.SEPARATOR + folder.getName() + RepositoryFile.SEPARATOR + "plugin.xml";
    Document doc = null;
    try {
        try {
            org.dom4j.io.SAXReader reader = XMLParserFactoryProducer.getSAXReader(new SolutionURIResolver());
            doc = reader.read(ActionSequenceResource.getInputStream(path, LocaleHelper.getLocale()));
        } catch (Throwable t) {
        // XML document can't be read. We'll just return a null document.
        }
        if (doc != null) {
            plugins.add(createPlugin(doc, session, folder.getName(), hasLib));
        }
    } catch (Exception e) {
        throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0005_CANNOT_PROCESS_PLUGIN_XML", path), // $NON-NLS-1$
        e);
    }
    if (doc == null) {
        throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0005_CANNOT_PROCESS_PLUGIN_XML", // $NON-NLS-1$
        path));
    }
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) Document(org.dom4j.Document) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) SolutionURIResolver(org.pentaho.platform.engine.services.SolutionURIResolver) FilenameFilter(java.io.FilenameFilter) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException)

Example 2 with SolutionURIResolver

use of org.pentaho.platform.engine.services.SolutionURIResolver in project pentaho-platform by pentaho.

the class DashboardWidgetComponent method getXmlContent.

/**
 * Create a dial image.
 * <ul>
 * <li>Load the specified XML document describing the dial definition</li>
 * <li>Create a dial definition object from the XML definition</li>
 * <li>Use the JFreeChartEngine to create a dial image</li>
 * <li>Create an XML document describing the dial</li>
 * <li>Return the XML document</li>
 * </ul>
 *
 * @return The XML document describing this dial
 */
@Override
public Document getXmlContent() {
    WidgetDefinition widget = null;
    if (type == DashboardWidgetComponent.TYPE_DIAL) {
        // load the XML document that defines the dial
        IActionSequenceResource resource = new // $NON-NLS-1$
        ActionSequenceResource(// $NON-NLS-1$
        title, // $NON-NLS-1$
        IActionSequenceResource.SOLUTION_FILE_RESOURCE, // $NON-NLS-1$
        "text/xml", definitionPath);
        Document dialDefinition = null;
        try {
            org.dom4j.io.SAXReader reader = XMLParserFactoryProducer.getSAXReader(new SolutionURIResolver());
            dialDefinition = reader.read(resource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale()));
        } catch (Throwable t) {
        // XML document can't be read. We'll just return a null document.
        }
        if (dialDefinition == null) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("Widget.ERROR_0002_INVALID_RESOURCE", definitionPath));
            return null;
        }
        // create a dial definition from the XML definition
        widget = new DialWidgetDefinition(dialDefinition, 0, width, height, getSession());
        if (widget != null) {
            // set the value to be displayed on the dial
            widget.setValue(new Double(value));
        }
    }
    /*
     * else if( type == TYPE_THERMOMETER ) { // load the XML document that defines the thermometer
     * 
     * ActionResource resource = new ActionResource( title, IActionResource.SOLUTION_FILE_RESOURCE, "text/xml",
     * //$NON-NLS-1$ PentahoSystem.getApplicationContext().getSolutionPath( definitionPath ) ); //$NON-NLS-1$
     * Document thermometerDefinition = null; try { thermometerDefinition = PentahoSystem.getResourceAsDocument(
     * resource ); } catch (IOException e) {} // create a dial definition from the XML definition widget =
     * createThermometer( thermometerDefinition );
     * 
     * if( widget != null ) { // set the value to be displayed on the dial widget.setValue( new Double(value) ); //
     * Set the XSL file to be used to generate the HTML setXsl( "text/html", "DialWidget.xsl" ); //$NON-NLS-1$
     * //$NON-NLS-2$ } else { error( Messages.getInstance().getString("Widget.ERROR_0001_COULD_NOT_CREATE") );
     * //$NON-NLS-1$ return null; } }
     */
    if (widget == null) {
        // $NON-NLS-1$
        error(Messages.getInstance().getString("Widget.ERROR_0001_COULD_NOT_CREATE"));
        return null;
    }
    // create an image for the dial using the JFreeChart engine
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    // create temporary file names
    // $NON-NLS-1$
    String solutionDir = "system/tmp/";
    // $NON-NLS-1$
    String fileNamePrefix = "tmp_pie_";
    // $NON-NLS-1$
    String extension = ".png";
    String fileName = null;
    String filePathWithoutExtension = null;
    try {
        File file = PentahoSystem.getApplicationContext().createTempFile(getSession(), fileNamePrefix, extension, true);
        fileName = file.getName();
        filePathWithoutExtension = solutionDir + fileName.substring(0, fileName.indexOf('.'));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // $NON-NLS-1$
    String dialTitle = "";
    JFreeChartEngine.saveChart(widget, dialTitle, units, filePathWithoutExtension, width, height, JFreeChartEngine.OUTPUT_PNG, printWriter, this);
    // Create a document that describes the result
    Document result = DocumentHelper.createDocument();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setXslProperty("baseUrl", requestContext.getContextPath());
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setXslProperty("fullyQualifiedServerUrl", PentahoSystem.getApplicationContext().getFullyQualifiedServerURL());
    // $NON-NLS-1$
    Element root = result.addElement("widget");
    // $NON-NLS-1$
    root.addElement("title").setText(title);
    // $NON-NLS-1$
    root.addElement("units").setText(units);
    // $NON-NLS-1$
    root.addElement("width").setText(Integer.toString(width));
    // $NON-NLS-1$
    root.addElement("height").setText(Integer.toString(height));
    // $NON-NLS-1$
    Element valueNode = root.addElement("value");
    valueNode.setText(Double.toString(value));
    // $NON-NLS-1$
    valueNode.addAttribute("in-image", Boolean.toString(widget.getValueFont() != null));
    // $NON-NLS-1$
    root.addElement("image").setText(fileName);
    return result;
}
Also used : Element(org.dom4j.Element) IOException(java.io.IOException) Document(org.dom4j.Document) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource) SolutionURIResolver(org.pentaho.platform.engine.services.SolutionURIResolver) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) StringWriter(java.io.StringWriter) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource) ActionSequenceResource(org.pentaho.platform.engine.services.actionsequence.ActionSequenceResource) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 3 with SolutionURIResolver

use of org.pentaho.platform.engine.services.SolutionURIResolver in project pentaho-platform by pentaho.

the class WidgetGridComponent method setDataAction.

public boolean setDataAction(final String widgetGridDataDefinition) {
    try {
        Document dataActionDocument = null;
        try {
            org.dom4j.io.SAXReader reader = XMLParserFactoryProducer.getSAXReader(new SolutionURIResolver());
            dataActionDocument = reader.read(ActionSequenceResource.getInputStream(widgetGridDataDefinition, LocaleHelper.getLocale()));
        } catch (Throwable t) {
            return false;
        }
        // $NON-NLS-1$
        Node dataNode = dataActionDocument.selectSingleNode("widgetgrid/data");
        // $NON-NLS-1$
        solution = XmlDom4JHelper.getNodeText("data-solution", dataNode);
        // $NON-NLS-1$
        actionPath = XmlDom4JHelper.getNodeText("data-path", dataNode);
        // $NON-NLS-1$
        actionName = XmlDom4JHelper.getNodeText("data-action", dataNode);
        // $NON-NLS-1$
        actionOutput = XmlDom4JHelper.getNodeText("data-output", dataNode);
        // $NON-NLS-1$
        valueItem = XmlDom4JHelper.getNodeText("data-value", dataNode);
        // $NON-NLS-1$
        nameItem = XmlDom4JHelper.getNodeText("data-name", dataNode);
        // $NON-NLS-1$
        widgetWidth = (int) XmlDom4JHelper.getNodeText("widgetgrid/width", dataActionDocument, 125);
        // $NON-NLS-1$
        widgetHeight = (int) XmlDom4JHelper.getNodeText("widgetgrid/height", dataActionDocument, 125);
        // $NON-NLS-1$
        columns = (int) XmlDom4JHelper.getNodeText("widgetgrid/columns", dataActionDocument, 2);
        // $NON-NLS-1$
        style = XmlDom4JHelper.getNodeText("widgetgrid/style", dataActionDocument);
    } catch (Exception e) {
        error(Messages.getInstance().getErrorString("WidgetGrid.ERROR_0003_DEFINITION_NOT_VALID", widgetGridDataDefinition), // $NON-NLS-1$
        e);
        return false;
    }
    return true;
}
Also used : Node(org.dom4j.Node) Document(org.dom4j.Document) IOException(java.io.IOException) SolutionURIResolver(org.pentaho.platform.engine.services.SolutionURIResolver)

Example 4 with SolutionURIResolver

use of org.pentaho.platform.engine.services.SolutionURIResolver in project pentaho-platform by pentaho.

the class InputFormComponent method getXmlContent.

/*
   * (non-Javadoc)
   * 
   * @see org.pentaho.core.ui.component.BaseUIComponent#getXmlContent()
   */
@Override
public Document getXmlContent() {
    ActionSequenceJCRHelper actionHelper = new ActionSequenceJCRHelper(getSession());
    IActionSequence actionSequence = actionHelper.getActionSequence(ActionInfo.buildSolutionPath(solution, path, actionName), getLoggingLevel(), RepositoryFilePermission.READ);
    if (actionSequence == null) {
        // TODO log this
        // $NON-NLS-1$
        error(Messages.getInstance().getString("InputForm.ERROR_0004_ACTION_NOT_FOUND") + solution + path + actionName);
        return null;
    }
    List actions = actionSequence.getActionDefinitionsAndSequences();
    ISolutionActionDefinition action = (ISolutionActionDefinition) actions.get(0);
    Node node = action.getComponentSection();
    if (node == null) {
        // $NON-NLS-1$
        error(Messages.getInstance().getString("InputForm.ERROR_0005_INBOX_DEFINITION_MISSING") + solution + path + actionName);
        return null;
    }
    if (templateName == null) {
        // see if the template is specified in the action document
        // $NON-NLS-1$
        Node templateNode = node.selectSingleNode("//template");
        if (templateNode != null) {
            templateName = templateNode.getText();
        }
        if (templateName == null) {
            // $NON-NLS-1$
            error(Messages.getInstance().getString("InputForm.ERROR_0006_TEMPLATE_NOT_SPECIFIED"));
            return null;
        }
    }
    // $NON-NLS-1$
    Node xFormNode = node.selectSingleNode("//xForm");
    try {
        String actionTitle = actionSequence.getTitle();
        if (actionTitle != null) {
            // $NON-NLS-1$
            setXslProperty("title", actionTitle);
        }
        String description = actionSequence.getDescription();
        if (description != null) {
            // $NON-NLS-1$
            setXslProperty("description", description);
        }
        String xFormHtml = XForm.transformSnippet(xFormNode, getSession(), new SolutionURIResolver());
        if (xFormHtml == null) {
            // $NON-NLS-1$
            error(Messages.getInstance().getString("InputForm.ERROR_0007_INBOX_DEFINITION_INVALID") + solution + path + actionName);
            return null;
        }
        Document document = DocumentHelper.parseText(xFormHtml);
        // $NON-NLS-1$
        Node xFormHtmlNode = document.selectSingleNode("//xForm");
        // $NON-NLS-1$
        setXslProperty("xForm", xFormHtmlNode.asXML());
        if ((stylesheetName != null) && !"".equals(stylesheetName)) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            setXslProperty("css", stylesheetName);
        }
        // $NON-NLS-1$
        setXsl("text/html", templateName);
        return document;
    } catch (Exception e) {
        return null;
    }
}
Also used : IActionSequence(org.pentaho.platform.api.engine.IActionSequence) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition) Node(org.dom4j.Node) List(java.util.List) ActionSequenceJCRHelper(org.pentaho.platform.engine.services.ActionSequenceJCRHelper) Document(org.dom4j.Document) SolutionURIResolver(org.pentaho.platform.engine.services.SolutionURIResolver)

Example 5 with SolutionURIResolver

use of org.pentaho.platform.engine.services.SolutionURIResolver in project pentaho-platform by pentaho.

the class RuntimeContext method getResourceAsDocument.

public Document getResourceAsDocument(final IActionSequenceResource actionResource) throws IOException {
    if (isEmbeddedResource(actionResource)) {
        try {
            return XmlDom4JHelper.getDocFromString(getEmbeddedResource(actionResource), null);
        } catch (XmlParseException e) {
            // $NON-NLS-1$
            error(Messages.getInstance().getString("RuntimeContext.ERROR_UNABLE_TO_GET_RESOURCE_AS_DOCUMENT"), e);
            return null;
        }
    }
    Document document = null;
    try {
        org.dom4j.io.SAXReader reader = XMLParserFactoryProducer.getSAXReader(new SolutionURIResolver());
        document = reader.read(actionResource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale()));
    } catch (Throwable t) {
    // XML document can't be read. We'll just return a null document.
    }
    return document;
}
Also used : XmlParseException(org.pentaho.platform.api.util.XmlParseException) Document(org.dom4j.Document) SolutionURIResolver(org.pentaho.platform.engine.services.SolutionURIResolver)

Aggregations

Document (org.dom4j.Document)9 SolutionURIResolver (org.pentaho.platform.engine.services.SolutionURIResolver)9 File (java.io.File)2 IOException (java.io.IOException)2 Element (org.dom4j.Element)2 Node (org.dom4j.Node)2 FilenameFilter (java.io.FilenameFilter)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 TransformerException (javax.xml.transform.TransformerException)1 NameFileFilter (org.apache.commons.io.filefilter.NameFileFilter)1 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)1 ActionSequencePromptException (org.pentaho.platform.api.engine.ActionSequencePromptException)1 IActionSequence (org.pentaho.platform.api.engine.IActionSequence)1 IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)1 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)1