Search in sources :

Example 1 with XMLOutput

use of org.eigenbase.xom.XMLOutput in project mondrian by pentaho.

the class DiffRepository method write.

/**
 * Serializes an XML document as text.
 *
 * <p>FIXME: I'm sure there's a library call to do this, but I'm danged
 * if I can find it. -- jhyde, 2006/2/9.
 */
private static void write(Document doc, Writer w) {
    final XMLOutput out = new XMLOutput(w);
    out.setIndentString("    ");
    writeNode(doc, out);
}
Also used : XMLOutput(org.eigenbase.xom.XMLOutput)

Example 2 with XMLOutput

use of org.eigenbase.xom.XMLOutput in project mondrian by pentaho.

the class Workbench method saveMenuItemActionPerformed.

public void saveMenuItemActionPerformed(ActionEvent evt) {
    JInternalFrame jf = desktopPane.getSelectedFrame();
    // Don't save if nothing there
    if (jf == null || jf.getContentPane() == null) {
        return;
    }
    if (jf.getContentPane().getComponent(0) instanceof SchemaExplorer) {
        SchemaExplorer se = (SchemaExplorer) jf.getContentPane().getComponent(0);
        java.io.File schemaFile = se.getSchemaFile();
        if (se.isNewFile()) {
            saveAsMenuItemActionPerformed(evt);
            return;
        }
        se.setDirty(false);
        se.setDirtyFlag(false);
        // sets title of iframe
        se.setTitle();
        MondrianGuiDef.Schema schema = se.getSchema();
        if (!isSchemaValid(schema)) {
            // the schema would not be re-loadable.  Abort save.
            return;
        }
        MondrianProperties.instance();
        try {
            XMLOutput out = new XMLOutput(new FileWriter(schemaFile));
            out.setAlwaysQuoteCData(true);
            out.setIndentString("  ");
            schema.displayXML(out);
            setLastUsed(schemaFile.getName(), schemaFile.toURI().toURL().toString());
        } catch (Exception ex) {
            LOGGER.error("saveMenuItemActionPerformed", ex);
        }
    }
}
Also used : java.io(java.io) XMLOutput(org.eigenbase.xom.XMLOutput) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException)

Example 3 with XMLOutput

use of org.eigenbase.xom.XMLOutput in project mondrian by pentaho.

the class Workbench method isSchemaValid.

/**
 * Validates that the schema can be parsed and loaded,
 * showing a warning message if any errors are encountered.
 */
private boolean isSchemaValid(MondrianGuiDef.Schema schema) {
    try {
        StringWriter writer = new StringWriter();
        XMLOutput xmlOutput = new XMLOutput(writer);
        schema.displayXML(xmlOutput);
        Parser xmlParser = XOMUtil.createDefaultParser();
        Reader reader = new StringReader(writer.getBuffer().toString());
        // attempt to create a new schema
        new MondrianGuiDef.Schema(xmlParser.parse(reader));
    } catch (XOMException e) {
        JOptionPane.showMessageDialog(this, getResourceConverter().getFormattedString("workbench.save.invalid.schema", "Please correct the following error before saving:", e.getLocalizedMessage()), getResourceConverter().getFormattedString("workbench.save.invalid.schema.title", "Cannot Save"), JOptionPane.WARNING_MESSAGE);
        return false;
    }
    return true;
}
Also used : XMLOutput(org.eigenbase.xom.XMLOutput)

Example 4 with XMLOutput

use of org.eigenbase.xom.XMLOutput in project mondrian by pentaho.

the class Workbench method saveAsMenuItemActionPerformed.

private void saveAsMenuItemActionPerformed(ActionEvent evt) {
    JInternalFrame jf = desktopPane.getSelectedFrame();
    if (jf != null && jf.getContentPane().getComponent(0) instanceof SchemaExplorer) {
        SchemaExplorer se = (SchemaExplorer) jf.getContentPane().getComponent(0);
        java.io.File schemaFile = se.getSchemaFile();
        java.io.File oldSchemaFile = schemaFile;
        java.io.File suggSchemaFile = new File(schemaFile == null ? se.getSchema().name.trim() + ".xml" : schemaFile.getName());
        MondrianGuiDef.Schema schema = se.getSchema();
        JFileChooser jfc = new JFileChooser();
        MondrianProperties.instance();
        jfc.setSelectedFile(suggSchemaFile);
        if (!isSchemaValid(schema)) {
            // the schema would not be re-loadable.  Abort save.
            return;
        }
        if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                schemaFile = jfc.getSelectedFile();
                if (!oldSchemaFile.equals(schemaFile) && schemaFile.exists()) {
                    // new file already exists, check for overwrite
                    int answer = JOptionPane.showConfirmDialog(null, getResourceConverter().getFormattedString("workbench.saveAs.schema.confirm", "{0} schema file already exists. Do you want to replace it?", schemaFile.getAbsolutePath()), getResourceConverter().getString("workbench.saveAs.schema.confirm.title", "Save As"), JOptionPane.YES_NO_OPTION);
                    if (answer == 1) {
                        // no=1 ; yes=0
                        return;
                    }
                }
                if (se.isNewFile() && !oldSchemaFile.equals(schemaFile)) {
                    oldSchemaFile.delete();
                }
                if (se.isNewFile()) {
                    se.setNewFile(false);
                }
                se.setDirty(false);
                se.setDirtyFlag(false);
                XMLOutput out = new XMLOutput(new java.io.FileWriter(jfc.getSelectedFile()));
                out.setAlwaysQuoteCData(true);
                out.setIndentString("  ");
                schema.displayXML(out);
                se.setSchemaFile(schemaFile);
                // sets title of iframe
                se.setTitle();
                setLastUsed(jfc.getSelectedFile().getName(), jfc.getSelectedFile().toURI().toURL().toString());
                // Update menu item with new file name, then update catalog
                // list for mdx queries
                JMenuItem sMenuItem = schemaWindowMap.get(jf);
                String[] mtexttokens = sMenuItem.getText().split(" ");
                sMenuItem.setText(mtexttokens[0] + " " + se.getSchemaFile().getName());
                // Schema menu item updated, now update mdx query windows
                // with updated catalog list.
                updateMDXCatalogList();
            } catch (Exception ex) {
                LOGGER.error(ex);
            }
        }
    }
}
Also used : java.io(java.io) XMLOutput(org.eigenbase.xom.XMLOutput) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException)

Example 5 with XMLOutput

use of org.eigenbase.xom.XMLOutput 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)

Aggregations

XMLOutput (org.eigenbase.xom.XMLOutput)5 java.io (java.io)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 KettleException (org.pentaho.di.core.exception.KettleException)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 URL (java.net.URL)1 Document (org.dom4j.Document)1 OutputFormat (org.dom4j.io.OutputFormat)1 XMLWriter (org.dom4j.io.XMLWriter)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 XmlParseException (org.pentaho.platform.api.util.XmlParseException)1 PentahoEntityResolver (org.pentaho.platform.engine.services.solution.PentahoEntityResolver)1