Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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 2006 - 2009 Pentaho Corporation.  All rights reserved.
  *
 */
 package org.pentaho.platform.plugin.action.jfreereport.helper;
 
 import java.net.URL;
 import java.util.Map;
 
 import  org.pentaho.reporting.libraries.resourceloader.ResourceData;
 import  org.pentaho.reporting.libraries.resourceloader.ResourceKey;
 import  org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException;
 import  org.pentaho.reporting.libraries.resourceloader.ResourceLoader;
 import  org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException;
 import  org.pentaho.reporting.libraries.resourceloader.ResourceManager;
 import  org.pentaho.reporting.libraries.resourceloader.loader.LoaderUtils;

This class is implemented to support loading solution files from the pentaho repository into JFreeReport

Author(s):
Will Gorman
 
 public class PentahoResourceLoader implements ResourceLoader {
 
   public static final String SOLUTION_SCHEMA_NAME = "solution"//$NON-NLS-1$
 
   public static final String SCHEMA_SEPARATOR = ":/"//$NON-NLS-1$
 
   public static final String PATH_SEPARATOR = "/"//$NON-NLS-1$
 
   public static final String WIN_PATH_SEPARATOR = "\\"//$NON-NLS-1$
 
  
keep track of the resource manager
 
   private ResourceManager manager;

  
default constructor
 
   public PentahoResourceLoader() {
   }

  
set the resource manager

Parameters:
manager resource manager
 
   public void setResourceManager(final ResourceManager manager) {
     this. = manager;
   }

  
get the resource manager

Returns:
resource manager
 
   public ResourceManager getManager() {
     return ;
   }

  
get the schema name, in this case it's always "solution"

Returns:
the schema name
 
   public String getSchema() {
   }

  
create a resource data object

Parameters:
key resource key
Returns:
resource data
Throws:
ResourceLoadingException
 
   public ResourceData load(final ResourceKey keythrows ResourceLoadingException {
     return new PentahoResourceData(key);
   }

  
see if the pentaho resource loader can support the content key path

Parameters:
values map of values to look in
Returns:
true if class supports the content key.
  public boolean isSupportedKey(final ResourceKey key) {
    if (key.getSchema().equals(getSchema())) {
      return true;
    }
    return false;
  }

  
create a new key based on the values provided

Parameters:
values map of values
Returns:
new resource key
Throws:
ResourceKeyCreationException
  public ResourceKey createKey(final Object valuefinal Map factoryKeysthrows ResourceKeyCreationException {
    if (value instanceof String) {
      String valueString = (Stringvalue;
      if (valueString.startsWith(getSchema() + .)) {
        valueString = valueString.replace('\\''/');
        String path = valueString.substring(getSchema().length() + ..length());
        return new ResourceKey(getSchema(), pathfactoryKeys);
      }
    }
    return null;
  }

  
derive a key from an existing key, used when a relative path is given.

Parameters:
parent the parent key
data the new data to be keyed
Returns:
derived key
Throws:
ResourceKeyCreationException
  public ResourceKey deriveKey(final ResourceKey parentfinal String pathfinal Map data)
      throws ResourceKeyCreationException {
    if (isSupportedKey(parent) == false) {
      throw new ResourceKeyCreationException("Assertation: Unsupported parent key type"); //$NON-NLS-1$
    }
    final String resource;
    if (path.startsWith("solution://")) //$NON-NLS-1$
    {
      resource = path;
    } else if (path.startsWith("/")) //$NON-NLS-1$
    {
      resource = "solution:/" + path//$NON-NLS-1$
    } else {
      resource = LoaderUtils.mergePaths((Stringparent.getIdentifier(), path);
    }
    if (!resource.startsWith(getSchema())) {
        throw new ResourceKeyCreationException("Assertation: Unsupported key type"); //$NON-NLS-1$
    }
    final Map map;
    if (data != null) {
      map = new HashMap();
      map.putAll(parent.getFactoryParameters());
      map.putAll(data);
    } else {
      map = parent.getFactoryParameters();
    }
    
    return new ResourceKey(parent.getSchema(), resourcemap);
  }
  public URL toURL(final ResourceKey key) {
    // not supported ..
    return null;
  }
New to GrepCode? Check out our FAQ X