Package org.pentaho.reporting.engine.classic.core.metadata

Source Code of org.pentaho.reporting.engine.classic.core.metadata.ElementMetaDataParser

/*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
* Foundation.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* or from the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* Copyright (c) 2001 - 2009 Object Refinery Ltd, Pentaho Corporation and Contributors..  All rights reserved.
*/

package org.pentaho.reporting.engine.classic.core.metadata;

import java.net.URL;
import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
import org.pentaho.reporting.libraries.base.boot.ModuleInitializeException;
import org.pentaho.reporting.libraries.base.config.Configuration;
import org.pentaho.reporting.libraries.base.util.ObjectUtilities;

/**
* Todo: Document Me
*
* @author Thomas Morgner
*/
public class ElementMetaDataParser
{
  public static final String GLOBAL_INCLUDES_PREFIX =
      "org.pentaho.reporting.engine.classic.core.metadata.global-includes.";

  private static final Log logger = LogFactory.getLog(ElementMetaDataParser.class);

  private ElementMetaDataParser()
  {
  }

  public static void initializeElementMetaData() throws ModuleInitializeException
  {

    final String namespaceRegistryPrefix = "org.pentaho.reporting.engine.classic.core.metadata.namespaces.";
    final Configuration configuration = ClassicEngineBoot.getInstance().getGlobalConfig();
    final Iterator keys = configuration.findPropertyKeys(namespaceRegistryPrefix);
    while (keys.hasNext())
    {
      final String key = (String) keys.next();
      final String prefix = key.substring(namespaceRegistryPrefix.length());
      final String namespaceUri = configuration.getConfigProperty(key);
      if (prefix.length() == 0 || namespaceUri == null || namespaceUri.length() == 0)
      {
        continue;
      }
      ElementTypeRegistry.getInstance().registerNamespacePrefix(namespaceUri, prefix);
    }


    final URL metaDataSource = ObjectUtilities.getResource
        ("org/pentaho/reporting/engine/classic/core/metadata/meta-elements.xml", ElementMetaDataParser.class);
    if (metaDataSource == null)
    {
      throw new ModuleInitializeException("Error: Could not find the core element meta-data description file");
    }
    try
    {
      ElementTypeRegistry.getInstance().registerFromXml(metaDataSource);
    }
    catch (Exception e)
    {
      logger.debug("Failed:", e);
      throw new ModuleInitializeException("Error: Could not parse the element meta-data description file", e);
    }

    final URL expressionMetaSource = ObjectUtilities.getResource
        ("org/pentaho/reporting/engine/classic/core/function/meta-expressions.xml", ElementMetaDataParser.class);
    if (expressionMetaSource == null)
    {
      throw new ModuleInitializeException("Error: Could not find the core expression meta-data description file");
    }
    try
    {
      ExpressionRegistry.getInstance().registerFromXml(expressionMetaSource);
    }
    catch (Exception e)
    {
      logger.debug("Failed:", e);
      throw new ModuleInitializeException("Error: Could not parse the expression meta-data description file", e);
    }

    final URL dataFactoryMetaSource = ObjectUtilities.getResource
        ("org/pentaho/reporting/engine/classic/core/metadata/meta-datafactory.xml", ElementMetaDataParser.class);
    if (dataFactoryMetaSource == null)
    {
      throw new ModuleInitializeException("Error: Could not find the core dataFactory meta-data description file");
    }
    try
    {
      DataFactoryRegistry.getInstance().registerFromXml(dataFactoryMetaSource);
    }
    catch (Exception e)
    {
      logger.debug("Failed:", e);
      throw new ModuleInitializeException("Error: Could not parse the datafactory meta-data description file", e);
    }

    final URL reportPreProcessorMetaSource = ObjectUtilities.getResource
        ("org/pentaho/reporting/engine/classic/core/metadata/meta-report-preprocessors.xml", ElementMetaDataParser.class);
    if (reportPreProcessorMetaSource == null)
    {
      throw new ModuleInitializeException("Error: Could not find the core report-preprocessor meta-data description file");
    }
    try
    {
      ReportPreProcessorRegistry.getInstance().registerFromXml(reportPreProcessorMetaSource);
    }
    catch (Exception e)
    {
      logger.debug("Failed:", e);
      throw new ModuleInitializeException("Error: Could not parse the report-preprocessor meta-data description file", e);
    }
  }

  public static void initializeOptionalReportPreProcessorMetaData(final String source) throws ModuleInitializeException
  {
    final URL reportPreProcessorMetaSource = ObjectUtilities.getResource(source, ElementMetaDataParser.class);
    if (reportPreProcessorMetaSource == null)
    {
      throw new ModuleInitializeException("Error: Could not find the core report-preprocessor meta-data description file");
    }
    try
    {
      ReportPreProcessorRegistry.getInstance().registerFromXml(reportPreProcessorMetaSource);
    }
    catch (Exception e)
    {
      logger.debug("Failed:", e);
      throw new ModuleInitializeException("Error: Could not parse the report-preprocessor meta-data description file", e);
    }
  }

  public static void initializeOptionalExpressionsMetaData(final String source) throws ModuleInitializeException
  {
    final URL expressionMetaSource = ObjectUtilities.getResource
        (source, ElementMetaDataParser.class);
    if (expressionMetaSource == null)
    {
      throw new ModuleInitializeException("Error: Could not find the expression meta-data description file");
    }
    try
    {
      ExpressionRegistry.getInstance().registerFromXml(expressionMetaSource);
    }
    catch (Exception e)
    {
      logger.debug("Failed:", e);
      throw new ModuleInitializeException("Error: Could not parse the expression meta-data description file", e);
    }
  }

  public static void initializeOptionalElementMetaData(final String source) throws ModuleInitializeException
  {
    final URL metaDataSource = ObjectUtilities.getResource(source, ElementMetaDataParser.class);
    if (metaDataSource == null)
    {
      throw new ModuleInitializeException("Error: Could not find the optional element meta-data description file");
    }
    try
    {
      ElementTypeRegistry.getInstance().registerFromXml(metaDataSource);
    }
    catch (Exception e)
    {
      logger.debug("Failed:", e);
      throw new ModuleInitializeException("Error: Could not parse the element meta-data description file", e);
    }

  }

  public static void initializeOptionalDataFactoryMetaData(final String source) throws ModuleInitializeException
  {
    final URL expressionMetaSource = ObjectUtilities.getResource(source, ElementMetaDataParser.class);
    if (expressionMetaSource == null)
    {
      throw new ModuleInitializeException("Error: Could not find the datafactory meta-data description file");
    }
    try
    {
      DataFactoryRegistry.getInstance().registerFromXml(expressionMetaSource);
    }
    catch (Exception e)
    {
      logger.debug("Failed:", e);
      throw new ModuleInitializeException("Error: Could not parse the datafactory meta-data description file", e);
    }
  }
}
TOP

Related Classes of org.pentaho.reporting.engine.classic.core.metadata.ElementMetaDataParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.