commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stain <...@git.apache.org>
Subject [GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface
Date Thu, 12 Jan 2017 17:22:48 GMT
Github user stain commented on a diff in the pull request:

    https://github.com/apache/commons-rdf/pull/27#discussion_r95841065
  
    --- Diff: api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java ---
    @@ -22,6 +22,124 @@
     import java.util.Optional;
     
     /**
    + * An RDF syntax, e.g. as used for parsing and writing RDF.
    + * <p>
    + * An RDF syntax is uniquely identified by its {@link #mediaType()}, and has a
    + * suggested {@link #fileExtension()}.
    + * <p>
    + * Some of the RDF syntaxes may {@link #supportsDataset()}, meaning they can
    + * represent {@link Quad}s.
    + * <p>
    + * An enumeration of the official RDF 1.1 syntaxes is available in 
    + * {@link OfficialRDFSyntax} - for convenience they are also accessible
    + * as constants here, e.g. <code>RDFSyntax.JSONLD</code>.
    + * 
    + */
    +public interface RDFSyntax {
    + 
    +    public static OfficialRDFSyntax JSONLD = OfficialRDFSyntax.JSONLD;
    +    public static OfficialRDFSyntax TURTLE = OfficialRDFSyntax.TURTLE;
    +    public static OfficialRDFSyntax NQUADS = OfficialRDFSyntax.NQUADS;
    +    public static OfficialRDFSyntax NTRIPLES = OfficialRDFSyntax.NTRIPLES;
    +    public static OfficialRDFSyntax RDFA_HTML = OfficialRDFSyntax.RDFA_HTML;
    +    public static OfficialRDFSyntax RDFA_XHTML = OfficialRDFSyntax.RDFA_XHTML;
    +    public static OfficialRDFSyntax RDFXML = OfficialRDFSyntax.RDFXML;
    +    public static OfficialRDFSyntax TRIG = OfficialRDFSyntax.TRIG;
    +    
    +    /**
    +     * A short name of the RDF Syntax.
    +     * <p>
    +     * The name typically corresponds to the {@link Enum#name()} of for
    +     * {@link OfficialRDFSyntax}, e.g. <code>JSONLD</code>.
    +     * 
    +     * @return Short name for RDF syntax
    +     */
    +    public String name();
    +
    +    /**
    +     * The title of the RDF Syntax.
    +     * <p>
    +     * This is generally the title of the corresponding standard, 
    +     * e.g. <em>RDF 1.1 Turtle</em>.
    +     * 
    +     * @return Title of RDF Syntax
    +     */
    +    public String title();    
    +    
    +    /**
    +     * The <a href="https://tools.ietf.org/html/rfc2046">IANA media type</a>
for
    +     * the RDF syntax.
    +     * <p>
    +     * The media type can be used as part of <code>Content-Type</code> and
    +     * <code>Accept</code> for <em>content negotiation</em> in
the
    +     * <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP
    +     * protocol</a>.
    +     */
    +    public String mediaType();
    +
    +    /**
    +     * The <a href="https://tools.ietf.org/html/rfc2046">IANA-registered</a>
    +     * file extension.
    +     * <p>
    +     * The file extension includes the leading period, e.g. <code>.jsonld</code>
    +     */
    +    public String fileExtension();
    +
    +    /**
    +     * Indicate if this RDF syntax supports
    +     * <a href="https://www.w3.org/TR/rdf11-concepts/#section-dataset">RDF
    +     * Datasets</a>.
    +     */
    +    public boolean supportsDataset();
    +
    +
    +    /**
    +     * Return the RDFSyntax with the specified media type.
    +     * <p>
    +     * The <code>mediaType</code> is compared in lower case, therefore it
might
    +     * not be equal to the {@link RDFSyntax#mediaType} of the returned
    +     * RDFSyntax.
    +     * <p>
    +     * For convenience matching of media types used in a
    +     * <code>Content-Type</code> header, if the <code>mediaType</code>
contains
    +     * the characters <code>;</code>, <code>,</code> or white
space, only the
    +     * part of the string to the left of those characters are considered.
    +     * 
    +     * @param mediaType
    +     *            The media type to match
    +     * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
    +     *         a matching {@link RDFSyntax#mediaType}, otherwise
    +     *         {@link Optional#empty()} indicating that no matching syntax was
    +     *         found.
    +     */
    +    public static Optional<RDFSyntax> byMediaType(String mediaType) {
    +        final String type = mediaType.toLowerCase(Locale.ENGLISH).split("\\s*[;,]", 2)[0];
    +        return Arrays.stream(OfficialRDFSyntax.values()).filter(t -> t.mediaType().equals(type))
    --- End diff --
    
    Changed `OfficialRDFSyntax`  to a package-protected class `W3CRDFSyntax` and referred
to its instances.
    
    `values()` renamed to `w3cSyntaxes()` which return a `Set<RDFSyntax>`. I don't think
we need to make a `HashMap` from media type/extension to `RDFSyntax` as there's only 8 instances
to iterate over anyway.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message