Strabon

changeset 227:d9d201dcc4c6

When storing a file, first check whether it exists, otherwise store input as string.
Is it useful to have a storeString method? I would say, no.
author Babis Nikolaou <charnik@di.uoa.gr>
date Sat Jun 02 18:33:58 2012 +0300 (2012-06-02)
parents dbbfb1a23017
children 788831ebb99b
files runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Sat Jun 02 18:06:53 2012 +0300
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Sat Jun 02 18:33:58 2012 +0300
     1.3 @@ -828,48 +828,26 @@
     1.4  		{
     1.5  			throw new InvalidDatasetFormatFault();
     1.6  		}
     1.7 +		
     1.8         try{
     1.9 -    	   URL source = new URL((String) src);
    1.10 +    	   URL source = new URL(src);
    1.11      	   storeURL(source, baseURI, uriContext, realFormat);
    1.12      	   
    1.13 -       }catch(MalformedURLException e){
    1.14 -    	   File file = new File((String) src);
    1.15 -    	   String urlfile = "file://"+src;
    1.16 -
    1.17 -    	   try
    1.18 -    	   {
    1.19 -    		   URL urlf  = new URL(urlfile);
    1.20 -    		   storeURL(urlf, baseURI, uriContext, realFormat); //file.toURL is deprecated  
    1.21 -    	   }
    1.22 -    	   catch(MalformedURLException ex)
    1.23 -    	   {
    1.24 +       } catch(MalformedURLException e) {
    1.25 +    	   File file = new File(src);
    1.26 +    	   if (file.exists()) {
    1.27 +    		   storeURL(new URL("file://" + src), baseURI, uriContext, realFormat);
    1.28 +    		   
    1.29 +    	   } else {
    1.30 +    		   logger.info("File \"" + src + "\" does not exist. Trying reading as String.");
    1.31      		   storeString((String)src, baseURI, uriContext, realFormat);
    1.32      	   }
    1.33 -    	   
    1.34         }
    1.35 -
    1.36 -		/*try
    1.37 -		{
    1.38 -			if(File.class.isInstance(src))
    1.39 -			{
    1.40 -				storeFile((File)src, baseURI, uriContext, realFormat);
    1.41 -			}
    1.42 -			else if(URL.class.isInstance(src))
    1.43 -			{
    1.44 -				storeURL((URL)src, baseURI, uriContext, realFormat);
    1.45 -			}
    1.46 -			else if(String.class.isInstance(src))
    1.47 -			{
    1.48 -				storeString((String)src, baseURI, uriContext, realFormat);
    1.49 -			}
    1.50 -		}
    1.51 -		catch(NullPointerException e) {
    1.52 -			logger.error("[Strabon.storeInRepo]", e.getStackTrace());
    1.53 -		}*/
    1.54  	}
    1.55  
    1.56  	private void storeURL(URL url, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException, RDFHandlerException
    1.57  	{
    1.58 +		logger.info("[Strabon.storeURL] Storing file.");
    1.59  		logger.info("[Strabon.storeURL] URL      : " + url.toString());
    1.60  		logger.info("[Strabon.storeURL] Base URI : " + ((baseURI == null) ? "null" : baseURI));
    1.61  		logger.info("[Strabon.storeURL] Context  : " + ((context == null) ? "null" : context));
    1.62 @@ -886,7 +864,7 @@
    1.63  		if (handler.getNumberOfTriples() > 0) {
    1.64  			logger.info("[Strabon.storeURL] Triples inferred:"+ handler.getTriples().toString());
    1.65  		}
    1.66 -		StringReader georeader= new StringReader(handler.getTriples().toString());
    1.67 +		StringReader georeader = new StringReader(handler.getTriples().toString());
    1.68  		handler.endRDF();
    1.69  
    1.70  		if (context == null) {
    1.71 @@ -895,6 +873,8 @@
    1.72  			con1.add(url, baseURI, format, context);
    1.73  		}
    1.74  		con1.add(georeader, "", RDFFormat.NTRIPLES);
    1.75 +		georeader.close();
    1.76 +		logger.info("[Strabon.storeURL] Storing was successful.");
    1.77  	}
    1.78  
    1.79  	private void storeString(String text, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException, RDFHandlerException
    1.80 @@ -902,6 +882,7 @@
    1.81  		if (baseURI == null)
    1.82  			baseURI = "";
    1.83  
    1.84 +		logger.info("[Strabon.storeString] Storing triples.");
    1.85  		logger.info("[Strabon.storeString] Text     : " + text);
    1.86  		logger.info("[Strabon.storeString] Base URI : " + ((baseURI == null) ? "null" : baseURI));
    1.87  		logger.info("[Strabon.storeString] Context  : " + ((context == null) ? "null" : context));
    1.88 @@ -918,7 +899,7 @@
    1.89  		if (handler.getNumberOfTriples() > 0) {
    1.90  			logger.info("[Strabon.storeString] Triples inferred:"+ handler.getTriples().toString());
    1.91  		}
    1.92 -		StringReader georeader= new StringReader(handler.getTriples().toString());
    1.93 +		StringReader georeader = new StringReader(handler.getTriples().toString());
    1.94  		handler.endRDF();
    1.95  
    1.96  		if (context == null) {
    1.97 @@ -930,6 +911,7 @@
    1.98  		}
    1.99  		con1.add(georeader, "", RDFFormat.NTRIPLES);
   1.100  		georeader.close();
   1.101 +		logger.info("[Strabon.storeString] Storing was successful.");
   1.102  	}
   1.103  
   1.104  	public void describe(String describeString, SailRepositoryConnection con, String outFile) throws MalformedQueryException