Search in sources :

Example 1 with XOMException

use of org.eigenbase.xom.XOMException in project pentaho-platform by pentaho.

the class MondrianCatalogHelper method parseDataSources.

protected DataSourcesConfig.DataSources parseDataSources(final String dataSourcesConfigString) {
    try {
        if (dataSourcesConfigString == null) {
            MondrianCatalogHelper.logger.warn(Messages.getInstance().getString(// $NON-NLS-1$
            "MondrianCatalogHelper.WARN_PARSE_NULL_INPUT"));
            return null;
        }
        String replacedConfigString = Util.replaceProperties(dataSourcesConfigString, Util.toMap(System.getProperties()));
        if (MondrianCatalogHelper.logger.isDebugEnabled()) {
            // $NON-NLS-1$
            String msg = "parseDataSources: dataSources=" + replacedConfigString;
            MondrianCatalogHelper.logger.debug(msg);
        }
        final Parser parser = XOMUtil.createDefaultParser();
        final DOMWrapper doc = parser.parse(replacedConfigString);
        catalogComplementInfoMap = makeCatalogComplementInfoMap(doc);
        return new DataSourcesConfig.DataSources(doc);
    } catch (XOMException e) {
        throw Util.newError(e, Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0002_FAILED_TO_PARSE_DATASOURCE_CONFIG", dataSourcesConfigString));
    }
}
Also used : DataSources(mondrian.xmla.DataSourcesConfig.DataSources) XOMException(org.eigenbase.xom.XOMException) DOMWrapper(org.eigenbase.xom.DOMWrapper) Parser(org.eigenbase.xom.Parser)

Example 2 with XOMException

use of org.eigenbase.xom.XOMException in project pentaho-platform by pentaho.

the class MondrianCatalogHelper method makeSchema.

protected MondrianSchema makeSchema(final String catalogStr) {
    if (MondrianCatalogHelper.logger.isDebugEnabled()) {
        MondrianCatalogHelper.logger.debug("makeSchema (catalogStr=" + catalogStr.substring(0, Math.min(40, catalogStr.length())) + "...)");
    }
    MondrianSchema schema = null;
    try {
        final Parser xmlParser = XOMUtil.createDefaultParser();
        final DOMWrapper def = xmlParser.parse(catalogStr);
        MondrianDef.Schema schemaFromXml = new MondrianDef.Schema(def);
        String schemaName = schemaFromXml.name;
        List<MondrianCube> mondrianCubes = new ArrayList<MondrianCube>();
        for (MondrianDef.Cube cube : schemaFromXml.cubes) {
            if (cube.enabled == null || cube.enabled.booleanValue()) {
                String name = cube.caption;
                if (StringUtils.isBlank(name)) {
                    name = cube.name;
                }
                mondrianCubes.add(new MondrianCube(name, cube.name));
            }
        }
        for (MondrianDef.VirtualCube cube : schemaFromXml.virtualCubes) {
            String name = cube.caption;
            if (StringUtils.isBlank(name)) {
                name = cube.name;
            }
            if (cube.enabled == null || cube.enabled.booleanValue()) {
                mondrianCubes.add(new MondrianCube(name, cube.name));
            }
        }
        // Interpret the role names
        MondrianDef.Role[] roles = schemaFromXml.roles;
        String[] roleNames = null;
        if ((roles != null) && (roles.length > 0)) {
            roleNames = new String[roles.length];
            for (int i = 0; i < roles.length; i++) {
                // Note - getName() doesn't return the role name, it returns the word Role
                roleNames[i] = roles[i].name;
            }
        }
        schema = new MondrianSchema(schemaName, mondrianCubes, roleNames);
    } catch (XOMException e) {
        if (MondrianCatalogHelper.logger.isErrorEnabled()) {
            MondrianCatalogHelper.logger.error(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0008_ERROR_OCCURRED"), // $NON-NLS-1$
            e);
        }
        throw Util.newError(e, Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0009_WHILE_PARSING_CATALOG", // $NON-NLS-1$
        catalogStr));
    }
    return schema;
}
Also used : XOMException(org.eigenbase.xom.XOMException) ArrayList(java.util.ArrayList) Parser(org.eigenbase.xom.Parser) MondrianDef(mondrian.olap.MondrianDef) DOMWrapper(org.eigenbase.xom.DOMWrapper)

Aggregations

DOMWrapper (org.eigenbase.xom.DOMWrapper)2 Parser (org.eigenbase.xom.Parser)2 XOMException (org.eigenbase.xom.XOMException)2 ArrayList (java.util.ArrayList)1 MondrianDef (mondrian.olap.MondrianDef)1 DataSources (mondrian.xmla.DataSourcesConfig.DataSources)1