From: Brett Porter Date: Thu, 6 Jul 2006 11:19:19 +0000 (+0000) Subject: fixes to the xwork integration X-Git-Tag: archiva-0.9-alpha-1~790 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=39a41a4b297d94593940fc3f6ac43baef1ecdc80;p=archiva.git fixes to the xwork integration git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@419521 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/maven-repository-webapp/pom.xml b/maven-repository-webapp/pom.xml index 8b7445d82..d3d80f162 100644 --- a/maven-repository-webapp/pom.xml +++ b/maven-repository-webapp/pom.xml @@ -42,6 +42,11 @@ plexus-xwork-integration 1.0-alpha-2-SNAPSHOT + + org.codehaus.plexus + plexus-container-default + 1.0-alpha-10-SNAPSHOT + org.apache.maven.repository maven-repository-indexer @@ -123,6 +128,14 @@ + + org.codehaus.plexus + plexus-maven-plugin + + plexus-request.xml + true + + diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java index b2c3e0318..f9e5f223d 100644 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java @@ -23,7 +23,6 @@ import org.apache.maven.repository.manager.web.execution.DiscovererExecution; import org.apache.maven.repository.manager.web.job.DiscovererScheduler; import org.apache.maven.repository.manager.web.utils.ConfigurationManager; -import java.io.File; import java.util.HashMap; import java.util.Map; @@ -31,7 +30,7 @@ import java.util.Map; * This is the Action class of index.jsp, which is the initial page of the web application. * It invokes the DiscovererScheduler to set the DiscoverJob in the scheduler. * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.BaseAction" + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="baseAction" */ public class BaseAction extends ActionSupport @@ -83,7 +82,7 @@ public class BaseAction this.parameters = parameters; //Configuration configuration = new Configuration(); // TODO! - execution.executeDiscovererIfIndexDoesNotExist( new File( config.getIndexPath() ) ); +// execution.executeDiscovererIfIndexDoesNotExist( new File( config.getIndexPath() ) ); discovererScheduler.setSchedule( config.getDiscoveryCronExpression() ); } catch ( Exception e ) diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/QuickSearchAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/QuickSearchAction.java new file mode 100644 index 000000000..78311e99a --- /dev/null +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/QuickSearchAction.java @@ -0,0 +1,117 @@ +package org.apache.maven.repository.manager.web.action; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.opensymphony.xwork.Action; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.apache.maven.repository.indexing.RepositoryIndexSearchException; +import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer; +import org.apache.maven.repository.indexing.RepositoryIndexingFactory; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.List; +import java.util.Map; + +/** + * Searches for searchString in all indexed fields. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="quickSearchAction" + */ +public class QuickSearchAction + implements Action +{ + /** + * Query string. + */ + private String q; + + /** + * Search results. + */ + private List searchResult; + + /** + * @plexus.requirement + */ + private RepositoryIndexingFactory factory; + + /** + * @plexus.requirement + */ + private RepositoryIndexSearchLayer searchLayer; + + /** + * @plexus.requirement + */ + private ArtifactRepositoryFactory repositoryFactory; + + /** + * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" + */ + private Map repositoryLayouts; + + public String execute() + throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException + { + if ( q != null && q.length() != 0 ) + { + Configuration configuration = new Configuration(); // TODO! + File indexPath = new File( configuration.getIndexPath() ); + + // TODO: [!] repository should only have been instantiated once + File repositoryDirectory = new File( configuration.getRepositoryDirectory() ); + String repoDir = repositoryDirectory.toURL().toString(); + + ArtifactRepositoryLayout layout = + (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getRepositoryLayout() ); + ArtifactRepository repository = + repositoryFactory.createArtifactRepository( "test", repoDir, layout, null, null ); + + ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository ); + + searchResult = searchLayer.searchGeneral( q, index ); + + return SUCCESS; + } + else + { + return ERROR; + } + } + + public String getQ() + { + return q; + } + + public void setQ( String q ) + { + this.q = q; + } + + public List getSearchResult() + { + return searchResult; + } + +} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java index 362308bd4..e91a91b0c 100644 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java @@ -134,20 +134,23 @@ public class ConfigurationManager File file = getConfigFile(); config = new Configuration(); - if ( !file.exists() ) + if ( file != null ) { - writeXmlDocument( getConfigFile() ); - } - else - { - try + if ( !file.exists() ) { - config = readXmlDocument( file ); + writeXmlDocument( getConfigFile() ); } - catch ( XmlPullParserException xe ) + else { - // TODO: fix error handling! - xe.printStackTrace(); + try + { + config = readXmlDocument( file ); + } + catch ( XmlPullParserException xe ) + { + // TODO: fix error handling! + xe.printStackTrace(); + } } } @@ -202,11 +205,14 @@ public class ConfigurationManager else { URL xmlPath = getClass().getClassLoader().getResource( "../" + WEB_XML_FILE ); - String path = xmlPath.getFile(); - int lastIndex = path.lastIndexOf( '/' ); - path = path.substring( 0, lastIndex + 1 ); - path = path + INDEX_CONFIG_FILE; - plexusDescriptor = new File( path ); + if ( xmlPath != null ) + { + String path = xmlPath.getFile(); + int lastIndex = path.lastIndexOf( '/' ); + path = path.substring( 0, lastIndex + 1 ); + path = path + INDEX_CONFIG_FILE; + plexusDescriptor = new File( path ); + } } return plexusDescriptor; diff --git a/maven-repository-webapp/src/main/resources/xwork.xml b/maven-repository-webapp/src/main/resources/xwork.xml index bbc1fa782..24e2876e2 100644 --- a/maven-repository-webapp/src/main/resources/xwork.xml +++ b/maven-repository-webapp/src/main/resources/xwork.xml @@ -26,12 +26,23 @@ - - - /WEB-INF/jsp/index.jsp + + /WEB-INF/jsp/quickSearch.jsp + + + + /WEB-INF/jsp/results.jsp /WEB-INF/jsp/index.jsp + + + /WEB-INF/jsp/generalresults.jsp /WEB-INF/jsp/index.jsp @@ -55,7 +66,7 @@ /WEB-INF/jsp/indexConfigUpdateSuccess.jsp /WEB-INF/jsp/index.jsp - + diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/quickSearch.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/quickSearch.jsp new file mode 100644 index 000000000..b23a7a4c4 --- /dev/null +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/quickSearch.jsp @@ -0,0 +1,38 @@ +<%@ taglib prefix="ww" uri="/webwork" %> +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --%> + + +Quick Search + + + +

Search

+ +
+ +
+ + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 0c4c135ac..abdc15c25 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,7 @@ org.codehaus.plexus plexus-maven-plugin + 1.3-SNAPSHOT @@ -227,7 +228,7 @@ org.apache.maven.repository maven-repository-converter ${pom.version} -
+ @@ -346,4 +347,11 @@ + + + + codehaus.snapshots + http://snapshots.repository.codehaus.org + +