Index: MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/CollectionProxyAction.java
===================================================================
--- MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/CollectionProxyAction.java	(revision 1495)
+++ MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/CollectionProxyAction.java	(revision 1496)
@@ -4,4 +4,6 @@
 import java.net.MalformedURLException;
 import java.net.URL;
+
+import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
 
 import net.sf.json.JSONObject;
@@ -55,5 +57,5 @@
 		if (base_url == null) {
 			//base_url = new URL(Admin.getConfig().getProperty(getProxyKey() + ".uri"));
-			base_url = new URL(getRepositoryPath());
+			base_url = new URL(WorkspaceProfile.getRepositoryPath(getRepository()));
 						//Admin.notifyUser("TEST-URLnew:" + base_url.toString());
 			
Index: MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java
===================================================================
--- MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java	(revision 1495)
+++ MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java	(revision 1496)
@@ -28,4 +28,5 @@
 import com.opensymphony.xwork2.ActionSupport;
 import eu.clarin.cmdi.mdservice.model.Diagnostics;
+import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
 
 /**
@@ -42,6 +43,4 @@
 	private static final long serialVersionUID = 1L;
 	
-	private static JSONArray repositories = null;
-	private static JSONObject wp_options = null;
 	
 	private Diagnostics diagnostics;
@@ -78,24 +77,10 @@
 	 
 	 public void setRepositoryByIndex(int id){
-		 try {
-				setRepositories(GenericProxyAction.createRepositories());
-				// static repositories
-				net.sf.json.JSONArray json = getRepositories();
+		
+				net.sf.json.JSONArray json = WorkspaceProfile.getRepositories();
 				if (json.size() > 0){
 					repository = json.getJSONObject(id).getString("name");
 				}
-			} catch (IOException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (InterruptedException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (TransformerException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (NoStylesheetException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
+			
 	 }
 	 
@@ -327,19 +312,4 @@
 */
 	
-	public JSONArray getRepositories(){
-		return repositories;
-	}
-	
-	public void setRepositories(JSONArray rep){
-		GenericProxyAction.repositories = rep;
-	}
-	
-	public JSONObject getWPOptions(){
-		return wp_options;
-	}
-	
-	public void setWPOptions(JSONObject op){
-		GenericProxyAction.wp_options = op;
-	}
 	
 	/**
@@ -435,216 +405,7 @@
 	}
 	
-	/*
-	 * TODO: this should go to Utilities!
-	 */
-	public  static String convertStreamToString(InputStream is) {  
-		
-		BufferedReader reader = new BufferedReader(new InputStreamReader(is));  
-		StringBuilder sb = new StringBuilder();  
-		String line = null;  
-		
-		try {
-			while ((line = reader.readLine()) != null) {  
-			                 sb.append(line + "\n");  
-			}
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}  finally {
-			try {
-				is.close();
-			} catch (IOException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-			try {
-				is.reset();
-			} catch (IOException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-		  
-		
-		return sb.toString();  
-	}
-
-	
-	public static JSONArray createRepositories() throws IOException, InterruptedException, TransformerException, NoStylesheetException{
-		String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;
-		File file=new File(path);
-		InputStream in  = new BufferedInputStream( new FileInputStream(path));;
-		
-		MDTransformer transformer = new MDTransformer();
-		transformer.setSrcFile(file.toURI().toURL());
-		transformer.setParams(MDTransformer.createParamsMap("xml2json"));
-		InputStream jsonstream = transformer.transformXML(in);
-		
-		JSONObject json = JSONObject.fromObject(convertStreamToString(jsonstream));
-		JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles");
-		JSONArray array = null;
-		for (int i = 0; i < wparray.size(); ++i) {     
-			JSONObject wp = wparray.getJSONObject(i); 
-			if (wp.get("Repositories") != null){
-				array = wp.getJSONArray("Repositories");
-				break;
-			}
-		}	
-		
-		// repository as static variable
-		return array;
-	
-		// repository as session attribute
-		/*
-		HttpSession session = getServletRequest().getSession();
-		//JSONArray param = (JSONArray) session.getAttribute("repositories");
-		JSONArray param = new JSONArray();
-        param.add(array);
-        session.setAttribute("repositories", param);
-		 */
-	}
-	
-	public static JSONObject createWPOptions() throws IOException, InterruptedException, TransformerException, NoStylesheetException{
-		String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;
-		File file=new File(path);
-		InputStream in  = new BufferedInputStream( new FileInputStream(path));;
-		
-		MDTransformer transformer = new MDTransformer();
-		transformer.setSrcFile(file.toURI().toURL());
-		transformer.setParams(MDTransformer.createParamsMap("xml2json"));
-		InputStream jsonstream = transformer.transformXML(in);
-		
-		JSONObject json = JSONObject.fromObject(convertStreamToString(jsonstream));
-		JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles");
-		JSONObject obj = null;
-		for (int i = 0; i < wparray.size(); ++i) {     
-			JSONObject wp = wparray.getJSONObject(i); 
-			if (wp.get("Options") != null){
-				obj = wp.getJSONObject("Options");
-				break;
-			}
-		}	
-		
-		// options as static variable
-		return obj;
-	
-	}
-	
-	public String getWPOption(String opt_key){
-		String option_val = null;
-		
-		
-		if (wp_options == null ) {
-			try {
-				setWPOptions(GenericProxyAction.createWPOptions());
-			} catch (IOException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (InterruptedException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (TransformerException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (NoStylesheetException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-		// static options
-		if (wp_options != null){
-			net.sf.json.JSONObject json = getWPOptions(); 
-			option_val = json.getString(opt_key);
-		}
-		
-		
-		return option_val;
-		
-	}
-	
-	public String getRepositoryPath(){
-		String repository_path = null;
-		
-		
-		if (repositories == null ) {
-			try {
-				setRepositories(GenericProxyAction.createRepositories());
-			} catch (IOException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (InterruptedException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (TransformerException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (NoStylesheetException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-		// static repositories
-		net.sf.json.JSONArray json = getRepositories(); 
-		for(int i=0;i<json.size();i++){
-			if (json.getJSONObject(i).getString("name").equals(getRepository())){
-				repository_path =  json.getJSONObject(i).getString("uri");
-			}
-		}
-		//Admin.notifyUser("REPOSITORY_PATH:" + repository_path);
-		
-		//session repositories
-		/*
-		HttpSession session = getServletRequest().getSession();
-		json = (net.sf.json.JSONArray) session.getAttribute("repositories");
-		for(int i=0;i<json.size();i++){
-			if (json.getJSONObject(i).getInt("id") == getRepository()){
-				repository_path =  json.getJSONObject(i).getString("uri");
-			}
-		}
-		Admin.notifyUser("REPOSITORY_PATH-SESSIONATTR:" + repository_path);
-		*/
-		return repository_path;
-		
-	}
-	
-	public String getRepositoryType(){
-	String typestr = "";
-		
-		if (repositories == null ) {
-			try {
-				setRepositories(GenericProxyAction.createRepositories());
-			} catch (IOException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (InterruptedException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (TransformerException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			} catch (NoStylesheetException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-		// static repositories
-		net.sf.json.JSONArray json = getRepositories(); 
-		for(int i=0;i<json.size();i++){
-			if (json.getJSONObject(i).getString("name").equals(getRepository())){
-				typestr =  json.getJSONObject(i).getString("type");
-			}
-		}
-		
-		return (typestr);
-
-	}
-	public Boolean isSRURepository(){
-		//Boolean issru = false;
-		String typestr = getRepositoryType();
-		
-		return (typestr.equals("sru"));
-		
-	}
-	public String addDurationKey(){
+	
+	
+		public String addDurationKey(){
 		String req_key = getRequestKey();
 	
@@ -682,5 +443,6 @@
 		}
 		//if (getRepository() != null){
-	        hm.put("repository_name", String.valueOf(getRepository()));	
+	        hm.put("repository_name", String.valueOf(getRepository()));
+	        hm.put("repository_type", WorkspaceProfile.getRepositoryType(this.getRepository()));
 		//}
         
Index: MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Helpers.java
===================================================================
--- MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Helpers.java	(revision 1495)
+++ MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Helpers.java	(revision 1496)
@@ -1,6 +1,8 @@
 package eu.clarin.cmdi.mdservice.action;
 
+import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PrintStream;
@@ -10,4 +12,9 @@
 import javax.xml.parsers.FactoryConfigurationError;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
 
 import org.w3c.dom.Document;
@@ -64,4 +71,78 @@
 		}
 	}
+	
+
+	public static Document getDocument(InputStream is){
+		Document doc = null;
+		DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+     	DocumentBuilder docBuilder;
+		try {
+			docBuilder = docFactory.newDocumentBuilder();
+			doc = docBuilder.parse(is);
+		} catch (ParserConfigurationException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (SAXException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}	
+		return doc;
+	}
+	
+	public static String getDocumentData(InputStream is, String expression){
+		String data = "";
+	
+		XPathFactory factory = XPathFactory.newInstance(); 
+	    XPath xpath = factory.newXPath(); 
+	    XPathExpression expr;
+		try {
+			expr = xpath.compile(expression);
+			data = (String) expr.evaluate(getDocument(is), XPathConstants.STRING);
+		} catch (XPathExpressionException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		        
+		return data;
+		
+	}
+	/*
+	 * TODO: this should go to Utilities!
+	 */
+	public  static String convertStreamToString(InputStream is) {  
+		
+		BufferedReader reader = new BufferedReader(new InputStreamReader(is));  
+		StringBuilder sb = new StringBuilder();  
+		String line = null;  
+		
+		try {
+			while ((line = reader.readLine()) != null) {  
+			                 sb.append(line + "\n");  
+			}
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}  finally {
+			try {
+				is.close();
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			try {
+				is.reset();
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+		  
+		
+		return sb.toString();  
+	}
+
 
 }
Index: MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/MDRepoProxyAction.java
===================================================================
--- MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/MDRepoProxyAction.java	(revision 1495)
+++ MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/MDRepoProxyAction.java	(revision 1496)
@@ -27,4 +27,5 @@
 
 import eu.clarin.cmdi.mdservice.model.Query;
+import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
 
 /**
@@ -49,5 +50,5 @@
 	@Override	
 	public String getBaseURI() {		
-		String uri = getRepositoryPath();		
+		String uri = WorkspaceProfile.getRepositoryPath(getRepository());		
 		return uri;
 	}
@@ -75,4 +76,20 @@
 	 } 
  
+	 public String fullQueryString(){
+		String full_query_string= this.getQ();
+			
+		if (!getSquery().equals("") && !this.getQ().equals("")){
+				full_query_string = "(" + this.getSquery() + " ) and (" + this.getQ() + ")";
+			} else if (!this.getSquery().equals("")) {
+				full_query_string = this.getSquery();
+			} else if (!this.getQ().equals("")){
+				full_query_string = this.getQ();
+			} else {
+				full_query_string = "";
+			}
+		
+		return full_query_string;
+	 }
+	 
 	/**
 	 * uses base_url + url_pattern (parametrized by actionkey) to form a url
@@ -80,4 +97,5 @@
 	 * @throws Exception 
 	 */
+	 @Override
 	public URL getTargetRequest() throws IOException {
         // URL targetURL =new URL( base_url, compname + ".xml");
@@ -113,4 +131,19 @@
 
 	@Override
+	public InputStream getSourceStream() throws IOException, NoStylesheetException {
+		
+		/*if (getCommand() == null){
+			try {
+				return getSourcePz2();
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		} 
+			*/
+		return super.getSourceStream();
+	}
+	
+	@Override
 	public void prepare() throws Exception{
 		super.prepare();
Index: MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Pz2ProxyAction.java
===================================================================
--- MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Pz2ProxyAction.java	(revision 1495)
+++ MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Pz2ProxyAction.java	(revision 1496)
@@ -34,4 +34,5 @@
 
 import eu.clarin.cmdi.mdservice.model.Query;
+import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
 
 /**
@@ -122,5 +123,5 @@
 	@Override
 	public String getBaseURI() {		
-		String uri = getRepositoryPath();		
+		String uri = WorkspaceProfile.getRepositoryPath(getRepository());		
 		return uri;
 	}
@@ -135,5 +136,5 @@
 	}
 	
-
+/*
 	@Override
 	public InputStream getSourceStream() throws IOException, NoStylesheetException {
@@ -186,4 +187,6 @@
 		
 	}
+	*/
+	/*
 	public InputStream getSourcePz2() throws Exception {
 		
@@ -224,5 +227,5 @@
 		return is;
 	}
-
+*/
 	
 }
Index: MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/RepoProxyAction.java
===================================================================
--- MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/RepoProxyAction.java	(revision 1496)
+++ MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/RepoProxyAction.java	(revision 1496)
@@ -0,0 +1,183 @@
+package eu.clarin.cmdi.mdservice.action;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.HashMap;
+import java.io.ByteArrayInputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+import eu.clarin.cmdi.mdservice.model.Query;
+import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
+
+/**
+ * Main Struts 2 controller 
+ * responds to requests (collections, model, recordset) 
+ * by dispatching the requests to appropriate internal methods and filling the inputStream with the result
+ * 
+ * It is possible to switch target-repository dynamically  (on every request). I.e. the client explicitly selects one of the repositories.
+ *  
+ * @author vronk
+ *
+ */
+public class RepoProxyAction extends MDRepoProxyAction {
+
+	private static final long serialVersionUID = 1L;
+
+	private String proxy_key = "repository";
+	
+	@Override
+	public String getProxyKey() {
+		return proxy_key;
+	}
+	
+	//TODO remove - just for tests
+	@Override
+	public String getCache() {
+		switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
+		{
+		    case PAZPAR: 
+		    	return Cache.SKIP;
+		    case SRU:
+		    	return Cache.SKIP;
+		    case MD:
+		    	return super.getCache();
+		    default:
+		    	return super.getCache();
+		}
+	}
+	
+	//TODO remove after xsl update
+	@Override
+	public String getFullFormat() {		
+		switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
+		{
+		    case PAZPAR: 
+		    	return "pazpar22" + this.getFormat();
+		    case SRU:
+		    	return "sru2" + this.getFormat();
+		    case MD:
+		    	return super.getFullFormat();
+		    default:
+		    	return super.getFullFormat();
+		}
+	}
+	
+public URL getTargetRequestSRU() throws IOException, NoStylesheetException{
+	
+	SRUProxyAction sruaction = new SRUProxyAction();
+	// TODO MD to SRU params
+	// missing collections, columns...
+	sruaction.setOperation("searchRetrieve");
+	//TODO what version
+	sruaction.setVersion("1.2");
+	sruaction.setStartRecord(Integer.parseInt(this.getStartItem()));
+	sruaction.setMaximumRecords(Integer.parseInt(this.getMaximumItems()));
+	sruaction.setRepository(getRepository());
+	sruaction.setQuery(this.fullQueryString());
+	
+	return sruaction.getTargetRequest();
+	
+}
+public InputStream getSourcePz2() throws Exception {
+		
+		InputStream is = null;
+		Pz2ProxyAction pzaction = new Pz2ProxyAction();
+		// TODO param settings
+		//init
+		pzaction.setRepository(getRepository());
+		pzaction.setCommand("init");
+		String sessionID = Helpers.getDocumentData(pzaction.getSourceStream(), "//init/session");
+		// get result
+		pzaction.setCommand("search");
+		pzaction.setSessionID(sessionID);
+		pzaction.setQuery(this.fullQueryString());
+		String ok = Helpers.getDocumentData(pzaction.getSourceStream(),"//search/status");
+		
+		String activeclients = "1";
+		pzaction.setCommand("show");
+		pzaction.setSort("relevance");
+		pzaction.setBlock("1");
+		//TODO timeout  settings
+		long startMillis = System.currentTimeMillis();
+		long timeout = 0;
+		if (WorkspaceProfile.getOption("pazpartimeout") == null){
+			timeout = 1000;
+		} else {
+			timeout = Integer.parseInt(WorkspaceProfile.getOption("pazpartimeout"));
+		}
+		while (Integer.parseInt(activeclients) > 0){
+			//activeclients = getDocumentData(this.getSourceStream(), "//show/activeclients");
+			is = pzaction.getSourceStream();
+			activeclients = Helpers.getDocumentData(is, "//show/activeclients");
+			Thread.sleep(1000); 
+			Admin.notifyUser("ActiveClients: " + activeclients, Admin.DEBUG);
+			if ((System.currentTimeMillis() - startMillis)/1000 > timeout) {
+				break;
+			}
+		}
+		is = pzaction.getSourceStream();
+		return is;
+	}
+		
+	@Override
+	public InputStream getSourceStream() throws IOException, NoStylesheetException {
+		
+		
+		switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
+		{
+		    case PAZPAR: 
+		    	try {
+					return getSourcePz2();
+				} catch (Exception e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+		    case SRU:
+		    	return super.getSourceStream();//getSourceSRU();
+		    case MD:
+		    	return super.getSourceStream();
+		    default:
+		    	return super.getSourceStream();
+		}
+		
+	}
+	
+	@Override
+	public URL getTargetRequest() throws IOException {
+		switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
+		{
+		    case PAZPAR: 
+		    	return base_url;
+		    case SRU:
+				try {
+					return getTargetRequestSRU();
+				} catch (NoStylesheetException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+		    case MD:
+		    	return super.getTargetRequest();
+		    default:
+		    	return super.getTargetRequest();
+		}
+	}
+}
Index: MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/SRUProxyAction.java
===================================================================
--- MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/SRUProxyAction.java	(revision 1495)
+++ MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/SRUProxyAction.java	(revision 1496)
@@ -51,4 +51,5 @@
 import eu.clarin.cmdi.mdservice.model.Diagnostic;
 import eu.clarin.cmdi.mdservice.model.Diagnostics;
+import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
 
 
@@ -79,4 +80,5 @@
 	private String x_cmd_repository;
 	private String x_cmd_collections;
+	private Set paramSet;
 
 	private MDRepoProxyAction mdrepoproxyaction;
@@ -88,4 +90,5 @@
 	private static int OP_EXPLAIN = 2;
 	private static int OP_SCAN = 3;
+	
 	
 	//TODO cache after analysis
@@ -120,4 +123,13 @@
 		 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();			 
+		 }
+		 
+		//TODO xsl usage according particular repositories ?
+		 this.setActionkey("sru");
 	 }
 	 
@@ -285,6 +297,6 @@
 	@Override
 	public String getBaseURI() {		
-		Admin.notifyUser("SRU-repositorypath:" + getRepositoryPath());
-		String uri = getRepositoryPath();//Admin.getConfig().getProperty(getProxyKey() + ".uri");		
+		Admin.notifyUser("SRU-repositorypath:" + WorkspaceProfile.getRepositoryPath(getRepository()));
+		String uri = WorkspaceProfile.getRepositoryPath(getRepository());//Admin.getConfig().getProperty(getProxyKey() + ".uri");		
 		return uri;
 	}
@@ -358,5 +370,5 @@
 							if (this.scanClause.equals("cmd.Repository")){
 								XMLSerializer xmlserializer = new XMLSerializer();
-								String xml = xmlserializer.write( mdrepoproxyaction.getRepositories() );  
+								String xml = xmlserializer.write( WorkspaceProfile.getRepositories());//mdrepoproxyaction.getRepositories() );  
 								this.setResultStream(new ByteArrayInputStream(xml.getBytes("UTF-8"))); 
 
@@ -498,4 +510,40 @@
 	}
 	
+	//TODO create query + query.toURLParams ?
+	public String createURLParams(){
+		String params = "";
+		
+		//TODO params
+		if (paramSet == null){
+			if (!(operation == null)){
+				params = params + "operation=" + operation;
+			}
+			if (!(version == null)){
+				params = params + "&version=" + version;
+			}
+			if (!(query == null)){
+				params = params + "&query=" + query;
+			}
+			if (getStartRecord() > 0){
+				params = params + "&startRecord=" + String.valueOf(getStartRecord());
+			}
+			if (getMaximumRecords()> 0){
+				params = params + "&numRecords=" + String.valueOf(getMaximumRecords());
+			}
+		} 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 {
@@ -508,16 +556,6 @@
 			requestURI = this.getBaseURI();
 		}
-		//TODO params
-		Set set = getServletRequest().getParameterMap().entrySet();
-		Iterator i = set.iterator();
-		String 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);
-	    targetURL = new URL(requestURI + "?" + params);
+	    
+	    targetURL = new URL(requestURI + "?" + createURLParams());
 		return targetURL;
 	}
@@ -525,12 +563,12 @@
 	@Override 
 	public void prepare() throws Exception{
-		this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository"));
-		this.setRepository(this.getX_cmd_repository());
+		//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.setActionkey("sru");
 		//this.setFormat("xml");
 		
 		//extern SRU repository
-		if (this.isSRURepository() || this.getBaseURI() == null){
+		if (WorkspaceProfile.isSRURepository(getRepository()) || this.getBaseURI() == null){
 			super.prepare();
 		}
Index: MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/model/WorkspaceProfile.java
===================================================================
--- MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/model/WorkspaceProfile.java	(revision 1496)
+++ MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/model/WorkspaceProfile.java	(revision 1496)
@@ -0,0 +1,214 @@
+package eu.clarin.cmdi.mdservice.model;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.transform.TransformerException;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+import eu.clarin.cmdi.mdservice.action.Admin;
+import eu.clarin.cmdi.mdservice.action.GenericProxyAction;
+import eu.clarin.cmdi.mdservice.action.Helpers;
+import eu.clarin.cmdi.mdservice.action.MDTransformer;
+import eu.clarin.cmdi.mdservice.action.NoStylesheetException;
+import eu.clarin.cmdi.mdservice.action.WorkspaceAction;
+
+/**
+ 
+ */
+
+
+
+public class WorkspaceProfile{	
+
+	//TODO new class
+	public static enum RepositoryType
+	{
+		MD, SRU, PAZPAR,NOVALUE;
+
+	    public static RepositoryType toRepositoryType(String str)
+	    {
+	        try {
+	            return valueOf(str.toUpperCase());
+	        } 
+	        catch (Exception ex) {
+	            return NOVALUE;
+	        }
+	    }   
+	}
+
+	private static JSONArray repositories = null;
+	private static JSONObject options = null;
+	
+	
+	public static JSONArray getRepositories(){
+		if (repositories == null){
+			try {
+				WorkspaceProfile.setRepositories(WorkspaceProfile.createRepositories());
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			} catch (InterruptedException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			} catch (TransformerException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			} catch (NoStylesheetException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+		return repositories;
+	}
+	
+	public static void setRepositories(JSONArray rep){
+		WorkspaceProfile.repositories = rep;
+	}
+	
+	public static JSONObject getOptions(){
+		if (options == null ) {
+			try {
+				WorkspaceProfile.setOptions(WorkspaceProfile.createOptions());
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			} catch (InterruptedException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			} catch (TransformerException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			} catch (NoStylesheetException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+		return options;
+	}
+	
+	public static void setOptions(JSONObject op){
+		WorkspaceProfile.options = op;
+	}
+	
+	public WorkspaceProfile() {
+	}
+	
+	public static JSONArray createRepositories() throws IOException, InterruptedException, TransformerException, NoStylesheetException{
+		String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;
+		File file=new File(path);
+		InputStream in  = new BufferedInputStream( new FileInputStream(path));;
+		
+		MDTransformer transformer = new MDTransformer();
+		transformer.setSrcFile(file.toURI().toURL());
+		transformer.setParams(MDTransformer.createParamsMap("xml2json"));
+		InputStream jsonstream = transformer.transformXML(in);
+		
+		JSONObject json = JSONObject.fromObject(Helpers.convertStreamToString(jsonstream));
+		JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles");
+		JSONArray array = null;
+		for (int i = 0; i < wparray.size(); ++i) {     
+			JSONObject wp = wparray.getJSONObject(i); 
+			if (wp.get("Repositories") != null){
+				array = wp.getJSONArray("Repositories");
+				break;
+			}
+		}	
+		
+		// repository as static variable
+		return array;
+	
+		// repository as session attribute
+		/*
+		HttpSession session = getServletRequest().getSession();
+		//JSONArray param = (JSONArray) session.getAttribute("repositories");
+		JSONArray param = new JSONArray();
+        param.add(array);
+        session.setAttribute("repositories", param);
+		 */
+	}
+	
+	public static JSONObject createOptions() throws IOException, InterruptedException, TransformerException, NoStylesheetException{
+		String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;
+		File file=new File(path);
+		InputStream in  = new BufferedInputStream( new FileInputStream(path));;
+		
+		MDTransformer transformer = new MDTransformer();
+		transformer.setSrcFile(file.toURI().toURL());
+		transformer.setParams(MDTransformer.createParamsMap("xml2json"));
+		InputStream jsonstream = transformer.transformXML(in);
+		
+		JSONObject json = JSONObject.fromObject(Helpers.convertStreamToString(jsonstream));
+		JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles");
+		JSONObject obj = null;
+		for (int i = 0; i < wparray.size(); ++i) {     
+			JSONObject wp = wparray.getJSONObject(i); 
+			if (wp.get("Options") != null){
+				obj = wp.getJSONObject("Options");
+				break;
+			}
+		}	
+		
+		// options as static variable
+		return obj;
+	
+	}
+	
+	public static String getOption(String opt_key){
+		String option_val = null;
+		
+		net.sf.json.JSONObject json = getOptions(); 
+		option_val = json.getString(opt_key);
+
+		return option_val;
+		
+	}
+	
+	public static String getRepositoryPath(String repository_name){
+		String repository_path = null;
+		
+		
+		
+		// static repositories
+		net.sf.json.JSONArray json = WorkspaceProfile.getRepositories(); 
+		for(int i=0;i<json.size();i++){
+			if (json.getJSONObject(i).getString("name").equals(repository_name)){
+				repository_path =  json.getJSONObject(i).getString("uri");
+			}
+		}
+		
+		return repository_path;
+		
+	}
+	
+	public static String getRepositoryType(String repository_name){
+	String typestr = "";
+		
+		
+		// static repositories
+		net.sf.json.JSONArray json = WorkspaceProfile.getRepositories(); 
+		for(int i=0;i<json.size();i++){
+			if (json.getJSONObject(i).getString("name").equals(repository_name)){
+				typestr =  json.getJSONObject(i).getString("type");
+			}
+		}
+		
+		return (typestr);
+
+	}
+	public static Boolean isSRURepository(String repository_name){
+		//Boolean issru = false;
+		String typestr = getRepositoryType(repository_name);
+		
+		return (typestr.equals("sru"));
+		
+	}
+
+
+}
+
+
