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);
}
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);
}
}
}
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;
}
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);
}
}
}
}
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);
}
Aggregations