Interface ContentParser


  • @ProviderType
    public interface ContentParser
    A ContentParser parses Sling resource trees from a file. Implementations have to be thread-safe. A consumer requiring a ContentParser reference should filter based on the SERVICE_PROPERTY_CONTENT_TYPE in order to get a content type specific parser.
    • Field Detail

      • SERVICE_PROPERTY_CONTENT_TYPE

        static final java.lang.String SERVICE_PROPERTY_CONTENT_TYPE
        OSGi service registration property indicating the content type this ContentParser supports. The simplest way to retrieve a ContentParser for a certain content type is to apply a filter on the service reference:
            @Reference(target = "(" + ContentParser.SERVICE_PROPERTY_CONTENT_TYPE + "=" + _value_ + ")")
             private ContentParser parser;
         
        If multiple services are registered for the same content type, the above code snippet will provide you with the service implementation with the highest ranking. However, if a certain implementation is needed, an additional filter can be added:
             @Reference(target = "(&(" + ContentParser.SERVICE_PROPERTY_CONTENT_TYPE + "=" + _value_ + ")(component.name=" + _class_name_ + "))")
              private ContentParser parser;
         
        See Also:
        Constant Field Values
    • Method Detail

      • parse

        void parse​(ContentHandler contentHandler,
                   java.io.InputStream inputStream,
                   ParserOptions parserOptions)
            throws java.io.IOException
        Parse content in a "stream-based" way. Each resource that is found in the content is reported to the ContentHandler.
        Parameters:
        contentHandler - content handler that accepts the parsed content
        inputStream - stream with serialized content
        parserOptions - parser options, providing different settings for handling the serialized content
        Throws:
        java.io.IOException - when an I/O or parsing error occurs