You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2012/12/17 11:33:47 UTC

svn commit: r1422835 - in /jena/trunk/jena-core/src: main/java/com/hp/hpl/jena/rdf/model/ResourceFactory.java test/java/com/hp/hpl/jena/rdf/model/test/TestResourceFactory.java

Author: andy
Date: Mon Dec 17 10:33:46 2012
New Revision: 1422835

URL: http://svn.apache.org/viewvc?rev=1422835&view=rev
Log:
Add ResourceFactory.createLangLiteral

Modified:
    jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/ResourceFactory.java
    jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestResourceFactory.java

Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/ResourceFactory.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/ResourceFactory.java?rev=1422835&r1=1422834&r2=1422835&view=diff
==============================================================================
--- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/ResourceFactory.java (original)
+++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/ResourceFactory.java Mon Dec 17 10:33:46 2012
@@ -92,9 +92,32 @@ public class ResourceFactory {
         return instance.createResource(uriref);
     }
     
+    /**
+    Answer a plain (untyped) literal with no language and the given content.
+    @param string the string which forms the value of the literal
+    @return a Literal node with that string as value
+     */
     public static Literal createPlainLiteral( String string ) {
         return instance.createPlainLiteral( string );
     }
+    
+    /**
+    Answer a plain (untyped) literal with no language and the given content.
+    @param string the string which forms the value of the literal
+    @param lang The language tag to be used
+    @return a Literal node with that string as value
+     */
+
+    public static Literal createLangLiteral( String string , String lang ) {
+        return instance.createLangLiteral( string , lang );
+    }
+
+    /**
+    Answer a typed literal.
+    @param string the string which forms the value of the literal
+    @param datatype RDFDatatype of the type literal
+    @return a Literal node with that string as value
+    */
 
     public static Literal createTypedLiteral( String string , RDFDatatype dType)
     {
@@ -173,6 +196,15 @@ public class ResourceFactory {
         public Literal createPlainLiteral( String string );
 
         /**
+        Answer a plain (untyped) literal with no language and the given content.
+        @param string the string which forms the value of the literal
+        @param lang The language tag to be used
+        @return a Literal node with that string as value
+         */
+
+        public Literal createLangLiteral( String string , String lang );
+
+        /**
         Answer a typed literal.
         @param string the string which forms the value of the literal
         @param datatype RDFDatatype of the type literal
@@ -237,6 +269,11 @@ public class ResourceFactory {
         }
 
         @Override
+        public Literal createLangLiteral( String string , String lang ) {
+            return new LiteralImpl(  Node.createLiteral( string, lang, false ), null );
+        }
+        
+        @Override
         public Literal createTypedLiteral( String string , RDFDatatype dType)
         {
             return new LiteralImpl(Node.createLiteral(string, "", dType), null) ;

Modified: jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestResourceFactory.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestResourceFactory.java?rev=1422835&r1=1422834&r2=1422835&view=diff
==============================================================================
--- jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestResourceFactory.java (original)
+++ jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestResourceFactory.java Mon Dec 17 10:33:46 2012
@@ -68,6 +68,15 @@ public class TestResourceFactory extends
         assertNull(l.getDatatypeURI()) ;
     }
     
+    public void testCreateLangLiteral()
+    {
+        Literal l = ResourceFactory.createLangLiteral("lex", "en") ;
+        assertTrue(l.getLexicalForm().equals("lex")) ;
+        assertTrue(l.getLanguage().equals("en")) ;
+        assertNull(l.getDatatype()) ;
+        assertNull(l.getDatatypeURI()) ;
+    }
+    
     public void testCreateTypedLiteral()
     {
         Literal l = ResourceFactory.createTypedLiteral("22", XSDDatatype.XSDinteger) ;
@@ -115,14 +124,17 @@ public class TestResourceFactory extends
         assertTrue(!r1.equals(r2));
     }
 
-    public void testSetInstance() {
-        Resource r = ResourceFactory.createResource();
-        ResourceFactory.Interface factory = new TestFactory(r);
-        ResourceFactory.setInstance(factory);
-        assertTrue(factory.equals(ResourceFactory.getInstance()));
-        assertTrue(ResourceFactory.createResource() == r);
+    public void testSetInstance()
+    {
+        ResourceFactory.Interface original = ResourceFactory.getInstance() ;
+        try {
+            Resource r = ResourceFactory.createResource() ;
+            ResourceFactory.Interface factory = new TestFactory(r) ;
+            ResourceFactory.setInstance(factory) ;
+            assertTrue(factory.equals(ResourceFactory.getInstance())) ;
+            assertTrue(ResourceFactory.createResource() == r) ;
+        } finally { ResourceFactory.setInstance(original) ; }
     }
-
     class TestFactory implements ResourceFactory.Interface {
 
         Resource resource;
@@ -147,6 +159,12 @@ public class TestResourceFactory extends
         }
 
         @Override
+        public Literal createLangLiteral( String string, String lang ) {
+            return null;
+        }
+
+
+        @Override
         public Literal createTypedLiteral(String string, RDFDatatype datatype)
         {
             return null ;