You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2012/02/12 18:39:35 UTC
svn commit: r1243282 - in
/incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch: ./
connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/
Author: kwright
Date: Sun Feb 12 17:39:35 2012
New Revision: 1243282
URL: http://svn.apache.org/viewvc?rev=1243282&view=rev
Log:
Commit latest patch.
Modified:
incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchAction.java
incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConfig.java
incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnection.java
incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java
incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchDelete.java
incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchIndex.java
incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchParam.java
incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchSpecs.java
incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/Messages.java
incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/pom.xml
Modified: incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchAction.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchAction.java?rev=1243282&r1=1243281&r2=1243282&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchAction.java (original)
+++ incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchAction.java Sun Feb 12 17:39:35 2012
@@ -1,33 +1,36 @@
/**
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.manifoldcf.agents.output.elasticsearch;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
-public class ElasticSearchAction extends ElasticSearchConnection {
+public class ElasticSearchAction extends ElasticSearchConnection
+{
- public enum CommandEnum {
+ public enum CommandEnum
+ {
_optimize, _refresh;
}
public ElasticSearchAction(CommandEnum cmd, ElasticSearchConfig config)
- throws ManifoldCFException {
+ throws ManifoldCFException
+ {
super(config);
StringBuffer url = getApiUrl(cmd.toString());
GetMethod method = new GetMethod(url.toString());
Modified: incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConfig.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConfig.java?rev=1243282&r1=1243281&r2=1243282&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConfig.java (original)
+++ incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConfig.java Sun Feb 12 17:39:35 2012
@@ -20,78 +20,81 @@ package org.apache.manifoldcf.agents.out
import org.apache.manifoldcf.core.interfaces.ConfigParams;
import org.apache.manifoldcf.core.interfaces.IPostParameters;
-public class ElasticSearchConfig extends ElasticSearchParam {
+public class ElasticSearchConfig extends ElasticSearchParam
+{
- /**
+ /**
*
*/
- private static final long serialVersionUID = -2071296573398352538L;
+ private static final long serialVersionUID = -2071296573398352538L;
- /**
- * Parameters used for the configuration
- */
- final private static ParameterEnum[] CONFIGURATIONLIST = {
- ParameterEnum.SERVERLOCATION, ParameterEnum.INDEXNAME,
- ParameterEnum.INDEXTYPE, ParameterEnum.USERNAME,
- ParameterEnum.APIKEY };
-
- /**
- * Build a set of ElasticSearchParameters by reading ConfigParams. If the
- * value returned by ConfigParams.getParameter is null, the default value is
- * set.
- *
- * @param paramList
- * @param params
- */
- public ElasticSearchConfig(ConfigParams params) {
- super(CONFIGURATIONLIST);
- for (ParameterEnum param : CONFIGURATIONLIST) {
- String value = params.getParameter(param.name());
- if (value == null)
- value = param.defaultValue;
- put(param, value);
- }
- }
-
- /**
- *
- * @return a unique identifier for one index on one ElasticSearch instance.
- */
- public String getUniqueIndexIdentifier() {
- StringBuffer sb = new StringBuffer();
- sb.append(getServerLocation());
- if (sb.charAt(sb.length() - 1) != '/')
- sb.append('/');
- sb.append(getIndexName());
- return sb.toString();
- }
-
- public final static void contextToConfig(IPostParameters variableContext,
- ConfigParams parameters) {
- for (ParameterEnum param : CONFIGURATIONLIST) {
- String p = variableContext.getParameter(param.name().toLowerCase());
- if (p != null)
- parameters.setParameter(param.name(), p);
- }
- }
-
- final public String getServerLocation() {
- return get(ParameterEnum.SERVERLOCATION);
- }
-
- final public String getIndexName() {
- return get(ParameterEnum.INDEXNAME);
- }
-
- final public String getIndexType() {
- return get(ParameterEnum.INDEXTYPE);
- }
-
- final public String getUserName() {
- return get(ParameterEnum.USERNAME);
- }
-
- final public String getApiKey() {
- return get(ParameterEnum.APIKEY);
- }
+ /** Parameters used for the configuration */
+ final private static ParameterEnum[] CONFIGURATIONLIST =
+ { ParameterEnum.SERVERLOCATION, ParameterEnum.INDEXNAME,
+ ParameterEnum.INDEXTYPE, ParameterEnum.USERNAME, ParameterEnum.APIKEY };
+
+ /** Build a set of ElasticSearchParameters by reading ConfigParams. If the
+ * value returned by ConfigParams.getParameter is null, the default value is
+ * set.
+ *
+ * @param paramList
+ * @param params */
+ public ElasticSearchConfig(ConfigParams params)
+ {
+ super(CONFIGURATIONLIST);
+ for (ParameterEnum param : CONFIGURATIONLIST)
+ {
+ String value = params.getParameter(param.name());
+ if (value == null)
+ value = param.defaultValue;
+ put(param, value);
+ }
+ }
+
+ /** @return a unique identifier for one index on one ElasticSearch instance. */
+ public String getUniqueIndexIdentifier()
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append(getServerLocation());
+ if (sb.charAt(sb.length() - 1) != '/')
+ sb.append('/');
+ sb.append(getIndexName());
+ return sb.toString();
+ }
+
+ public final static void contextToConfig(IPostParameters variableContext,
+ ConfigParams parameters)
+ {
+ for (ParameterEnum param : CONFIGURATIONLIST)
+ {
+ String p = variableContext.getParameter(param.name().toLowerCase());
+ if (p != null)
+ parameters.setParameter(param.name(), p);
+ }
+ }
+
+ final public String getServerLocation()
+ {
+ return get(ParameterEnum.SERVERLOCATION);
+ }
+
+ final public String getIndexName()
+ {
+ return get(ParameterEnum.INDEXNAME);
+ }
+
+ final public String getIndexType()
+ {
+ return get(ParameterEnum.INDEXTYPE);
+ }
+
+ final public String getUserName()
+ {
+ return get(ParameterEnum.USERNAME);
+ }
+
+ final public String getApiKey()
+ {
+ return get(ParameterEnum.APIKEY);
+ }
}
Modified: incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnection.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnection.java?rev=1243282&r1=1243281&r2=1243282&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnection.java (original)
+++ incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnection.java Sun Feb 12 17:39:35 2012
@@ -24,139 +24,166 @@ import java.net.URLEncoder;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.io.IOUtils;
import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
-public class ElasticSearchConnection {
+public class ElasticSearchConnection
+{
- private String serverLocation;
+ private MultiThreadedHttpConnectionManager connectionManager;
- private String indexName;
+ private String serverLocation;
- private String userName;
+ private String indexName;
- private String apiKey;
-
- private String resultDescription;
-
- private String callUrlSnippet;
-
- private String response;
-
- protected String jsonStatus = "\"ok\"";
- protected String jsonException = "\"error\"";
-
- public enum Result {
- OK, ERROR, UNKNOWN;
- }
-
- private Result result;
-
- protected ElasticSearchConnection(ElasticSearchConfig config) {
- result = Result.UNKNOWN;
- response = null;
- resultDescription = "";
- callUrlSnippet = null;
- serverLocation = config.getServerLocation();
- indexName = config.getIndexName();
- userName = config.getUserName();
- apiKey = config.getApiKey();
- }
-
- protected final String urlEncode(String t) throws ManifoldCFException {
- try {
- return URLEncoder.encode(t, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new ManifoldCFException(e);
- }
- }
-
- protected StringBuffer getApiUrl(String command) throws ManifoldCFException {
- StringBuffer url = new StringBuffer(serverLocation);
- if (!serverLocation.endsWith("/"))
- url.append('/');
- url.append(urlEncode(indexName));
- url.append("/" + command);
- callUrlSnippet = url.toString();
- if (userName != null && apiKey != null && userName.length() > 0
- && apiKey.length() > 0) {
- url.append("&login=");
- url.append(urlEncode(userName));
- url.append("&key=");
- url.append(apiKey);
- }
- return url;
- }
-
- protected void call(HttpMethod method) throws ManifoldCFException {
- 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)
- method.releaseConnection();
- }
- }
-
- protected String checkJson(String jsonQuery) throws ManifoldCFException {
- String result = null;
- if (response != null) {
- String[] tokens = response.replaceAll("\\{", "")
- .replaceAll("\\}", "").split(",");
- for (String token : tokens)
- if (token.contains(jsonQuery))
- result = token.substring(token.indexOf(":") + 1);
- }
- return result;
- }
-
- 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;
- }
-
- protected String getResponse() {
- return response;
- }
-
- private boolean checkResultCode(int code) {
- switch (code) {
- case 0:
- setResult(Result.UNKNOWN, null);
- return false;
- case 200:
- setResult(Result.OK, null);
- return true;
- case 404:
- setResult(Result.ERROR, "Server/page not found");
- return false;
- default:
- setResult(Result.ERROR, null);
- return false;
- }
- }
-
- public Result getResult() {
- return result;
- }
-
- public String getCallUrlSnippet() {
- return callUrlSnippet;
- }
+ private String userName;
+
+ private String apiKey;
+
+ private String resultDescription;
+
+ private String callUrlSnippet;
+
+ private String response;
+
+ protected String jsonStatus = "\"ok\"";
+ protected String jsonException = "\"error\"";
+
+ public enum Result
+ {
+ OK, ERROR, UNKNOWN;
+ }
+
+ private Result result;
+
+ protected ElasticSearchConnection(ElasticSearchConfig config)
+ {
+ result = Result.UNKNOWN;
+ response = null;
+ resultDescription = "";
+ callUrlSnippet = null;
+ serverLocation = config.getServerLocation();
+ indexName = config.getIndexName();
+ userName = config.getUserName();
+ apiKey = config.getApiKey();
+ connectionManager = new MultiThreadedHttpConnectionManager();
+ connectionManager.getParams().setMaxTotalConnections(1);
+ }
+
+ protected final String urlEncode(String t) throws ManifoldCFException
+ {
+ try
+ {
+ return URLEncoder.encode(t, "UTF-8");
+ } catch (UnsupportedEncodingException e)
+ {
+ throw new ManifoldCFException(e);
+ }
+ }
+
+ protected StringBuffer getApiUrl(String command) throws ManifoldCFException
+ {
+ StringBuffer url = new StringBuffer(serverLocation);
+ if (!serverLocation.endsWith("/"))
+ url.append('/');
+ url.append(urlEncode(indexName));
+ url.append("/" + command);
+ callUrlSnippet = url.toString();
+ if (userName != null && apiKey != null && userName.length() > 0
+ && apiKey.length() > 0)
+ {
+ url.append("&login=");
+ url.append(urlEncode(userName));
+ url.append("&key=");
+ url.append(apiKey);
+ }
+ return url;
+ }
+
+ protected void call(HttpMethod method) throws ManifoldCFException
+ {
+ HttpClient hc = new HttpClient(connectionManager);
+ 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)
+ method.releaseConnection();
+ }
+ }
+
+ protected String checkJson(String jsonQuery) throws ManifoldCFException
+ {
+ String result = null;
+ if (response != null)
+ {
+ String[] tokens = response.replaceAll("\\{", "").replaceAll("\\}", "")
+ .split(",");
+ for (String token : tokens)
+ if (token.contains(jsonQuery))
+ result = token.substring(token.indexOf(":") + 1);
+ }
+ return result;
+ }
+
+ 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;
+ }
+
+ protected String getResponse()
+ {
+ return response;
+ }
+
+ private boolean checkResultCode(int code)
+ {
+ switch (code)
+ {
+ case 0:
+ setResult(Result.UNKNOWN, null);
+ return false;
+ case 200:
+ setResult(Result.OK, null);
+ return true;
+ case 404:
+ setResult(Result.ERROR, "Server/page not found");
+ return false;
+ default:
+ setResult(Result.ERROR, null);
+ return false;
+ }
+ }
+
+ public Result getResult()
+ {
+ return result;
+ }
+
+ public String getCallUrlSnippet()
+ {
+ return callUrlSnippet;
+ }
}
Modified: incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java?rev=1243282&r1=1243281&r2=1243282&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java (original)
+++ incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java Sun Feb 12 17:39:35 2012
@@ -1,19 +1,19 @@
/**
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.manifoldcf.agents.output.elasticsearch;
@@ -45,36 +45,39 @@ import org.apache.manifoldcf.core.interf
import org.json.JSONException;
import org.json.JSONObject;
-public class ElasticSearchConnector extends BaseOutputConnector {
+public class ElasticSearchConnector extends BaseOutputConnector
+{
private final static String ELASTICSEARCH_INDEXATION_ACTIVITY = "Optimize";
private final static String ELASTICSEARCH_DELETION_ACTIVITY = "Deletion";
private final static String ELASTICSEARCH_OPTIMIZE_ACTIVITY = "Indexation";
- private final static String[] ELASTICSEARCH_ACTIVITIES = {
- ELASTICSEARCH_INDEXATION_ACTIVITY, ELASTICSEARCH_DELETION_ACTIVITY,
+ private final static String[] ELASTICSEARCH_ACTIVITIES =
+ { ELASTICSEARCH_INDEXATION_ACTIVITY, ELASTICSEARCH_DELETION_ACTIVITY,
ELASTICSEARCH_OPTIMIZE_ACTIVITY };
private final static String ELASTICSEARCH_TAB_ELASTICSEARCH = "ElasticSearch";
- /** Forward to the HTML template for rendering hidden fields when the Server tab is not selected */
+ /** Forward to the HTML template for rendering hidden fields when the Server
+ * tab is not selected */
private static final String HIDDEN_CONFIG_FORWARD = "hiddenConfiguration.html";
-
- /** Forward to the HTML template for rendering hidden fields when the CMIS Query tab is not selected */
+
+ /** Forward to the HTML template for rendering hidden fields when the CMIS
+ * Query tab is not selected */
private static final String HIDDEN_SPEC_FORWARD = "hiddenSpecification.html";
-
+
/** Forward to the HTML template to edit the configuration parameters */
private static final String EDIT_CONFIG_FORWARD = "editConfiguration.html";
-
+
/** Forward to the HTML template to view the configuration parameters */
private static final String VIEW_CONFIG_FORWARD = "viewConfiguration.html";
-
+
/** Forward to the javascript to check the configuration parameters */
private static final String EDIT_CONFIG_HEADER_FORWARD = "editConfiguration.js";
/** Forward to the template to view the specification parameters for the job */
private static final String VIEW_SPEC_FORWARD = "viewSpecification.html";
-
+
/** Forward to the template to edit the configuration parameters for the job */
private static final String EDIT_SPEC_FORWARD = "editSpecification.html";
@@ -84,66 +87,79 @@ public class ElasticSearchConnector exte
private String specsCacheOutpuDescription;
private ElasticSearchSpecs specsCache;
- public ElasticSearchConnector() {
+ public ElasticSearchConnector()
+ {
specsCacheOutpuDescription = null;
specsCache = null;
}
@Override
- public String[] getActivitiesList() {
+ public String[] getActivitiesList()
+ {
return ELASTICSEARCH_ACTIVITIES;
}
- /**
- * Read the content of a resource, replace the variable ${PARAMNAME} with the
+ /** Read the content of a resource, replace the variable ${PARAMNAME} with the
* value and copy it to the out.
*
* @param resName
* @param out
- * @throws ManifoldCFException
- */
+ * @throws ManifoldCFException */
private static void outputResource(String resName, IHTTPOutput out,
- Locale locale, ElasticSearchParam params) throws ManifoldCFException {
- Messages.outputResource(out,locale,resName,(params==null)?null:params.buildMap(),false);
+ Locale locale, ElasticSearchParam params) throws ManifoldCFException
+ {
+ Messages.outputResource(out, locale, resName, (params == null) ? null
+ : params.buildMap(), false);
}
@Override
public void outputConfigurationHeader(IThreadContext threadContext,
- IHTTPOutput out, Locale locale, ConfigParams parameters, List<String> tabsArray)
- throws ManifoldCFException, IOException {
- super.outputConfigurationHeader(threadContext, out, locale, parameters, tabsArray);
- tabsArray.add(Messages.getString(locale,"ElasticSearchConnector.Parameters"));
+ IHTTPOutput out, Locale locale, ConfigParams parameters,
+ List<String> tabsArray) throws ManifoldCFException, IOException
+ {
+ super.outputConfigurationHeader(threadContext, out, locale, parameters,
+ tabsArray);
+ tabsArray.add(Messages.getString(locale,
+ "ElasticSearchConnector.Parameters"));
outputResource(EDIT_CONFIG_HEADER_FORWARD, out, locale, null);
}
@Override
public void outputConfigurationBody(IThreadContext threadContext,
IHTTPOutput out, Locale locale, ConfigParams parameters, String tabName)
- throws ManifoldCFException, IOException {
- super.outputConfigurationBody(threadContext, out, locale, parameters, tabName);
+ throws ManifoldCFException, IOException
+ {
+ super.outputConfigurationBody(threadContext, out, locale, parameters,
+ tabName);
ElasticSearchConfig config = this.getConfigParameters(parameters);
- if (Messages.getString(locale,"ElasticSearchConnector.Parameters").equals(tabName)) {
+ if (Messages.getString(locale, "ElasticSearchConnector.Parameters").equals(
+ tabName))
+ {
outputResource(EDIT_CONFIG_FORWARD, out, locale, config);
- } else {
+ } else
+ {
outputResource(HIDDEN_CONFIG_FORWARD, out, locale, config);
}
}
@Override
- public void outputSpecificationHeader(IHTTPOutput out,
- Locale locale, OutputSpecification os, List<String> tabsArray)
- throws ManifoldCFException, IOException {
+ public void outputSpecificationHeader(IHTTPOutput out, Locale locale,
+ OutputSpecification os, List<String> tabsArray)
+ throws ManifoldCFException, IOException
+ {
super.outputSpecificationHeader(out, locale, os, tabsArray);
tabsArray.add(ELASTICSEARCH_TAB_ELASTICSEARCH);
outputResource(EDIT_SPEC_HEADER_FORWARD, out, locale, null);
}
- final private SpecificationNode getSpecNode(OutputSpecification os) {
+ final private SpecificationNode getSpecNode(OutputSpecification os)
+ {
int l = os.getChildCount();
- for (int i = 0; i < l; i++) {
+ for (int i = 0; i < l; i++)
+ {
SpecificationNode node = os.getChild(i);
- if (ElasticSearchSpecs.ELASTICSEARCH_SPECS_NODE.equals(node
- .getType())) {
+ if (ElasticSearchSpecs.ELASTICSEARCH_SPECS_NODE.equals(node.getType()))
+ {
return node;
}
}
@@ -151,23 +167,29 @@ public class ElasticSearchConnector exte
}
@Override
- public void outputSpecificationBody(IHTTPOutput out, Locale locale, OutputSpecification os,
- String tabName) throws ManifoldCFException, IOException {
+ public void outputSpecificationBody(IHTTPOutput out, Locale locale,
+ OutputSpecification os, String tabName) throws ManifoldCFException,
+ IOException
+ {
super.outputSpecificationBody(out, locale, os, tabName);
ElasticSearchSpecs specs = getSpecParameters(os);
- if (ELASTICSEARCH_TAB_ELASTICSEARCH.equals(tabName)) {
+ if (ELASTICSEARCH_TAB_ELASTICSEARCH.equals(tabName))
+ {
outputResource(EDIT_SPEC_FORWARD, out, locale, specs);
- } else {
+ } else
+ {
outputResource(HIDDEN_SPEC_FORWARD, out, locale, specs);
}
}
@Override
public String processSpecificationPost(IPostParameters variableContext,
- Locale locale, OutputSpecification os) throws ManifoldCFException {
+ Locale locale, OutputSpecification os) throws ManifoldCFException
+ {
ConfigurationNode specNode = getSpecNode(os);
boolean bAdd = (specNode == null);
- if (bAdd) {
+ if (bAdd)
+ {
specNode = new SpecificationNode(
ElasticSearchSpecs.ELASTICSEARCH_SPECS_NODE);
}
@@ -177,52 +199,58 @@ public class ElasticSearchConnector exte
return null;
}
- /**
- * Build a Set of ElasticSearch parameters. If configParams is null,
+ /** Build a Set of ElasticSearch parameters. If configParams is null,
* getConfiguration() is used.
*
- * @param configParams
- */
+ * @param configParams */
final private ElasticSearchConfig getConfigParameters(
- ConfigParams configParams) {
+ ConfigParams configParams)
+ {
if (configParams == null)
configParams = getConfiguration();
- synchronized (this) {
+ synchronized (this)
+ {
return new ElasticSearchConfig(configParams);
}
}
final private ElasticSearchSpecs getSpecParameters(OutputSpecification os)
- throws ManifoldCFException {
+ throws ManifoldCFException
+ {
return new ElasticSearchSpecs(getSpecNode(os));
}
final private ElasticSearchSpecs getSpecsCache(String outputDescription)
- throws ManifoldCFException {
- try {
- synchronized (this) {
+ throws ManifoldCFException
+ {
+ try
+ {
+ synchronized (this)
+ {
if (!outputDescription.equals(specsCacheOutpuDescription))
specsCache = null;
if (specsCache == null)
- specsCache = new ElasticSearchSpecs(new JSONObject(
- outputDescription));
+ specsCache = new ElasticSearchSpecs(new JSONObject(outputDescription));
return specsCache;
}
- } catch (JSONException e) {
+ } catch (JSONException e)
+ {
throw new ManifoldCFException(e);
}
}
@Override
public String getOutputDescription(OutputSpecification os)
- throws ManifoldCFException {
+ throws ManifoldCFException
+ {
ElasticSearchSpecs specs = new ElasticSearchSpecs(getSpecNode(os));
return specs.toJson().toString();
}
@Override
public boolean checkLengthIndexable(String outputDescription, long length)
- throws ManifoldCFException, ServiceInterruption {
+ throws ManifoldCFException, ServiceInterruption
+ {
ElasticSearchSpecs specs = getSpecsCache(outputDescription);
long maxFileSize = specs.getMaxFileSize();
if (length > maxFileSize)
@@ -232,7 +260,8 @@ public class ElasticSearchConnector exte
@Override
public boolean checkDocumentIndexable(String outputDescription, File localFile)
- throws ManifoldCFException, ServiceInterruption {
+ throws ManifoldCFException, ServiceInterruption
+ {
ElasticSearchSpecs specs = getSpecsCache(outputDescription);
return specs
.checkExtension(FilenameUtils.getExtension(localFile.getName()));
@@ -240,40 +269,49 @@ public class ElasticSearchConnector exte
@Override
public boolean checkMimeTypeIndexable(String outputDescription,
- String mimeType) throws ManifoldCFException, ServiceInterruption {
+ String mimeType) throws ManifoldCFException, ServiceInterruption
+ {
ElasticSearchSpecs specs = getSpecsCache(outputDescription);
return specs.checkMimeType(mimeType);
}
@Override
public void viewConfiguration(IThreadContext threadContext, IHTTPOutput out,
- Locale locale, ConfigParams parameters) throws ManifoldCFException, IOException {
- outputResource(VIEW_CONFIG_FORWARD, out, locale, getConfigParameters(parameters));
+ Locale locale, ConfigParams parameters) throws ManifoldCFException,
+ IOException
+ {
+ outputResource(VIEW_CONFIG_FORWARD, out, locale,
+ getConfigParameters(parameters));
}
@Override
- public void viewSpecification(IHTTPOutput out, Locale locale, OutputSpecification os)
- throws ManifoldCFException, IOException {
+ public void viewSpecification(IHTTPOutput out, Locale locale,
+ OutputSpecification os) throws ManifoldCFException, IOException
+ {
outputResource(VIEW_SPEC_FORWARD, out, locale, getSpecParameters(os));
}
@Override
public String processConfigurationPost(IThreadContext threadContext,
IPostParameters variableContext, ConfigParams parameters)
- throws ManifoldCFException {
+ throws ManifoldCFException
+ {
ElasticSearchConfig.contextToConfig(variableContext, parameters);
return null;
}
private static Map<String, Integer> ossInstances = null;
- private synchronized final Integer addInstance(ElasticSearchConfig config) {
+ private synchronized final Integer addInstance(ElasticSearchConfig config)
+ {
if (ossInstances == null)
ossInstances = new TreeMap<String, Integer>();
- synchronized (ossInstances) {
+ synchronized (ossInstances)
+ {
String uii = config.getUniqueIndexIdentifier();
Integer count = ossInstances.get(uii);
- if (count == null) {
+ if (count == null)
+ {
count = new Integer(1);
ossInstances.put(uii, count);
} else
@@ -282,10 +320,12 @@ public class ElasticSearchConnector exte
}
}
- private synchronized final void removeInstance(ElasticSearchConfig config) {
+ private synchronized final void removeInstance(ElasticSearchConfig config)
+ {
if (ossInstances == null)
return;
- synchronized (ossInstances) {
+ synchronized (ossInstances)
+ {
String uii = config.getUniqueIndexIdentifier();
Integer count = ossInstances.get(uii);
if (count == null)
@@ -299,21 +339,25 @@ public class ElasticSearchConnector exte
public int addOrReplaceDocument(String documentURI, String outputDescription,
RepositoryDocument document, String authorityNameString,
IOutputAddActivity activities) throws ManifoldCFException,
- ServiceInterruption {
+ ServiceInterruption
+ {
ElasticSearchConfig config = getConfigParameters(null);
Integer count = addInstance(config);
- synchronized (count) {
+ synchronized (count)
+ {
InputStream inputStream = document.getBinaryStream();
- try {
+ try
+ {
long startTime = System.currentTimeMillis();
ElasticSearchIndex oi = new ElasticSearchIndex(documentURI,
inputStream, config);
- activities.recordActivity(startTime,
- ELASTICSEARCH_INDEXATION_ACTIVITY, document.getBinaryLength(),
- documentURI, oi.getResult().name(), oi.getResultDescription());
+ activities.recordActivity(startTime, ELASTICSEARCH_INDEXATION_ACTIVITY,
+ document.getBinaryLength(), documentURI, oi.getResult().name(),
+ oi.getResultDescription());
if (oi.getResult() != Result.OK)
return DOCUMENTSTATUS_REJECTED;
- } finally {
+ } finally
+ {
removeInstance(config);
}
return DOCUMENTSTATUS_ACCEPTED;
@@ -323,29 +367,31 @@ public class ElasticSearchConnector exte
@Override
public void removeDocument(String documentURI, String outputDescription,
IOutputRemoveActivity activities) throws ManifoldCFException,
- ServiceInterruption {
+ ServiceInterruption
+ {
long startTime = System.currentTimeMillis();
ElasticSearchDelete od = new ElasticSearchDelete(documentURI,
getConfigParameters(null));
- activities.recordActivity(startTime, ELASTICSEARCH_DELETION_ACTIVITY,
- null, documentURI, od.getResult().name(), od.getResultDescription());
+ activities.recordActivity(startTime, ELASTICSEARCH_DELETION_ACTIVITY, null,
+ documentURI, od.getResult().name(), od.getResultDescription());
}
@Override
- public String check() throws ManifoldCFException {
- ElasticSearchSchema oss = new ElasticSearchSchema(
- getConfigParameters(null));
+ public String check() throws ManifoldCFException
+ {
+ ElasticSearchSchema oss = new ElasticSearchSchema(getConfigParameters(null));
return oss.getResult().name() + " " + oss.getResultDescription();
}
@Override
public void noteJobComplete(IOutputNotifyActivity activities)
- throws ManifoldCFException, ServiceInterruption {
+ throws ManifoldCFException, ServiceInterruption
+ {
long startTime = System.currentTimeMillis();
- ElasticSearchAction oo = new ElasticSearchAction(
- CommandEnum._optimize, getConfigParameters(null));
- activities.recordActivity(startTime, ELASTICSEARCH_OPTIMIZE_ACTIVITY,
- null, oo.getCallUrlSnippet(), oo.getResult().name(),
+ ElasticSearchAction oo = new ElasticSearchAction(CommandEnum._optimize,
+ getConfigParameters(null));
+ activities.recordActivity(startTime, ELASTICSEARCH_OPTIMIZE_ACTIVITY, null,
+ oo.getCallUrlSnippet(), oo.getResult().name(),
oo.getResultDescription());
}
Modified: incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchDelete.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchDelete.java?rev=1243282&r1=1243281&r2=1243282&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchDelete.java (original)
+++ incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchDelete.java Sun Feb 12 17:39:35 2012
@@ -21,18 +21,20 @@ import org.apache.commons.httpclient.met
import org.apache.commons.io.FilenameUtils;
import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
-public class ElasticSearchDelete extends ElasticSearchConnection {
+public class ElasticSearchDelete extends ElasticSearchConnection
+{
- public ElasticSearchDelete(String documentURI, ElasticSearchConfig config)
- throws ManifoldCFException {
- super(config);
- String fileName = FilenameUtils.getName(documentURI);
- DeleteMethod method = new DeleteMethod(config.getServerLocation());
- method.setPath("/" + config.getIndexName() + "/"
- + config.getIndexType() + "/" + fileName);
- call(method);
- if ("true".equals(checkJson(jsonStatus)))
- return;
- setResult(Result.ERROR, checkJson(jsonException));
- }
+ public ElasticSearchDelete(String documentURI, ElasticSearchConfig config)
+ throws ManifoldCFException
+ {
+ super(config);
+ String fileName = FilenameUtils.getName(documentURI);
+ DeleteMethod method = new DeleteMethod(config.getServerLocation());
+ method.setPath("/" + config.getIndexName() + "/" + config.getIndexType()
+ + "/" + fileName);
+ call(method);
+ if ("true".equals(checkJson(jsonStatus)))
+ return;
+ setResult(Result.ERROR, checkJson(jsonException));
+ }
}
Modified: incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchIndex.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchIndex.java?rev=1243282&r1=1243281&r2=1243282&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchIndex.java (original)
+++ incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchIndex.java Sun Feb 12 17:39:35 2012
@@ -29,69 +29,80 @@ import org.apache.commons.io.IOUtils;
import org.apache.manifoldcf.core.common.Base64;
import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
-public class ElasticSearchIndex extends ElasticSearchConnection {
+public class ElasticSearchIndex extends ElasticSearchConnection
+{
- private class IndexRequestEntity implements RequestEntity {
+ private class IndexRequestEntity implements RequestEntity
+ {
- private String documentURI;
+ 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 "application/x-www-form-urlencoded";
- }
-
- public boolean isRepeatable() {
- return false;
- }
-
- public void writeRequest(OutputStream out) throws IOException {
- PrintWriter pw = new PrintWriter(out);
- try {
- pw.print("{");
- pw.print("\"fieldName\" : ");
- pw.print("\"" + documentURI + "\"" + ",");
- pw.print("\"fileName\" : ");
- pw.print("\"" + fileName + "\"" + ",");
- pw.print("\"binaryValue\" : \"");
- Base64 base64 = new Base64();
- base64.encodeStream(inputStream, pw);
- pw.print("\"");
- pw.print("}");
- } catch (ManifoldCFException e) {
- throw new IOException(e.getMessage());
- } finally {
- IOUtils.closeQuietly(pw);
- }
- }
- }
-
- public ElasticSearchIndex(String documentURI, InputStream inputStream,
- ElasticSearchConfig config) throws ManifoldCFException {
- super(config);
- String fileName = FilenameUtils.getName(documentURI);
- StringBuffer url = getApiUrl(config.getIndexType() + "/" + fileName);
- PutMethod put = new PutMethod(url.toString());
- RequestEntity entity = new IndexRequestEntity(documentURI, inputStream);
- put.setRequestEntity(entity);
- call(put);
- if ("true".equals(checkJson(jsonStatus)))
- return;
- String error = checkJson(jsonException);
- setResult(Result.ERROR, error);
- System.err.println(getResponse());
- }
+ 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 "application/x-www-form-urlencoded";
+ }
+
+ public boolean isRepeatable()
+ {
+ return false;
+ }
+
+ public void writeRequest(OutputStream out) throws IOException
+ {
+ PrintWriter pw = new PrintWriter(out);
+ try
+ {
+ pw.print("{");
+ pw.print("\"fieldName\" : ");
+ pw.print("\"" + documentURI + "\"" + ",");
+ pw.print("\"fileName\" : ");
+ pw.print("\"" + fileName + "\"" + ",");
+ pw.print("\"binaryValue\" : \"");
+ Base64 base64 = new Base64();
+ base64.encodeStream(inputStream, pw);
+ pw.print("\"");
+ pw.print("}");
+ } catch (ManifoldCFException e)
+ {
+ throw new IOException(e.getMessage());
+ } finally
+ {
+ IOUtils.closeQuietly(pw);
+ }
+ }
+ }
+
+ public ElasticSearchIndex(String documentURI, InputStream inputStream,
+ ElasticSearchConfig config) throws ManifoldCFException
+ {
+ super(config);
+ String fileName = FilenameUtils.getName(documentURI);
+ StringBuffer url = getApiUrl(config.getIndexType() + "/" + fileName);
+ PutMethod put = new PutMethod(url.toString());
+ RequestEntity entity = new IndexRequestEntity(documentURI, inputStream);
+ put.setRequestEntity(entity);
+ call(put);
+ if ("true".equals(checkJson(jsonStatus)))
+ return;
+ String error = checkJson(jsonException);
+ setResult(Result.ERROR, error);
+ System.err.println(getResponse());
+ }
}
Modified: incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchParam.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchParam.java?rev=1243282&r1=1243281&r2=1243282&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchParam.java (original)
+++ incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchParam.java Sun Feb 12 17:39:35 2012
@@ -1,19 +1,19 @@
/**
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.manifoldcf.agents.output.elasticsearch;
@@ -22,64 +22,67 @@ import java.util.Map;
import org.apache.manifoldcf.agents.output.elasticsearch.ElasticSearchParam.ParameterEnum;
-public class ElasticSearchParam extends HashMap<ParameterEnum, String> {
+public class ElasticSearchParam extends HashMap<ParameterEnum, String>
+{
+
+ /** Parameters constants */
+ public enum ParameterEnum
+ {
+ SERVERLOCATION("http://localhost:9200/"),
+
+ INDEXNAME("index"),
+
+ INDEXTYPE("generictype"),
+
+ USERNAME(""),
+
+ APIKEY(""),
+
+ 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;
+
+ private ParameterEnum(String defaultValue)
+ {
+ this.defaultValue = defaultValue;
+ }
+ }
+
+ private static final long serialVersionUID = -1593234685772720029L;
+
+ protected ElasticSearchParam(ParameterEnum[] params)
+ {
+ super(params.length);
+ }
+
+ final public Map<String, String> buildMap()
+ {
+ Map<String, String> rval = new HashMap<String, String>();
+ for (Map.Entry<ParameterEnum, String> entry : this.entrySet())
+ rval.put(entry.getKey().name(), entry.getValue());
+ return rval;
+ }
- /**
- * Parameters constants
- */
- public enum ParameterEnum {
- SERVERLOCATION("http://localhost:9200/"),
-
- INDEXNAME("index"),
-
- INDEXTYPE("generictype"),
-
- USERNAME(""),
-
- APIKEY(""),
-
- 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;
-
- private ParameterEnum(String defaultValue) {
- this.defaultValue = defaultValue;
- }
- }
-
- private static final long serialVersionUID = -1593234685772720029L;
-
- protected ElasticSearchParam(ParameterEnum[] params) {
- super(params.length);
- }
-
- final public Map<String,String> buildMap() {
- Map<String,String> rval = new HashMap<String,String>();
- for (Map.Entry<ParameterEnum, String> entry : this.entrySet())
- rval.put(entry.getKey().name(), entry.getValue());
- return rval;
- }
-
}
Modified: incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchSpecs.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchSpecs.java?rev=1243282&r1=1243281&r2=1243282&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchSpecs.java (original)
+++ incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchSpecs.java Sun Feb 12 17:39:35 2012
@@ -1,19 +1,19 @@
/**
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.manifoldcf.agents.output.elasticsearch;
@@ -30,15 +30,16 @@ import org.apache.manifoldcf.core.interf
import org.json.JSONException;
import org.json.JSONObject;
-public class ElasticSearchSpecs extends ElasticSearchParam {
+public class ElasticSearchSpecs extends ElasticSearchParam
+{
/**
*
*/
private static final long serialVersionUID = 1859653440572662025L;
- final public static ParameterEnum[] SPECIFICATIONLIST = {
- ParameterEnum.MAXFILESIZE, ParameterEnum.MIMETYPES,
+ final public static ParameterEnum[] SPECIFICATIONLIST =
+ { ParameterEnum.MAXFILESIZE, ParameterEnum.MIMETYPES,
ParameterEnum.EXTENSIONS };
final public static String ELASTICSEARCH_SPECS_NODE = "ELASTICSEARCH_SPECS_NODE";
@@ -47,19 +48,19 @@ public class ElasticSearchSpecs extends
private Set<String> mimeTypeSet;
- /**
- * Build a set of ElasticSearch parameters by reading an JSON object
+ /** Build a set of ElasticSearch parameters by reading an JSON object
*
* @param json
* @throws JSONException
- * @throws ManifoldCFException
- */
+ * @throws ManifoldCFException */
public ElasticSearchSpecs(JSONObject json) throws JSONException,
- ManifoldCFException {
+ ManifoldCFException
+ {
super(SPECIFICATIONLIST);
extensionSet = null;
mimeTypeSet = null;
- for (ParameterEnum param : SPECIFICATIONLIST) {
+ for (ParameterEnum param : SPECIFICATIONLIST)
+ {
String value = null;
value = json.getString(param.name());
if (value == null)
@@ -70,17 +71,16 @@ public class ElasticSearchSpecs extends
mimeTypeSet = createStringSet(getMimeTypes());
}
- /**
- * Build a set of ElasticSearch parameters by reading an instance of
+ /** Build a set of ElasticSearch parameters by reading an instance of
* SpecificationNode.
*
* @param node
- * @throws ManifoldCFException
- */
- public ElasticSearchSpecs(ConfigurationNode node)
- throws ManifoldCFException {
+ * @throws ManifoldCFException */
+ public ElasticSearchSpecs(ConfigurationNode node) throws ManifoldCFException
+ {
super(SPECIFICATIONLIST);
- for (ParameterEnum param : SPECIFICATIONLIST) {
+ for (ParameterEnum param : SPECIFICATIONLIST)
+ {
String value = null;
if (node != null)
value = node.getAttributeValue(param.name());
@@ -93,62 +93,72 @@ public class ElasticSearchSpecs extends
}
public static void contextToSpecNode(IPostParameters variableContext,
- ConfigurationNode specNode) {
- for (ParameterEnum param : SPECIFICATIONLIST) {
+ ConfigurationNode specNode)
+ {
+ for (ParameterEnum param : SPECIFICATIONLIST)
+ {
String p = variableContext.getParameter(param.name().toLowerCase());
if (p != null)
specNode.setAttribute(param.name(), p);
}
}
- /**
- *
- * @return a JSON representation of the parameter list
- */
- public JSONObject toJson() {
+ /** @return a JSON representation of the parameter list */
+ public JSONObject toJson()
+ {
return new JSONObject(this);
}
- public long getMaxFileSize() {
+ public long getMaxFileSize()
+ {
return Long.parseLong(get(ParameterEnum.MAXFILESIZE));
}
- public String getMimeTypes() {
+ public String getMimeTypes()
+ {
return get(ParameterEnum.MIMETYPES);
}
- public String getExtensions() {
+ public String getExtensions()
+ {
return get(ParameterEnum.EXTENSIONS);
}
private final static TreeSet<String> createStringSet(String content)
- throws ManifoldCFException {
+ throws ManifoldCFException
+ {
TreeSet<String> set = new TreeSet<String>();
BufferedReader br = null;
StringReader sr = null;
- try {
+ try
+ {
sr = new StringReader(content);
br = new BufferedReader(sr);
String line = null;
- while ((line = br.readLine()) != null) {
+ while ((line = br.readLine()) != null)
+ {
line = line.trim();
if (line.length() > 0)
set.add(line);
}
return set;
- } catch (IOException e) {
+ } catch (IOException e)
+ {
throw new ManifoldCFException(e);
- } finally {
+ } finally
+ {
if (br != null)
IOUtils.closeQuietly(br);
}
}
- public boolean checkExtension(String extension) {
+ public boolean checkExtension(String extension)
+ {
return extensionSet.contains(extension);
}
- public boolean checkMimeType(String mimeType) {
+ public boolean checkMimeType(String mimeType)
+ {
return mimeTypeSet.contains(mimeType);
}
}
Modified: incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/Messages.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/Messages.java?rev=1243282&r1=1243281&r2=1243282&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/Messages.java (original)
+++ incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/Messages.java Sun Feb 12 17:39:35 2012
@@ -1,19 +1,19 @@
/**
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.manifoldcf.agents.output.elasticsearch;
import java.util.Locale;
@@ -23,15 +23,14 @@ import org.apache.manifoldcf.core.interf
public class Messages extends org.apache.manifoldcf.ui.i18n.Messages
{
- public static final String DEFAULT_BUNDLE_NAME="org.apache.manifoldcf.agents.output.elasticsearch.common";
- public static final String DEFAULT_PATH_NAME="org.apache.manifoldcf.crawler.connectors.elasticsearch";
-
- /** Constructor - do no instantiate
- */
+ public static final String DEFAULT_BUNDLE_NAME = "org.apache.manifoldcf.agents.output.elasticsearch.common";
+ public static final String DEFAULT_PATH_NAME = "org.apache.manifoldcf.crawler.connectors.elasticsearch";
+
+ /** Constructor - do no instantiate */
protected Messages()
{
}
-
+
public static String getString(Locale locale, String messageKey)
{
return getString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
@@ -47,14 +46,17 @@ public class Messages extends org.apache
return getBodyString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
}
- public static String getAttributeJavascriptString(Locale locale, String messageKey)
+ public static String getAttributeJavascriptString(Locale locale,
+ String messageKey)
{
- return getAttributeJavascriptString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
+ return getAttributeJavascriptString(DEFAULT_BUNDLE_NAME, locale,
+ messageKey, null);
}
public static String getBodyJavascriptString(Locale locale, String messageKey)
{
- return getBodyJavascriptString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
+ return getBodyJavascriptString(DEFAULT_BUNDLE_NAME, locale, messageKey,
+ null);
}
public static String getString(Locale locale, String messageKey, Object[] args)
@@ -62,62 +64,78 @@ public class Messages extends org.apache
return getString(DEFAULT_BUNDLE_NAME, locale, messageKey, args);
}
- public static String getAttributeString(Locale locale, String messageKey, Object[] args)
+ public static String getAttributeString(Locale locale, String messageKey,
+ Object[] args)
{
return getAttributeString(DEFAULT_BUNDLE_NAME, locale, messageKey, args);
}
-
- public static String getBodyString(Locale locale, String messageKey, Object[] args)
+
+ public static String getBodyString(Locale locale, String messageKey,
+ Object[] args)
{
return getBodyString(DEFAULT_BUNDLE_NAME, locale, messageKey, args);
}
- public static String getAttributeJavascriptString(Locale locale, String messageKey, Object[] args)
+ public static String getAttributeJavascriptString(Locale locale,
+ String messageKey, Object[] args)
{
- return getAttributeJavascriptString(DEFAULT_BUNDLE_NAME, locale, messageKey, args);
+ return getAttributeJavascriptString(DEFAULT_BUNDLE_NAME, locale,
+ messageKey, args);
}
- public static String getBodyJavascriptString(Locale locale, String messageKey, Object[] args)
+ public static String getBodyJavascriptString(Locale locale,
+ String messageKey, Object[] args)
{
- return getBodyJavascriptString(DEFAULT_BUNDLE_NAME, locale, messageKey, args);
+ return getBodyJavascriptString(DEFAULT_BUNDLE_NAME, locale, messageKey,
+ args);
}
- // More general methods which allow bundlenames and class loaders to be specified.
-
- public static String getString(String bundleName, Locale locale, String messageKey, Object[] args)
+ // More general methods which allow bundlenames and class loaders to be
+ // specified.
+
+ public static String getString(String bundleName, Locale locale,
+ String messageKey, Object[] args)
{
- return getString(Messages.class.getClassLoader(), bundleName, locale, messageKey, args);
+ return getString(Messages.class.getClassLoader(), bundleName, locale,
+ messageKey, args);
}
- public static String getAttributeString(String bundleName, Locale locale, String messageKey, Object[] args)
+ public static String getAttributeString(String bundleName, Locale locale,
+ String messageKey, Object[] args)
{
- return getAttributeString(Messages.class.getClassLoader(), bundleName, locale, messageKey, args);
+ return getAttributeString(Messages.class.getClassLoader(), bundleName,
+ locale, messageKey, args);
}
- public static String getBodyString(String bundleName, Locale locale, String messageKey, Object[] args)
+ public static String getBodyString(String bundleName, Locale locale,
+ String messageKey, Object[] args)
{
- return getBodyString(Messages.class.getClassLoader(), bundleName, locale, messageKey, args);
+ return getBodyString(Messages.class.getClassLoader(), bundleName, locale,
+ messageKey, args);
}
-
- public static String getAttributeJavascriptString(String bundleName, Locale locale, String messageKey, Object[] args)
+
+ public static String getAttributeJavascriptString(String bundleName,
+ Locale locale, String messageKey, Object[] args)
{
- return getAttributeJavascriptString(Messages.class.getClassLoader(), bundleName, locale, messageKey, args);
+ return getAttributeJavascriptString(Messages.class.getClassLoader(),
+ bundleName, locale, messageKey, args);
}
- public static String getBodyJavascriptString(String bundleName, Locale locale, String messageKey, Object[] args)
+ public static String getBodyJavascriptString(String bundleName,
+ Locale locale, String messageKey, Object[] args)
{
- return getBodyJavascriptString(Messages.class.getClassLoader(), bundleName, locale, messageKey, args);
+ return getBodyJavascriptString(Messages.class.getClassLoader(), bundleName,
+ locale, messageKey, args);
}
// Resource output
-
- public static void outputResource(IHTTPOutput output, Locale locale, String resourceKey,
- Map<String,String> substitutionParameters, boolean mapToUpperCase)
- throws ManifoldCFException
+
+ public static void outputResource(IHTTPOutput output, Locale locale,
+ String resourceKey, Map<String, String> substitutionParameters,
+ boolean mapToUpperCase) throws ManifoldCFException
{
- outputResource(output,Messages.class,DEFAULT_PATH_NAME,locale,resourceKey,
- substitutionParameters,mapToUpperCase);
+ outputResource(output, Messages.class, DEFAULT_PATH_NAME, locale,
+ resourceKey, substitutionParameters, mapToUpperCase);
}
-
-}
+}
Modified: incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/pom.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/pom.xml?rev=1243282&r1=1243281&r2=1243282&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/pom.xml (original)
+++ incubator/lcf/branches/CONNECTORS-288/connectors/elasticsearch/pom.xml Sun Feb 12 17:39:35 2012
@@ -28,8 +28,8 @@
<developers>
<developer>
<name>Luca Stancapiano</name>
- <organization></organization>
- <organizationUrl></organizationUrl>
+ <organization>vige</organization>
+ <organizationUrl>http://www.vige.it</organizationUrl>
<url></url>
</developer>
</developers>