Package org.pentaho.reporting.libraries.resourceloader

Examples of org.pentaho.reporting.libraries.resourceloader.ResourceKey


    }

    if (value instanceof ResourceKey)
    {
      // Get the source from the resource key (checking for embedded first)
      final ResourceKey resourceKey = (ResourceKey) value;
      final Object source = resourceKey.getFactoryParameters().get(ClassicEngineFactoryParameters.ORIGINAL_VALUE);
      if (source != null)
      {
        return String.valueOf(source);
      }
      return resourceKey.getIdentifierAsString();
    }

    return value.toString();
  }
View Full Code Here


    if (newValue instanceof ResourceKey && shouldBeLoaded((ResourceKey) newValue))
    {
      try
      {
        // Embed the file and swap in the key which refers to the embedded resource
        final ResourceKey newKey = loadResourceIntoKey((ResourceKey) newValue);
        if (newKey != null)
        {
          // Swap out the old key with the new key (the new key has the resource loaded)
          reportElement.setAttribute(attributeChange.getNamespace(), attributeChange.getName(), newKey);
        }
View Full Code Here

      parameters.put(ClassicEngineFactoryParameters.ORIGINAL_VALUE, source);
      parameters.put(ClassicEngineFactoryParameters.MIME_TYPE, mimeType);
      parameters.put(ClassicEngineFactoryParameters.PATTERN, pattern);
      parameters.put(ClassicEngineFactoryParameters.EMBED, "true"); // NON-NLS
      // create an embedded key in here.
      final ResourceKey key = ResourceKeyUtils.toResourceKey
          (source, reportRenderContext.getResourceManager(),
              reportRenderContext.getReportDefinition().getContentBase(), parameters);
      return ResourceKeyUtils.embedResourceInKey(reportRenderContext.getResourceManager(),
          key, key.getFactoryParameters());
    }

    // See if we can create a valid resource key
    final ResourceKey contentBaseKey = reportRenderContext.getReportDefinition().getContentBase();
    final ResourceKey resourceKey = ResourceKeyUtils.toResourceKey
        (source, reportRenderContext.getResourceManager(), contentBaseKey, Collections.EMPTY_MAP);
    if (isDerivedKey(resourceKey, contentBaseKey))
    {
      return source;
    }
View Full Code Here

                                   final ReportDocumentContext activeContext,
                                   final Component parent)
  {
    // Get the current file target
    final MasterReport report = activeContext.getContextRoot();
    final ResourceKey definitionSource = report.getDefinitionSource();
    File target = SaveReportUtilities.getCurrentFile(definitionSource);

    // If there is no target, this file has not been save before ... prompt for a filename
    if (target == null)
    {
      target = SaveReportUtilities.promptReportFilename(parent, null);
    }
    else
    {
      target = SaveReportUtilities.validateFileExtension(target, parent);
    }
    if (target == null)
    {
      return false;
    }

    // if no name has been set for the report, default to the name of the file

    try
    {
      report.setAttribute(ReportDesignerBoot.DESIGNER_NAMESPACE, "report-save-path", target.getCanonicalPath()); // NON-NLS
    }
    catch (IOException ioe)
    {
      // then let's not set the save path attribute to the *canonical path*
      report.setAttribute(ReportDesignerBoot.DESIGNER_NAMESPACE, "report-save-path", target.getAbsolutePath()); // NON-NLS
    }

    // Write the report to the filename
    if (SaveReportUtilities.saveReport(context, activeContext, target))
    {
      try
      {
        // Update the definition source to be the location from which the file is saved
        final ResourceManager resourceManager = report.getResourceManager();
        final Resource bundleResource = resourceManager.createDirectly(target, DocumentBundle.class);
        final DocumentBundle bundle = (DocumentBundle) bundleResource.getResource();
        final ResourceKey bundleKey = bundle.getBundleKey();
        report.setDefinitionSource(bundleKey);
        report.setContentBase(bundleKey);
        report.setResourceManager(bundle.getResourceManager());
        activeContext.resetChangeTracker();
      }
View Full Code Here

                                     final ReportDocumentContext activeContext,
                                     final Component parent)
  {
    // Get the current file target
    final MasterReport report = activeContext.getContextRoot();
    final ResourceKey definitionSource = report.getDefinitionSource();
    final File defaultFile = SaveReportUtilities.getCurrentFile(definitionSource);

    // Prompt for the filename
    final File target = SaveReportUtilities.promptReportFilename(parent, defaultFile);
    if (target == null)
    {
      return false;
    }

    try
    {
      report.setAttribute(ReportDesignerBoot.DESIGNER_NAMESPACE, "report-save-path", target.getCanonicalPath()); // NON-NLS
    }
    catch (IOException ioe)
    {
      // then let's not set the save path attribute
    }


    // Save the report
    if (SaveReportUtilities.saveReport(context, activeContext, target))
    // Update the definition source to be the location from which the file is saved
    {
      try
      {
        // Update the definition source to be the location from which the file is saved
        final ResourceManager resourceManager = report.getResourceManager();
        final Resource bundleResource = resourceManager.createDirectly(target, DocumentBundle.class);
        final DocumentBundle bundle = (DocumentBundle) bundleResource.getResource();
        final ResourceKey bundleKey = bundle.getBundleKey();
        report.setDefinitionSource(bundleKey);
        report.setContentBase(bundleKey);
        report.setBundle(bundle);
        report.setResourceManager(bundle.getResourceManager());
        activeContext.resetChangeTracker();
View Full Code Here

      throws ResourceCreationException, ResourceLoadingException
  {
    try
    {
      final Parser parser = CSSParserFactory.getInstance().createCSSParser();
      final ResourceKey key;
      final long version;
      if (context == null)
      {
        key = data.getKey();
        version = data.getVersion(manager);
View Full Code Here

  {
    try
    {
      final Parser parser = CSSParserFactory.getInstance().createCSSParser();

      final ResourceKey key;
      final long version;
      if (context == null)
      {
        key = data.getKey();
        version = data.getVersion(manager);
View Full Code Here

  public void testSerialize() throws Exception
  {
    final FileResourceLoader fileResourceLoader = new FileResourceLoader();
    final ResourceManager manager = new ResourceManager();
    manager.registerDefaults();
    ResourceKey key = null;
    Map<ParameterKey, Object> factoryParameters = new HashMap<ParameterKey, Object>();
    String serializedVersion = null;

    // Test with null parameter
    try
View Full Code Here

    catch (ResourceKeyCreationException rkce)
    {
      // success
    }
    final ResourceKey key1 = fileResourceLoader.deserialize(null, DESERIALIZE_PREFIX + ';' + tempFile.getCanonicalPath() +
        ";\"\"\"f:this=that\"\":\"\"f:invalid\"\":\"\"f:null=\"\"\"");
    assertNotNull(key1);
    assertTrue(key1.getIdentifier() instanceof File);
    assertEquals(FileResourceLoader.class.getName(), key1.getSchema());
    assertEquals(tempFile.getCanonicalPath(), ((File)key1.getIdentifier()).getCanonicalPath());
    assertEquals(2, key1.getFactoryParameters().size());
    assertTrue(!key1.getFactoryParameters().containsKey(new FactoryParameterKey("invalid")));
    assertTrue(key1.getFactoryParameters().containsKey(new FactoryParameterKey("null")));
    assertNull(key1.getFactoryParameters().get(new FactoryParameterKey("null")));
    assertEquals("that", key1.getFactoryParameters().get(new FactoryParameterKey("this")));
  }
View Full Code Here

    final ResourceManager manager = new ResourceManager();
    manager.registerDefaults();
  
    factoryParams.put(new FactoryParameterKey("this"), "that");
    factoryParams.put(new FactoryParameterKey("null"), null);
    final ResourceKey originalKey = manager.createKey(tempFile, factoryParams);
   
    final String serializedVersion = fileResourceLoader.serialize(null, originalKey);
    final ResourceKey duplicateKey = fileResourceLoader.deserialize(null, serializedVersion);
    assertNotNull(duplicateKey);
    assertTrue(originalKey.equals(duplicateKey));
  }
View Full Code Here

TOP

Related Classes of org.pentaho.reporting.libraries.resourceloader.ResourceKey

Copyright © 2018 www.massapicom. 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.