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 2011/09/30 15:32:03 UTC
svn commit: r1177649 [3/4] - in /incubator/jena/Scratch/AFS/Jena-Dev/trunk:
./ .settings/ Archive/ Archive/Lists/ Archive/ResultSet/ Archive/SSE/
Grammar/ src/ src/dev/ src/fm2/ src/fm2/atlas/ src/fm2/jenautil/
src/opexec/ src/reports/ src/reports/arch...
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/LocatorFile.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/LocatorFile.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/LocatorFile.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/LocatorFile.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,154 @@
+/**
+ * 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 fm2.atlas;
+
+import java.io.File ;
+import java.io.FileInputStream ;
+import java.io.IOException ;
+import java.io.InputStream ;
+import java.security.AccessControlException ;
+
+import org.openjena.atlas.lib.IRILib ;
+import org.openjena.atlas.lib.Lib ;
+import org.openjena.atlas.web.TypedStream ;
+import org.openjena.riot.Lang ;
+import org.openjena.riot.WebContent ;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+import com.hp.hpl.jena.util.FileUtils ;
+
+/** Location files in the filing system.
+ * A FileLocator can have a "current directory" - this is separate from any
+ * location mapping (see @link{LocationMapping}) as it applies only to files.
+ */
+
+public class LocatorFile implements Locator
+{
+ static Logger log = LoggerFactory.getLogger(LocatorFile.class) ;
+ private String altDir = null ;
+ private String altDirLogStr = "" ;
+
+ public LocatorFile() { this(null) ; }
+
+ public LocatorFile(String dir)
+ {
+ if ( dir != null )
+ {
+ if ( dir.endsWith("/") || dir.endsWith(java.io.File.separator) )
+ dir = dir.substring(0,dir.length()-1) ;
+ altDirLogStr = " ["+dir+"]" ;
+ }
+ altDir = dir ;
+ }
+
+ // Two LocatorFile are the same if they would look up names to the same files.
+
+ @Override
+ public boolean equals( Object other )
+ {
+ return
+ other instanceof LocatorFile
+ && Lib.equal(altDir, ((LocatorFile) other).altDir );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ if ( altDir == null ) return 57 ;
+ return altDir.hashCode();
+ }
+
+ /** To a File, after processing the filename for file: or relative filename */
+ public File toFile(String filenameIRI)
+ {
+ String scheme = FileUtils.getScheme(filenameIRI) ;
+ String fn = filenameIRI ;
+ // Windows : C:\\ is not a scheme name!
+ if ( scheme != null && scheme.length() > 1 )
+ {
+ if ( ! scheme.equalsIgnoreCase("file") )
+ // Not filename or a file: IRI
+ return null ;
+ fn = IRILib.IRIToFilename(filenameIRI) ;
+ }
+ // AltDir.
+ // "/" is a path separator on Windows.
+ if ( altDir != null && ! fn.startsWith("/") && ! fn.startsWith(File.pathSeparator) )
+ fn = altDir+"/"+fn ;
+ return new File(fn) ;
+ }
+
+ public boolean exists(String fileIRI)
+ {
+ File f = toFile(fileIRI) ;
+
+ if ( f == null )
+ return false ;
+
+ return f.exists() ;
+ }
+
+ /** Opne anything that looks a bit like a file name */
+ @Override
+ public TypedStream open(String filenameIRI)
+ {
+ File f = toFile(filenameIRI) ;
+
+ try {
+ if ( f == null || !f.exists() )
+ {
+ if ( StreamManager.logAllLookups && log.isTraceEnabled())
+ log.trace("Not found: "+filenameIRI+altDirLogStr) ;
+ return null ;
+ }
+ } catch (AccessControlException e) {
+ log.warn("Security problem testing for file", e);
+ return null;
+ }
+
+ try {
+ InputStream in = new FileInputStream(f) ;
+
+ if ( StreamManager.logAllLookups && log.isTraceEnabled() )
+ log.trace("Found: "+filenameIRI+altDirLogStr) ;
+
+ // Guess content from extension.
+ Lang lang = Lang.guess(filenameIRI) ;
+ String contentType = WebContent.mapLangToContentType(lang) ;
+ String charset = WebContent.getCharsetForContentType(contentType) ;
+ return new TypedStream(in, contentType, charset) ;
+ } catch (IOException ioEx)
+ {
+ // Includes FileNotFoundException
+ // We already tested whether the file exists or not.
+ log.warn("File unreadable (but exists): "+f.getPath()+" Exception: "+ioEx.getMessage()) ;
+ return null ;
+ }
+ }
+
+ @Override
+ public String getName()
+ {
+ String tmp = "LocatorFile" ;
+ if ( altDir != null )
+ tmp = tmp+"("+altDir+")" ;
+ return tmp ;
+ }
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/LocatorURL.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/LocatorURL.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/LocatorURL.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/LocatorURL.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,156 @@
+/**
+ * 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 fm2.atlas;
+
+import java.io.BufferedInputStream ;
+import java.io.IOException ;
+import java.io.InputStream ;
+import java.net.MalformedURLException ;
+import java.net.URL ;
+import java.net.URLConnection ;
+
+import org.openjena.atlas.web.TypedStream ;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+/** Location files named by a URL */
+
+public class LocatorURL implements Locator
+{
+ static Logger log = LoggerFactory.getLogger(LocatorURL.class) ;
+ static final String acceptHeader = "application/rdf+xml,application/xml;q=0.9,*/*;q=0.5" ;
+
+ static final String[] schemeNames = { "http:" , "https:" } ; // Must be lower case and include the ":"
+
+ @Override
+ public TypedStream open(String filenameOrURI)
+ {
+ if ( ! acceptByScheme(filenameOrURI) )
+ {
+ if ( StreamManager.logAllLookups && log.isTraceEnabled() )
+ log.trace("Not found : "+filenameOrURI) ;
+ return null;
+ }
+
+ try
+ {
+ URL url = new URL(filenameOrURI);
+ URLConnection conn = url.openConnection();
+ conn.setRequestProperty("Accept", acceptHeader) ;
+ conn.setRequestProperty("Accept-Charset", "utf-8,*") ;
+ conn.setDoInput(true) ;
+ conn.setDoOutput(false) ;
+ // Default is true. See javadoc for HttpURLConnection
+ //((HttpURLConnection)conn).setInstanceFollowRedirects(true) ;
+ conn.connect() ;
+ InputStream in = new BufferedInputStream(conn.getInputStream());
+
+ if ( StreamManager.logAllLookups && log.isTraceEnabled() )
+ log.trace("Found: "+filenameOrURI) ;
+ // Parse content type into a ContentType and ...
+ //return new TypedStream(in, ct) ;
+ return new TypedStream(in) ;
+ }
+ catch (java.io.FileNotFoundException ex)
+ {
+ if ( StreamManager.logAllLookups && log.isTraceEnabled() )
+ log.trace("LocatorURL: not found: "+filenameOrURI) ;
+ return null ;
+ }
+ catch (MalformedURLException ex)
+ {
+ log.warn("Malformed URL: " + filenameOrURI);
+ return null;
+ }
+ // IOExceptions that occur sometimes.
+ catch (java.net.UnknownHostException ex)
+ {
+ if ( StreamManager.logAllLookups && log.isTraceEnabled() )
+ log.trace("LocatorURL: not found (UnknownHostException): "+filenameOrURI) ;
+ return null ;
+ }
+ catch (java.net.ConnectException ex)
+ {
+ if ( StreamManager.logAllLookups && log.isTraceEnabled() )
+ log.trace("LocatorURL: not found (ConnectException): "+filenameOrURI) ;
+ return null ;
+ }
+ catch (java.net.SocketException ex)
+ {
+ if ( StreamManager.logAllLookups && log.isTraceEnabled() )
+ log.trace("LocatorURL: not found (SocketException): "+filenameOrURI) ;
+ return null ;
+ }
+ // And IOExceptions we don't expect
+ catch (IOException ex)
+ {
+ log.warn("I/O Exception opening URL: " + filenameOrURI+" "+ex.getMessage(), ex);
+ return null;
+ }
+ }
+
+ @Override
+ public boolean equals( Object other )
+ {
+ return other instanceof LocatorURL;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return LocatorURL.class.hashCode();
+ }
+
+ @Override
+ public String getName() { return "LocatorURL" ; }
+
+ private boolean acceptByScheme(String filenameOrURI)
+ {
+ String uriSchemeName = getScheme(filenameOrURI) ;
+ if ( uriSchemeName == null )
+ return false ;
+ uriSchemeName = uriSchemeName.toLowerCase() ;
+ for ( int i = 0 ; i < schemeNames.length ; i++ )
+ {
+ if ( uriSchemeName.equals(schemeNames[i]) )
+ return true ;
+ }
+ return false ;
+ }
+
+ private boolean hasScheme(String uri, String scheme)
+ {
+ String actualScheme = getScheme(uri) ;
+ if ( actualScheme == null )
+ return false ;
+ return actualScheme.equalsIgnoreCase(scheme) ;
+ }
+
+ // Not perfect - but we support Java 1.3 (as of August 2004)
+ private String getScheme(String uri)
+ {
+ int ch = uri.indexOf(':') ;
+ if ( ch < 0 )
+ return null ;
+
+ // Includes the :
+ return uri.substring(0,ch+1) ;
+ }
+
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/LocatorZip.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/LocatorZip.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/LocatorZip.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/LocatorZip.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,87 @@
+/**
+ * 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 fm2.atlas;
+
+import java.io.IOException ;
+import java.io.InputStream ;
+import java.util.zip.ZipEntry ;
+import java.util.zip.ZipFile ;
+
+import org.openjena.atlas.web.TypedStream ;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+import com.hp.hpl.jena.shared.JenaException ;
+
+
+/** Location files in a zip file */
+
+public class LocatorZip implements Locator
+{
+ static Logger log = LoggerFactory.getLogger(LocatorZip.class) ;
+ String zipFileName = null ;
+ ZipFile zipFile = null ;
+
+ public LocatorZip(String zfn)
+ {
+ try {
+ zipFileName = zfn ;
+ zipFile = new ZipFile(zipFileName) ;
+ } catch (IOException ex)
+ {
+ throw new JenaException("Problems accessing "+zipFileName, ex) ;
+ }
+ }
+
+ @Override
+ public TypedStream open(String filenameOrURI)
+ {
+ ZipEntry entry = zipFile.getEntry(filenameOrURI) ;
+ if ( entry == null )
+ {
+ if ( StreamManager.logAllLookups && log.isDebugEnabled() )
+ log.debug("Not found: "+zipFileName+" : "+filenameOrURI) ;
+ return null ;
+
+ }
+ try
+ {
+ InputStream in = zipFile.getInputStream(entry) ;
+
+ if ( in == null )
+ {
+ if ( StreamManager.logAllLookups && log.isTraceEnabled() )
+ log.trace("Not found: "+filenameOrURI) ;
+ return null ;
+ }
+
+ if ( StreamManager.logAllLookups && log.isTraceEnabled() )
+ log.trace("Found: "+filenameOrURI) ;
+ return new TypedStream(in) ;
+ }
+ catch (IOException ex)
+ {
+ log.warn("IO Exception opening zip entry: " + filenameOrURI);
+ return null;
+ }
+ }
+ @Override
+ public String getName() { return "LocatorZip("+zipFileName+")" ; }
+
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/StreamManager.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/StreamManager.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/StreamManager.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/StreamManager.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,120 @@
+/**
+ * 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 fm2.atlas;
+
+import java.io.InputStream ;
+import java.util.ArrayList ;
+import java.util.List ;
+
+import org.openjena.atlas.lib.IRILib ;
+import org.openjena.atlas.web.TypedStream ;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+/** Operations to open streams, indirecting via a LocationMapper.
+ * Inckludes filename to IRI, handling ".gz" and "-"
+ *
+ * */
+public class StreamManager
+{
+ // Need to combine with IO to do the .gz and "-" things.
+
+ private static Logger log = LoggerFactory.getLogger(StreamManager.class) ;
+
+ public static boolean logAllLookups = true ;
+
+ protected List<Locator> handlers = new ArrayList<Locator>() ;
+ protected LocationMapper mapper = null ;
+
+ /** Open a file using the locators of this FileManager */
+ public InputStream open(String filenameOrURI)
+ {
+ if ( log.isDebugEnabled())
+ log.debug("open("+filenameOrURI+")") ;
+
+ String uri = mapURI(filenameOrURI) ;
+
+ if ( log.isDebugEnabled() && ! uri.equals(filenameOrURI) )
+ log.debug("open: mapped to "+uri) ;
+
+ return openNoMap(uri) ;
+ }
+
+ /** Apply the mapping of a filename or URI */
+ public String mapURI(String filenameOrURI)
+ {
+ // XXX NO
+ // allow any string (e.g. relative filename - made absolute in LocatorFile)
+
+ String uriFilename = IRILib.filenameToIRI(filenameOrURI) ;
+
+
+ if ( mapper == null )
+ return uriFilename ;
+
+ String uri = mapper.altMapping(uriFilename, null) ;
+
+ if ( uri == null )
+ {
+ if ( StreamManager.logAllLookups && log.isDebugEnabled() )
+ log.debug("Not mapped: "+filenameOrURI) ;
+ uri = uriFilename ;
+ }
+ else
+ {
+ if ( log.isDebugEnabled() )
+ log.debug("Mapped: "+filenameOrURI+" => "+uri) ;
+ }
+ return uri ;
+ }
+
+ /** Open a file using the locators of this FileManager
+ * but without location mapping */
+ public InputStream openNoMap(String filenameOrURI)
+ {
+ TypedStream in = openNoMapOrNull(filenameOrURI) ;
+ if ( in == null )
+ return null ;
+// if ( in == null )
+// throw new NotFoundException(filenameOrURI) ;
+ return in.getInput() ;
+ }
+
+ /** Open a file using the locators of this FileManager
+ * but without location mapping.
+ * Return null if not found
+ */
+
+ public TypedStream openNoMapOrNull(String filenameOrURI)
+ {
+ String uriFilename = IRILib.filenameToIRI(filenameOrURI) ;
+ for (Locator loc : handlers)
+ {
+ TypedStream in = loc.open(uriFilename) ;
+ if ( in != null )
+ {
+ if ( log.isDebugEnabled() )
+ log.debug("Found: "+uriFilename+" ("+loc.getName()+")") ;
+ return in ;
+ }
+ }
+ return null;
+ }
+
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TS_IO2.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TS_IO2.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TS_IO2.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TS_IO2.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,34 @@
+/**
+ * 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 fm2.atlas;
+
+
+import org.junit.runner.RunWith ;
+import org.junit.runners.Suite ;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( {
+ TestStreamManager.class
+ , TestLocationMapper.class
+ , TestLocators.class
+})
+public class TS_IO2
+{
+
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TestLocationMapper.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TestLocationMapper.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TestLocationMapper.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TestLocationMapper.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,184 @@
+/**
+ * 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 fm2.atlas;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.util.FileManager;
+import com.hp.hpl.jena.util.LocationMapper;
+
+import fm2.TestFileManager ;
+
+/** TestLocationMapper
+ *
+ * @author Andy Seaborne
+ * @version $Id: TestLocationMapper.java,v 1.1 2009/06/29 18:42:05 andy_seaborne Exp $
+ */
+
+public class TestLocationMapper extends TestCase
+{
+ static Logger log = LoggerFactory.getLogger(TestLocationMapper.class) ;
+ static final String testingDir = TestFileManager.testingDir ;
+ static final String filename1 = "file:test" ;
+ static final String notFilename = "zzzz" ;
+ static final String filename2 = "file:"+testingDir+"/location-mapping-test-file" ;
+ public static final String mapping = "location-mapping-test.n3;"+
+ testingDir+"/location-mapping-test.n3" ;
+
+
+ public TestLocationMapper( String name )
+ {
+ super(name);
+ }
+
+ public static TestSuite suite()
+ {
+ return new TestSuite( TestLocationMapper.class );
+ }
+
+ public void testLocationMapper()
+ {
+ LocationMapper locMap = new LocationMapper(mapping) ;
+ String alt = locMap.altMapping(filename1) ;
+ assertNotNull(alt) ;
+ assertEquals(alt, filename2) ;
+ }
+
+ public void testLocationMapperMiss()
+ {
+ LocationMapper locMap = new LocationMapper(mapping) ;
+ String alt = locMap.altMapping(notFilename) ;
+ assertNotNull(alt) ;
+ assertEquals(alt, notFilename) ;
+ }
+
+ public void testLocationMapperURLtoFile()
+ {
+ LocationMapper locMap = new LocationMapper(mapping) ;
+ String alt = locMap.altMapping("http://example.org/file") ;
+ assertNotNull(alt) ;
+ assertEquals(alt, "file:"+testingDir+"/location-mapping-test-file") ;
+ }
+
+ public void testLocationMapperFromModel()
+ {
+ Model model = FileManager.get().loadModel(testingDir+"/location-mapping-test.n3") ;
+ LocationMapper loc = new LocationMapper(model) ;
+
+ // Light test that the two location mappers are "the same"
+ LocationMapper locMap = new LocationMapper(mapping) ;
+ for ( Iterator<String> iter = loc.listAltEntries() ; iter.hasNext() ; )
+ {
+ String e = iter.next() ;
+ String v1 = locMap.getAltEntry(e) ;
+ String v2 = loc.getAltEntry(e) ;
+ assertEquals("Different entries", v1, v2) ;
+ }
+ for ( Iterator<String> iter = loc.listAltPrefixes() ; iter.hasNext() ; )
+ {
+ String e = iter.next() ;
+ String v1 = locMap.getAltPrefix(e) ;
+ String v2 = loc.getAltPrefix(e) ;
+ assertEquals("Different entries", v1, v2) ;
+ }
+ }
+
+ public void testLocationMapperClone1()
+ {
+ LocationMapper locMap1 = new LocationMapper(mapping) ;
+ // See testLocationMapperURLtoFile
+// String alt = locMap.altMapping("http://example.org/file") ;
+// assertNotNull(alt) ;
+// assertEquals(alt, "file:"+testingDir+"/location-mapping-test-file") ;
+
+ LocationMapper locMap2 = new LocationMapper(locMap1) ;
+ // Remove from original
+ locMap1.removeAltEntry("http://example.org/file") ;
+ String alt = locMap2.altMapping("http://example.org/file") ;
+ assertNotNull(alt) ;
+ assertEquals(alt, "file:"+testingDir+"/location-mapping-test-file") ;
+ }
+
+ public void testLocationMapperClone2()
+ {
+ LocationMapper locMap1 = new LocationMapper(mapping) ;
+ // See testLocationMapperURLtoFile
+// String alt = locMap.altMapping("http://example.org/file") ;
+// assertNotNull(alt) ;
+// assertEquals(alt, "file:"+testingDir+"/location-mapping-test-file") ;
+
+ LocationMapper locMap2 = new LocationMapper(locMap1) ;
+
+ // Change this one
+ locMap2.addAltPrefix("http://example.org/OTHER", "file:OTHER") ;
+ {
+ String alt = locMap2.altMapping("http://example.org/OTHER/f") ;
+ assertNotNull(alt) ;
+ assertEquals(alt, "file:OTHER/f") ;
+ }
+ // Not the other
+ {
+ String alt = locMap1.altMapping("http://example.org/OTHER/f") ;
+ assertNotNull(alt) ;
+ // Did not change
+ assertEquals(alt, "http://example.org/OTHER/f") ;
+ }
+ }
+
+ public void testLocationMapperEquals1()
+ {
+ LocationMapper locMap1 = new LocationMapper(mapping) ;
+ LocationMapper locMap2 = new LocationMapper(mapping) ;
+ assertEquals(locMap1, locMap2) ;
+ assertEquals(locMap1.hashCode(), locMap2.hashCode()) ;
+ }
+
+ public void testLocationMapperEquals2()
+ {
+ LocationMapper locMap1 = new LocationMapper(mapping) ;
+ LocationMapper locMap2 = new LocationMapper(mapping) ;
+ locMap2.addAltEntry("file:nowhere", "file:somewhere") ;
+ assertFalse(locMap1.equals(locMap2)) ;
+ assertFalse(locMap2.equals(locMap1)) ;
+ }
+
+ public void testLocationMapperToModel1()
+ {
+ LocationMapper locMap1 = new LocationMapper(mapping) ;
+ LocationMapper locMap2 = new LocationMapper(locMap1.toModel()) ;
+ assertEquals(locMap1, locMap2) ;
+ assertEquals(locMap1.hashCode(), locMap2.hashCode()) ;
+ }
+
+ public void testLocationMapperToModel2()
+ {
+ LocationMapper locMap1 = new LocationMapper(mapping) ;
+ LocationMapper locMap2 = new LocationMapper(mapping) ;
+ locMap1 = new LocationMapper(locMap1.toModel()) ;
+ locMap2.addAltEntry("file:nowhere", "file:somewhere") ;
+ assertFalse(locMap1.equals(locMap2)) ;
+ assertFalse(locMap2.equals(locMap1)) ;
+ }
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TestLocators.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TestLocators.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TestLocators.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TestLocators.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,83 @@
+/**
+ * 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 fm2.atlas;
+
+import java.io.File ;
+
+import org.junit.Test ;
+import org.openjena.atlas.junit.BaseTest ;
+import org.openjena.atlas.web.TypedStream ;
+import org.openjena.riot.WebContent ;
+
+public class TestLocators extends BaseTest
+{
+ public static final String testingDir = "testing/RIOT/Files/" ;
+
+ @Test public void locatorFile_01()
+ {
+ LocatorFile loc = new LocatorFile() ;
+ assertTrue(loc.exists("pom.xml")) ;
+ assertTrue(loc.exists(testingDir+"data.ttl")) ;
+ assertFalse(loc.exists("IDoNotExist")) ;
+ }
+
+ @Test public void locatorFile_02()
+ {
+ LocatorFile loc = new LocatorFile(".") ;
+ assertTrue(loc.exists("pom.xml")) ;
+ assertTrue(loc.exists(testingDir+"data.ttl")) ;
+ assertFalse(loc.exists("IDoNotExist")) ;
+ }
+
+ @Test public void locatorFile_03()
+ {
+ String dir = new File(".").getAbsolutePath() ;
+ LocatorFile loc = new LocatorFile(dir) ;
+ assertTrue(loc.exists("pom.xml")) ;
+ assertFalse(loc.exists("IDoNotExist")) ;
+ }
+
+ @Test public void locatorFile_04()
+ {
+ String dir = new File("src").getAbsolutePath() ;
+ LocatorFile loc = new LocatorFile(dir) ;
+
+ assertFalse(loc.exists("pom.xml")) ;
+ assertTrue(loc.exists("org")) ;
+ assertFalse(loc.exists(testingDir+"data.ttl")) ;
+ assertTrue(loc.exists("../pom.xml")) ;
+ assertFalse(loc.exists("/../"+testingDir+"data.ttl")) ;
+ }
+
+ @Test public void locatorFile_05()
+ {
+ LocatorFile loc = new LocatorFile() ;
+ TypedStream ts = loc.open(testingDir+"data.ttl") ;
+ assertTrue("Not equal: "+WebContent.contentTypeTurtle+" != "+ts.getMediaType(),
+ WebContent.contentTypeTurtleAlt1.equalsIgnoreCase(ts.getContentType())) ;
+ }
+
+ // TypedStream
+
+ @Test public void locatorURL_01() {}
+
+ @Test public void locatorZip_01() {}
+
+ @Test public void locatorClassloader_01() {}
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TestStreamManager.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TestStreamManager.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TestStreamManager.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/atlas/TestStreamManager.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,27 @@
+/**
+ * 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 fm2.atlas;
+
+import org.junit.Test ;
+import org.openjena.atlas.junit.BaseTest ;
+
+public class TestStreamManager extends BaseTest
+{
+ @Test public void streamManager_01() {}
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/jenautil/FileManager2.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/jenautil/FileManager2.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/jenautil/FileManager2.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/jenautil/FileManager2.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,458 @@
+/**
+ * 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 fm2.jenautil;
+
+import java.io.File ;
+import java.io.IOException ;
+import java.util.HashMap ;
+import java.util.Iterator ;
+import java.util.Map ;
+
+import org.openjena.atlas.web.TypedStream ;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.shared.JenaException ;
+import com.hp.hpl.jena.shared.NotFoundException ;
+import com.hp.hpl.jena.util.FileUtils ;
+
+import fm2.atlas.LocationMapper ;
+import fm2.atlas.Locator ;
+import fm2.atlas.LocatorClassLoader ;
+import fm2.atlas.LocatorFile ;
+import fm2.atlas.LocatorURL ;
+import fm2.atlas.LocatorZip ;
+import fm2.atlas.StreamManager ;
+
+/** FileManager
+ *
+ * A FileManager provides access to named file-like resources by opening
+ * InputStreams to things in the filing system, by URL (http: and file:) and
+ * found by the classloader. It can also load RDF data from such a system
+ * resource into an existing model or create a new (Memory-based) model.
+ * There is a global FileManager which provide uniform access to system
+ * resources: applications may also create specialised FileManagers.
+ *
+ * A FileManager contains a list of location functions to try: the global
+ * FileManger has one {@link LocatorFile}, one {@link LocatorClassLoader} and
+ * one {@link LocatorURL}
+ *
+ * Main operations:
+ * * <ul>
+ * <li>loadModel, readModel : URI to model</li>
+ * <li>open, openNoMap : URI to input stream</li>
+ * <li>mapURI : map URI to another by {@link LocationMapper}</li>
+ * </ul>
+ *
+ * Utilities:
+ * <ul>
+ * <li>readWholeFileAsUTF8</li>
+ * <li>optional caching of models<li>
+ * </ul>
+ *
+ * A FileManager works in conjunction with a LocationMapper.
+ * A {@link LocationMapper} is a set of alternative locations for system
+ * resources and a set of alternative prefix locations. For example, a local
+ * copy of a common RDF dataset may be used whenever the usual URL is used by
+ * the application.
+ *
+ * The {@link LocatorFile} also supports the idea of "current directory".
+ *
+ * @see LocationMapper
+ * @see FileUtils
+ */
+
+public class FileManager2 extends StreamManager
+{
+ /** Delimiter between path entries : because URI scheme names use : we only allow ; */
+ public static final String PATH_DELIMITER = ";";
+ public static final String filePathSeparator = java.io.File.separator ;
+ private static Logger log = LoggerFactory.getLogger(FileManager2.class) ;
+
+ static FileManager2 instance = null ;
+
+ boolean cacheModelLoads = false ;
+ Map<String, Model> modelCache = null ;
+
+ /** Get the global file manager.
+ * @return the global file manager
+ */
+ public static FileManager2 get()
+ {
+ // Singleton pattern adopted in case we later have several file managers.
+ if ( instance == null )
+ instance = makeGlobal() ;
+ return instance ;
+ }
+
+ /** Set the global file manager (as returned by get())
+ * If called before any call to get(), then the usual default filemanager is not created
+ * @param globalFileManager
+ */
+ public static void setGlobalFileManager(FileManager2 globalFileManager)
+ {
+ instance = globalFileManager ;
+ }
+
+ /** Create an uninitialized FileManager */
+ public FileManager2() {}
+
+ /** Create a new file manager that is a deep copy another.
+ * Location mapper and locators chain are copied (the locators are not cloned).
+ * The model cache is not copied and is initially set to not cache.
+ * @param filemanager
+ */
+ public FileManager2(FileManager2 filemanager)
+ {
+ handlers.addAll(filemanager.handlers) ;
+ mapper = null ;
+ if ( filemanager.getLocationMapper() != null )
+ mapper = new LocationMapper(filemanager.getLocationMapper()) ;
+ cacheModelLoads = false ;
+ modelCache = null ;
+ }
+
+ /** Create a "standard" FileManager. */
+ public static FileManager2 makeGlobal()
+ {
+ FileManager2 fMgr = new FileManager2(JenaIOEnvironment.get()) ;
+ setStdLocators(fMgr) ;
+ return fMgr ;
+ }
+
+ /** Force a file handler to have the default configuration. */
+ public static void setStdLocators(FileManager2 fMgr)
+ {
+ fMgr.handlers.clear() ;
+ fMgr.addLocatorFile() ;
+ fMgr.addLocatorURL() ;
+ fMgr.addLocatorClassLoader(fMgr.getClass().getClassLoader()) ;
+ }
+ /** Create with the given location mapper */
+ public FileManager2(LocationMapper _mapper) { setLocationMapper(_mapper) ; }
+
+ /** @deprecated Use setLocationMapper */
+ @Deprecated
+ public void setMapper(LocationMapper _mapper) { setLocationMapper(_mapper) ; }
+
+
+ /** Set the location mapping */
+ public void setLocationMapper(LocationMapper _mapper) { mapper = _mapper ; }
+
+ /** Get the location mapping */
+ public LocationMapper getLocationMapper() { return mapper ; }
+
+ /** Return an iterator over all the handlers */
+ public Iterator<Locator> locators() { return handlers.listIterator() ; }
+
+ /** Add a locator to the end of the locators list */
+ public void addLocator(Locator loc)
+ {
+ log.debug("Add location: "+loc.getName()) ;
+ handlers.add(loc) ; }
+
+ /** Add a file locator */
+ public void addLocatorFile() { addLocatorFile(null) ; }
+
+ /** Add a file locator which uses dir as its working directory */
+ public void addLocatorFile(String dir)
+ {
+ LocatorFile fLoc = new LocatorFile(dir) ;
+ addLocator(fLoc) ;
+ }
+
+ /** Add a class loader locator */
+ public void addLocatorClassLoader(ClassLoader cLoad)
+ {
+ LocatorClassLoader cLoc = new LocatorClassLoader(cLoad) ;
+ addLocator(cLoc) ;
+ }
+
+ /** Add a URL locator */
+ public void addLocatorURL()
+ {
+ Locator loc = new LocatorURL() ;
+ addLocator(loc) ;
+ }
+
+ /** Add a zip file locator */
+ public void addLocatorZip(String zfn)
+ {
+ Locator loc = new LocatorZip(zfn) ;
+ addLocator(loc) ;
+ }
+
+
+ /** Remove a locator */
+ public void remove(Locator loc) { handlers.remove(loc) ; }
+
+ // -------- Cache operations
+
+ /** Reset the model cache */
+ public void resetCache()
+ {
+ if ( modelCache != null )
+ modelCache.clear() ;
+ }
+
+ /** Change the state of model cache : does not clear the cache */
+
+ public void setModelCaching(boolean state)
+ {
+ cacheModelLoads = state ;
+ if ( cacheModelLoads && modelCache == null )
+ modelCache = new HashMap<String, Model>() ;
+ }
+
+ /** return whether caching is on of off */
+ public boolean getCachingModels() { return cacheModelLoads ; }
+
+ /** Read out of the cache - return null if not in the cache */
+ public Model getFromCache(String filenameOrURI)
+ {
+ if ( ! getCachingModels() )
+ return null;
+ return modelCache.get(filenameOrURI) ;
+ }
+
+ public boolean hasCachedModel(String filenameOrURI)
+ {
+ if ( ! getCachingModels() )
+ return false ;
+ return modelCache.containsKey(filenameOrURI) ;
+ }
+
+ public void addCacheModel(String uri, Model m)
+ {
+ if ( getCachingModels() )
+ modelCache.put(uri, m) ;
+ }
+
+ public void removeCacheModel(String uri)
+ {
+ if ( getCachingModels() )
+ modelCache.remove(uri) ;
+ }
+
+ // -------- Cache operations (end)
+
+ /** Load a model from a file (local or remote).
+ * Guesses the syntax of the file based on filename extension,
+ * defaulting to RDF/XML.
+ * @param filenameOrURI The filename or a URI (file:, http:)
+ * @return a new model
+ * @exception JenaException if there is syntax error in file.
+ */
+
+ public Model loadModel(String filenameOrURI)
+ {
+ if ( log.isDebugEnabled() )
+ log.debug("loadModel("+filenameOrURI+")") ;
+
+ return loadModelWorker(filenameOrURI, null, null) ;
+ }
+
+
+ /** Load a model from a file (local or remote).
+ * URI is the base for reading the model.
+ *
+ * @param filenameOrURI The filename or a URI (file:, http:)
+ * @param rdfSyntax RDF Serialization syntax.
+ * @return a new model
+ * @exception JenaException if there is syntax error in file.
+ */
+
+ public Model loadModel(String filenameOrURI, String rdfSyntax)
+ {
+ if ( log.isDebugEnabled() )
+ log.debug("loadModel("+filenameOrURI+", "+rdfSyntax+")") ;
+ return loadModelWorker(filenameOrURI, null, rdfSyntax) ;
+ }
+
+ /** Load a model from a file (local or remote).
+ *
+ * @param filenameOrURI The filename or a URI (file:, http:)
+ * @param baseURI Base URI for loading the RDF model.
+ * @param rdfSyntax RDF Serialization syntax.
+ * @return a new model
+ * @exception JenaException if there is syntax error in file.
+ */
+
+
+ public Model loadModel(String filenameOrURI, String baseURI, String rdfSyntax)
+ {
+ if ( log.isDebugEnabled() )
+ log.debug("loadModel("+filenameOrURI+", "+baseURI+", "+rdfSyntax+")") ;
+
+ return loadModelWorker(filenameOrURI, baseURI, rdfSyntax) ;
+ }
+
+ private Model loadModelWorker(String filenameOrURI, String baseURI, String rdfSyntax)
+ {
+ // Better: if ( hasCachedModel(filenameOrURI) ) return getFromCache(filenameOrURI) ;
+ if ( modelCache != null && modelCache.containsKey(filenameOrURI) )
+ {
+ if ( log.isDebugEnabled() )
+ log.debug("Model cache hit: "+filenameOrURI) ;
+ return modelCache.get(filenameOrURI) ;
+ }
+
+ Model m = ModelFactory.createDefaultModel() ;
+ readModelWorker(m, filenameOrURI, baseURI, rdfSyntax) ;
+
+ if ( this.cacheModelLoads )
+ modelCache.put(filenameOrURI, m) ;
+ return m ;
+ }
+
+ /**
+ * Read a file of RDF into a model. Guesses the syntax of the file based on filename extension,
+ * defaulting to RDF/XML.
+ * @param model
+ * @param filenameOrURI
+ * @return The model or null, if there was an error.
+ * @exception JenaException if there is syntax error in file.
+ */
+
+ public Model readModel(Model model, String filenameOrURI)
+ {
+ if ( log.isDebugEnabled() )
+ log.debug("readModel(model,"+filenameOrURI+")") ;
+ return readModel(model, filenameOrURI, null);
+ }
+
+ /**
+ * Read a file of RDF into a model.
+ * @param model
+ * @param filenameOrURI
+ * @param rdfSyntax RDF Serialization syntax.
+ * @return The model or null, if there was an error.
+ * @exception JenaException if there is syntax error in file.
+ */
+
+ public Model readModel(Model model, String filenameOrURI, String rdfSyntax)
+ {
+ if ( log.isDebugEnabled() )
+ log.debug("readModel(model,"+filenameOrURI+", "+rdfSyntax+")") ;
+ return readModelWorker(model, filenameOrURI, null, rdfSyntax);
+ }
+
+ /**
+ * Read a file of RDF into a model.
+ * @param model
+ * @param filenameOrURI
+ * @param baseURI
+ * @param syntax
+ * @return The model
+ * @exception JenaException if there is syntax error in file.
+ */
+
+ public Model readModel(Model model, String filenameOrURI, String baseURI, String syntax)
+ {
+
+ if ( log.isDebugEnabled() )
+ log.debug("readModel(model,"+filenameOrURI+", "+baseURI+", "+syntax+")") ;
+ return readModelWorker(model, filenameOrURI, baseURI, syntax) ;
+ }
+
+ private Model readModelWorker(Model model, String filenameOrURI, String baseURI, String syntax)
+ {
+ // Doesn't call open() - we want to make the synatx guess based on the mapped URI.
+ String mappedURI = mapURI(filenameOrURI) ;
+
+ if ( log.isDebugEnabled() && ! mappedURI.equals(filenameOrURI) )
+ log.debug("Map: "+filenameOrURI+" => "+mappedURI) ;
+
+ if ( syntax == null && baseURI == null && mappedURI.startsWith( "http:" ) )
+ {
+ // No syntax, no baseURI, HTTP URL ==> use content negotiation
+ model.read(mappedURI) ;
+ return model ;
+ }
+
+ if ( syntax == null )
+ {
+ syntax = FileUtils.guessLang(mappedURI) ;
+ if ( syntax == null || syntax.equals("") )
+ syntax = FileUtils.langXML ;
+ if ( log.isDebugEnabled() )
+ log.debug("Syntax guess: "+syntax);
+ }
+
+ if ( baseURI == null )
+ baseURI = chooseBaseURI(filenameOrURI) ;
+
+ TypedStream in = openNoMapOrNull(mappedURI) ;
+ if ( in == null )
+ {
+ if ( log.isDebugEnabled() )
+ log.debug("Failed to locate '"+mappedURI+"'") ;
+ throw new NotFoundException("Not found: "+filenameOrURI) ;
+ }
+ if ( in.getMediaType() != null )
+ {
+ // XXX
+ //syntax
+ }
+ model.read(in.getInput(), baseURI, syntax) ;
+ try { in.getInput().close(); } catch (IOException ex) {}
+ return model ;
+ }
+
+ private static String chooseBaseURI(String baseURI)
+ {
+ String scheme = FileUtils.getScheme(baseURI) ;
+
+ if ( scheme != null )
+ {
+ if ( scheme.equals("file") )
+ {
+ if ( ! baseURI.startsWith("file:///") )
+ {
+ try {
+ // Fix up file URIs. Yuk.
+ String tmp = baseURI.substring("file:".length()) ;
+ File f = new File(tmp) ;
+ baseURI = "file:///"+f.getCanonicalPath() ;
+ baseURI = baseURI.replace('\\','/') ;
+
+// baseURI = baseURI.replace(" ","%20");
+// baseURI = baseURI.replace("~","%7E");
+ // Convert to URI. Except that it removes ///
+ // Could do that and fix up (again)
+ //java.net.URL u = new java.net.URL(baseURI) ;
+ //baseURI = u.toExternalForm() ;
+ } catch (Exception ex) {}
+ }
+ }
+ return baseURI ;
+ }
+
+ if ( baseURI.startsWith("/") )
+ return "file://"+baseURI ;
+ return "file:"+baseURI ;
+ }
+
+ /** @deprecated Use mapURI */
+ @Deprecated
+ public String remap(String filenameOrURI)
+ { return mapURI(filenameOrURI) ; }
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/jenautil/JenaIOEnvironment.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/jenautil/JenaIOEnvironment.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/jenautil/JenaIOEnvironment.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/fm2/jenautil/JenaIOEnvironment.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,239 @@
+/**
+ * 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 fm2.jenautil;
+
+import java.io.InputStream ;
+import java.util.StringTokenizer ;
+
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+import com.hp.hpl.jena.JenaRuntime ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.rdf.model.RDFNode ;
+import com.hp.hpl.jena.rdf.model.Resource ;
+import com.hp.hpl.jena.rdf.model.Statement ;
+import com.hp.hpl.jena.rdf.model.StmtIterator ;
+import com.hp.hpl.jena.shared.JenaException ;
+import com.hp.hpl.jena.util.FileUtils ;
+import com.hp.hpl.jena.vocabulary.LocationMappingVocab ;
+
+import fm2.atlas.LocationMapper ;
+
+/** Code for using the general facilities of the location mapper/ filemanager subsystem
+ * and set up for Jena usage. e.g. find a location mapper with RDf description.
+ */
+public class JenaIOEnvironment
+{
+ // TODO Singletons
+
+ static LocationMapper theMapper = null ;
+ /** Get the global LocationMapper */
+ public static LocationMapper getLocationMapper()
+ {
+ if ( theMapper == null )
+ {
+ theMapper = new LocationMapper() ;
+ if ( getGlobalConfigPath() != null )
+ JenaIOEnvironment.createLocationMapper(getGlobalConfigPath()) ;
+ }
+ return theMapper ;
+ }
+
+ static Logger log = LoggerFactory.getLogger(JenaIOEnvironment.class) ;
+
+ /** The default path for searching for the location mapper */
+ public static final String DEFAULT_PATH =
+ "file:location-mapping.rdf;file:location-mapping.n3;file:location-mapping.ttl;"+
+ "file:etc/location-mapping.rdf;file:etc/location-mapping.n3;"+
+ "file:etc/location-mapping.ttl" ;
+ public static final String GlobalMapperSystemProperty1 = "http://jena.hpl.hp.com/2004/08/LocationMap" ;
+ public static final String GlobalMapperSystemProperty2 = "LocationMap" ;
+
+ static String s_globalMapperPath = null ;
+
+
+
+ static private String getGlobalConfigPath()
+ {
+ if ( s_globalMapperPath == null )
+ s_globalMapperPath = JenaRuntime.getSystemProperty(GlobalMapperSystemProperty1,null) ;
+ if ( s_globalMapperPath == null )
+ s_globalMapperPath = JenaRuntime.getSystemProperty(GlobalMapperSystemProperty2,null) ;
+ if ( s_globalMapperPath == null )
+ s_globalMapperPath = DEFAULT_PATH ;
+ return s_globalMapperPath ;
+ }
+
+ /** Get the global LocationMapper */
+ public static LocationMapper get()
+ {
+ if ( theMapper == null )
+ {
+ theMapper = new LocationMapper() ;
+ if ( getGlobalConfigPath() != null )
+ JenaIOEnvironment.createLocationMapper(getGlobalConfigPath()) ;
+ }
+ return theMapper ;
+ }
+
+ /** Set the global lcoation mapper. (as returned by get())
+ * If called before any call to get(), then the usual default global location mapper is not created
+ * @param globalLocationMapper
+ */
+ public static void setGlobalLocationMapper(LocationMapper globalLocationMapper)
+ {
+ theMapper = globalLocationMapper ;
+ }
+
+ /** Make a location mapper from the path settings */
+ static public LocationMapper makeGlobal()
+ {
+ LocationMapper lMap = new LocationMapper() ;
+ if ( getGlobalConfigPath() != null )
+ {
+ LocationMapper lMap2 = JenaIOEnvironment.createLocationMapper(getGlobalConfigPath()) ;
+ lMap.copyFrom(lMap2) ;
+ }
+ return lMap ;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /** Create a LocationMapper based on Model */
+ public static LocationMapper processConfig(Model m)
+ {
+ LocationMapper locMap = new LocationMapper() ;
+ StmtIterator mappings =
+ m.listStatements(null, LocationMappingVocab.mapping, (RDFNode)null) ;
+
+ for (; mappings.hasNext();)
+ {
+ Statement s = mappings.nextStatement() ;
+ Resource mapping = s.getResource() ;
+
+ if ( mapping.hasProperty(LocationMappingVocab.name) )
+ {
+ try
+ {
+ String name = mapping.getRequiredProperty(LocationMappingVocab.name)
+ .getString() ;
+ String altName = mapping.getRequiredProperty(LocationMappingVocab.altName)
+ .getString() ;
+ locMap.addAltEntry(name, altName) ;
+ log.debug("Mapping: "+name+" => "+altName) ;
+ } catch (JenaException ex)
+ {
+ log.warn("Error processing name mapping: "+ex.getMessage()) ;
+ throw ex ;
+ }
+ }
+
+ if ( mapping.hasProperty(LocationMappingVocab.prefix) )
+ {
+ try
+ {
+ String prefix = mapping.getRequiredProperty(LocationMappingVocab.prefix)
+ .getString() ;
+ String altPrefix = mapping.getRequiredProperty(LocationMappingVocab.altPrefix)
+ .getString() ;
+ locMap.addAltPrefix(prefix, altPrefix) ;
+ log.debug("Prefix mapping: "+prefix+" => "+altPrefix) ;
+ } catch (JenaException ex)
+ {
+ log.warn("Error processing prefix mapping: "+ex.getMessage()) ;
+ throw ex ;
+ }
+ }
+ }
+ return locMap ;
+ }
+
+ /** Search a path (which is delimited by ";" because ":" is used in URIs)
+ * to find a description of a LocationMapper, then create and return a
+ * LocationMapper based on the description.
+ */
+ public static LocationMapper createLocationMapper(String configPath)
+ {
+ LocationMapper locMap = new LocationMapper() ;
+ if ( configPath == null || configPath.length() == 0 )
+ {
+ log.warn("Null configuration") ;
+ return null ;
+ }
+
+ // Make a file manager to look for the location mapping file
+ FileManager2 fm = new FileManager2() ;
+ fm.addLocatorFile() ;
+ fm.addLocatorClassLoader(fm.getClass().getClassLoader()) ;
+
+ try {
+ String uriConfig = null ;
+ InputStream in = null ;
+
+ StringTokenizer pathElems = new StringTokenizer( configPath, FileManager2.PATH_DELIMITER );
+ while (pathElems.hasMoreTokens()) {
+ String uri = pathElems.nextToken();
+ if ( uri == null || uri.length() == 0 )
+ break ;
+
+ in = fm.openNoMap(uri) ;
+ if ( in != null )
+ {
+ uriConfig = uri ;
+ break ;
+ }
+ }
+
+ if ( in == null )
+ {
+ log.debug("Failed to find configuration: "+configPath) ;
+ return null ;
+ }
+ // TODO
+ String syntax = FileUtils.guessLang(uriConfig) ;
+ Model model = ModelFactory.createDefaultModel() ;
+ model.read(in, uriConfig, syntax) ;
+ processConfig(model) ;
+ } catch (JenaException ex)
+ {
+ LoggerFactory.getLogger(LocationMapper.class).warn("Error in configuration file: "+ex.getMessage()) ;
+ }
+ return locMap ;
+ }
+
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/opexec/OpExecutorExample.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/opexec/OpExecutorExample.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/opexec/OpExecutorExample.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/opexec/OpExecutorExample.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,149 @@
+/**
+ * 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 opexec;
+
+import java.io.StringReader ;
+
+import org.openjena.atlas.lib.StrUtils ;
+import org.openjena.atlas.logging.Log ;
+
+import com.hp.hpl.jena.query.ARQ ;
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.query.ResultSetFormatter ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.sparql.algebra.op.OpBGP ;
+import com.hp.hpl.jena.sparql.algebra.op.OpFilter ;
+import com.hp.hpl.jena.sparql.core.BasicPattern ;
+import com.hp.hpl.jena.sparql.engine.ExecutionContext ;
+import com.hp.hpl.jena.sparql.engine.QueryIterator ;
+import com.hp.hpl.jena.sparql.engine.main.OpExecutor ;
+import com.hp.hpl.jena.sparql.engine.main.OpExecutorFactory ;
+import com.hp.hpl.jena.sparql.engine.main.QC ;
+import com.hp.hpl.jena.sparql.engine.main.StageBuilder ;
+
+/** Example skeleton for a query engine.
+ * To just extend ARQ by custom basic graph pattern matching (a very common case)
+ * see the arq.examples.bgpmatching package */
+
+public class OpExecutorExample //extends QueryEngineMain
+{
+ // UNFINISHED
+ // Check where OpExecutorFactory.create happens.
+
+ /* To install a custom OpExecutor, the application needs
+ *
+ *
+ * The example MyQueryEngine shows how to take over the
+ * execution of a SPARQL algebra expression. This allows
+ * customization of optimizations running before query execution
+ * starts.
+ *
+ * An OpExecutor controls the running of an algebra expression.
+ * An executor needs to cope with the fact a dataset might be composed
+ * of a mixture of graphs, and that it might be be being called for any
+ * kind of storage unit, not just one it is designed for.
+ *
+ * Thsi is done by having a chain (via subclassing) of OpExecutors,
+ * with the base class being hthe general purpose one for ARQ that can
+ * operate on any data storage layer.
+ *
+ */
+
+
+ static void init()
+ {
+ // Wire the new factory into the system.
+ ARQ.init() ;
+ // *** Where is the factory choosen?
+ OpExecutorFactory current = QC.getFactory(ARQ.getContext()) ;
+ // maybe null
+ QC.setFactory(ARQ.getContext(), new MyOpExecutorFactory(current)) ;
+ }
+
+
+ public static void main(String ...argv)
+ {
+ Log.setLog4j() ;
+ init() ;
+ Model m = data() ;
+
+ String s = "SELECT DISTINCT ?s { ?s ?p ?o FILTER (?o=12) } " ;
+ Query query = QueryFactory.create(s) ;
+ QueryExecution qExec = QueryExecutionFactory.create(query, m) ;
+ ResultSetFormatter.out(qExec.execSelect()) ;
+ qExec.close() ;
+ }
+
+
+
+ private static Model data()
+ {
+ String s = StrUtils.strjoinNL("<s> <p> 12 .",
+ "<s> <p> 15 .") ;
+ Model m = ModelFactory.createDefaultModel() ;
+ m.read(new StringReader(s), null , "TTL") ;
+ return m ;
+ }
+
+
+ // This is a simple example.
+ // For execution logging, see:
+ // http://openjena.org/wiki/ARQ/Explain
+ // which printout more information.
+ static class MyOpExecutor extends OpExecutor
+ {
+ protected MyOpExecutor(ExecutionContext execCxt)
+ {
+ super(execCxt) ;
+ }
+
+ @Override
+ protected QueryIterator execute(OpBGP opBGP, QueryIterator input)
+ {
+ System.out.print("Execute: "+opBGP) ;
+ // This is an illustration - it's a copy of the default implementation
+ BasicPattern pattern = opBGP.getPattern() ;
+ return StageBuilder.execute(pattern, input, execCxt) ;
+ }
+
+ @Override
+ protected QueryIterator execute(OpFilter opFilter, QueryIterator input)
+ {
+ System.out.print("Execute: "+opFilter) ;
+ return super.execute(opFilter, input) ;
+ }
+ }
+
+ /** A factory to make OpExecutors */
+ static class MyOpExecutorFactory implements OpExecutorFactory
+ {
+ private final OpExecutorFactory other ;
+
+ public MyOpExecutorFactory(OpExecutorFactory other) { this.other = other ; }
+ @Override
+ public OpExecutor create(ExecutionContext execCxt)
+ {
+ return new MyOpExecutor(execCxt) ;
+ }
+ }
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportDBPedia2.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportDBPedia2.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportDBPedia2.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportDBPedia2.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,62 @@
+/**
+ * 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 reports;
+
+import com.hp.hpl.jena.query.Query;
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.query.QueryExecutionFactory;
+import com.hp.hpl.jena.query.QueryFactory;
+import com.hp.hpl.jena.query.QuerySolution;
+import com.hp.hpl.jena.query.ResultSet;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+
+public class ReportDBPedia2
+{
+ // public class TestJena {
+ public static void main(String[] args) {
+
+ // http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=PREFIX+rdf%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0D%0APREFIX+dbpedia-owl%3A+%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2F%3E%0D%0ASELECT+%3Fvar+%0D%0AWHERE+{+%3Fvar+rdf%3Atype+dbpedia-owl%3ACompany+.+}&debug=on&timeout=&format=text%2Fhtml&save=display&fname=
+
+ String queryString = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ + "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>"
+ + "SELECT ?var "
+ + "WHERE { ?var rdf:type dbpedia-owl:Company . }";
+
+ System.out.println(queryString) ;
+
+ Query query = QueryFactory.create(queryString);
+
+ QueryExecution qexec = QueryExecutionFactory.sparqlService(
+ "http://dbpedia.org/sparql", query);
+ ResultSet rs = null;
+
+ rs = qexec.execSelect();
+ // **** TOO EARLY
+ //qexec.close();
+
+ while(rs.hasNext()) {
+ QuerySolution sqs = rs.next();
+ RDFNode node = sqs.get("var");
+ System.out.println(node);
+ }
+ qexec.close();
+ }
+
+
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportDatasetGraphAddNPE.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportDatasetGraphAddNPE.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportDatasetGraphAddNPE.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportDatasetGraphAddNPE.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,38 @@
+/**
+ * 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 reports;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.query.DataSource ;
+import com.hp.hpl.jena.sparql.core.DataSourceImpl ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+
+public class ReportDatasetGraphAddNPE
+{
+ public static void main(String ...strings)
+ {
+ DataSource dataSource = DataSourceImpl.createMem();
+ Node subject = Node.createURI("http://example/s");
+ Node predicate = Node.createURI("http://example/p");
+ Node object = Node.createAnon();
+ dataSource.asDatasetGraph().add(new Quad(Quad.defaultGraphIRI, subject, predicate, object));
+ dataSource.asDatasetGraph().deleteAny(Node.ANY, subject, null, null);
+ System.out.println("DONE") ;
+ }
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportFilterEquality.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportFilterEquality.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportFilterEquality.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportFilterEquality.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,64 @@
+/**
+ * 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 reports;
+
+import org.openjena.atlas.lib.StrUtils ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.query.ResultSet ;
+import com.hp.hpl.jena.query.ResultSetFormatter ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.sparql.algebra.Algebra ;
+import com.hp.hpl.jena.sparql.algebra.Op ;
+import com.hp.hpl.jena.sparql.sse.SSE ;
+import com.hp.hpl.jena.sparql.util.graph.GraphFactory ;
+
+public class ReportFilterEquality
+{
+ public static void main(String...argv)
+ {
+ String qs = StrUtils.strjoinNL(
+ "PREFIX ex: <http://example.com/ns#>" ,
+ "SELECT ?x WHERE {" ,
+ " ?s a ?c" ,
+ " OPTIONAL { ?s ex:property ?x }" ,
+ " FILTER (?c = ex:v)",
+ "}") ;
+ Query query = QueryFactory.create(qs) ;
+
+ Op op = Algebra.compile(query) ;
+ Op op2 = Algebra.optimize(op) ;
+ System.out.println(op) ;
+ System.out.println(op2) ;
+
+ Graph g = GraphFactory.createGraphMem() ;
+ Triple t = SSE.parseTriple("(<x> rdf:type <T>)") ;
+ g.add(t) ;
+ Model m = ModelFactory.createModelForGraph(g) ;
+ QueryExecution qExec = QueryExecutionFactory.create(query, m) ;
+ ResultSet rs = qExec.execSelect() ;
+ ResultSetFormatter.out(rs) ;
+ }
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportOracle1.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportOracle1.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportOracle1.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportOracle1.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,78 @@
+/**
+ * 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 reports;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.query.DataSource ;
+import com.hp.hpl.jena.query.DatasetFactory ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.update.UpdateAction ;
+
+public class ReportOracle1
+{
+ public static void main(String ...argv)
+ {
+ DataSource ds = DatasetFactory.create();
+
+ //ModelOracleSem model = ModelOracleSem.createOracleSemModel(oracle, szModelName);
+ Model model = ModelFactory.createDefaultModel() ;
+ model.getGraph().add(Triple.create(Node.createURI("http://example.org/bob"),
+ Node.createURI("http://purl.org/dc/elements/1.1/publisher"),
+ Node.createLiteral("Bob Hacker")));
+ model.getGraph().add(Triple.create(Node.createURI("http://example.org/alice"),
+ Node.createURI("http://purl.org/dc/elements/1.1/publisher"),
+ Node.createLiteral("alice Hacker")));
+
+
+ //ModelOracleSem model1 = ModelOracleSem.createOracleSemModel(oracle, szModelName+"1");
+ Model model1 = ModelFactory.createDefaultModel() ;
+
+ model1.getGraph().add(Triple.create(Node.createURI("urn:bob"),
+ Node.createURI("http://xmlns.com/foaf/0.1/name"),
+ Node.createLiteral("Bob")
+ ));
+ model1.getGraph().add(Triple.create(Node.createURI("urn:bob"),
+ Node.createURI("http://xmlns.com/foaf/0.1/mbox"),
+ Node.createURI("mailto:bob@example")
+ ));
+
+ //ModelOracleSem model2 = ModelOracleSem.createOracleSemModel(oracle, szModelName+"2");
+ Model model2 = ModelFactory.createDefaultModel() ;
+ model2.getGraph().add(Triple.create(Node.createURI("urn:alice"),
+ Node.createURI("http://xmlns.com/foaf/0.1/name"),
+ Node.createLiteral("Alice")
+ ));
+ model2.getGraph().add(Triple.create(Node.createURI("urn:alice"),
+ Node.createURI("http://xmlns.com/foaf/0.1/mbox"),
+ Node.createURI("mailto:alice@example")
+ ));
+
+ ds.setDefaultModel(model);
+ //ds.addNamedModel("<http://example.org/bob>",model1);
+ ds.addNamedModel("http://example.org/bob",model1);
+ // ds.addNamedModel("http://example.org/alice",model2);
+
+ String insertString =
+ "INSERT DATA <http://example.org/bob> {<urn:alice> <urn:loves> <urn:apples> } ";
+ UpdateAction.parseExecute(insertString, ds);
+ System.out.println("DONE") ;
+ }
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportPathCycles.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportPathCycles.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportPathCycles.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportPathCycles.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,59 @@
+/**
+ * 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 reports;
+
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.query.ResultSet ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.rdf.model.Resource ;
+import com.hp.hpl.jena.vocabulary.RDFS ;
+
+public class ReportPathCycles
+{
+ public static void main(String...argv)
+ {
+ Model model = ModelFactory.createDefaultModel();
+ // Create chain
+ int count = 1000;
+ for(int i = 0; i < count; i++) {
+ Resource subClass = model.createResource("urn:x-test:class-" + i);
+ Resource superClass = model.createResource("urn:x-test:class-" + (i + 1));
+ model.add(subClass, RDFS.subClassOf, superClass);
+ }
+ // Create random cycles
+ for(int i = 0; i < 100; i++) {
+ Resource subClass = model.createResource("urn:x-test:class-" + (int)(Math.random() * count));
+ Resource superClass = model.createResource("urn:x-test:class-" + (int)(Math.random() * count));
+ model.add(subClass, RDFS.subClassOf, superClass);
+ }
+ Query query = QueryFactory.create("SELECT * WHERE { ?x <" + RDFS.subClassOf + ">* ?y }");
+ QueryExecution qexec = QueryExecutionFactory.create(query, model);
+ ResultSet rs = qexec.execSelect();
+ int x = 0 ;
+ while(rs.hasNext()) {
+ x++ ;
+ rs.next();
+ }
+ System.out.println("results = "+x) ;
+ }
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportReifierRemove.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportReifierRemove.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportReifierRemove.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportReifierRemove.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,70 @@
+/**
+ * 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 reports;
+
+import org.junit.Test ;
+import static org.junit.Assert.* ;
+
+import com.hp.hpl.jena.graph.Reifier ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.rdf.model.Property ;
+import com.hp.hpl.jena.rdf.model.Resource ;
+import com.hp.hpl.jena.rdf.model.Statement ;
+import com.hp.hpl.jena.sparql.graph.Reifier2 ;
+
+public class ReportReifierRemove
+{
+ @Test
+ public void testOverenthusiasticDeletion_1() {
+
+
+ Model model = ModelFactory.createDefaultModel() ;
+ model.setNsPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#") ;
+ model.setNsPrefix("rex", "http://jug.basistech.com/2011/01/rex-entity#") ;
+ model.setNsPrefix("g", "urn:jug:global#") ;
+
+ Resource per1 = model.createResource("urn:jug:global#per1");
+ Resource per2 = model.createResource("urn:jug:global#per2");
+ Property pred1 = model.createProperty("http://jug.basistech.com/2011/01/rex-entity#coOccurInSentence");
+ Property pred2 = model.createProperty("http://jug.basistech.com/2011/01/rex-entity#hasSibling");
+ Statement s1 = model.createStatement(per1, pred1, per2);
+ Statement s2 = model.createStatement(per2, pred2, per2);
+
+ s1.createReifiedStatement();
+ s2.createReifiedStatement();
+
+ model.write(System.out, "TTL") ;
+ System.out.println() ;
+ System.out.println() ;
+ System.out.println() ;
+ System.out.println() ;
+ assertEquals(2, model.listReifiedStatements().toList().size());
+
+ Reifier r = new Reifier2(model.getGraph()) ;
+
+ //r = model.getGraph().getReifier() ;
+
+ r.remove(s2.asTriple()) ;
+ //s2.removeReification();
+ model.write(System.out, "TTL") ;
+ assertEquals(1, model.listReifiedStatements().toList().size());
+ }
+
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportRemoteVirtuoso.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportRemoteVirtuoso.java?rev=1177649&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportRemoteVirtuoso.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/ReportRemoteVirtuoso.java Fri Sep 30 13:32:00 2011
@@ -0,0 +1,91 @@
+/**
+ * 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 reports;
+
+import org.openjena.atlas.logging.Log ;
+
+import com.hp.hpl.jena.query.ARQ ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.QuerySolution ;
+import com.hp.hpl.jena.query.ResultSet ;
+import com.hp.hpl.jena.rdf.model.RDFNode ;
+
+
+public class ReportRemoteVirtuoso
+{
+ static { Log.setLog4j() ; }
+
+ public static void main(String[] args) {
+
+ String service = "http://pubmed.bio2rdf.org/sparql";
+ String querystring = "PREFIX dc:<http://purl.org/dc/terms/> \n"
+ + "PREFIX pub:<http://bio2rdf.org/pubmed:> \n"
+ + "PREFIX pubres:<http://bio2rdf.org/pubmed_resource:> \n"
+ + "PREFIX foaf:<http://xmlns.com/foaf/0.1/> \n"
+ + "select ?title ?mesh ?last ?first \n"
+ + "where { \n"
+ + "pub:18231773 dc:title ?title . \n"
+ + "pub:18231773 pubres:subject_headings ?mesh . \n"
+ + "pub:18231773 pubres:author ?authorid . \n"
+ + "?authorid foaf:lastName ?last . \n"
+ + "?authorid foaf:firstName ?first . \n"
+ + "} ";
+
+ ResultSet results = remoteSelectQuery(service, querystring);
+ String[] kws = {"title", "mesh", "author"};
+
+// long count = ResultSetFormatter.consume(results) ;
+// System.out.println("Count = "+count) ;
+
+ printResults(results, kws);
+ }
+
+ private static ResultSet remoteSelectQuery(String service, String querystring) {
+ System.out.println(querystring);
+
+ if ( true )
+ ARQ.getContext().setTrue(ARQ.useSAX) ;
+
+ QueryExecution qexec = QueryExecutionFactory.sparqlService(service, querystring);
+
+ try {
+ return qexec.execSelect();
+ } finally {
+ //****** TOO EARLY
+ qexec.close();
+ }
+ }
+
+ private static void printResults(ResultSet results, String[] strings) {
+ int line = 0 ;
+ while (results.hasNext()) {
+ line++ ;
+ System.out.printf("%03d: ", line) ;
+ QuerySolution soln = results.nextSolution();
+ for (String s : strings) {
+ RDFNode x = soln.get(s); // Get a result variable by name.
+ if (x != null) {
+ System.out.println(s + ": " + x.toString());
+ }
+ }
+ }
+ }
+
+}