manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1157102 - /incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/
Date Fri, 12 Aug 2011 13:32:42 GMT
Author: kwright
Date: Fri Aug 12 13:32:42 2011
New Revision: 1157102

URL: http://svn.apache.org/viewvc?rev=1157102&view=rev
Log:
Folded in patch4.

Modified:
    incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerAction.java
    incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerConnection.java
    incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerConnector.java
    incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerDelete.java
    incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerIndex.java
    incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerParam.java

Modified: incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerAction.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerAction.java?rev=1157102&r1=1157101&r2=1157102&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerAction.java
(original)
+++ incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerAction.java
Fri Aug 12 13:32:42 2011
@@ -9,13 +9,16 @@ public class OpenSearchServerAction exte
 		optimize, reload;
 	}
 
-	public OpenSearchServerAction(CommandEnum cmd, OpenSearchServerParam params)
+	public OpenSearchServerAction(CommandEnum cmd, OpenSearchServerConfig config)
 			throws ManifoldCFException {
-		super(params);
+		super(config);
 		StringBuffer url = getApiUrl("action");
 		url.append("&action=");
 		url.append(cmd.name());
 		GetMethod method = new GetMethod(url.toString());
 		call(method);
+		if ("OK".equals(checkXPath(xPathStatus)))
+			return;
+		setResult(Result.ERROR, checkXPath(xPathException));
 	}
 }

Modified: incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerConnection.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerConnection.java?rev=1157102&r1=1157101&r2=1157102&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerConnection.java
(original)
+++ incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerConnection.java
Fri Aug 12 13:32:42 2011
@@ -1,14 +1,26 @@
 package org.apache.manifoldcf.agents.output.opensearchserver;
 
 import java.io.IOException;
+import java.io.StringReader;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpException;
 import org.apache.commons.httpclient.HttpMethod;
-import org.apache.manifoldcf.agents.output.opensearchserver.OpenSearchServerParam.ParameterEnum;
+import org.apache.commons.io.IOUtils;
 import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
 
 public class OpenSearchServerConnection {
 
@@ -20,20 +32,33 @@ public class OpenSearchServerConnection 
 
 	private String apiKey;
 
-	private String resultCode;
-
 	private String resultDescription;
 
 	private String callUrlSnippet;
 
-	protected OpenSearchServerConnection(OpenSearchServerParam params) {
-		resultCode = null;
-		resultDescription = null;
+	private String response;
+
+	private Document xmlResponse;
+
+	protected String xPathStatus = "/response/entry[@key='Status']/text()";
+	protected String xPathException = "/response/entry[@key='Exception']/text()";
+
+	public enum Result {
+		OK, ERROR, UNKNOWN;
+	}
+
+	private Result result;
+
+	protected OpenSearchServerConnection(OpenSearchServerConfig config) {
+		result = Result.UNKNOWN;
+		response = null;
+		xmlResponse = null;
+		resultDescription = "";
 		callUrlSnippet = null;
-		serverLocation = params.get(ParameterEnum.SERVERLOCATION);
-		indexName = params.get(ParameterEnum.INDEXNAME);
-		userName = params.get(ParameterEnum.USERNAME);
-		apiKey = params.get(ParameterEnum.APIKEY);
+		serverLocation = config.getServerLocation();
+		indexName = config.getIndexName();
+		userName = config.getUserName();
+		apiKey = config.getApiKey();
 	}
 
 	protected final String urlEncode(String t) throws ManifoldCFException {
@@ -66,43 +91,91 @@ public class OpenSearchServerConnection 
 		HttpClient hc = new HttpClient();
 		try {
 			hc.executeMethod(method);
+			if (!checkResultCode(method.getStatusCode()))
+				throw new ManifoldCFException(getResultDescription());
+			response = IOUtils.toString(method.getResponseBodyAsStream());
 		} catch (HttpException e) {
+			setResult(Result.ERROR, e.getMessage());
 			throw new ManifoldCFException(e);
 		} catch (IOException e) {
+			setResult(Result.ERROR, e.getMessage());
 			throw new ManifoldCFException(e);
 		} finally {
-			if (method != null) {
-				setResultCode(method.getStatusCode());
-				setResultDescription(method.getStatusText());
+			if (method != null)
 				method.releaseConnection();
-			}
 		}
 	}
 
-	private void setResultDescription(String desc) {
-		resultDescription = desc;
+	private void readXmlResponse() throws ManifoldCFException {
+		if (xmlResponse != null)
+			return;
+		StringReader sw = null;
+		try {
+			sw = new StringReader(response);
+			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+			dbf.setNamespaceAware(true); // never forget this!
+			DocumentBuilder builder;
+			builder = dbf.newDocumentBuilder();
+			xmlResponse = builder.parse(new InputSource(sw));
+		} catch (ParserConfigurationException e) {
+			throw new ManifoldCFException(e);
+		} catch (SAXException e) {
+			throw new ManifoldCFException(e);
+		} catch (IOException e) {
+			throw new ManifoldCFException(e);
+		} finally {
+			if (sw != null)
+				IOUtils.closeQuietly(sw);
+		}
+	}
+
+	protected String checkXPath(String xPathQuery) throws ManifoldCFException {
+		try {
+			readXmlResponse();
+			XPathFactory factory = XPathFactory.newInstance();
+			XPath xpath = factory.newXPath();
+			XPathExpression xPathExpr = xpath.compile(xPathQuery);
+			return xPathExpr.evaluate(xmlResponse);
+		} catch (XPathExpressionException e) {
+			throw new ManifoldCFException(e);
+		}
+	}
+
+	protected void setResult(Result res, String desc) {
+		if (res != null)
+			result = res;
+		if (desc != null)
+			if (desc.length() > 0)
+				resultDescription = desc;
 	}
 
 	public String getResultDescription() {
 		return resultDescription;
 	}
 
-	private void setResultCode(int code) {
+	protected String getResponse() {
+		return response;
+	}
+
+	private boolean checkResultCode(int code) {
 		switch (code) {
 		case 0:
-			resultCode = null;
-			break;
+			setResult(Result.UNKNOWN, null);
+			return false;
 		case 200:
-			resultCode = "OK";
-			break;
+			setResult(Result.OK, null);
+			return true;
+		case 404:
+			setResult(Result.ERROR, "Server/page not found");
+			return false;
 		default:
-			resultCode = "ERR (" + code + ")";
-			break;
+			setResult(Result.ERROR, null);
+			return false;
 		}
 	}
 
-	public String getResultCode() {
-		return resultCode;
+	public Result getResult() {
+		return result;
 	}
 
 	public String getCallUrlSnippet() {

Modified: incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerConnector.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerConnector.java?rev=1157102&r1=1157101&r2=1157102&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerConnector.java
(original)
+++ incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerConnector.java
Fri Aug 12 13:32:42 2011
@@ -1,25 +1,35 @@
 package org.apache.manifoldcf.agents.output.opensearchserver;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
 
+import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.manifoldcf.agents.interfaces.IOutputAddActivity;
 import org.apache.manifoldcf.agents.interfaces.IOutputNotifyActivity;
 import org.apache.manifoldcf.agents.interfaces.IOutputRemoveActivity;
+import org.apache.manifoldcf.agents.interfaces.OutputSpecification;
 import org.apache.manifoldcf.agents.interfaces.RepositoryDocument;
 import org.apache.manifoldcf.agents.interfaces.ServiceInterruption;
 import org.apache.manifoldcf.agents.output.BaseOutputConnector;
 import org.apache.manifoldcf.agents.output.opensearchserver.OpenSearchServerAction.CommandEnum;
+import org.apache.manifoldcf.agents.output.opensearchserver.OpenSearchServerConnection.Result;
 import org.apache.manifoldcf.core.interfaces.ConfigParams;
+import org.apache.manifoldcf.core.interfaces.ConfigurationNode;
 import org.apache.manifoldcf.core.interfaces.IHTTPOutput;
 import org.apache.manifoldcf.core.interfaces.IPostParameters;
 import org.apache.manifoldcf.core.interfaces.IThreadContext;
 import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
+import org.apache.manifoldcf.core.interfaces.SpecificationNode;
+import org.json.JSONException;
+import org.json.JSONObject;
 
 public class OpenSearchServerConnector extends BaseOutputConnector {
 
@@ -33,9 +43,15 @@ public class OpenSearchServerConnector e
 			OPENSEARCHSERVER_OPTIMIZE_ACTIVITY };
 
 	private final static String OPENSEARCHSERVER_TAB_PARAMETER = "Parameters";
+	private final static String OPENSEARCHSERVER_TAB_OPENSEARCHSERVER = "OpenSearchServer";
 
-	// private final static String OPENSEARCHSERVER_TAB_FIELDMAPPING =
-	// "Field mapping";
+	private String specsCacheOutpuDescription;
+	private OpenSearchServerSpecs specsCache;
+
+	public OpenSearchServerConnector() {
+		specsCacheOutpuDescription = null;
+		specsCache = null;
+	}
 
 	@Override
 	public String[] getActivitiesList() {
@@ -58,7 +74,10 @@ public class OpenSearchServerConnector e
 			br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
 			String line;
 			while ((line = br.readLine()) != null)
-				out.println(params.replace(line));
+				if (params != null)
+					out.println(params.replace(line));
+				else
+					out.println(line);
 		} catch (UnsupportedEncodingException e) {
 			throw new ManifoldCFException(e);
 		} catch (IOException e) {
@@ -78,6 +97,7 @@ public class OpenSearchServerConnector e
 		super.outputConfigurationHeader(threadContext, out, parameters,
 				tabsArray);
 		tabsArray.add(OPENSEARCHSERVER_TAB_PARAMETER);
+		outputResource("configuration.js", out, null);
 	}
 
 	@Override
@@ -86,80 +106,200 @@ public class OpenSearchServerConnector e
 			throws ManifoldCFException, IOException {
 		super.outputConfigurationBody(threadContext, out, parameters, tabName);
 		if (OPENSEARCHSERVER_TAB_PARAMETER.equals(tabName)) {
-			outputResource("configuration.html", out, getParameters(parameters));
+			outputResource("configuration.html", out,
+					getConfigParameters(parameters));
 		}
 	}
 
-	// @Override
-	// public void outputSpecificationHeader(IHTTPOutput out,
-	// OutputSpecification os, List<String> tabsArray)
-	// throws ManifoldCFException, IOException {
-	// super.outputSpecificationHeader(out, os, tabsArray);
-	// tabsArray.add(OPENSEARCHSERVER_TAB_FIELDMAPPING);
-	// }
-	//
-	// @Override
-	// public void outputSpecificationBody(IHTTPOutput out,
-	// OutputSpecification os, String tabName) throws ManifoldCFException,
-	// IOException {
-	// super.outputSpecificationBody(out, os, tabName);
-	// if (OPENSEARCHSERVER_TAB_FIELDMAPPING.equals(tabName)) {
-	// Set<OpenSearchServerParam> params = OpenSearchServerParam
-	// .getParameters(OpenSearchServerParam.SPECIFICATIONLIST, os);
-	// outputResource("fieldmapping.html", out, params);
-	// }
-	// }
+	@Override
+	public void outputSpecificationHeader(IHTTPOutput out,
+			OutputSpecification os, List<String> tabsArray)
+			throws ManifoldCFException, IOException {
+		super.outputSpecificationHeader(out, os, tabsArray);
+		tabsArray.add(OPENSEARCHSERVER_TAB_OPENSEARCHSERVER);
+	}
+
+	final private SpecificationNode getSpecNode(OutputSpecification os) {
+		int l = os.getChildCount();
+		for (int i = 0; i < l; i++) {
+			SpecificationNode node = os.getChild(i);
+			if (OpenSearchServerSpecs.OPENSEARCHSERVER_SPECS_NODE.equals(node
+					.getType())) {
+				return node;
+			}
+		}
+		return null;
+	}
+
+	@Override
+	public void outputSpecificationBody(IHTTPOutput out,
+			OutputSpecification os, String tabName) throws ManifoldCFException,
+			IOException {
+		super.outputSpecificationBody(out, os, tabName);
+		if (OPENSEARCHSERVER_TAB_OPENSEARCHSERVER.equals(tabName)) {
+			outputResource("specifications.html", out, getSpecParameters(os));
+		}
+	}
+
+	@Override
+	public String processSpecificationPost(IPostParameters variableContext,
+			OutputSpecification os) throws ManifoldCFException {
+		ConfigurationNode specNode = getSpecNode(os);
+		boolean bAdd = (specNode == null);
+		if (bAdd) {
+			specNode = new SpecificationNode(
+					OpenSearchServerSpecs.OPENSEARCHSERVER_SPECS_NODE);
+		}
+		OpenSearchServerSpecs.contextToSpecNode(variableContext, specNode);
+		if (bAdd)
+			os.addChild(os.getChildCount(), specNode);
+		return null;
+	}
 
 	/**
-	 * Build a Set of OpenSearchServerParam. If configParams is null,
+	 * Build a Set of OpenSearchServer parameters. If configParams is null,
 	 * getConfiguration() is used.
 	 * 
 	 * @param configParams
-	 * @return
 	 */
-	final private OpenSearchServerParam getParameters(ConfigParams configParams) {
+	final private OpenSearchServerConfig getConfigParameters(
+			ConfigParams configParams) {
 		if (configParams == null)
 			configParams = getConfiguration();
-		OpenSearchServerParam parameters = new OpenSearchServerParam(
-				OpenSearchServerParam.CONFIGURATIONLIST, configParams);
-		return parameters;
+		synchronized (this) {
+			return new OpenSearchServerConfig(configParams);
+		}
+	}
+
+	final private OpenSearchServerSpecs getSpecParameters(OutputSpecification os)
+			throws ManifoldCFException {
+		return new OpenSearchServerSpecs(getSpecNode(os));
+	}
+
+	final private OpenSearchServerSpecs getSpecsCache(String outputDescription)
+			throws ManifoldCFException {
+		try {
+			synchronized (this) {
+				if (!outputDescription.equals(specsCacheOutpuDescription))
+					specsCache = null;
+				if (specsCache == null)
+					specsCache = new OpenSearchServerSpecs(new JSONObject(
+							outputDescription));
+				return specsCache;
+			}
+		} catch (JSONException e) {
+			throw new ManifoldCFException(e);
+		}
+	}
+
+	@Override
+	public String getOutputDescription(OutputSpecification os)
+			throws ManifoldCFException {
+		OpenSearchServerSpecs specs = new OpenSearchServerSpecs(getSpecNode(os));
+		return specs.toJson().toString();
+	}
+
+	@Override
+	public boolean checkLengthIndexable(String outputDescription, long length)
+			throws ManifoldCFException, ServiceInterruption {
+		OpenSearchServerSpecs specs = getSpecsCache(outputDescription);
+		long maxFileSize = specs.getMaxFileSize();
+		if (length > maxFileSize)
+			return false;
+		return super.checkLengthIndexable(outputDescription, length);
+	}
+
+	@Override
+	public boolean checkDocumentIndexable(String outputDescription,
+			File localFile) throws ManifoldCFException, ServiceInterruption {
+		OpenSearchServerSpecs specs = getSpecsCache(outputDescription);
+		return specs.checkExtension(FilenameUtils.getExtension(localFile
+				.getName()));
+	}
+
+	@Override
+	public boolean checkMimeTypeIndexable(String outputDescription,
+			String mimeType) throws ManifoldCFException, ServiceInterruption {
+		OpenSearchServerSpecs specs = getSpecsCache(outputDescription);
+		return specs.checkMimeType(mimeType);
 	}
 
 	@Override
 	public void viewConfiguration(IThreadContext threadContext,
 			IHTTPOutput out, ConfigParams parameters)
 			throws ManifoldCFException, IOException {
-		outputResource("view.html", out, getParameters(parameters));
+		outputResource("view.html", out, getConfigParameters(parameters));
+	}
+
+	@Override
+	public void viewSpecification(IHTTPOutput out, OutputSpecification os)
+			throws ManifoldCFException, IOException {
+		outputResource("viewSpec.html", out, getSpecParameters(os));
 	}
 
 	@Override
 	public String processConfigurationPost(IThreadContext threadContext,
 			IPostParameters variableContext, ConfigParams parameters)
 			throws ManifoldCFException {
-		OpenSearchServerParam.contextToConfig(
-				OpenSearchServerParam.CONFIGURATIONLIST, variableContext,
-				parameters);
+		OpenSearchServerConfig.contextToConfig(variableContext, parameters);
 		return null;
 	}
 
+	private static Map<String, Integer> ossInstances = null;
+
+	private synchronized final Integer addInstance(OpenSearchServerConfig config) {
+		if (ossInstances == null)
+			ossInstances = new TreeMap<String, Integer>();
+		synchronized (ossInstances) {
+			String uii = config.getUniqueIndexIdentifier();
+			Integer count = ossInstances.get(uii);
+			if (count == null) {
+				count = new Integer(1);
+				ossInstances.put(uii, count);
+			} else
+				count++;
+			return count;
+		}
+	}
+
+	private synchronized final void removeInstance(OpenSearchServerConfig config) {
+		if (ossInstances == null)
+			return;
+		synchronized (ossInstances) {
+			String uii = config.getUniqueIndexIdentifier();
+			Integer count = ossInstances.get(uii);
+			if (count == null)
+				return;
+			if (--count == 0)
+				ossInstances.remove(uii);
+		}
+	}
+
 	@Override
 	public int addOrReplaceDocument(String documentURI,
 			String outputDescription, RepositoryDocument document,
 			String authorityNameString, IOutputAddActivity activities)
 			throws ManifoldCFException, ServiceInterruption {
-		InputStream inputStream = document.getBinaryStream();
-		try {
-			long startTime = System.currentTimeMillis();
-			OpenSearchServerIndex oi = new OpenSearchServerIndex(documentURI,
-					inputStream, getParameters(null));
-			activities.recordActivity(startTime,
-					OPENSEARCHSERVER_INDEXATION_ACTIVITY,
-					document.getBinaryLength(), documentURI,
-					oi.getResultCode(), oi.getResultDescription());
-		} finally {
-			IOUtils.closeQuietly(inputStream);
+		OpenSearchServerConfig config = getConfigParameters(null);
+		Integer count = addInstance(config);
+		synchronized (count) {
+			InputStream inputStream = document.getBinaryStream();
+			try {
+				long startTime = System.currentTimeMillis();
+				OpenSearchServerIndex oi = new OpenSearchServerIndex(
+						documentURI, inputStream, config);
+				activities.recordActivity(startTime,
+						OPENSEARCHSERVER_INDEXATION_ACTIVITY, document
+								.getBinaryLength(), documentURI, oi.getResult()
+								.name(), oi.getResultDescription());
+				if (oi.getResult() != Result.OK)
+					return DOCUMENTSTATUS_REJECTED;
+			} finally {
+				IOUtils.closeQuietly(inputStream);
+				removeInstance(config);
+			}
+			return DOCUMENTSTATUS_ACCEPTED;
 		}
-		return DOCUMENTSTATUS_ACCEPTED;
 	}
 
 	@Override
@@ -168,10 +308,17 @@ public class OpenSearchServerConnector e
 			ServiceInterruption {
 		long startTime = System.currentTimeMillis();
 		OpenSearchServerDelete od = new OpenSearchServerDelete(documentURI,
-				getParameters(null));
+				getConfigParameters(null));
 		activities.recordActivity(startTime,
-				OPENSEARCHSERVER_DELETION_ACTIVITY, null, documentURI,
-				od.getResultCode(), od.getResultDescription());
+				OPENSEARCHSERVER_DELETION_ACTIVITY, null, documentURI, od
+						.getResult().name(), od.getResultDescription());
+	}
+
+	@Override
+	public String check() throws ManifoldCFException {
+		OpenSearchServerSchema oss = new OpenSearchServerSchema(
+				getConfigParameters(null));
+		return oss.getResult().name() + " " + oss.getResultDescription();
 	}
 
 	@Override
@@ -179,12 +326,11 @@ public class OpenSearchServerConnector e
 			throws ManifoldCFException, ServiceInterruption {
 		long startTime = System.currentTimeMillis();
 		OpenSearchServerAction oo = new OpenSearchServerAction(
-				CommandEnum.optimize, getParameters(null));
+				CommandEnum.optimize, getConfigParameters(null));
 		activities.recordActivity(startTime,
 				OPENSEARCHSERVER_OPTIMIZE_ACTIVITY, null,
-				oo.getCallUrlSnippet(), oo.getResultCode(),
+				oo.getCallUrlSnippet(), oo.getResult().name(),
 				oo.getResultDescription());
-
 	}
 
 }

Modified: incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerDelete.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerDelete.java?rev=1157102&r1=1157101&r2=1157102&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerDelete.java
(original)
+++ incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerDelete.java
Fri Aug 12 13:32:42 2011
@@ -6,12 +6,15 @@ import org.apache.manifoldcf.core.interf
 public class OpenSearchServerDelete extends OpenSearchServerConnection {
 
 	public OpenSearchServerDelete(String documentURI,
-			OpenSearchServerParam params) throws ManifoldCFException {
-		super(params);
+			OpenSearchServerConfig config) throws ManifoldCFException {
+		super(config);
 		StringBuffer url = getApiUrl("delete");
 		url.append("&uniq=");
 		url.append(urlEncode(documentURI));
 		GetMethod method = new GetMethod(url.toString());
 		call(method);
+		if ("OK".equals(checkXPath(xPathStatus)))
+			return;
+		setResult(Result.ERROR, checkXPath(xPathException));
 	}
 }

Modified: incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerIndex.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerIndex.java?rev=1157102&r1=1157101&r2=1157102&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerIndex.java
(original)
+++ incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerIndex.java
Fri Aug 12 13:32:42 2011
@@ -2,62 +2,81 @@ package org.apache.manifoldcf.agents.out
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
 
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.httpclient.methods.PutMethod;
 import org.apache.commons.httpclient.methods.RequestEntity;
-import org.apache.commons.httpclient.methods.StringRequestEntity;
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.io.IOUtils;
+import org.apache.manifoldcf.core.common.Base64;
 import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
 
 public class OpenSearchServerIndex extends OpenSearchServerConnection {
 
-	public OpenSearchServerIndex(String documentURI, InputStream inputStream,
-			OpenSearchServerParam params) throws ManifoldCFException {
-		super(params);
-		try {
-			StringBuffer url = getApiUrl("update");
-			PutMethod put = new PutMethod(url.toString());
-			RequestEntity entity = new StringRequestEntity(getXML(documentURI,
-					inputStream), "text/xml", "UTF-8");
-			put.setRequestEntity(entity);
-			call(put);
-		} catch (UnsupportedEncodingException e) {
-			throw new ManifoldCFException(e);
-		} catch (XMLStreamException e) {
-			throw new ManifoldCFException(e);
-		} catch (IOException e) {
-			throw new ManifoldCFException(e);
+	private class IndexRequestEntity implements RequestEntity {
+
+		private String documentURI;
+
+		private InputStream inputStream;
+
+		private String fileName;
+
+		public IndexRequestEntity(String documentURI, InputStream inputStream) {
+			this.documentURI = documentURI;
+			this.inputStream = inputStream;
+			this.fileName = FilenameUtils.getName(documentURI);
+		}
+
+		public long getContentLength() {
+			return -1;
 		}
+
+		public String getContentType() {
+			return "text/xml; charset=utf-8";
+		}
+
+		public boolean isRepeatable() {
+			return false;
+		}
+
+		public void writeRequest(OutputStream out) throws IOException {
+			PrintWriter pw = new PrintWriter(out);
+			try {
+				pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
+				pw.println("<index>);");
+				pw.print("<document><field name=\"uri\"><value>");
+				pw.print(documentURI);
+				pw.println("</value></field>");
+				pw.print("<binary fileName=\"");
+				pw.print(fileName);
+				pw.println("\">");
+				Base64 base64 = new Base64();
+				base64.encodeStream(inputStream, pw);
+				pw.println("</binary></document>");
+				pw.println("</index>");
+			} catch (ManifoldCFException e) {
+				throw new IOException(e);
+			} finally {
+				IOUtils.closeQuietly(pw);
+			}
+		}
+
 	}
 
-	private String getXML(String documentURI, InputStream inputStream)
-			throws XMLStreamException, IOException {
-		String fileName = FilenameUtils.getName(documentURI);
-		XMLOutputFactory factory = XMLOutputFactory.newInstance();
-		StringWriter sw = new StringWriter();
-		XMLStreamWriter writer = factory.createXMLStreamWriter(sw);
-		writer.writeStartDocument("UTF-8", "1.0");
-		writer.writeStartElement("index");
-		writer.writeStartElement("document");
-		writer.writeStartElement("field");
-		writer.writeAttribute("name", "uri");
-		writer.writeStartElement("value");
-		writer.writeCData(documentURI);
-		writer.writeEndElement(); // ends value
-		writer.writeEndElement(); // ends field
-		writer.writeStartElement("binary");
-		writer.writeAttribute("fileName", fileName);
-		writer.writeCharacters(new String(Base64.encodeBase64(
-				IOUtils.toByteArray(inputStream), true)));
-		writer.writeEndDocument();
-		return sw.toString();
+	public OpenSearchServerIndex(String documentURI, InputStream inputStream,
+			OpenSearchServerConfig config) throws ManifoldCFException {
+		super(config);
+		StringBuffer url = getApiUrl("update");
+		PutMethod put = new PutMethod(url.toString());
+		RequestEntity entity = new IndexRequestEntity(documentURI, inputStream);
+		put.setRequestEntity(entity);
+		call(put);
+		if ("OK".equals(checkXPath(xPathStatus)))
+			return;
+		String error = checkXPath(xPathException);
+		setResult(Result.ERROR, error);
+		System.err.println(getResponse());
 	}
+
 }

Modified: incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerParam.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerParam.java?rev=1157102&r1=1157101&r2=1157102&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerParam.java
(original)
+++ incubator/lcf/branches/CONNECTORS-224/connectors/opensearchserver/connector/src/main/java/org/apache/manifoldcf/agents/output/opensearchserver/OpenSearchServerParam.java
Fri Aug 12 13:32:42 2011
@@ -4,8 +4,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.manifoldcf.agents.output.opensearchserver.OpenSearchServerParam.ParameterEnum;
-import org.apache.manifoldcf.core.interfaces.ConfigParams;
-import org.apache.manifoldcf.core.interfaces.IPostParameters;
 
 public class OpenSearchServerParam extends HashMap<ParameterEnum, String> {
 
@@ -21,7 +19,29 @@ public class OpenSearchServerParam exten
 
 		APIKEY(""),
 
-		FIELDLIST("");
+		FIELDLIST(""),
+
+		MAXFILESIZE("16777216"),
+
+		MIMETYPES(
+				"application/msword\n"
+						+ "application/vnd.ms-excel\n"
+						+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document\n"
+						+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\n"
+						+ "text/html\n"
+						+ "application/pdf\n"
+						+ "application/vnd.ms-powerpoint\n"
+						+ "application/vnd.openxmlformats-officedocument.presentationml.presentation\n"
+						+ "application/vnd.oasis.opendocument.text\n"
+						+ "application/vnd.oasis.opendocument.spreadsheet\n"
+						+ "application/vnd.oasis.opendocument.formula\n"
+						+ "application/rtf\n" + "text/plain\n" + "audio/mpeg\n"
+						+ "audio/x-wav\n" + "audio/ogg\n" + "audio/flac\n"
+						+ "application/x-bittorrent"),
+
+		EXTENSIONS("doc\n" + "docx\n" + "xls\n" + "xlsx\n" + "ppt\n" + "pptx\n"
+				+ "html\n" + "pdf\n" + "odt\n" + "ods\n" + "rtf\n" + "txt\n"
+				+ "mp3\n" + "mp4\n" + "wav\n" + "ogg\n" + "flac\n" + "torrent");
 
 		final protected String defaultValue;
 
@@ -30,32 +50,10 @@ public class OpenSearchServerParam exten
 		}
 	}
 
-	/**
-	 * Parameters used for the configuration
-	 */
-	final public static ParameterEnum[] CONFIGURATIONLIST = {
-			ParameterEnum.SERVERLOCATION, ParameterEnum.INDEXNAME,
-			ParameterEnum.USERNAME, ParameterEnum.APIKEY };
-
-	final public static ParameterEnum[] SPECIFICATIONLIST = { ParameterEnum.FIELDLIST };
-
 	private static final long serialVersionUID = -1593234685772720029L;
 
-	/**
-	 * Build a set of OpenSearchServerParameters by reading ConfigParams. If the
-	 * value returned by ConfigParams.getParameter is null, the default value is
-	 * set.
-	 * 
-	 * @param paramList
-	 * @param params
-	 */
-	public OpenSearchServerParam(ParameterEnum[] paramList, ConfigParams params) {
-		for (ParameterEnum param : paramList) {
-			String value = params.getParameter(param.name());
-			if (value == null)
-				value = param.defaultValue;
-			put(param, value);
-		}
+	protected OpenSearchServerParam(ParameterEnum[] params) {
+		super(params.length);
 	}
 
 	/**
@@ -71,13 +69,4 @@ public class OpenSearchServerParam exten
 		return text;
 	}
 
-	public static void contextToConfig(ParameterEnum[] paramList,
-			IPostParameters variableContext, ConfigParams parameters) {
-		for (ParameterEnum param : paramList) {
-			String p = variableContext.getParameter(param.name().toLowerCase());
-			if (p != null)
-				parameters.setParameter(param.name(), p);
-		}
-	}
-
 }



Mime
View raw message