XWiki Platform
  1. XWiki Platform
  2. XWIKI-10375

Refactor the temporary resource concept inside the Resource module

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 6.0
    • Fix Version/s: 8.3, 8.2.2, 7.4.6
    • Component/s: Resource
    • Labels:
      None
    • Tests:
      Unit
    • Development Priority:
      High
    • Difficulty:
      Medium
    • Similar issues:

      Description

      Right now several modules need to generate temporary resources and they each reimplement it differently. For example:

      • The Chart macro
      • The Formula macro
      • The image plugin
      • The OfficeViewer macro

      The idea is to have all of them use a generic temporary Resource Reference and Resource Reference Handler.

        Issue Links

          Activity

          Hide
          Vincent Massol added a comment -

          First commit done, more work is required to finish it though.

          Show
          Vincent Massol added a comment - First commit done, more work is required to finish it though.
          Hide
          Marius Dumitru Florea added a comment -

          FYI, the office viewer is using the temp action too.

          Show
          Marius Dumitru Florea added a comment - FYI, the office viewer is using the temp action too.
          Hide
          Vincent Massol added a comment -
          Show
          Vincent Massol added a comment - URL format proposal: http://markmail.org/message/axtura7fakv4uvml
          Hide
          Marius Dumitru Florea added a comment -

          Here's how you can create temporary resources from Java:

          @Inject
          private TemporaryResourceStore temporaryResourceStore;
          
          @Inject
          @Named("standard/tmp")
          private ResourceReferenceSerializer<TemporaryResourceReference, ExtendedURL> urlTemporaryResourceReferenceSerializer;
          
          // (1) Create the temporary resource reference.
          String moduleName = "chart";
          List<String> resourcePath = Arrays.asList("pie", "issuesByReporter.png");
          EntityReference owningEntityReference = new DocumentReference("wiki", Arrays.asList("Path", "To"), "Page");
          TemporaryResourceReference temporaryResourceReference =
              new TemporaryResourceReference(moduleName, resourcePath, owningEntityReference);
          
          // (2) Create the temporary file.
          InputStream content = new ByteArrayInputStream("content".getBytes());
          File tempFile = this.temporaryResourceStore.createTemporaryFile(temporaryResourceReference, content);
          
          // Or retrieve the temporary file by its reference (e.g. if you want to update it).
          tempFile = this.temporaryResourceStore.getTemporaryFile(temporaryResourceReference);
          
          // (3) Obtain the URL that can be used to access the above temporary file.
          String temporaryResourceURL =
              this.urlTemporaryResourceReferenceSerializer.serialize(temporaryResourceReference).serialize();
          
          Show
          Marius Dumitru Florea added a comment - Here's how you can create temporary resources from Java: @Inject private TemporaryResourceStore temporaryResourceStore; @Inject @Named( "standard/tmp" ) private ResourceReferenceSerializer<TemporaryResourceReference, ExtendedURL> urlTemporaryResourceReferenceSerializer; // (1) Create the temporary resource reference. String moduleName = "chart" ; List< String > resourcePath = Arrays.asList( "pie" , "issuesByReporter.png" ); EntityReference owningEntityReference = new DocumentReference( "wiki" , Arrays.asList( "Path" , "To" ), "Page" ); TemporaryResourceReference temporaryResourceReference = new TemporaryResourceReference(moduleName, resourcePath, owningEntityReference); // (2) Create the temporary file. InputStream content = new ByteArrayInputStream( "content" .getBytes()); File tempFile = this .temporaryResourceStore.createTemporaryFile(temporaryResourceReference, content); // Or retrieve the temporary file by its reference (e.g. if you want to update it). tempFile = this .temporaryResourceStore.getTemporaryFile(temporaryResourceReference); // (3) Obtain the URL that can be used to access the above temporary file. String temporaryResourceURL = this .urlTemporaryResourceReferenceSerializer.serialize(temporaryResourceReference).serialize();

            People

            • Assignee:
              Marius Dumitru Florea
              Reporter:
              Vincent Massol
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Date of First Response: