1
1
/**
2
2
* Copyright (C) 2000 - 2012 Silverpeas
3
3
*
4
- * This program is free software: you can redistribute it and/or modify
5
- * it under the terms of the GNU Affero General Public License as
6
- * published by the Free Software Foundation, either version 3 of the
7
- * License, or (at your option) any later version.
4
+ * This program is free software: you can redistribute it and/or modify it under the terms of the
5
+ * GNU Affero General Public License as published by the Free Software Foundation, either version 3
6
+ * of the License, or (at your option) any later version.
8
7
*
9
- * As a special exception to the terms and conditions of version 3.0 of
10
- * the GPL, you may redistribute this Program in connection with Free/Libre
11
- * Open Source Software ("FLOSS") applications as described in Silverpeas's
12
- * FLOSS exception. You should have received a copy of the text describing
13
- * the FLOSS exception, and it is also available here:
8
+ * As a special exception to the terms and conditions of version 3.0 of the GPL, you may
9
+ * redistribute this Program in connection with Free/Libre Open Source Software ("FLOSS")
10
+ * applications as described in Silverpeas's FLOSS exception. You should have received a copy of the
11
+ * text describing the FLOSS exception, and it is also available here:
14
12
* "http://www.silverpeas.org/docs/core/legal/floss_exception.html"
15
13
*
16
- * This program is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU Affero General Public License for more details.
14
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
15
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Affero General Public License for more details.
20
17
*
21
- * You should have received a copy of the GNU Affero General Public License
22
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ * You should have received a copy of the GNU Affero General Public License along with this program.
19
+ * If not, see <http://www.gnu.org/licenses/>.
23
20
*/
24
21
package org .silverpeas .search .indexEngine .model ;
25
22
28
25
import java .util .Collections ;
29
26
import java .util .List ;
30
27
28
+ import com .silverpeas .util .FileUtil ;
31
29
import com .stratelia .silverpeas .silvertrace .SilverTrace ;
32
- import com .stratelia .webactiv .util .FileRepositoryManager ;
33
- import com .stratelia .webactiv .util .ResourceLocator ;
34
30
35
31
/**
36
32
* An RepositoryIndexer allow to index files in a whole repository except the directories
37
33
*/
38
34
public class RepositoryIndexer {
39
35
36
+ public static final String ADD_ACTION = "add" ;
37
+ public static final String REMOVE_ACTION = "remove" ;
40
38
private String spaceId = null ;
41
39
private String componentId = null ;
42
40
private int count = 0 ;
43
41
private char separator ;
44
- ResourceLocator resource = null ;
45
- IndexManager indexManager = null ;
42
+ private IndexManager indexManager = new IndexManager ();
46
43
47
44
public RepositoryIndexer (String spaceId , String componentId ) {
48
45
SilverTrace .debug ("indexEngine" , "RepositoryIndexer.RepositoryIndexer()" ,
49
46
"root.MSG_GEN_PARAM_VALUE" , "spaceId=" + spaceId + " ComponentId=" + componentId );
50
- setSpaceId (spaceId );
51
- setComponentId (componentId );
52
- resource = new ResourceLocator (
53
- "com.stratelia.webactiv.util.attachment.mime_types" , "fr" );
54
- indexManager = new IndexManager ();
55
- }
56
-
57
- public final void setSpaceId (String spaceId ) {
58
47
this .spaceId = spaceId ;
48
+ this .componentId = componentId ;
59
49
}
60
50
61
51
public String getSpaceId () {
62
52
return spaceId ;
63
53
}
64
54
65
- public final void setComponentId (String componentId ) {
66
- this .componentId = componentId ;
67
- }
68
-
69
55
public String getComponentId () {
70
56
return componentId ;
71
57
}
72
58
73
- public void pathIndexer (String path , String creationDate , String creatorId ,
74
- String action ) {
75
- SilverTrace .debug ("indexEngine" , "RepositoryIndexer.pathIndexer()" ,
76
- "root.MSG_GEN_ENTER_METHOD" , "path=" + path );
77
-
59
+ public void pathIndexer (String path , String creationDate , String creatorId , String action ) {
60
+ SilverTrace .debug ("indexEngine" , "RepositoryIndexer.pathIndexer()" , "root.MSG_GEN_ENTER_METHOD" ,
61
+ "path=" + path );
78
62
separator = path .charAt (0 );
79
- SilverTrace .debug ("indexEngine" , "RepositoryIndexer.pathIndexer()" ,
80
- "root.MSG_GEN_PARAM_VALUE" , "separator = " + separator );
81
-
63
+ SilverTrace .debug ("indexEngine" , "RepositoryIndexer.pathIndexer()" , "root.MSG_GEN_PARAM_VALUE" ,
64
+ "separator = " + separator );
82
65
File dir = new File (path );
83
66
if (dir .isDirectory ()) {
84
67
// index directory
85
68
indexDirectory (action , creationDate , creatorId , dir );
86
-
87
69
// index directory's content
88
70
processFileList (dir , creationDate , creatorId , action );
89
71
}
@@ -94,6 +76,7 @@ public void pathIndexer(String path, String creationDate, String creatorId,
94
76
95
77
/**
96
78
* Recursive function which covers directories. For each file, the file is indexed.
79
+ *
97
80
* @param fileList an array which contains directories and files
98
81
* @param path the current path
99
82
* @param currentDirectoryName the current directory name
@@ -125,35 +108,33 @@ private void processFileList(File dir, String creationDate, String creatorId, St
125
108
}
126
109
}
127
110
128
- private void indexDirectory (String action , String creationDate ,
129
- String creatorId , File directory ) {
130
- if ("add" .equals (action )) {
111
+ private void indexDirectory (String action , String creationDate , String creatorId , File directory ) {
112
+ if (ADD_ACTION .equals (action )) {
131
113
// indexer le répertoire
132
- FullIndexEntry fullIndexEntry = new FullIndexEntry (getComponentId (), "LinkedDir" ,
133
- directory .getPath ());
114
+ FullIndexEntry fullIndexEntry = new FullIndexEntry (getComponentId (), "LinkedDir" ,
115
+ directory .getPath ());
134
116
fullIndexEntry .setTitle (directory .getName ());
135
117
fullIndexEntry .setCreationDate (creationDate );
136
118
fullIndexEntry .setCreationUser (creatorId );
137
119
indexManager .addIndexEntry (fullIndexEntry );
138
120
count ++;
139
- } else if ("remove" .equals (action )) {
121
+ } else if (REMOVE_ACTION .equals (action )) {
140
122
IndexEntryPK indexEntry = new IndexEntryPK (getComponentId (), "LinkedDir" , directory .getPath ());
141
123
indexManager .removeIndexEntry (indexEntry );
142
124
}
143
125
}
144
126
145
- public void indexFile (String action , String creationDate , String creatorId ,
146
- File file ) {
127
+ public void indexFile (String action , String creationDate , String creatorId , File file ) {
147
128
indexFile (action , creationDate , creatorId , file , true );
148
129
}
149
130
150
- public void indexFile (String action , String creationDate , String creatorId ,
151
- File file , boolean closeIndex ) {
131
+ public void indexFile (String action , String creationDate , String creatorId , File file ,
132
+ boolean closeIndex ) {
152
133
// String path = currentPath + separator + fileName;
153
134
154
135
String filePath = file .getPath ();
155
136
156
- if ("add" .equals (action )) {
137
+ if (ADD_ACTION .equals (action )) {
157
138
String fileName = file .getName ();
158
139
159
140
// Add file in index
@@ -172,13 +153,13 @@ public void indexFile(String action, String creationDate, String creatorId,
172
153
fullIndexEntry .setCreationUser (creatorId );
173
154
174
155
if (haveGotExtension && !fileName .startsWith ("~" )) {
175
- String format = getMimeType (fileName );
156
+ String format = FileUtil . getMimeType (fileName );
176
157
String lang = "fr" ;
177
158
fullIndexEntry .addFileContent (filePath , null , format , lang );
178
159
}
179
160
indexManager .addIndexEntry (fullIndexEntry );
180
161
count ++;
181
- } else if ("remove" .equals (action )) { // Remove file from index
162
+ } else if (REMOVE_ACTION .equals (action )) { // Remove file from index
182
163
IndexEntryPK indexEntry = new IndexEntryPK (getComponentId (), "LinkedFile" , filePath );
183
164
indexManager .removeIndexEntry (indexEntry );
184
165
}
@@ -187,13 +168,4 @@ public void indexFile(String action, String creationDate, String creatorId,
187
168
indexManager .optimize ();
188
169
}
189
170
}
190
-
191
- private String getMimeType (String fileName ) {
192
- String mimeType = null ;
193
- String fileExtension = FileRepositoryManager .getFileExtension (fileName );
194
- if (resource != null && fileExtension != null ) {
195
- mimeType = resource .getString (fileExtension .toLowerCase ());
196
- }
197
- return mimeType ;
198
- }
199
171
}
0 commit comments