Uploaded image for project: 'Stanbol (Retired)'
  1. Stanbol (Retired)
  2. STANBOL-44

Use an adapter pattern in ContentItem

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 0.9.0-incubating
    • Enhancer
    • None

    Description

      Reported by project member bdelacretaz, May 26, 2010

      The ContentItem can currently only provide an InputStream for its data, but in some cases other
      data types (String, RDF graph, etc.) might be convenient.

      As discussed at the hackathon, using an adapter pattern allows us to do this in a flexible way, the
      ContentItem interface would then look like this:

      public interface ContentItem {
      /** Unique ID, either supplied by client or generated by FISE */
      String getId();

      /** The binary content stream

      • @deprecated use adaptTo(InputStream.class) */
        InputStream getStream();

      /** Adapt to specified class, for example InputStream, String,

      • RDF graph or future raw/formatted content types.
      • @return null if not adaptable
        */
        <AdapterType> AdapterType adaptTo(Class<AdapterType> type);

      /** Mime-type of the input stream */
      String getMimeType();

      /** Optional metadata */
      MGraph getMetadata();
      }

      At first adaptTo would only work for InputStream, so it's a minor code change.

      Later we can add an AdapterFactory service interface to provide more adapters.

      The Sling codebase uses that pattern, see examples there.

      The adaptTo method needs a second parameter for options, probably a Map.

      Use case: adapt to an InputStream with mime type image/jpeg

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              fchrist Fabian Christ
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: