]> source.dussan.org Git - archiva.git/blob
b80ab60137fdeda02038db8235af1e005ee120e5
[archiva.git] /
1 package org.apache.maven.repository.manager.web.action;\r
2 \r
3 /*\r
4  * Copyright 2005-2006 The Apache Software Foundation.\r
5  *\r
6  * Licensed under the Apache License, Version 2.0 (the "License");\r
7  * you may not use this file except in compliance with the License.\r
8  * You may obtain a copy of the License at\r
9  *\r
10  *      http://www.apache.org/licenses/LICENSE-2.0\r
11  *\r
12  * Unless required by applicable law or agreed to in writing, software\r
13  * distributed under the License is distributed on an "AS IS" BASIS,\r
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
15  * See the License for the specific language governing permissions and\r
16  * limitations under the License.\r
17  */\r
18 \r
19 import com.opensymphony.xwork.Action;\r
20 import org.apache.maven.artifact.repository.ArtifactRepository;\r
21 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;\r
22 import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;\r
23 import org.apache.maven.repository.indexing.RepositoryIndexException;\r
24 import org.apache.maven.repository.indexing.RepositoryIndexSearchException;\r
25 import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer;\r
26 import org.apache.maven.repository.indexing.RepositoryIndexingFactory;\r
27 import org.apache.maven.repository.manager.web.job.Configuration;\r
28 \r
29 import java.io.File;\r
30 import java.net.MalformedURLException;\r
31 import java.util.List;\r
32 \r
33 /**\r
34  * Searches for searchString in all indexed fields.\r
35  *\r
36  * @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.GeneralSearchAction"\r
37  */\r
38 public class GeneralSearchAction\r
39     implements Action\r
40 {\r
41     private String searchString;\r
42 \r
43     private List searchResult;\r
44 \r
45     /**\r
46      * @plexus.requirement\r
47      */\r
48     private RepositoryIndexingFactory factory;\r
49 \r
50     /**\r
51      * @plexus.requirement\r
52      */\r
53     private RepositoryIndexSearchLayer searchLayer;\r
54 \r
55     /**\r
56      * @plexus.requirement\r
57      */\r
58     private ArtifactRepositoryFactory repositoryFactory;\r
59 \r
60     /**\r
61      * @plexus.requirement\r
62      */\r
63     private Configuration configuration;\r
64 \r
65     public String execute()\r
66         throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException\r
67     {\r
68         if ( searchString != null && searchString.length() != 0 )\r
69         {\r
70             String indexPath = configuration.getIndexDirectory();\r
71 \r
72             // TODO: reduce the amount of lookup?\r
73 \r
74             File repositoryDirectory = new File( configuration.getRepositoryDirectory() );\r
75             String repoDir = repositoryDirectory.toURL().toString();\r
76 \r
77             ArtifactRepository repository =\r
78                 repositoryFactory.createArtifactRepository( "test", repoDir, configuration.getLayout(), null, null );\r
79 \r
80             ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository );\r
81 \r
82             searchResult = searchLayer.searchGeneral( searchString, index );\r
83 \r
84             return SUCCESS;\r
85         }\r
86         else\r
87         {\r
88             return ERROR;\r
89         }\r
90     }\r
91 \r
92     public void setSearchString( String searchString )\r
93     {\r
94         this.searchString = searchString;\r
95     }\r
96 \r
97     public List getSearchResult()\r
98     {\r
99         return searchResult;\r
100     }\r
101 \r
102 }\r