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