Search in sources :

Example 6 with XmlParseException

use of org.pentaho.platform.api.util.XmlParseException in project pentaho-platform by pentaho.

the class MondrianCatalogHelper method writeDataSources.

@Deprecated
protected void writeDataSources(DataSources dataSources) {
    File dataSourcesFile;
    try {
        // dataSourcesConfigResource.getFile();
        dataSourcesFile = new File(new URL(dataSourcesConfig).getFile());
    } catch (IOException e) {
        throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0005_RESOURCE_NOT_AVAILABLE"), e, // $NON-NLS-1$
        Reason.GENERAL);
    }
    Writer sxml;
    try {
        sxml = new FileWriter(dataSourcesFile);
    } catch (IOException e) {
        throw new MondrianCatalogServiceException(e);
    }
    StringWriter sw = new StringWriter();
    XMLOutput pxml = new XMLOutput(sw);
    // $NON-NLS-1$
    pxml.print("<?xml version=\"1.0\"?>\n");
    dataSources.displayXML(pxml, 0);
    Document doc = null;
    try {
        doc = XmlDom4JHelper.getDocFromString(sw.toString(), new PentahoEntityResolver());
    } catch (XmlParseException e) {
        throw new MondrianCatalogServiceException(e);
    }
    // pretty print
    try {
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setEncoding(doc.getXMLEncoding());
        XMLWriter writer = new XMLWriter(sxml, format);
        writer.write(doc);
        writer.close();
    // CleanXmlHelper.saveDomToWriter(doc, sxml);
    } catch (IOException e) {
        throw new MondrianCatalogServiceException(e);
    }
    IOUtils.closeQuietly(sxml);
}
Also used : FileWriter(java.io.FileWriter) XMLOutput(org.eigenbase.xom.XMLOutput) OutputFormat(org.dom4j.io.OutputFormat) IOException(java.io.IOException) XmlParseException(org.pentaho.platform.api.util.XmlParseException) Document(org.dom4j.Document) PentahoEntityResolver(org.pentaho.platform.engine.services.solution.PentahoEntityResolver) XMLWriter(org.dom4j.io.XMLWriter) URL(java.net.URL) StringWriter(java.io.StringWriter) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) Writer(java.io.Writer) XMLWriter(org.dom4j.io.XMLWriter) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter)

Example 7 with XmlParseException

use of org.pentaho.platform.api.util.XmlParseException in project pentaho-platform by pentaho.

the class OpenFlashChartComponent method executeAction.

protected boolean executeAction() {
    // $NON-NLS-1$
    log.debug("start to run open flash chart component......");
    // input data
    IPentahoResultSet data = (IPentahoResultSet) getInputValue(CHART_DATA);
    if (!data.isScrollable()) {
        // $NON-NLS-1$
        getLogger().debug("ResultSet is not scrollable. Copying into memory");
        IPentahoResultSet memSet = data.memoryCopy();
        data.close();
        data = memSet;
    }
    // chart width
    String chartWidth = null;
    String inputWidth = getInputStringValue(CHART_WIDTH);
    if (inputWidth == null) {
        chartWidth = DEFAULT_WIDTH;
    } else {
        chartWidth = inputWidth;
    }
    // chart height
    String chartHeight = null;
    String inputHeight = getInputStringValue(CHART_HEIGHT);
    if (null == inputHeight) {
        chartHeight = DEFAULT_HEIGHT;
    } else {
        chartHeight = inputHeight;
    }
    // swf file location
    String ofcURL = getInputStringValue(OFC_URL);
    if (ofcURL == null || "".equals(ofcURL)) {
        // $NON-NLS-1$
        ofcURL = PentahoRequestContextHolder.getRequestContext().getContextPath() + DEFAULT_FLASH_LOC;
    }
    // swf file name
    String ofclibname = getInputStringValue(OFC_LIB_NAME);
    if (ofclibname == null || "".equals(ofclibname)) {
        // $NON-NLS-1$
        ofclibname = DEFAULT_FLASH_SWF;
    }
    // chart definition
    String chartAttributeString = null;
    if (getInputNames().contains(CHART_ATTRIBUTES)) {
        chartAttributeString = getInputStringValue(CHART_ATTRIBUTES);
    } else if (isDefinedResource(CHART_ATTRIBUTES)) {
        IActionSequenceResource resource = getResource(CHART_ATTRIBUTES);
        chartAttributeString = getResourceAsString(resource);
    }
    Node chartNode = null;
    if (chartAttributeString != null) {
        // apply any additional inputs to the chart definition
        chartAttributeString = applyInputsToFormat(chartAttributeString);
        try {
            Document chartDocument = XmlDom4JHelper.getDocFromString(chartAttributeString, new PentahoEntityResolver());
            chartNode = chartDocument.selectSingleNode(CHART_NODE_LOC);
            if (chartNode == null) {
                chartNode = chartDocument.selectSingleNode(CHART_ATTRIBUTES);
            }
        } catch (XmlParseException e) {
            getLogger().error(Messages.getInstance().getErrorString("OpenFlashChartComponent.ERROR_0001_CANT_DOCUMENT_FROM_STRING"), // $NON-NLS-1$
            e);
            return false;
        }
    } else {
        // see if the chart-attributes node is available in the component definition
        chartNode = getComponentDefinition(true).selectSingleNode(CHART_ATTRIBUTES);
    }
    if (chartNode == null) {
        getLogger().error(// $NON-NLS-1$
        Messages.getInstance().getErrorString("OpenFlashChartComponent.ERROR_0002_CHART_DEFINITION_NOT_FOUND"));
        return false;
    }
    // Determine if we are going to read the chart data set by row or by column
    boolean byRow = false;
    if (getInputStringValue(BY_ROW_PROP) != null) {
        byRow = Boolean.valueOf(getInputStringValue(BY_ROW_PROP)).booleanValue();
    }
    String chartJson = generateChartJson(data, chartNode, byRow);
    // generate a unique name for the function
    // $NON-NLS-1$ //$NON-NLS-2$
    String chartId = UUIDUtil.getUUIDAsString().replaceAll("[^\\w]", "");
    // populate the flash html template
    Properties props = new Properties();
    // $NON-NLS-1$
    props.setProperty("chartId", chartId);
    // $NON-NLS-1$ //$NON-NLS-2$
    props.setProperty("dataFunction", "getData" + chartId);
    // $NON-NLS-1$
    props.setProperty("chart-width", chartWidth);
    // $NON-NLS-1$
    props.setProperty("chart-height", chartHeight);
    // $NON-NLS-1$
    props.setProperty("ofc-url", ofcURL);
    // $NON-NLS-1$
    props.setProperty("ofc-libname", ofclibname);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    props.setProperty("chartJson", chartJson.replaceAll("\"", "\\\\\""));
    String flashContent = TemplateUtil.applyTemplate(getFlashFragment(), props, null);
    // set output value
    // $NON-NLS-1$
    log.debug("html_fragment=" + flashContent);
    if (this.isDefinedOutput("html_fragment")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        this.setOutputValue("html_fragment", flashContent);
    }
    if (this.isDefinedOutput("image-tag")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        this.setOutputValue("image-tag", flashContent);
    }
    return true;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) Node(org.dom4j.Node) XmlParseException(org.pentaho.platform.api.util.XmlParseException) Document(org.dom4j.Document) Properties(java.util.Properties) PentahoEntityResolver(org.pentaho.platform.engine.services.solution.PentahoEntityResolver) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource)

Example 8 with XmlParseException

use of org.pentaho.platform.api.util.XmlParseException in project pentaho-platform by pentaho.

the class XmlDom4JHelper method convertToDom4JDoc.

public static org.dom4j.Document convertToDom4JDoc(final org.w3c.dom.Document doc) throws TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError, DocumentException {
    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(new StringWriter());
    TransformerFactory.newInstance().newTransformer().transform(source, result);
    String theXML = result.getWriter().toString();
    Document dom4jDoc = null;
    try {
        dom4jDoc = getDocFromString(theXML, null);
    } catch (XmlParseException e) {
        new TransformerFactoryConfigurationError(e);
    }
    return dom4jDoc;
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) DOMSource(javax.xml.transform.dom.DOMSource) StreamResult(javax.xml.transform.stream.StreamResult) StringWriter(java.io.StringWriter) XmlParseException(org.pentaho.platform.api.util.XmlParseException) Document(org.dom4j.Document)

Aggregations

XmlParseException (org.pentaho.platform.api.util.XmlParseException)8 Document (org.dom4j.Document)7 PentahoEntityResolver (org.pentaho.platform.engine.services.solution.PentahoEntityResolver)6 Node (org.dom4j.Node)4 StringWriter (java.io.StringWriter)3 File (java.io.File)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 List (java.util.List)2 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)2 IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)2 BufferedWriter (java.io.BufferedWriter)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1