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 2014/10/03 17:13:30 UTC
svn commit: r1629223 - in
/manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript:
AlfrescoAuthorityConnector.java ConfigurationHandler.java Messages.java
Author: kwright
Date: Fri Oct 3 15:13:29 2014
New Revision: 1629223
URL: http://svn.apache.org/r1629223
Log:
Commit first part of reformatting patch from Maurizio.
Modified:
manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/AlfrescoAuthorityConnector.java
manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/ConfigurationHandler.java
manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/Messages.java
Modified: manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/AlfrescoAuthorityConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/AlfrescoAuthorityConnector.java?rev=1629223&r1=1629222&r2=1629223&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/AlfrescoAuthorityConnector.java (original)
+++ manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/AlfrescoAuthorityConnector.java Fri Oct 3 15:13:29 2014
@@ -16,30 +16,26 @@
*/
package org.apache.manifoldcf.authorities.authorities.alfrescowebscript;
-import java.io.IOException;
-import java.util.List;
-import java.util.Locale;
-
import org.alfresco.consulting.indexer.client.AlfrescoClient;
import org.alfresco.consulting.indexer.client.AlfrescoDownException;
import org.alfresco.consulting.indexer.client.AlfrescoUser;
import org.alfresco.consulting.indexer.client.WebScriptsAlfrescoClient;
import org.apache.manifoldcf.authorities.authorities.BaseAuthorityConnector;
import org.apache.manifoldcf.authorities.interfaces.AuthorizationResponse;
-import org.apache.manifoldcf.core.interfaces.ConfigParams;
-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.authorities.system.Logging;
+import org.apache.manifoldcf.core.interfaces.*;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Locale;
public class AlfrescoAuthorityConnector extends BaseAuthorityConnector {
-
+
private AlfrescoClient alfrescoClient;
-
+
private static final AuthorizationResponse denied = new AuthorizationResponse(
- new String[] { "DEAD_AUTHORITY" }, AuthorizationResponse.RESPONSE_UNREACHABLE);
-
+ new String[]{"DEAD_AUTHORITY"}, AuthorizationResponse.RESPONSE_UNREACHABLE);
+
public void setClient(AlfrescoClient client) {
alfrescoClient = client;
}
@@ -55,7 +51,7 @@ public class AlfrescoAuthorityConnector
String password = getConfig(config, "password", null);
alfrescoClient = new WebScriptsAlfrescoClient(protocol, hostname, endpoint,
- null, null, username, password);
+ null, null, username, password);
}
private static String getConfig(ConfigParams config,
@@ -74,12 +70,14 @@ public class AlfrescoAuthorityConnector
*/
@Override
public String check() throws ManifoldCFException {
- try{
+ try {
alfrescoClient.fetchUserAuthorities("admin");
return super.check();
- }catch(AlfrescoDownException e){
- Logging.authorityConnectors.warn(e.getMessage(),e);
- return "Connection failed: "+e.getMessage();
+ } catch (AlfrescoDownException e) {
+ if (Logging.authorityConnectors != null) {
+ Logging.authorityConnectors.warn(e.getMessage(), e);
+ }
+ return "Connection failed: " + e.getMessage();
}
}
@@ -91,36 +89,34 @@ public class AlfrescoAuthorityConnector
public void disconnect() throws ManifoldCFException {
super.disconnect();
}
-
+
/*
* (non-Javadoc)
* @see org.apache.manifoldcf.authorities.authorities.BaseAuthorityConnector#getDefaultAuthorizationResponse(java.lang.String)
*/
@Override
- public AuthorizationResponse getDefaultAuthorizationResponse(String userName)
- {
+ public AuthorizationResponse getDefaultAuthorizationResponse(String userName) {
return denied;
}
-
+
/*
* (non-Javadoc)
* @see org.apache.manifoldcf.authorities.authorities.BaseAuthorityConnector#getAuthorizationResponse(java.lang.String)
*/
@Override
public AuthorizationResponse getAuthorizationResponse(String userName)
- throws ManifoldCFException {
- try{
+ throws ManifoldCFException {
+ try {
AlfrescoUser permissions = alfrescoClient.fetchUserAuthorities(userName);
- if(permissions.getUsername() == null
- || permissions.getUsername().isEmpty()
- || permissions.getAuthorities().isEmpty())
+ if (permissions.getUsername() == null
+ || permissions.getUsername().isEmpty()
+ || permissions.getAuthorities().isEmpty())
return new AuthorizationResponse(null, AuthorizationResponse.RESPONSE_USERNOTFOUND);
else
return new AuthorizationResponse(
- permissions.getAuthorities().toArray(new String[permissions.getAuthorities().size()]),
- AuthorizationResponse.RESPONSE_OK);
- }catch(AlfrescoDownException e){
- Logging.authorityConnectors.warn(e.getMessage(),e);
+ permissions.getAuthorities().toArray(new String[permissions.getAuthorities().size()]),
+ AuthorizationResponse.RESPONSE_OK);
+ } catch (AlfrescoDownException e) {
return new AuthorizationResponse(null, AuthorizationResponse.RESPONSE_UNREACHABLE);
}
}
@@ -130,30 +126,30 @@ public class AlfrescoAuthorityConnector
IHTTPOutput out, Locale locale, ConfigParams parameters,
List<String> tabsArray) throws ManifoldCFException, IOException {
ConfigurationHandler.outputConfigurationHeader(threadContext, out, locale,
- parameters, tabsArray);
+ parameters, tabsArray);
}
@Override
public void outputConfigurationBody(IThreadContext threadContext,
IHTTPOutput out, Locale locale, ConfigParams parameters, String tabName)
- throws ManifoldCFException, IOException {
+ throws ManifoldCFException, IOException {
ConfigurationHandler.outputConfigurationBody(threadContext, out, locale,
- parameters, tabName);
+ parameters, tabName);
}
@Override
public String processConfigurationPost(IThreadContext threadContext,
IPostParameters variableContext, Locale locale, ConfigParams parameters)
- throws ManifoldCFException {
+ throws ManifoldCFException {
return ConfigurationHandler.processConfigurationPost(threadContext,
- variableContext, locale, parameters);
+ variableContext, locale, parameters);
}
@Override
public void viewConfiguration(IThreadContext threadContext, IHTTPOutput out,
Locale locale, ConfigParams parameters) throws ManifoldCFException,
- IOException {
+ IOException {
ConfigurationHandler.viewConfiguration(threadContext, out, locale,
- parameters);
- }
+ parameters);
+ }
}
Modified: manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/ConfigurationHandler.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/ConfigurationHandler.java?rev=1629223&r1=1629222&r2=1629223&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/ConfigurationHandler.java (original)
+++ manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/ConfigurationHandler.java Fri Oct 3 15:13:29 2014
@@ -16,6 +16,11 @@
*/
package org.apache.manifoldcf.authorities.authorities.alfrescowebscript;
+import org.apache.commons.io.IOUtils;
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
@@ -24,27 +29,19 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
-import org.apache.commons.io.IOUtils;
-import org.apache.manifoldcf.core.interfaces.ConfigParams;
-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.velocity.VelocityContext;
-import org.apache.velocity.app.VelocityEngine;
-
public class ConfigurationHandler {
private static final String PARAM_PROTOCOL = "protocol";
private static final String PARAM_HOSTNAME = "hostname";
private static final String PARAM_ENDPOINT = "endpoint";
private static final String PARAM_USERNAME = "username";
private static final String PARAM_PASSWORD = "password";
-
+
private static final String EDIT_CONFIG_HEADER = "editConfiguration.js";
private static final String EDIT_CONFIG_SERVER = "editConfiguration_Server.html";
private static final String VIEW_CONFIG = "viewConfiguration.html";
private static final Map<String, String> DEFAULT_CONFIGURATION_PARAMETERS = new HashMap<String, String>();
+
static {
DEFAULT_CONFIGURATION_PARAMETERS.put(PARAM_PROTOCOL, "http");
DEFAULT_CONFIGURATION_PARAMETERS.put(PARAM_HOSTNAME, "localhost");
@@ -57,8 +54,9 @@ public class ConfigurationHandler {
}
public static void outputConfigurationHeader(IThreadContext threadContext,
- IHTTPOutput out, Locale locale, ConfigParams parameters,
- List<String> tabsArray) throws ManifoldCFException, IOException {
+ IHTTPOutput out, Locale locale,
+ ConfigParams parameters,
+ List<String> tabsArray) throws ManifoldCFException, IOException {
tabsArray.add("Server");
Map<String, Object> paramMap = new HashMap<String, Object>();
fillInParameters(paramMap, parameters);
@@ -66,7 +64,7 @@ public class ConfigurationHandler {
}
private static void fillInParameters(Map<String, Object> paramMap,
- ConfigParams parameters) {
+ ConfigParams parameters) {
for (Map.Entry<String, String> parameter : DEFAULT_CONFIGURATION_PARAMETERS
.entrySet()) {
String paramValue = parameters.getParameter(parameter.getKey());
@@ -78,7 +76,8 @@ public class ConfigurationHandler {
}
public static void outputConfigurationBody(IThreadContext threadContext,
- IHTTPOutput out, Locale locale, ConfigParams parameters, String tabName)
+ IHTTPOutput out, Locale locale,
+ ConfigParams parameters, String tabName)
throws ManifoldCFException, IOException {
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("tabName", tabName);
@@ -86,16 +85,9 @@ public class ConfigurationHandler {
Messages.outputResourceWithVelocity(out, locale, EDIT_CONFIG_SERVER, paramMap);
}
- private static VelocityContext createVelocityContext(Map<String, String> paramMap) {
- VelocityContext context = new VelocityContext();
- for (Map.Entry<String, String> entry : paramMap.entrySet()) {
- context.put(entry.getKey(), entry.getValue());
- }
- return context;
- }
-
public static String processConfigurationPost(IThreadContext threadContext,
- IPostParameters variableContext, Locale locale, ConfigParams parameters)
+ IPostParameters variableContext,
+ Locale locale, ConfigParams parameters)
throws ManifoldCFException {
for (String paramName : DEFAULT_CONFIGURATION_PARAMETERS.keySet()) {
String paramValue = variableContext.getParameter(paramName);
@@ -107,7 +99,8 @@ public class ConfigurationHandler {
}
public static void viewConfiguration(IThreadContext threadContext,
- IHTTPOutput out, Locale locale, ConfigParams parameters)
+ IHTTPOutput out, Locale locale,
+ ConfigParams parameters)
throws ManifoldCFException, IOException {
Map<String, Object> paramMap = new HashMap<String, Object>();
fillInParameters(paramMap, parameters);
Modified: manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/Messages.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/Messages.java?rev=1629223&r1=1629222&r2=1629223&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/Messages.java (original)
+++ manifoldcf/branches/CONNECTORS-1037/connectors/alfresco-webscript/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/alfrescowebscript/Messages.java Fri Oct 3 15:13:29 2014
@@ -16,123 +16,105 @@
*/
package org.apache.manifoldcf.authorities.authorities.alfrescowebscript;
+import org.apache.manifoldcf.core.interfaces.IHTTPOutput;
+import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
+
import java.util.Locale;
import java.util.Map;
-import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
-import org.apache.manifoldcf.core.interfaces.IHTTPOutput;
-public class Messages extends org.apache.manifoldcf.ui.i18n.Messages
-{
- public static final String DEFAULT_BUNDLE_NAME="org.apache.manifoldcf.authorities.authorities.alfrescowebscript.common";
- public static final String DEFAULT_PATH_NAME="org.apache.manifoldcf.authorities.authorities.alfrescowebscript";
-
- /** Constructor - do no instantiate
- */
- protected Messages()
- {
- }
-
- public static String getString(Locale locale, String messageKey)
- {
- return getString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
- }
-
- public static String getAttributeString(Locale locale, String messageKey)
- {
- return getAttributeString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
- }
-
- public static String getBodyString(Locale locale, String messageKey)
- {
- return getBodyString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
- }
-
- public static String getAttributeJavascriptString(Locale locale, String messageKey)
- {
- return getAttributeJavascriptString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
- }
-
- public static String getBodyJavascriptString(Locale locale, String messageKey)
- {
- return getBodyJavascriptString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
- }
-
- public static String getString(Locale locale, String messageKey, Object[] args)
- {
- return getString(DEFAULT_BUNDLE_NAME, locale, messageKey, 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)
- {
- return getBodyString(DEFAULT_BUNDLE_NAME, locale, messageKey, args);
- }
-
- public static String getAttributeJavascriptString(Locale locale, String messageKey, Object[] args)
- {
- return getAttributeJavascriptString(DEFAULT_BUNDLE_NAME, locale, messageKey, args);
- }
-
- public static String getBodyJavascriptString(Locale locale, String messageKey, Object[] 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)
- {
- return getString(Messages.class, bundleName, locale, messageKey, args);
- }
-
- public static String getAttributeString(String bundleName, Locale locale, String messageKey, Object[] args)
- {
- return getAttributeString(Messages.class, bundleName, locale, messageKey, args);
- }
-
- public static String getBodyString(String bundleName, Locale locale, String messageKey, Object[] args)
- {
- return getBodyString(Messages.class, bundleName, locale, messageKey, args);
- }
-
- public static String getAttributeJavascriptString(String bundleName, Locale locale, String messageKey, Object[] args)
- {
- return getAttributeJavascriptString(Messages.class, bundleName, locale, messageKey, args);
- }
-
- public static String getBodyJavascriptString(String bundleName, Locale locale, String messageKey, Object[] args)
- {
- return getBodyJavascriptString(Messages.class, bundleName, locale, messageKey, args);
- }
-
- // Resource output
-
- 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);
- }
-
- public static void outputResourceWithVelocity(IHTTPOutput output, Locale locale, String resourceKey,
- Map<String,String> substitutionParameters, boolean mapToUpperCase)
- throws ManifoldCFException
- {
- outputResourceWithVelocity(output,Messages.class,DEFAULT_BUNDLE_NAME,DEFAULT_PATH_NAME,locale,resourceKey,
- substitutionParameters,mapToUpperCase);
- }
-
- public static void outputResourceWithVelocity(IHTTPOutput output, Locale locale, String resourceKey,
- Map<String,Object> contextObjects)
- throws ManifoldCFException
- {
- outputResourceWithVelocity(output,Messages.class,DEFAULT_BUNDLE_NAME,DEFAULT_PATH_NAME,locale,resourceKey,
- contextObjects);
- }
+public class Messages extends org.apache.manifoldcf.ui.i18n.Messages {
+ public static final String DEFAULT_BUNDLE_NAME = "org.apache.manifoldcf.authorities.authorities.alfrescowebscript.common";
+ public static final String DEFAULT_PATH_NAME = "org.apache.manifoldcf.authorities.authorities.alfrescowebscript";
+
+ /**
+ * Constructor - do no instantiate
+ */
+ protected Messages() {
+ }
+
+ public static String getString(Locale locale, String messageKey) {
+ return getString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
+ }
+
+ public static String getAttributeString(Locale locale, String messageKey) {
+ return getAttributeString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
+ }
+
+ public static String getBodyString(Locale locale, String messageKey) {
+ return getBodyString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
+ }
+
+ public static String getAttributeJavascriptString(Locale locale, String messageKey) {
+ return getAttributeJavascriptString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
+ }
+
+ public static String getBodyJavascriptString(Locale locale, String messageKey) {
+ return getBodyJavascriptString(DEFAULT_BUNDLE_NAME, locale, messageKey, null);
+ }
+
+ public static String getString(Locale locale, String messageKey, Object[] args) {
+ return getString(DEFAULT_BUNDLE_NAME, locale, messageKey, 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) {
+ return getBodyString(DEFAULT_BUNDLE_NAME, locale, messageKey, args);
+ }
+
+ public static String getAttributeJavascriptString(Locale locale, String messageKey, Object[] args) {
+ return getAttributeJavascriptString(DEFAULT_BUNDLE_NAME, locale, messageKey, args);
+ }
+
+ public static String getBodyJavascriptString(Locale locale, String messageKey, Object[] 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) {
+ return getString(Messages.class, bundleName, locale, messageKey, args);
+ }
+
+ public static String getAttributeString(String bundleName, Locale locale, String messageKey, Object[] args) {
+ return getAttributeString(Messages.class, bundleName, locale, messageKey, args);
+ }
+
+ public static String getBodyString(String bundleName, Locale locale, String messageKey, Object[] args) {
+ return getBodyString(Messages.class, bundleName, locale, messageKey, args);
+ }
+
+ public static String getAttributeJavascriptString(String bundleName, Locale locale, String messageKey, Object[] args) {
+ return getAttributeJavascriptString(Messages.class, bundleName, locale, messageKey, args);
+ }
+
+ public static String getBodyJavascriptString(String bundleName, Locale locale, String messageKey, Object[] args) {
+ return getBodyJavascriptString(Messages.class, bundleName, locale, messageKey, args);
+ }
+
+ // Resource output
+
+ 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);
+ }
+
+ public static void outputResourceWithVelocity(IHTTPOutput output, Locale locale, String resourceKey,
+ Map<String, String> substitutionParameters, boolean mapToUpperCase)
+ throws ManifoldCFException {
+ outputResourceWithVelocity(output, Messages.class, DEFAULT_BUNDLE_NAME, DEFAULT_PATH_NAME, locale, resourceKey,
+ substitutionParameters, mapToUpperCase);
+ }
+
+ public static void outputResourceWithVelocity(IHTTPOutput output, Locale locale, String resourceKey,
+ Map<String, Object> contextObjects)
+ throws ManifoldCFException {
+ outputResourceWithVelocity(output, Messages.class, DEFAULT_BUNDLE_NAME, DEFAULT_PATH_NAME, locale, resourceKey,
+ contextObjects);
+ }
}