Shinsuke Sugaya 10 年 前
コミット
40388c1af0

+ 2 - 2
pom.xml

@@ -3,7 +3,7 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>jp.sf.fess</groupId>
   <artifactId>fess</artifactId>
-  <version>9.3.4-SNAPSHOT</version>
+  <version>9.4.0-SNAPSHOT</version>
   <packaging>war</packaging>
   <name>Fess</name>
   <description>Fess is Full tExt Search System.</description>
@@ -109,7 +109,7 @@
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <dbflute.version>1.0.5L</dbflute.version>
-    <s2robot.version>0.8.0</s2robot.version>
+    <s2robot.version>0.8.1</s2robot.version>
     <solr.version>4.10.3</solr.version>
     <slf4j.version>1.7.7</slf4j.version>
     <tika.version>1.6</tika.version>

+ 1 - 1
src/main/config/tablemeta.properties

@@ -779,7 +779,7 @@ fileCrawlingConfig.name.doubleTypeParam=
 fileCrawlingConfig.name.dateTypeParam=
 fileCrawlingConfig.name.defaultValue=
 fileCrawlingConfig.paths.requiredParam=(target = "confirmfromcreate,create,confirmfromupdate,update,delete")
-fileCrawlingConfig.paths.additionalAnnotation=@UriType(protocols = "file:,smb:")@Maxbytelength(maxbytelength = 4000)
+fileCrawlingConfig.paths.additionalAnnotation=@UriType(protocols = "file:,smb:,ftp:")@Maxbytelength(maxbytelength = 4000)
 fileCrawlingConfig.paths.annotation=
 fileCrawlingConfig.paths.enableJavaType=true
 fileCrawlingConfig.paths.longTypeParam=

+ 2 - 0
src/main/java/jp/sf/fess/Constants.java

@@ -256,6 +256,8 @@ public class Constants extends CoreLibConstants {
 
     public static final String SAMBA = "SAMBA";
 
+    public static final String FTP = "FTP";
+
     public static final String[] RESERVED = { "+", "-", "&&", "||", "!", "(",
             ")", "{", "}", "[", "]", "^", "~", "*", "?", "\\", ";", ":", "/" };
 

+ 3 - 0
src/main/java/jp/sf/fess/action/admin/FileAuthenticationAction.java

@@ -174,6 +174,9 @@ public class FileAuthenticationAction extends BsFileAuthenticationAction {
         items.add(createItem(MessageResourcesUtil.getMessage(RequestUtil
                 .getRequest().getLocale(),
                 "labels.file_authentication_scheme_samba"), Constants.SAMBA));
+        items.add(createItem(MessageResourcesUtil.getMessage(RequestUtil
+                .getRequest().getLocale(),
+                "labels.file_authentication_scheme_ftp"), Constants.FTP));
         return items;
     }
 

+ 1 - 1
src/main/java/jp/sf/fess/action/admin/WizardAction.java

@@ -277,7 +277,7 @@ public class WizardAction implements Serializable {
 
     protected String convertCrawlingPath(final String path) {
         if (path.startsWith("http:") || path.startsWith("https:")
-                || path.startsWith("smb:")) {
+                || path.startsWith("smb:") || path.startsWith("ftp:")) {
             return path;
         }
 

+ 1 - 1
src/main/java/jp/sf/fess/crud/form/admin/BsFileCrawlingConfigForm.java

@@ -52,7 +52,7 @@ public abstract class BsFileCrawlingConfigForm {
     public String name;
 
     @Required(target = "confirmfromcreate,create,confirmfromupdate,update,delete")
-    @UriType(protocols = "file:,smb:")
+    @UriType(protocols = "file:,smb:,ftp:")
     @Maxbytelength(maxbytelength = 4000)
     public String paths;
 

+ 38 - 1
src/main/java/jp/sf/fess/db/exentity/DataCrawlingConfig.java

@@ -38,6 +38,8 @@ import org.apache.http.impl.auth.DigestScheme;
 import org.apache.http.impl.auth.NTLMScheme;
 import org.codelibs.core.util.StringUtil;
 import org.codelibs.robot.client.S2RobotClientFactory;
+import org.codelibs.robot.client.ftp.FtpAuthentication;
+import org.codelibs.robot.client.ftp.FtpClient;
 import org.codelibs.robot.client.http.Authentication;
 import org.codelibs.robot.client.http.HcHttpClient;
 import org.codelibs.robot.client.http.impl.AuthenticationImpl;
@@ -315,7 +317,8 @@ public class DataCrawlingConfig extends BsDataCrawlingConfig implements
         final String fileAuthStr = paramMap.get(S2ROBOT_FILE_AUTH);
         if (StringUtil.isNotBlank(fileAuthStr)) {
             final String[] fileAuthNames = fileAuthStr.split(",");
-            final List<SmbAuthentication> smbAuthList = new ArrayList<SmbAuthentication>();
+            final List<SmbAuthentication> smbAuthList = new ArrayList<>();
+            final List<FtpAuthentication> ftpAuthList = new ArrayList<>();
             for (final String fileAuthName : fileAuthNames) {
                 final String scheme = paramMap.get(S2ROBOT_FILE_AUTH + "."
                         + fileAuthName + ".scheme");
@@ -352,6 +355,35 @@ public class DataCrawlingConfig extends BsDataCrawlingConfig implements
                     smbAuth.setPassword(password == null ? StringUtil.EMPTY
                             : password);
                     smbAuthList.add(smbAuth);
+                } else if (Constants.FTP.equals(scheme)) {
+                    final String hostname = paramMap.get(S2ROBOT_FILE_AUTH
+                            + "." + fileAuthName + ".host");
+                    final String port = paramMap.get(S2ROBOT_FILE_AUTH + "."
+                            + fileAuthName + ".port");
+                    final String username = paramMap.get(S2ROBOT_FILE_AUTH
+                            + "." + fileAuthName + ".username");
+                    final String password = paramMap.get(S2ROBOT_FILE_AUTH
+                            + "." + fileAuthName + ".password");
+
+                    if (StringUtil.isEmpty(username)) {
+                        logger.warn("username is empty. fileAuth:"
+                                + fileAuthName);
+                        continue;
+                    }
+
+                    final FtpAuthentication ftpAuth = new FtpAuthentication();
+                    ftpAuth.setServer(hostname);
+                    if (StringUtil.isNotBlank(port)) {
+                        try {
+                            ftpAuth.setPort(Integer.parseInt(port));
+                        } catch (final NumberFormatException e) {
+                            logger.warn("Failed to parse " + port, e);
+                        }
+                    }
+                    ftpAuth.setUsername(username);
+                    ftpAuth.setPassword(password == null ? StringUtil.EMPTY
+                            : password);
+                    ftpAuthList.add(ftpAuth);
                 }
             }
             if (!smbAuthList.isEmpty()) {
@@ -359,6 +391,11 @@ public class DataCrawlingConfig extends BsDataCrawlingConfig implements
                         smbAuthList.toArray(new SmbAuthentication[smbAuthList
                                 .size()]));
             }
+            if (!ftpAuthList.isEmpty()) {
+                factoryParamMap.put(FtpClient.FTP_AUTHENTICATIONS_PROPERTY,
+                        ftpAuthList.toArray(new FtpAuthentication[ftpAuthList
+                                .size()]));
+            }
         }
 
     }

+ 13 - 1
src/main/java/jp/sf/fess/db/exentity/FileCrawlingConfig.java

@@ -33,6 +33,8 @@ import jp.sf.fess.util.ParameterUtil;
 
 import org.codelibs.core.util.StringUtil;
 import org.codelibs.robot.client.S2RobotClientFactory;
+import org.codelibs.robot.client.ftp.FtpAuthentication;
+import org.codelibs.robot.client.ftp.FtpClient;
 import org.codelibs.robot.client.smb.SmbAuthentication;
 import org.codelibs.robot.client.smb.SmbClient;
 import org.seasar.framework.container.SingletonS2Container;
@@ -222,7 +224,8 @@ public class FileCrawlingConfig extends BsFileCrawlingConfig implements
         // auth params
         final List<FileAuthentication> fileAuthList = fileAuthenticationService
                 .getFileAuthenticationList(getId());
-        final List<SmbAuthentication> smbAuthList = new ArrayList<SmbAuthentication>();
+        final List<SmbAuthentication> smbAuthList = new ArrayList<>();
+        final List<FtpAuthentication> ftpAuthList = new ArrayList<>();
         for (final FileAuthentication fileAuth : fileAuthList) {
             if (Constants.SAMBA.equals(fileAuth.getProtocolScheme())) {
                 final SmbAuthentication smbAuth = new SmbAuthentication();
@@ -235,10 +238,19 @@ public class FileCrawlingConfig extends BsFileCrawlingConfig implements
                 smbAuth.setUsername(fileAuth.getUsername());
                 smbAuth.setPassword(fileAuth.getPassword());
                 smbAuthList.add(smbAuth);
+            } else if (Constants.FTP.equals(fileAuth.getProtocolScheme())) {
+                final FtpAuthentication ftpAuth = new FtpAuthentication();
+                ftpAuth.setServer(fileAuth.getHostname());
+                ftpAuth.setPort(fileAuth.getPort());
+                ftpAuth.setUsername(fileAuth.getUsername());
+                ftpAuth.setPassword(fileAuth.getPassword());
+                ftpAuthList.add(ftpAuth);
             }
         }
         paramMap.put(SmbClient.SMB_AUTHENTICATIONS_PROPERTY,
                 smbAuthList.toArray(new SmbAuthentication[smbAuthList.size()]));
+        paramMap.put(FtpClient.FTP_AUTHENTICATIONS_PROPERTY,
+                ftpAuthList.toArray(new FtpAuthentication[ftpAuthList.size()]));
 
     }
 

+ 1 - 1
src/main/java/jp/sf/fess/helper/WebFsIndexHelper.java

@@ -334,7 +334,7 @@ public class WebFsIndexHelper implements Serializable {
                 if (StringUtil.isNotBlank(u)) {
                     u = u.trim();
                     if (!u.startsWith("#")) {
-                        if (!u.startsWith("file:") && !u.startsWith("smb:")) {
+                        if (!u.startsWith("file:") && !u.startsWith("smb:") && !u.startsWith("ftp:")) {
                             if (u.startsWith("/")) {
                                 u = "file:" + u;
                             } else {

+ 1 - 0
src/main/resources/application.properties

@@ -1180,6 +1180,7 @@ labels.file_authentication_password=Password
 labels.file_authentication_parameters=Parameters
 labels.file_authentication_file_crawling_config=FS Config
 labels.file_authentication_scheme_samba=Samba
+labels.file_authentication_scheme_ftp=FTP
 
 # view/admin/fileAuthentication/confirm.jsp
 labels.file_authentication_title_confirm=File Authentication

+ 1 - 0
src/main/resources/application_ja.properties

@@ -1180,6 +1180,7 @@ labels.file_authentication_password=\u30d1\u30b9\u30ef\u30fc\u30c9
 labels.file_authentication_parameters=\u30d1\u30e9\u30e1\u30fc\u30bf
 labels.file_authentication_file_crawling_config=FS\u8a2d\u5b9a\u540d
 labels.file_authentication_scheme_samba=Samba
+labels.file_authentication_scheme_ftp=FTP
 
 # view/admin/fileAuthentication/confirm.jsp
 labels.file_authentication_title_confirm=\u30d5\u30a1\u30a4\u30eb\u8a8d\u8a3c