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