Skip to content

Pages without a base URI cannot be parsed #28

@quoll

Description

@quoll

Web pages without a base URI cannot be parsed with the default Resolvers. For instance, one of the example pages on the home page doesn't have a base:
http://examples.tobyinkster.co.uk/hcard

The IRIResolver first looks at the "base" (provided in the first parameter) and throws a RuntimeException if this is null. Since web pages can be messy, then this will happen too often for an approach like this to be useful. The simplest solution for the user is to subclass IRIResolver with something like:
public String resolver(String base, String relative) {
return super(base == null ? getDefaultBase() : base, relative);
}

However, with the aim of providing flexibility to all web pages, this is required all the time, and not just for special configurations. Also, the docs on the home page don't mention this class at all, so some exploring needed to find the solution.

I'd like to suggest using one of these approaches:

  1. Drop the method ParserFactory.createReaderForFormat(StatementSink, ParserFactory.Format , Setting...), and make IRIResolver abstract.
  2. Introduce a new version of ParserFactory.createReaderForFormat that has a "default base" as a new parameter. Since createReaderForFormat is already the main method that users read about, then the issue should be more apparent to them.
  3. Add a method to the StatementSink that allows the sink to specify where it wants relative URIs to be resolved against. This is the main code that a user will be writing (other than the call to createReaderForFormat), so it is the other reasonable place to consider putting it. The base could be returned from something like getDefaultBase. This is my least-preferred method, since it breaks existing implementations of StatementSink.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions