changeset 338:d50fefb90edb

Improved the RDF-Handling in the rdf2hash-method.
author slarti
date Thu, 04 Nov 2004 17:06:13 +0100
parents e1c10653f143
children d10e4ce2a153
files servlet/src/digilib/servlet/DigilibRequest.java servlet/src/digilib/servlet/DocumentBean.java
diffstat 2 files changed, 39 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/servlet/DigilibRequest.java	Wed Nov 03 14:38:39 2004 +0100
+++ b/servlet/src/digilib/servlet/DigilibRequest.java	Thu Nov 04 17:06:13 2004 +0100
@@ -37,14 +37,11 @@
 
 import org.apache.log4j.Logger;
 
-import com.hp.hpl.mesa.rdf.jena.common.SelectorImpl;
 import com.hp.hpl.mesa.rdf.jena.mem.ModelMem;
 import com.hp.hpl.mesa.rdf.jena.model.Model;
-import com.hp.hpl.mesa.rdf.jena.model.NodeIterator;
 import com.hp.hpl.mesa.rdf.jena.model.Property;
-import com.hp.hpl.mesa.rdf.jena.model.RDFNode;
 import com.hp.hpl.mesa.rdf.jena.model.Resource;
-import com.hp.hpl.mesa.rdf.jena.model.Selector;
+import com.hp.hpl.mesa.rdf.jena.model.ResIterator;
 import com.hp.hpl.mesa.rdf.jena.model.Statement;
 import com.hp.hpl.mesa.rdf.jena.model.StmtIterator;
 
@@ -77,6 +74,9 @@
 
 	private static final long serialVersionUID = -4707707539569977901L;
 
+	private final static String ECHO = "http://echo.unibe.ch/digilib/rdf#";
+	private final static String DIGILIB = "Digilib";
+
 	private Logger logger = Logger.getLogger(this.getClass());
 
 	private boolean boolRDF = false; // use RDF Parameters
@@ -182,7 +182,7 @@
 	/**
 	 * Populate the request object with data from a ServletRequest.
 	 * 
-	 * 
+	 *
 	 * @param request
 	 */
 	public void setWithRequest(ServletRequest request) {
@@ -441,46 +441,33 @@
 			Model model = new ModelMem();
 			StringReader sr = new StringReader(strRDF);
 			model.read(sr, "");
-			// get Property fn -> digilib
-			Property p = model.getProperty("http://echo.unibe.ch/digilib/rdf#",
-					"fn");
-			if (p != null) {
-				// get URI
-				String strURI = null;
-				NodeIterator i = model.listObjectsOfProperty(p);
-				if (i.hasNext()) {
-					strURI = "urn:echo:" + i.next().toString();
-					Resource r = model.getResource(strURI);
-					Selector selector = new SelectorImpl(r, null,
-							(RDFNode) null);
-					// list the statements in the graph
-					StmtIterator iter = model.listStatements(selector);
-					// add predicate and object to Hashtable
-					while (iter.hasNext()) {
-						Statement stmt = iter.next(); // get next statement
-						Resource subject = stmt.getSubject();
-						// get the subject
-						Property predicate = stmt.getPredicate();
-						// get the predicate
-						RDFNode object = stmt.getObject(); // get the object
-
-						String strKey = predicate.toString();
-						String strValue = "";
-
-						if (object instanceof Resource) {
-							strValue = object.toString();
-						} else {
-							// object is a literal
-							strValue = object.toString();
+			// get Property type -> digilib
+			Property property = model.getProperty(this.ECHO, "type");
+			if(property != null) {
+				ResIterator resourceIterator = model.listSubjectsWithProperty(property);
+				while(resourceIterator.hasNext()) {
+					Resource resource = resourceIterator.next();
+					StmtIterator statementIterator = resource.listProperties();
+					String type = resource.getProperty(property).getResource().getURI();
+					if(type == null) {
+						continue;
+					}
+					if(type.equals(this.ECHO+this.DIGILIB)) {
+						while(statementIterator.hasNext()) {
+							Statement statement = statementIterator.next();
+							Property predicate = statement.getPredicate();
+							if(predicate.getNameSpace().equals(this.ECHO)) {
+								hashParams.put(predicate.getLocalName(),statement.getObject().toString());
+							}
 						}
-						String strDigilibKey = strKey.substring(strKey
-								.indexOf("#") + 1, strKey.length());
-						hashParams.put(strDigilibKey, strValue);
 					}
 				}
+			} else {
+				logger.warn("The type property was null! So the rdf-model"
+						+" sent to Digilib was probably incorrect!");
 			}
 		} catch (Exception e) {
-			logger.warn("rdf3hash failed", e);
+			logger.warn("rdf2hash function caused an error: ", e);
 		}
 		return hashParams;
 	}
@@ -575,4 +562,4 @@
 		return servletRequest;
 	}
 
-}
\ No newline at end of file
+}
--- a/servlet/src/digilib/servlet/DocumentBean.java	Wed Nov 03 14:38:39 2004 +0100
+++ b/servlet/src/digilib/servlet/DocumentBean.java	Thu Nov 04 17:06:13 2004 +0100
@@ -1,27 +1,27 @@
 /*
  * DocumentBean -- Access control bean for JSP
- * 
+ *
  * Digital Image Library servlet components
- * 
+ *
  * Copyright (C) 2001, 2002, 2003 Robert Casties (robcast@mail.berlios.de)
- * 
+ *
  * This program is free software; you can redistribute it and/or modify it under
  * the terms of the GNU General Public License as published by the Free Software
  * Foundation; either version 2 of the License, or (at your option) any later
  * version.
- * 
+ *
  * Please read license.txt for the full details. A copy of the GPL may be found
  * at http://www.gnu.org/copyleft/lgpl.html
- * 
+ *
  * You should have received a copy of the GNU General Public License along with
  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  * Place, Suite 330, Boston, MA 02111-1307 USA
- *  
+ *
  */
 
 package digilib.servlet;
 
-import java.util.List;
+import java.util.*;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -65,10 +65,11 @@
 	 * Constructor for DocumentBean.
 	 */
 	public DocumentBean() {
-		super();
+        logger.debug("new DocumentBean");
 	}
 
 	public DocumentBean(ServletConfig conf) {
+        logger.debug("new DocumentBean");
 		try {
 			setConfig(conf);
 		} catch (Exception e) {
@@ -143,6 +144,7 @@
 	 */
 	public boolean doAuthentication(HttpServletResponse response)
 			throws Exception {
+        logger.debug("doAuthenication-Method");
 		return doAuthentication(dlRequest, response);
 	}
 
@@ -292,4 +294,4 @@
 		return dlRequest;
 	}
 
-}
\ No newline at end of file
+}