You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "Claude Warren (JIRA)" <ji...@apache.org> on 2012/09/22 09:32:07 UTC

[jira] [Created] (JENA-331) XSDDatatype does not properly handle URIs

Claude Warren created JENA-331:
----------------------------------

             Summary: XSDDatatype does not properly handle URIs
                 Key: JENA-331
                 URL: https://issues.apache.org/jira/browse/JENA-331
             Project: Apache Jena
          Issue Type: Improvement
          Components: Jena
    Affects Versions: Jena 2.7.3
            Reporter: Claude Warren


Using the TypeMapper to convert a URI to a literal and back again fails as a String is returned not a URI.

Test code:


import com.hp.hpl.jena.datatypes.RDFDatatype;
import com.hp.hpl.jena.datatypes.TypeMapper;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.ResourceFactory;

import java.net.URI;

import org.junit.Assert;
import org.junit.Test;


public class XSDDatatypeTest
{
 @Test
 public void testURIConversion() throws Exception
 {
	 TypeMapper typeMapper = TypeMapper.getInstance();
	 RDFDatatype dt = typeMapper.getTypeByClass( java.net.URI.class );

	 URI uri = new URI("http://example.com" );

	 String lexicalForm = dt.unparse( uri );
	 Literal l = ResourceFactory.createTypedLiteral( lexicalForm, dt );
	
	 Object o = dt.parse( l.getLexicalForm()  );
	 Assert.assertEquals( uri, o );
 }
}


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (JENA-331) XSDDatatype does not properly handle URIs

Posted by "Dave Reynolds (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JENA-331?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13461365#comment-13461365 ] 

Dave Reynolds commented on JENA-331:
------------------------------------

Thanks for the suggestion.

We originally left the java value for xsd:anyURI as a string because Jena has historically used Strings to carry URIs (which may or may not have been a good idea). We then allowed conversion from java.net.URI as a convenience extra.  

I can see that sets up an expectation of round tripping but that's not possible in general, java.net.URI is not an adequate direct representation for anyURI. The lexical form for anyURI [1] allows strings not allowed by java.net.URI so that valid xsd:anyURI values (e.g. http://example.com/foo|bar) will throw URISyntaxExceptions. We could do the %-encoding in convertValidatedDataValue to convert the incoming anyURI syntax to a URI I would rather not mess with lexical forms that way, too easy to end up with the wrong number of %-encodings applied.

An alternative would be to remove the support for URI or to replace it with IRI.

[1] http://www.w3.org/TR/xmlschema-2/#anyURI
                
> XSDDatatype does not properly handle URIs
> -----------------------------------------
>
>                 Key: JENA-331
>                 URL: https://issues.apache.org/jira/browse/JENA-331
>             Project: Apache Jena
>          Issue Type: Improvement
>          Components: Jena
>    Affects Versions: Jena 2.7.3
>            Reporter: Claude Warren
>         Attachments: JENA-331.patch
>
>
> Using the TypeMapper to convert a URI to a literal and back again fails as a String is returned not a URI.
> Test code:
> import com.hp.hpl.jena.datatypes.RDFDatatype;
> import com.hp.hpl.jena.datatypes.TypeMapper;
> import com.hp.hpl.jena.rdf.model.Literal;
> import com.hp.hpl.jena.rdf.model.ResourceFactory;
> import java.net.URI;
> import org.junit.Assert;
> import org.junit.Test;
> public class XSDDatatypeTest
> {
>  @Test
>  public void testURIConversion() throws Exception
>  {
> 	 TypeMapper typeMapper = TypeMapper.getInstance();
> 	 RDFDatatype dt = typeMapper.getTypeByClass( java.net.URI.class );
> 	 URI uri = new URI("http://example.com" );
> 	 String lexicalForm = dt.unparse( uri );
> 	 Literal l = ResourceFactory.createTypedLiteral( lexicalForm, dt );
> 	
> 	 Object o = dt.parse( l.getLexicalForm()  );
> 	 Assert.assertEquals( uri, o );
>  }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (JENA-331) XSDDatatype does not properly handle URIs

Posted by "Dave Reynolds (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JENA-331?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13461365#comment-13461365 ] 

Dave Reynolds edited comment on JENA-331 at 9/23/12 9:34 PM:
-------------------------------------------------------------

Thanks for the suggestion.

We originally left the java value for xsd:anyURI as a string because Jena has historically used Strings to carry URIs (which may or may not have been a good idea). We then allowed conversion from java.net.URI as a convenience extra.  

I can see that sets up an expectation of round tripping but that's not possible in general, java.net.URI is not an adequate direct representation for anyURI. The lexical form for anyURI [1] allows strings not allowed by java.net.URI so that valid xsd:anyURI values (e.g. http://example.com/foo|bar) will throw URISyntaxExceptions. We could do the %-encoding in convertValidatedDataValue to convert the incoming anyURI syntax to a URI but I would rather not mess with lexical forms that way, too easy to end up with the wrong number of %-encodings applied.

An alternative would be to remove the support for URI or to replace it with IRI.

[1] http://www.w3.org/TR/xmlschema-2/#anyURI
                
      was (Author: der):
    Thanks for the suggestion.

We originally left the java value for xsd:anyURI as a string because Jena has historically used Strings to carry URIs (which may or may not have been a good idea). We then allowed conversion from java.net.URI as a convenience extra.  

I can see that sets up an expectation of round tripping but that's not possible in general, java.net.URI is not an adequate direct representation for anyURI. The lexical form for anyURI [1] allows strings not allowed by java.net.URI so that valid xsd:anyURI values (e.g. http://example.com/foo|bar) will throw URISyntaxExceptions. We could do the %-encoding in convertValidatedDataValue to convert the incoming anyURI syntax to a URI I would rather not mess with lexical forms that way, too easy to end up with the wrong number of %-encodings applied.

An alternative would be to remove the support for URI or to replace it with IRI.

[1] http://www.w3.org/TR/xmlschema-2/#anyURI
                  
> XSDDatatype does not properly handle URIs
> -----------------------------------------
>
>                 Key: JENA-331
>                 URL: https://issues.apache.org/jira/browse/JENA-331
>             Project: Apache Jena
>          Issue Type: Improvement
>          Components: Jena
>    Affects Versions: Jena 2.7.3
>            Reporter: Claude Warren
>         Attachments: JENA-331.patch
>
>
> Using the TypeMapper to convert a URI to a literal and back again fails as a String is returned not a URI.
> Test code:
> import com.hp.hpl.jena.datatypes.RDFDatatype;
> import com.hp.hpl.jena.datatypes.TypeMapper;
> import com.hp.hpl.jena.rdf.model.Literal;
> import com.hp.hpl.jena.rdf.model.ResourceFactory;
> import java.net.URI;
> import org.junit.Assert;
> import org.junit.Test;
> public class XSDDatatypeTest
> {
>  @Test
>  public void testURIConversion() throws Exception
>  {
> 	 TypeMapper typeMapper = TypeMapper.getInstance();
> 	 RDFDatatype dt = typeMapper.getTypeByClass( java.net.URI.class );
> 	 URI uri = new URI("http://example.com" );
> 	 String lexicalForm = dt.unparse( uri );
> 	 Literal l = ResourceFactory.createTypedLiteral( lexicalForm, dt );
> 	
> 	 Object o = dt.parse( l.getLexicalForm()  );
> 	 Assert.assertEquals( uri, o );
>  }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (JENA-331) XSDDatatype does not properly handle URIs

Posted by "Claude Warren (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JENA-331?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claude Warren updated JENA-331:
-------------------------------

    Attachment: JENA-331.patch

Patch to add URI creation on parse
                
> XSDDatatype does not properly handle URIs
> -----------------------------------------
>
>                 Key: JENA-331
>                 URL: https://issues.apache.org/jira/browse/JENA-331
>             Project: Apache Jena
>          Issue Type: Improvement
>          Components: Jena
>    Affects Versions: Jena 2.7.3
>            Reporter: Claude Warren
>         Attachments: JENA-331.patch
>
>
> Using the TypeMapper to convert a URI to a literal and back again fails as a String is returned not a URI.
> Test code:
> import com.hp.hpl.jena.datatypes.RDFDatatype;
> import com.hp.hpl.jena.datatypes.TypeMapper;
> import com.hp.hpl.jena.rdf.model.Literal;
> import com.hp.hpl.jena.rdf.model.ResourceFactory;
> import java.net.URI;
> import org.junit.Assert;
> import org.junit.Test;
> public class XSDDatatypeTest
> {
>  @Test
>  public void testURIConversion() throws Exception
>  {
> 	 TypeMapper typeMapper = TypeMapper.getInstance();
> 	 RDFDatatype dt = typeMapper.getTypeByClass( java.net.URI.class );
> 	 URI uri = new URI("http://example.com" );
> 	 String lexicalForm = dt.unparse( uri );
> 	 Literal l = ResourceFactory.createTypedLiteral( lexicalForm, dt );
> 	
> 	 Object o = dt.parse( l.getLexicalForm()  );
> 	 Assert.assertEquals( uri, o );
>  }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (JENA-331) XSDDatatype does not properly handle URIs

Posted by "Dave Reynolds (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JENA-331?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dave Reynolds updated JENA-331:
-------------------------------

    Priority: Minor  (was: Major)
    
> XSDDatatype does not properly handle URIs
> -----------------------------------------
>
>                 Key: JENA-331
>                 URL: https://issues.apache.org/jira/browse/JENA-331
>             Project: Apache Jena
>          Issue Type: Improvement
>          Components: Jena
>    Affects Versions: Jena 2.7.3
>            Reporter: Claude Warren
>            Priority: Minor
>         Attachments: JENA-331.patch
>
>
> Using the TypeMapper to convert a URI to a literal and back again fails as a String is returned not a URI.
> Test code:
> import com.hp.hpl.jena.datatypes.RDFDatatype;
> import com.hp.hpl.jena.datatypes.TypeMapper;
> import com.hp.hpl.jena.rdf.model.Literal;
> import com.hp.hpl.jena.rdf.model.ResourceFactory;
> import java.net.URI;
> import org.junit.Assert;
> import org.junit.Test;
> public class XSDDatatypeTest
> {
>  @Test
>  public void testURIConversion() throws Exception
>  {
> 	 TypeMapper typeMapper = TypeMapper.getInstance();
> 	 RDFDatatype dt = typeMapper.getTypeByClass( java.net.URI.class );
> 	 URI uri = new URI("http://example.com" );
> 	 String lexicalForm = dt.unparse( uri );
> 	 Literal l = ResourceFactory.createTypedLiteral( lexicalForm, dt );
> 	
> 	 Object o = dt.parse( l.getLexicalForm()  );
> 	 Assert.assertEquals( uri, o );
>  }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira