Skip to content

Commit

Permalink
JENA-1124: Add rdf:HTML as datatype and constant in RDF.
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Jan 28, 2016
1 parent 64c4732 commit a063c4d
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.apache.jena.datatypes;

import java.util.Objects ;

import org.apache.jena.graph.impl.LiteralLabel ;

/**
Expand Down Expand Up @@ -151,6 +153,24 @@ protected static boolean isEqualPlain(LiteralLabel litLabel1, LiteralLabel litLa
&& litLabel1.getValue().equals(litLabel2.getValue());
}


/**
* Equality for datatypes based solely on lexcial form,
* i.e. there value space is equivalent to their lexical space.
*/
protected static boolean isEqualByTerm(LiteralLabel value1, LiteralLabel value2) {
if ( value2 == null && value1 == null )
return true ;
if ( value2 == null )
return false ;
if ( value1 == null )
return false ;
return
Objects.equals(value1.getLexicalForm(), value2.getLexicalForm()) &&
Objects.equals(value1.getDatatype(), value2.getDatatype()) &&
Objects.equals(value1.language(), value2.language()) ;
}

/**
Default implementation of getHashCode() delegates to the default from
the literal label.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ private RDFLangString(String uri) {
*/
@Override
public boolean isEqual(LiteralLabel value1, LiteralLabel value2) {
if ( value2 == null )
return false ;
if ( ! rdfLangString.equals(value2.getDatatype()) )
return false ;

return value1.getLexicalForm().equals(value2.getLexicalForm()) &&
value1.language().equalsIgnoreCase(value2.language()) ;
return isEqualByTerm(value1, value2) ;
}

// This covers the unusual case of "foo"^^"rdf:langString"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.jena.datatypes.xsd.impl;

import org.apache.jena.datatypes.BaseDatatype ;
import org.apache.jena.datatypes.RDFDatatype ;
import org.apache.jena.graph.impl.LiteralLabel ;

/** rdf:html.
* This only implements syntacic equality, not value equality (parsed HTML5, DOM normalized)
*/

public class RDFhtml extends BaseDatatype implements RDFDatatype {
/** Singleton instance */
// Include the string for the RDF namespace, not use RDF.getURI(), to avoid an initializer circularity
public static final RDFDatatype rdfHTML = new RDFhtml("http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML");

/**
* Private constructor.
*/
private RDFhtml(String uri) {
super(uri);
}

/**
* Compares two instances of values of the given datatype.
*/
@Override
public boolean isEqual(LiteralLabel value1, LiteralLabel value2) {
return isEqualByTerm(value1, value2) ;
}

@Override
public Object parse(String lexicalForm) { return lexicalForm ; }

@Override
public String unparse(Object value) { return value.toString(); }
}

48 changes: 28 additions & 20 deletions jena-core/src/main/java/org/apache/jena/vocabulary/RDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.jena.datatypes.RDFDatatype ;
import org.apache.jena.datatypes.xsd.impl.RDFLangString ;
import org.apache.jena.datatypes.xsd.impl.RDFhtml ;
import org.apache.jena.datatypes.xsd.impl.XMLLiteralType ;
import org.apache.jena.graph.Node ;
import org.apache.jena.rdf.model.Property ;
Expand Down Expand Up @@ -70,33 +71,40 @@ public static Property li( int i )

// RDF 1.1 - the datatypes of language strings
public static final Resource langString = ResourceFactory.createResource(RDFLangString.rdfLangString.getURI()) ;

// RDF 1.1 - rdf:HTML
public static final Resource HTML = ResourceFactory.createResource(RDFhtml.rdfHTML.getURI()) ;

// rdf:XMLLiteral
public static final Resource xmlLiteral = ResourceFactory.createResource(XMLLiteralType.theXMLLiteralType.getURI()) ;

public static final RDFDatatype dtLangString = RDFLangString.rdfLangString ;
public static final RDFDatatype dtXMLLiteral = XMLLiteralType.theXMLLiteralType ;
public static final RDFDatatype dtRDFHTML = RDFhtml.rdfHTML;
public static final RDFDatatype dtLangString = RDFLangString.rdfLangString;
public static final RDFDatatype dtXMLLiteral = XMLLiteralType.theXMLLiteralType;

/**
The same items of vocabulary, but at the Node level, parked inside a
nested class so that there's a simple way to refer to them.
*/
@SuppressWarnings("hiding") public static final class Nodes
{
public static final Node Alt = RDF.Alt.asNode();
public static final Node Bag = RDF.Bag.asNode();
public static final Node Property = RDF.Property.asNode();
public static final Node Seq = RDF.Seq.asNode();
public static final Node Statement = RDF.Statement.asNode();
public static final Node List = RDF.List.asNode();
public static final Node nil = RDF.nil.asNode();
public static final Node first = RDF.first.asNode();
public static final Node rest = RDF.rest.asNode();
public static final Node subject = RDF.subject.asNode();
public static final Node predicate = RDF.predicate.asNode();
public static final Node object = RDF.object.asNode();
public static final Node type = RDF.type.asNode();
public static final Node value = RDF.value.asNode();
@SuppressWarnings("hiding")
public static final class Nodes
{
public static final Node Alt = RDF.Alt.asNode();
public static final Node Bag = RDF.Bag.asNode();
public static final Node Property = RDF.Property.asNode();
public static final Node Seq = RDF.Seq.asNode();
public static final Node Statement = RDF.Statement.asNode();
public static final Node List = RDF.List.asNode();
public static final Node nil = RDF.nil.asNode();
public static final Node first = RDF.first.asNode();
public static final Node rest = RDF.rest.asNode();
public static final Node subject = RDF.subject.asNode();
public static final Node predicate = RDF.predicate.asNode();
public static final Node object = RDF.object.asNode();
public static final Node type = RDF.type.asNode();
public static final Node value = RDF.value.asNode();
public static final Node langString = RDF.langString.asNode();
}

public static final Node HTML = RDF.HTML.asNode();
public static final Node xmlLiteral = RDF.xmlLiteral.asNode();
}
}

0 comments on commit a063c4d

Please sign in to comment.