use of org.pentaho.reporting.libraries.resourceloader.ResourceKey in project pentaho-platform by pentaho.
the class PentahoResourceLoader method deriveKey.
/**
* derive a key from an existing key, used when a relative path is given.
*
* @param parent
* the parent key
* @param data
* the new data to be keyed
* @return derived key
* @throws ResourceKeyCreationException
*/
public ResourceKey deriveKey(final ResourceKey parent, final String path, final Map data) throws ResourceKeyCreationException {
if (isSupportedKey(parent) == false) {
// $NON-NLS-1$
throw new ResourceKeyCreationException("Assertation: Unsupported parent key type");
}
String resource;
if (path.startsWith("solution://")) {
resource = path;
} else if (path.startsWith("/")) {
// $NON-NLS-1$
resource = "solution:/" + path;
} else {
resource = LoaderUtils.mergePaths((String) parent.getIdentifier(), path);
// add the slash. We do need to make sure that the resource is not a url
if (!resource.startsWith(HTTP_URL_PREFIX) && !resource.startsWith(PATH_SEPARATOR)) {
resource = PATH_SEPARATOR + resource;
}
}
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(), resource, map);
}
use of org.pentaho.reporting.libraries.resourceloader.ResourceKey in project pentaho-kettle by pentaho.
the class PentahoReportingOutputTest method setUp.
@Before
public void setUp() throws ResourceException {
testResourceUrl = this.getClass().getResource("relative-path.prpt");
resourceKey = new ResourceKey("org.pentaho.reporting.libraries.resourceloader.loader.URLResourceLoader", testResourceUrl, null);
DataFactory mockedDataFactory = mock(DataFactory.class);
when(mockedDataFactory.getQueryNames()).thenReturn(new String[] { QUERY_NAME });
ResourceManager manager = new ResourceManager();
manager.registerDefaults();
MasterReport mockedMasterReport = mock(MasterReport.class);
when(mockedMasterReport.getDataFactory()).thenReturn(mockedDataFactory);
when(mockedMasterReport.getResourceManager()).thenReturn(manager);
Resource resource = mock(CompoundResource.class);
when(resource.getResource()).thenReturn(mockedMasterReport);
when(resource.getDependencies()).thenReturn(new ResourceKey[] {});
when(resource.getSource()).thenReturn(resourceKey);
when(resource.getTargetType()).thenReturn(MasterReport.class);
manager.getFactoryCache().put(resource);
PowerMockito.stub(PowerMockito.method(DefaultResourceManagerBackend.class, "create")).toReturn(resource);
}
use of org.pentaho.reporting.libraries.resourceloader.ResourceKey in project pentaho-platform by pentaho.
the class JFreeReportComponent method parseReport.
private MasterReport parseReport(final IActionSequenceResource resource) {
try {
// define the resource url so that PentahoResourceLoader recognizes the path.
String resourceUrl = PentahoResourceLoader.SOLUTION_SCHEMA_NAME + PentahoResourceLoader.SCHEMA_SEPARATOR + resource.getAddress();
String fullyQualifiedServerURL = PentahoSystem.getApplicationContext().getFullyQualifiedServerURL();
HashMap<FactoryParameterKey, Object> helperObjects = new HashMap<FactoryParameterKey, Object>();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
helperObjects.put(new FactoryParameterKey("pentahoBaseURL"), fullyQualifiedServerURL);
// trim out the server and port
helperObjects.put(new FactoryParameterKey("serverBaseURL"), getBaseServerURL(fullyQualifiedServerURL));
// $NON-NLS-1$
helperObjects.put(new FactoryParameterKey("solutionRoot"), // $NON-NLS-1$ //$NON-NLS-2$
PentahoSystem.getApplicationContext().getSolutionPath(""));
// get the host:port portion only
// $NON-NLS-1$
helperObjects.put(new FactoryParameterKey("hostColonPort"), getHostColonPort(fullyQualifiedServerURL));
// get the requestContextPath
helperObjects.put(new FactoryParameterKey("requestContextPath"), // $NON-NLS-1$
PentahoRequestContextHolder.getRequestContext().getContextPath());
Iterator it = getInputNames().iterator();
while (it.hasNext()) {
try {
String inputName = (String) it.next();
// on how the report definition would be parsed
if (AbstractJFreeReportComponent.DATACOMPONENT_DATAINPUT.equals(inputName)) {
continue;
}
String inputValue = getInputStringValue(inputName);
helperObjects.put(new FactoryParameterKey(inputName), inputValue);
} catch (Exception e) {
// ignore
}
}
ResourceManager resourceManager = new ResourceManager();
resourceManager.registerDefaults();
ResourceKey contextKey = resourceManager.createKey(resourceUrl, helperObjects);
ResourceKey key = resourceManager.createKey(resourceUrl, helperObjects);
return ReportGenerator.getInstance().parseReport(resourceManager, key, contextKey);
} catch (Exception ex) {
error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0007_COULD_NOT_PARSE", resource.getAddress()), // $NON-NLS-1$
ex);
return null;
}
}
use of org.pentaho.reporting.libraries.resourceloader.ResourceKey in project pentaho-platform by pentaho.
the class JFreeReportLoadComponent method parseReport.
/**
* Parses the report, using the given ActionResource as initial report definition.
*
* @param resource
* @return
*/
private MasterReport parseReport(final IActionSequenceResource resource) {
try {
// define the resource url so that PentahoResourceLoader recognizes the path.
String resourceUrl = PentahoResourceLoader.SOLUTION_SCHEMA_NAME + PentahoResourceLoader.SCHEMA_SEPARATOR + resource.getAddress();
String fullyQualifiedServerUrl = PentahoSystem.getApplicationContext().getFullyQualifiedServerURL();
HashMap helperObjects = new HashMap();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
helperObjects.put(new FactoryParameterKey("pentahoBaseURL"), fullyQualifiedServerUrl);
// trim out the server and port
// $NON-NLS-1$
helperObjects.put(new FactoryParameterKey("serverBaseURL"), getBaseServerURL(fullyQualifiedServerUrl));
helperObjects.put(new FactoryParameterKey("solutionRoot"), // $NON-NLS-1$ //$NON-NLS-2$
PentahoSystem.getApplicationContext().getSolutionPath(""));
// get the host:port portion only
// $NON-NLS-1$
helperObjects.put(new FactoryParameterKey("hostColonPort"), getHostColonPort(fullyQualifiedServerUrl));
// get the requestContextPath
helperObjects.put(new FactoryParameterKey("requestContextPath"), // $NON-NLS-1$
PentahoRequestContextHolder.getRequestContext().getContextPath());
Iterator it = getInputNames().iterator();
while (it.hasNext()) {
try {
String inputName = (String) it.next();
String inputValue = getInputStringValue(inputName);
helperObjects.put(new FactoryParameterKey(inputName), inputValue);
} catch (Exception e) {
// ignore
}
}
ResourceManager resourceManager = new ResourceManager();
resourceManager.registerDefaults();
ResourceKey contextKey = resourceManager.createKey(resourceUrl, helperObjects);
ResourceKey key = resourceManager.createKey(resourceUrl, helperObjects);
return ReportGenerator.getInstance().parseReport(resourceManager, key, contextKey);
} catch (Exception ex) {
error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0007_COULD_NOT_PARSE", resource.getAddress()), // $NON-NLS-1$
ex);
return null;
}
}
Aggregations