Index: /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericAction.java
===================================================================
--- /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericAction.java	(revision 1626)
+++ /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericAction.java	(revision 1627)
@@ -335,76 +335,10 @@
 		params = new HashMap(getServletRequest().getParameterMap());	
 
-		// set defaults
-		if ( params.get("version") == null){
-			addParam("version","1.2");
-		}
-		if ( params.get("operation") == null){
-			addParam("operation","searchRetrieve");
-		}
-		//q=query			
-		if (getQ() != null) {
-			addParam("q",getQ());
-			addParam("query",getQ());
-		} else {
-			addParam("q",this.getParam("query"));
-		}
-		
-		if ( params.get("startRecord") == null){
-			addParam("startRecord","1");
-		}
-		if ( params.get("maximumRecords") == null){
-			addParam("maximumRecords","50");
-		}
-		
-		if ( params.get("x-cmd-maxdepth") == null){
-			if (params.get("maxdepth") == null){
-				addParam("maxdepth","2");
-			} 
-		} else {
-			addParam("maxdepth",params.get("x-cmd-maxdepth")[0]);
-		}
-		
-		if ( params.get("x-cmd-repository") == null){
-			if (params.get("repository") == null){
-				addParam("repository",WorkspaceProfile.getRepositoryByIndex(0));
-			} 
-		} else {
-			addParam("repository",params.get("x-cmd-repository")[0]);
-		}
-		
-		if ( params.get("x-cmd-cache") == null){
-			if (params.get("cache") == null){
-				addParam("cache",Cache.SKIP);
-			} 
-		} else {
-			addParam("cache",params.get("x-cmd-cache")[0]);
-		}
-		
-		if ( params.get("x-cmd-lang") == null){
-			if (params.get("lang") == null){
-				addParam("lang","en");
-			} 
-		} else {
-			addParam("lang",params.get("x-cmd-lang")[0]);
-		}
-		
-		if ( params.get("x-cmd-format") == null){
-			if (params.get("format") == null){
-				if (this.format == null) {
-					addParam("format","xml");
-				} else if (this.format.equals("")){
-					addParam("format","xml");
-				} else {
-					addParam("format",this.format);
-				}
-			} 
-		} else {
-			addParam("format",params.get("x-cmd-format")[0]);
-		}
-
-		addParam("fullformat",getFullFormat());
-		
+		setDefaultParams();		
 	}
         
+	protected void setDefaultParams(){
+		
+	}
 	/**
 	 * Gets the local parameter map.
Index: /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/RepoAction.java
===================================================================
--- /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/RepoAction.java	(revision 1626)
+++ /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/RepoAction.java	(revision 1627)
@@ -2,6 +2,9 @@
 
 import java.net.URL;
+import java.util.HashMap;
 
 import org.apache.log4j.Logger;
+
+import eu.clarin.cmdi.mdservice.internal.Cache;
 import eu.clarin.cmdi.mdservice.model.Diagnostic;
 import eu.clarin.cmdi.mdservice.model.Query;
@@ -30,5 +33,5 @@
 	
 	protected URL base_url ;
-	Query query;
+	//Query query;
 	
 	@Override
@@ -38,8 +41,84 @@
 
 	@Override
-	@SuppressWarnings("unchecked")
-	protected void loadParams() {	
-		super.loadParams();
-		query = new Query(getActionkey(), this.getParams());
+	protected void setDefaultParams() {	
+		//q=query			
+		if (getQ() != null) {
+			addParam("q",getQ());
+			addParam("query",getQ());
+		} else {
+			addParam("q",this.getParam("query"));
+		}
+		
+		// set defaults
+		/*
+		if ( params.get("version") == null){
+			addParam("version","1.2");
+		}
+		if ( params.get("operation") == null){
+			addParam("operation","searchRetrieve");
+		}
+		//q=query			
+		if (getQ() != null) {
+			addParam("q",getQ());
+			addParam("query",getQ());
+		} else {
+			addParam("q",this.getParam("query"));
+		}
+		
+		if ( params.get("startRecord") == null){
+			addParam("startRecord","1");
+		}
+		if ( params.get("maximumRecords") == null){
+			addParam("maximumRecords","50");
+		}
+		
+		if ( params.get("x-cmd-maxdepth") == null){
+			if (params.get("maxdepth") == null){
+				addParam("maxdepth","2");
+			} 
+		} else {
+			addParam("maxdepth",params.get("x-cmd-maxdepth")[0]);
+		}
+		
+		if ( params.get("x-cmd-repository") == null){
+			if (params.get("repository") == null){
+				addParam("repository",WorkspaceProfile.getRepositoryByIndex(0));
+			} 
+		} else {
+			addParam("repository",params.get("x-cmd-repository")[0]);
+		}
+		
+		if ( params.get("x-cmd-cache") == null){
+			if (params.get("cache") == null){
+				addParam("cache",Cache.SKIP);
+			} 
+		} else {
+			addParam("cache",params.get("x-cmd-cache")[0]);
+		}
+		
+		if ( params.get("x-cmd-lang") == null){
+			if (params.get("lang") == null){
+				addParam("lang","en");
+			} 
+		} else {
+			addParam("lang",params.get("x-cmd-lang")[0]);
+		}
+		
+		if ( params.get("x-cmd-format") == null){
+			if (params.get("format") == null){
+				if (this.format == null) {
+					addParam("format","xml");
+				} else if (this.format.equals("")){
+					addParam("format","xml");
+				} else {
+					addParam("format",this.format);
+				}
+			} 
+		} else {
+			addParam("format",params.get("x-cmd-format")[0]);
+		}
+
+		addParam("fullformat",getFullFormat());
+		*/
 	}
 	/**
@@ -62,11 +141,11 @@
 			{		
 			    case PAZPAR: 
-			    	setTargetProxy(new Pz2Proxy());
+			    	setTargetProxy(new Pz2Proxy(new Query(getActionkey(), this.getParams())));
 			    	return;
 			    case SRU:
-			    	setTargetProxy(new SRUProxy(query));
+			    	setTargetProxy(new SRUProxy(new Query(getActionkey(), this.getParams())));
 			    	return;
 			    case MD:
-			    	setTargetProxy(new MDRepoProxy(query));
+			    	setTargetProxy(new MDRepoProxy(new Query(getActionkey(), this.getParams())));
 			    	return;
 			    default:
Index: /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/SRUAction.java
===================================================================
--- /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/SRUAction.java	(revision 1626)
+++ /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/SRUAction.java	(revision 1627)
@@ -22,4 +22,10 @@
 import eu.clarin.cmdi.mdservice.internal.Cache;
 import eu.clarin.cmdi.mdservice.internal.Utils;
+import eu.clarin.cmdi.mdservice.model.Diagnostic;
+import eu.clarin.cmdi.mdservice.model.Query;
+import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
+import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy;
+import eu.clarin.cmdi.mdservice.proxy.Pz2Proxy;
+import eu.clarin.cmdi.mdservice.proxy.SRUProxy;
 
 
@@ -64,12 +70,23 @@
 	}
 	
-	private final static HashMap<String,String> hash_operations = new HashMap<String,String>();
-	 static
-	 {	 
-		 hash_operations.put("searchRetrieve", "recordset");
-		 hash_operations.put("explain", "model"); /* could be terms*/ 
-		 hash_operations.put("scan", "values");
-	 }
-	 
+	@Override
+	public String getRepository() {
+		if (getParams().get("repository") == null){
+			return getParam("x-cmd-repository");
+		}
+		return getParam("repository");
+	}
+	
+	@Override
+	public String getFormat() {
+		if (getParams().get("format") == null){
+			if (getParams().get("x-cmd-format") == null){
+				return "xml";
+			}
+			return getParam("x-cmd-format");
+		}
+		return getParam("format");
+	}
+	
 	 private final static HashMap<String,Integer> operation_code = new HashMap<String,Integer>();
 	 static
@@ -80,150 +97,4 @@
 	 }
 	 
-	 public SRUAction(){
-		 super();
-		 initialize();
-	 }
-	 
-	 protected void  initialize(){
-		 //repository = 1;
-		 //this.startRecord = 1;
-		 //this.maximumRecords = 50;
-		 /*
-		 if (getServletRequest() != null){
-			 this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository"));
-			//this.setRepository(this.getX_cmd_repository());
-			 //paramSet = getServletRequest().getParameterMap().entrySet();			 
-		 }
-		 */
-		 
-	 }
-	/*
-	 public String getQ() {
-			return q;
-		}
-
-		public void setQ(String q) {
-			this.q = q;
-		}
-	 
-
-	public String getVersion() {
-		return version;
-	}
-
-	public void setVersion(String version) {
-		this.version = version;
-	}
-
-	public String getOperation() {
-		return operation;
-	}
-
-	public void setOperation(String operation) {
-		this.operation = operation;
-	}
-	
-	public String getQuery() {
-		return query;
-	}
-
-	public void setQuery(String query) {
-		this.query = query;
-	}
-
-	public String getScanClause() {
-		return scanClause;
-	}
-
-	public void setScanClause(String scanClause) {
-		this.scanClause = scanClause;
-	}
-
-	
-	public int getStartRecord() {
-		return startRecord;
-	}
-
-	public void setStartRecord(int startRecord) {
-		this.startRecord = startRecord;
-	}
-	public int getMaximumRecords() {
-		return maximumRecords;
-	}
-
-	public void setMaximumRecords(int maximumRecords) {
-		this.maximumRecords = maximumRecords;
-	}
-	
-	public String getRecordPacking() {
-		return recordPacking;
-	}
-
-	public void setRecordPacking(String recordPacking) {
-		this.recordPacking = recordPacking;
-	}
-
-	public String getRecordSchema() {
-		return recordSchema;
-	}
-
-	public void setRecordSchema(String recordSchema) {
-		this.recordSchema = recordSchema;
-	}
-
-	public String getRecordXPath() {
-		return recordXPath;
-	}
-
-	public void setRecordXPath(String recordXPath) {
-		this.recordXPath = recordXPath;
-	}
-
-	public int getResultSetTTL() {
-		return resultSetTTL;
-	}
-
-	public void setResultSetTTL(int resultSetTTL) {
-		this.resultSetTTL = resultSetTTL;
-	}
-	
-	public String getSortKeys() {
-		return sortKeys;
-	}
-
-	public void setSortKeys(String sortKeys) {
-		this.sortKeys = sortKeys;
-	}
-		
-	public String getStylesheet() {
-		return stylesheet;
-	}
-
-	public void setStylesheet(String stylesheet) {
-		this.stylesheet = stylesheet;
-	}
-	
-	public String getX_cmd_repository(){
-		return x_cmd_repository;
-	}
-	
-	public void setX_cmd_repository(String x_cmd_repository){
-		this.x_cmd_repository = x_cmd_repository;
-	}
-
-	public String getX_cmd_collections(){
-		return x_cmd_collections;
-	}
-	
-	public void setX_cmd_collections(String x_cmd_collections){
-		this.x_cmd_collections = x_cmd_collections;
-	}
-
-	*/
-	public String getDiagnosticStreamName() throws TransformerConfigurationException, UnsupportedEncodingException, ParserConfigurationException, TransformerException, TransformerFactoryConfigurationError{
-		this.setResultStream(Utils.document2Stream(getDiagnostics().buildXMLDocument()));//getDiagnostics().buildXMLStream());
-		return "resultStream";
-	}
-	
 	/**
 	 * primitive identification of the target-proxy
@@ -235,13 +106,78 @@
 		return "";
 	}
-	/*
+
 	@Override
-	public String getBaseURI() {		
-		log.debug("SRU-repositorypath:" + WorkspaceProfile.getRepositoryPath(getRepository()));
-		String uri = WorkspaceProfile.getRepositoryPath(getRepository());//Utils.getConfig().getProperty(getProxyKey() + ".uri");		
-		return uri;
-	}
-	*/
-	
+	protected void setDefaultParams() {		
+		// set defaults
+	/*	if ( params.get("version") == null){
+			addParam("version","1.2");
+		}
+		if ( params.get("operation") == null){
+			addParam("operation","searchRetrieve");
+		}
+		//q=query			
+		if (getQ() != null) {
+			addParam("q",getQ());
+			addParam("query",getQ());
+		} else {
+			addParam("q",this.getParam("query"));
+		}
+		
+		if ( params.get("startRecord") == null){
+			addParam("startRecord","1");
+		}
+		if ( params.get("maximumRecords") == null){
+			addParam("maximumRecords","50");
+		}
+		
+		if ( params.get("x-cmd-maxdepth") == null){
+			if (params.get("maxdepth") == null){
+				addParam("maxdepth","2");
+			} 
+		} else {
+			addParam("maxdepth",params.get("x-cmd-maxdepth")[0]);
+		}
+		
+		if ( params.get("x-cmd-repository") == null){
+			if (params.get("repository") == null){
+				addParam("repository",WorkspaceProfile.getRepositoryByIndex(0));
+			} 
+		} else {
+			addParam("repository",params.get("x-cmd-repository")[0]);
+		}
+		
+		if ( params.get("x-cmd-cache") == null){
+			if (params.get("cache") == null){
+				addParam("cache",Cache.SKIP);
+			} 
+		} else {
+			addParam("cache",params.get("x-cmd-cache")[0]);
+		}
+		
+		if ( params.get("x-cmd-lang") == null){
+			if (params.get("lang") == null){
+				addParam("lang","en");
+			} 
+		} else {
+			addParam("lang",params.get("x-cmd-lang")[0]);
+		}
+		
+		if ( params.get("x-cmd-format") == null){
+			if (params.get("format") == null){
+				if (this.format == null) {
+					addParam("format","xml");
+				} else if (this.format.equals("")){
+					addParam("format","xml");
+				} else {
+					addParam("format",this.format);
+				}
+			} 
+		} else {
+			addParam("format",params.get("x-cmd-format")[0]);
+		}
+
+		addParam("fullformat",getFullFormat());
+		*/
+	}
 	/* 
 	public void prepareOperation() throws UnsupportedEncodingException{
@@ -384,4 +320,5 @@
  * @throws IOException
  */
+	/*
 	public static String inputStreamAsString(InputStream stream)
 		throws IOException {
@@ -404,5 +341,5 @@
 		if (this.getRecordPacking() != null){
 			if (this.getRecordPacking().toLowerCase().equals("string")){
-				/*
+				
 				try {
 					// FIXME: Which package is IOUTils from? 
@@ -411,5 +348,5 @@
 					// TODO Auto-generated catch block
 					e.printStackTrace();
-				}*/
+				}
 
 			}
@@ -466,8 +403,8 @@
 
 		}
-*/
+
 		return params;
 	}
-	
+*/	
 
 /*	
@@ -490,4 +427,23 @@
 	}
 */
-	
+	@Override
+	public void setTargetProxy(){
+		
+		//Query query = new Query();
+		switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
+		{		
+		    case PAZPAR: 
+		    	setTargetProxy(new Pz2Proxy(new Query(getActionkey(), this.getParams())));
+		    	return;
+		    case SRU:
+		    	setTargetProxy(new SRUProxy(new Query(Query.SRUEXTERN,getParams())));
+		    	return;
+		    case MD:
+		    	setTargetProxy(new MDRepoProxy(new Query(Query.RECORDSET,getParams())));
+		    	return;	
+		    default:
+		    	//TODO error  = bad workspaceProfile configuration
+		    	getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, "Error in workspaceprofile configuration", "repository=" + getRepository() );
+		}
 }
+}
Index: /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Query.java
===================================================================
--- /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Query.java	(revision 1626)
+++ /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Query.java	(revision 1627)
@@ -190,4 +190,9 @@
 		params.put(key, sarr);	
 	}
+	
+	public void setParam(String key, String value){
+		addParam(key, value);	
+	}
+	
 	/**
 	 * This is for simplified access to the the values of the request-parameters 
@@ -410,12 +415,16 @@
 
 		} else if (type.equals(SRUEXTERN)) {
-			targetRequest = "";//fromCMDIndex2Xpath() + "&maxdepth=" + getMaxdepth()  ; /* + "&maxdepth=" + getMaxdepth() );  "&collection=" + getCollection() + */
-			
-			Set set = sruMap.entrySet();
+			String paramsign = "?";
+			targetRequest = "";
+			
+			Set set = params.entrySet();
 			Iterator i = set.iterator();
 			
 		    while(i.hasNext()){
 			      Map.Entry me = (Map.Entry)i.next();
-			      targetRequest = targetRequest + "&" + me.getKey() + "=" + me.getValue();
+			      if (!(((String)me.getKey()).startsWith("x-cmd"))){
+			    	  targetRequest = targetRequest + paramsign + me.getKey() + "=" + ((String[])me.getValue())[0];
+				      paramsign = "&";
+			      }    
 			}
 					
Index: /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/MDRepoProxy.java
===================================================================
--- /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/MDRepoProxy.java	(revision 1626)
+++ /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/MDRepoProxy.java	(revision 1627)
@@ -1,10 +1,16 @@
 package eu.clarin.cmdi.mdservice.proxy;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.util.HashMap;
+
+import net.sf.json.xml.XMLSerializer;
+
 import org.apache.log4j.Logger;
 
 import eu.clarin.cmdi.mdservice.internal.CQLParseException;
+import eu.clarin.cmdi.mdservice.internal.Cache;
 import eu.clarin.cmdi.mdservice.model.Diagnostic;
 import eu.clarin.cmdi.mdservice.model.Query;
@@ -29,9 +35,17 @@
 
 	
-	public MDRepoProxy(Query q){
-		setQuery(q);
-	}
+	private final static HashMap<String,String> hash_sruoperations = new HashMap<String,String>();
+	 static
+	 {	 
+		 hash_sruoperations.put("searchRetrieve", Query.RECORDSET);
+		 hash_sruoperations.put("explain", Query.MODEL); /* could be terms*/ 
+		 hash_sruoperations.put("scan", Query.VALUES);
+	 }
 	
 	
+	 public MDRepoProxy(Query q) {
+			super(q);
+	}
+
 	/**
 	 * Override of the basic method provided by the super-class 
@@ -60,4 +74,76 @@
 	 } 
  
+	 
+	 public void addParam (String key, String value){
+		 getSourceAction().addParam(key, value);
+	 }
+	 @Override
+	 public void checkParams() {
+		// set defaults
+			
+		if ( getParams().get("startRecord") == null){
+				addParam("startRecord","1");
+			}
+		if ( getParams().get("maximumRecords") == null){
+				addParam("maximumRecords","50");
+			}
+			
+		if ( getParams().get("x-cmd-maxdepth") == null){
+				if (getParams().get("maxdepth") == null){
+					addParam("maxdepth","2");
+				} 
+		} else {
+				addParam("maxdepth",getParams().get("x-cmd-maxdepth")[0]);
+		}
+			
+		if ( getParams().get("x-cmd-repository") == null){
+				if (getParams().get("repository") == null){
+					addParam("repository",WorkspaceProfile.getRepositoryByIndex(0));
+				} 
+		} else {
+				addParam("repository",getParams().get("x-cmd-repository")[0]);
+		}
+			
+		if ( getParams().get("x-cmd-cache") == null){
+				if (getParams().get("cache") == null){
+					addParam("cache",Cache.SKIP);
+				} 
+		} else {
+				addParam("cache",getParams().get("x-cmd-cache")[0]);
+		}
+			
+		if ( getParams().get("x-cmd-lang") == null){
+				if (getParams().get("lang") == null){
+					addParam("lang","en");
+				} 
+		} else {
+				addParam("lang",getParams().get("x-cmd-lang")[0]);
+		}
+			
+		if ( getParams().get("x-cmd-format") == null){
+				if (getParams().get("format") == null){
+					if (getSourceAction().getFormat() == null) {
+						addParam("format","xml");
+					} else if (getSourceAction().getFormat().equals("")){
+						addParam("format","xml");
+					} else {
+						addParam("format",getSourceAction().getFormat());
+					}
+				} 
+		} else {
+				addParam("format",getParams().get("x-cmd-format")[0]);
+		}
+
+		addParam("fullformat",getSourceAction().getFullFormat());
+		 
+		super.checkParams();
+		
+		// TODO ?????
+		 if (getSourceAction().getActionkey().equals("sru")){
+			 getQuery().setType(hash_sruoperations.get(getParam("operation")));
+			 getSourceAction().setActionkey(hash_sruoperations.get(getParam("operation")));
+		 }
+	 }
+	 
 	/**
 	 * uses base_url + url_pattern (parametrized by actionkey) to form a url
Index: /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/Pz2Proxy.java
===================================================================
--- /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/Pz2Proxy.java	(revision 1626)
+++ /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/Pz2Proxy.java	(revision 1627)
@@ -44,8 +44,14 @@
 public class Pz2Proxy extends RepoProxy {
 
+	
+
 	private static final long serialVersionUID = 1L;
 	private static Logger log = Logger.getLogger("Pz2Proxy");
 	
 	private String proxy_key = "pazpar2";
+	
+	public Pz2Proxy(Query q) {
+		super(q);
+	}
 	
 	//private String command;
Index: /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/RepoProxy.java
===================================================================
--- /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/RepoProxy.java	(revision 1626)
+++ /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/RepoProxy.java	(revision 1627)
@@ -13,4 +13,5 @@
 import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
 import eu.clarin.cmdi.mdservice.model.Diagnostic;
+import eu.clarin.cmdi.mdservice.model.Diagnostics;
 import eu.clarin.cmdi.mdservice.model.Query;
 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
@@ -34,5 +35,6 @@
  
 	private String proxy_key = "repo";
-		
+	private Diagnostics diagnostics;
+
 	// should perhaps be RepoAction, but it gets complicated with the types
 	private GenericAction source_action;
@@ -41,4 +43,7 @@
 	
 	
+	public RepoProxy(Query q){
+		setQuery(q);
+	}
 	
 	public GenericAction getSourceAction() {
@@ -54,4 +59,12 @@
 		source_action = action;
 		
+	}
+	
+	public Diagnostics getDiagnostics(){
+		return this.diagnostics;
+	}
+	
+	public void setDiagnostics(Diagnostics diagnostics){
+		this.diagnostics = diagnostics;
 	}
 	
@@ -101,4 +114,10 @@
 	}
 
+	public Diagnostics Diagnostics(){
+		if (this.diagnostics == null){
+			this.diagnostics = new Diagnostics();
+		}
+		return this.diagnostics;
+	}
 	/**
 	 * Provides the base-URL specific to given target repository or registry 
Index: /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/SRUProxy.java
===================================================================
--- /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/SRUProxy.java	(revision 1626)
+++ /MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/SRUProxy.java	(revision 1627)
@@ -1,24 +1,11 @@
 package eu.clarin.cmdi.mdservice.proxy;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.net.URL;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.log4j.Logger;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
 
-import eu.clarin.cmdi.mdservice.model.Diagnostics;
+import eu.clarin.cmdi.mdservice.internal.CQLParseException;
+import eu.clarin.cmdi.mdservice.model.Diagnostic;
 import eu.clarin.cmdi.mdservice.model.Query;
 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
@@ -26,5 +13,4 @@
 
 public class SRUProxy extends RepoProxy
-//implements ServletRequestAware 
 {
 
@@ -32,237 +18,32 @@
 	
 	private String proxy_key = "sru";
-	private static Logger log = Logger.getLogger("SRUProxy");
-	
-	private Diagnostics diagnostics;
-	
-	
-	/** 
-	 * Properties to be filled by Struts with according request-parameters
-	 */	
-	/*
-	private String q;
-	private String version;
-	private String operation;
-	private String query;
-	private String scanClause;
-	private int startRecord;
-	private int maximumRecords;
-	private String recordPacking;
-	private String recordSchema;
-	private String recordXPath;
-	private int resultSetTTL;
-	private String sortKeys;
-	private String stylesheet;	
-	private String x_cmd_repository;
-	private String x_cmd_collections;
-	*/
-	private Set paramSet;
-
-	private static int OP_SEARCHRETRIEVE = 1;
-	private static int OP_EXPLAIN = 2;
-	private static int OP_SCAN = 3;
-	
-	
-	
-	
-	private final static HashMap<String,String> hash_operations = new HashMap<String,String>();
-	 static
-	 {	 
-		 hash_operations.put("searchRetrieve", "recordset");
-		 hash_operations.put("explain", "model"); /* could be terms*/ 
-		 hash_operations.put("scan", "values");
-	 }
+	private static Logger log = Logger.getLogger("SRUProxy");		 
 	 
-	 private final static HashMap<String,Integer> operation_code = new HashMap<String,Integer>();
-	 static
-	 {	 
-		 operation_code.put("searchRetrieve", OP_SEARCHRETRIEVE);
-		 operation_code.put("explain", OP_EXPLAIN);
-		 operation_code.put("scan", OP_SCAN);
-	 }
+	public SRUProxy(Query q) {
+		super(q);
+		// TODO Auto-generated constructor stub
+	}
 	 
-	 public SRUProxy(){
-		 super();
-		 initialize();
-	 }
-	 
-	 public SRUProxy(Query q){
-			setQuery(q);
-		}
-	 
-	 protected void  initialize(){
-		/*		
-		 // TODO set SRU params
-			// missing collections, columns...
-			setOperation("searchRetrieve");
-			//TODO what version
-			setVersion("1.2");
-			//setStartRecord(Integer.parseInt(getSourceAction().getStartItem()));
-			//setMaximumRecords(Integer.parseInt(getSourceAction().getMaximumItems()));
-		// This is probably bloedsinn:
-			setX_cmd_repository(getSourceAction().getRepository());
-			setQuery(this.fullQueryString());
-		*/	
-	/*	 
-		 if (getServletRequest() != null){
-			 this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository"));
-			 this.setRepository(this.getX_cmd_repository());
-			 paramSet = getServletRequest().getParameterMap().entrySet();			 
-		 }
-		*/
-	 }
-	 
-	 @Override
+	@Override
 	public String getProxyKey() {				
 			return proxy_key;		
 	}
-
-	 /*@Override
-		public void setServletRequest(HttpServletRequest arg0) {
-			request = arg0;
+	
+	@Override
+	public void checkParams() {
+		// required Params
+		// check and set defaults
+		if (getParam("operation").equals("")) {
+			getSourceAction().getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "operation");
+		}
+		if (getParam("version").equals("")) {
+			getSourceAction().getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "version");
+		}
+		if (getParam("query").equals("")) {
+			getSourceAction().getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "query");
 		}
 
-		public HttpServletRequest getServletRequest() {
-			return request;
-		}
-		*/
-		public Diagnostics getDiagnostics(){
-			return this.diagnostics;
-		}
-		
-		public void setDiagnostics(Diagnostics diagnostics){
-			this.diagnostics = diagnostics;
-		}
-	
-	/*	
-	 public String getQ() {
-			return q;
-		}
 
-		public void setQ(String q) {
-			this.q = q;
-		}
-		*/
-	 /*
-	 public InputStream getResultStream() {
-	     return resultStream;
-	 }
-	 public void setResultStream(InputStream _resultStream){
-		resultStream = _resultStream;
-	 }
-	*/
-/*
-	public String getVersion() {
-		return version;
 	}
-
-	public void setVersion(String version) {
-		this.version = version;
-	}
-
-	public String getOperation() {
-		return operation;
-	}
-
-	public void setOperation(String operation) {
-		this.operation = operation;
-	}
-	
-	public String getQuery() {
-		return query;
-	}
-
-	public void setQuery(String query) {
-		this.query = query;
-	}
-
-	public String getScanClause() {
-		return scanClause;
-	}
-
-	public void setScanClause(String scanClause) {
-		this.scanClause = scanClause;
-	}
-
-	
-	public int getStartRecord() {
-		return startRecord;
-	}
-
-	public void setStartRecord(int startRecord) {
-		this.startRecord = startRecord;
-	}
-	public int getMaximumRecords() {
-		return maximumRecords;
-	}
-
-	public void setMaximumRecords(int maximumRecords) {
-		this.maximumRecords = maximumRecords;
-	}
-	
-	public String getRecordPacking() {
-		return recordPacking;
-	}
-
-	public void setRecordPacking(String recordPacking) {
-		this.recordPacking = recordPacking;
-	}
-
-	public String getRecordSchema() {
-		return recordSchema;
-	}
-
-	public void setRecordSchema(String recordSchema) {
-		this.recordSchema = recordSchema;
-	}
-
-	public String getRecordXPath() {
-		return recordXPath;
-	}
-
-	public void setRecordXPath(String recordXPath) {
-		this.recordXPath = recordXPath;
-	}
-
-	public int getResultSetTTL() {
-		return resultSetTTL;
-	}
-
-	public void setResultSetTTL(int resultSetTTL) {
-		this.resultSetTTL = resultSetTTL;
-	}
-	
-	public String getSortKeys() {
-		return sortKeys;
-	}
-
-	public void setSortKeys(String sortKeys) {
-		this.sortKeys = sortKeys;
-	}
-		
-	public String getStylesheet() {
-		return stylesheet;
-	}
-
-	public void setStylesheet(String stylesheet) {
-		this.stylesheet = stylesheet;
-	}
-	
-	public String getX_cmd_repository(){
-		return x_cmd_repository;
-	}
-	
-	public void setX_cmd_repository(String x_cmd_repository){
-		this.x_cmd_repository = x_cmd_repository;
-	}
-
-	public String getX_cmd_collections(){
-		return x_cmd_collections;
-	}
-	
-	public void setX_cmd_collections(String x_cmd_collections){
-		this.x_cmd_collections = x_cmd_collections;
-	}
-	*/
 	
 	@Override
@@ -272,290 +53,26 @@
 		return uri;
 	}
-	
-	public Diagnostics Diagnostics(){
-		if (this.diagnostics == null){
-			this.diagnostics = new Diagnostics();
+
+	 @Override
+	public URL getTargetRequest() throws IOException, CQLParseException {
+	        		
+			log.debug("SRUP.getQuery:" + getParam("query"));
+			log.debug("SRUP.getActionkey:" + getSourceAction().getActionkey());		
+
+		// check if the query could get parsed
+			if (getQuery().isStatus(Query.PARSEERROR)) {
+				log.debug("SRUP.query.PARSEERROR:" + getQuery().getMsg());
+				throw new CQLParseException("SRUP.query.PARSEERROR:" + getQuery().getMsg());
+			} else {
+			
+				URL targetURL = null;
+				URL tmp = getBaseURL();
+				targetURL =new URL( tmp.toString() + getQuery().toURLParam());
+			
+				log.debug("SRUPA.targetURL:" + targetURL);
+
+				return targetURL;
+			}
+			 
 		}
-		return this.diagnostics;
-	}
-/*	
-	public void prepareOperation() throws UnsupportedEncodingException{
-		
-		mdrepoproxyaction = new MDRepoProxyAction();
-		mdrepoproxyaction.setDiagnostics(diagnostics);
-		mdrepoproxyaction.setActionkey(hash_operations.get(this.getOperation()));
-		
-		// set the SRU extern property in proxyaction
-		if (this.getX_cmd_repository() != null ) {
-			mdrepoproxyaction.setRepository(this.getX_cmd_repository());
-			//TODO\
-			if (mdrepoproxyaction.getBaseURI() == null) this.Diagnostics().Add(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "Unknown repository." + getX_cmd_repository());
-		}
-		
-		if (operation.equals("searchRetrieve")){
-			
-			//query
-			mdrepoproxyaction.setSquery("");
-			if (this.query == null) {
-				this.Diagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "query");
-				//return -1;
-			}
-			mdrepoproxyaction.setQ(getQuery());			
-			mdrepoproxyaction.setFormat("xml");
-			
-			if ((this.startRecord < 0 ) ||((getServletRequest().getParameter("startRecord") != null)&&(getServletRequest().getParameter("startRecord").equals("0")))) {
-				this.Diagnostics().Add(new Diagnostic(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "startRecord must by grater than 0."));//,Diagnostic.NONFATALNONSURORGATE));
-				//mdrepoproxyaction.setStartItem("1");
-			} else {
-				mdrepoproxyaction.setStartItem(Integer.toString(getStartRecord()));
-			}
-		
-			if ((this.maximumRecords < 0 ) ||((getServletRequest().getParameter("maximumRecords") != null) && (getServletRequest().getParameter("maximumRecords").equals("0")))){
-				   this.Diagnostics().Add(new Diagnostic(Diagnostic.UNSUPPORTED_PARAMETERVALUE, 
-						   "maximumRecords must by greater than 0."));
-			} else {
-				mdrepoproxyaction.setMaximumItems(Integer.toString(this.getMaximumRecords()));	
-			}
-			
-			if (this.getX_cmd_repository() != null ) {
-				mdrepoproxyaction.setRepository(this.getX_cmd_repository());
-				//TODO\
-				if (mdrepoproxyaction.getBaseURI() == null) this.Diagnostics().Add(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "Unknown repository." + getX_cmd_repository());
-			}
-			if (this.getX_cmd_collections() != null ) {
-				mdrepoproxyaction.setCollection(this.getX_cmd_collections());
-			}
-
-		} else {
-			if (operation.equals("explain") || operation == null){
-				log.debug("explaining", "debug");
-			}else {
-				if (operation.equals("scan")){
-					if (this.scanClause == null) {
-						this.Diagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "scanClause");
-						//return -1;
-					} else{
-						if (this.scanClause.equals("cmd.Collections")){
-							
-						} else {
-							if (this.scanClause.equals("cmd.Repository")){
-								XMLSerializer xmlserializer = new XMLSerializer();
-								String xml = xmlserializer.write( WorkspaceProfile.getRepositories());//mdrepoproxyaction.getRepositories() );  
-								this.setResultStream(new ByteArrayInputStream(xml.getBytes("UTF-8"))); 
-
-							} else {
-								
-							}
-						}
-					}
-				}else {
-					this.Diagnostics().Add(Diagnostic.UNSUPPOERTED_OPERATION, "Only searchRetrieve,explain scan supported.");				}
-			}
-		}
-	}
-	
-	public void sru2MD() throws UnsupportedEncodingException{
-		// special handling of parameter setting, x-cmd-... not alowed in java
-		this.setX_cmd_collections(getServletRequest().getParameter("x-cmd-collections"));		
-		// root call own SRU SERVER
-		//operation
-		if (operation.equals("explain") || operation == null){
-			// TODO: version param is mandatory for explain as well, but for root-request not!
-			//explain
-			termsproxyaction = new TermsProxyAction();
-			termsproxyaction.setDiagnostics(diagnostics);
-			termsproxyaction.setActionkey("terms");
-			
-			termsproxyaction.setQ("all");			
-			termsproxyaction.setFormat("sru-explain");			
-			
-			//return -1;
-		} else {				
-			//version		
-			if (this.version == null) {
-				this.Diagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "version");
-				//return -1;
-			} else {
-				if (!version.equals("1.2")) {
-					this.Diagnostics().Add(Diagnostic.UNSUPPORTED_VERSION, "Version 1.2 supported.");
-					//return -1;
-				}
-			}
-			
-			prepareOperation();
-		}
-		
-	}
-	
-	public void  prepareMD() throws Exception{
-		sru2MD();
-		if (Diagnostics().Accepted()){
-			// root-explain
-			if (this.termsproxyaction != null) {			
-				if (this.termsproxyaction.execute() == SUCCESS){
-					this.setResultStream(this.termsproxyaction.getResultStream());
-					//return SUCCESS;
-				}
-			} else {
-				//TODO diagnostic			 
-				if (this.mdrepoproxyaction.getTargetRequest() == null) {
-					Diagnostics().Add(Diagnostic.QUERYSYNTAXERROR);
-					//return ERROR;
-				}
-				if (this.mdrepoproxyaction.execute() == SUCCESS){
-					this.setResultStream(this.mdrepoproxyaction.getResultStream());
-					postprocess();
-					//return SUCCESS;
-				}
-			}
-		}
-		//return ERROR;
-	}
-	*/
-	
-/** TODO: move to Utils
- * 
- * @param stream
- * @return
- * @throws IOException
- */
-	public static String inputStreamAsString(InputStream stream)
-		throws IOException {
-		BufferedReader br = new BufferedReader(new InputStreamReader(stream));
-		StringBuilder sb = new StringBuilder();
-		String line = null;
-
-		while ((line = br.readLine()) != null) {
-		sb.append(line + "\n");
-		}
-
-		br.close();
-		return sb.toString();
-	}
-
-	 public static Document newDocumentFromInputStream(InputStream in) {
-		    DocumentBuilderFactory factory = null;
-		    DocumentBuilder builder = null;
-		    Document ret = null;
-
-		    try {
-		      factory = DocumentBuilderFactory.newInstance();
-		      builder = factory.newDocumentBuilder();
-		    } catch (ParserConfigurationException e) {
-		      e.printStackTrace();
-		    }
-
-		    try {
-		      ret = builder.parse(new InputSource(in));
-		    } catch (SAXException e) {
-		      e.printStackTrace();
-		    } catch (IOException e) {
-		      e.printStackTrace();
-		    }
-		    return ret;
-		  }
-
-/*
-	public void postprocess() throws TransformerConfigurationException, UnsupportedEncodingException, ParserConfigurationException, TransformerException, TransformerFactoryConfigurationError{
-		//recordPacking
-		if (this.getRecordPacking() != null){
-			if (this.getRecordPacking().toLowerCase().equals("string")){
-				try {
-					this.setResultStream(IOUtils.toInputStream(StringEscapeUtils.escapeXml(inputStreamAsString(this.getResultStream()))));
-				} catch (IOException e) {
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				}
-
-			}
-		}
-		
-		// add diagnostics
-		if (Diagnostics().Exists()){
-			Document doc = newDocumentFromInputStream(this.getResultStream());
-			Node r_element=  doc.getElementsByTagName("searchRetrieveResponse").item(0);
-			Document ddoc = Diagnostics().buildXMLDocument();
-			Node d_element=  ddoc.getElementsByTagName("diagnostics").item(0);
-			doc.adoptNode(d_element);
-			r_element.appendChild(d_element);
-			DOMSource source = new DOMSource(doc);   
-			StringWriter xmlAsWriter = new StringWriter();   
-			StreamResult result = new StreamResult(xmlAsWriter);    
-			TransformerFactory.newInstance().newTransformer().transform(source, result);
-			this.setResultStream(new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8")));
-		}
-	}
-	*/
-	//TODO create query + query.toURLParams ?
-	public String createURLParams(){
-		String params = "";
-		
-		//TODO params
-		if (paramSet == null){
-			if (!(getParam("operation") == null)){
-				params = params + "operation=" + getParam("operation");
-			}
-			if (!(getParam("version") == null)){
-				params = params + "&version=" + getParam("version");
-			}
-			if (!(getParam("query") == null)){
-				params = params + "&query=" + getParam("query");
-			}
-			if (Integer.parseInt(getParam("startRecord")) > 0){
-				params = params + "&startRecord=" + String.valueOf(getParam("startRecord"));
-			}
-			if (Integer.parseInt(getParam("maximumRecords"))> 0){
-				params = params + "&numRecords=" + String.valueOf(getParam("maximumRecords"));
-			}
-		} else {
-			Iterator i = paramSet.iterator();
-			params = "";
-		    while(i.hasNext()){
-			      Map.Entry me = (Map.Entry)i.next();
-			      if (!(me.getKey().equals("x-cmd-repository") || me.getKey().equals("x-cmd-collections"))){
-				      params = params + "&" + me.getKey() + "=" + ((String[])me.getValue())[0];  
-			      }
-			}
-		    params = params.substring(1);
-
-		}
-
-		return params;
-	}
-	@Override
-	public URL getTargetRequest() throws IOException {
-		String requestURI = "";
-		URL targetURL;
-		
-		if (this.getBaseURI() == null){
-			requestURI = getParam("x_cmd_repository");//this.getX_cmd_repository();
-		} else {
-			requestURI = this.getBaseURI();
-		}
-	    
-	    targetURL = new URL(requestURI + "?" + createURLParams());
-		return targetURL;
-	}
-
-
-	/*
-	@Override 
-	public void prepare() throws Exception{
-		//this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository"));
-		//this.setRepository(this.getX_cmd_repository());
-		//TODO xsl usage according particular repositories ?
-		//this.setActionkey("sru");
-		//this.setFormat("xml");
-		
-		//extern SRU repository
-		if (WorkspaceProfile.isSRURepository(getRepository()) || this.getBaseURI() == null){
-			super.prepare();
-		}
-		else {
-			 prepareMD();
-		}
-		
-	}
-	*/
-
 }
Index: /MDService2/branches/MDService_simple3/src/struts.xml
===================================================================
--- /MDService2/branches/MDService_simple3/src/struts.xml	(revision 1626)
+++ /MDService2/branches/MDService_simple3/src/struts.xml	(revision 1627)
@@ -122,5 +122,5 @@
 		
 		<action name="sru" class="eu.clarin.cmdi.mdservice.action.SRUAction" method="execute"> 
-			<param name="q">{1}</param>
+			<param name="actionkey">sru</param>
 			<result name="success" type="stream">			       
 				<param name="contentType">text/xml</param> 
