]> source.dussan.org Git - archiva.git/commitdiff
fixes to the xwork integration
authorBrett Porter <brett@apache.org>
Thu, 6 Jul 2006 11:19:19 +0000 (11:19 +0000)
committerBrett Porter <brett@apache.org>
Thu, 6 Jul 2006 11:19:19 +0000 (11:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@419521 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-webapp/pom.xml
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/QuickSearchAction.java [new file with mode: 0644]
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java
maven-repository-webapp/src/main/resources/xwork.xml
maven-repository-webapp/src/main/webapp/WEB-INF/jsp/quickSearch.jsp [new file with mode: 0644]
pom.xml

index 8b7445d82acc1d255e6a6231ee209615f52f6eb8..d3d80f1629caec54c604e16ebb0f8e012cacb51b 100644 (file)
       <artifactId>plexus-xwork-integration</artifactId>
       <version>1.0-alpha-2-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-container-default</artifactId>
+      <version>1.0-alpha-10-SNAPSHOT</version>
+    </dependency>
     <dependency>
       <groupId>org.apache.maven.repository</groupId>
       <artifactId>maven-repository-indexer</artifactId>
           </instrumentation>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-maven-plugin</artifactId>
+        <configuration>
+          <fileName>plexus-request.xml</fileName>
+          <containerDescriptor>true</containerDescriptor>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
   <repositories>
index b2c3e031891ea7f9e6589fe20eb736e204310037..f9e5f223d0ef0a6f7a39624ea07d28a6a76bc432 100644 (file)
@@ -23,7 +23,6 @@ import org.apache.maven.repository.manager.web.execution.DiscovererExecution;
 import org.apache.maven.repository.manager.web.job.DiscovererScheduler;\r
 import org.apache.maven.repository.manager.web.utils.ConfigurationManager;\r
 \r
-import java.io.File;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
 \r
@@ -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.\r
  * It invokes the DiscovererScheduler to set the DiscoverJob in the scheduler.\r
  *\r
- * @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.BaseAction"\r
+ * @plexus.component role="com.opensymphony.xwork.Action" role-hint="baseAction"\r
  */\r
 public class BaseAction\r
     extends ActionSupport\r
@@ -83,7 +82,7 @@ public class BaseAction
             this.parameters = parameters;\r
 \r
             //Configuration configuration = new Configuration(); // TODO!\r
-            execution.executeDiscovererIfIndexDoesNotExist( new File( config.getIndexPath() ) );\r
+//            execution.executeDiscovererIfIndexDoesNotExist( new File( config.getIndexPath() ) );\r
             discovererScheduler.setSchedule( config.getDiscoveryCronExpression() );\r
         }\r
         catch ( Exception e )\r
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 (file)
index 0000000..78311e9
--- /dev/null
@@ -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;
+    }
+
+}
index 362308bd4c60fda89d607c398556a44d79a2fd19..e91a91b0ce4292a681269b83b024312edf091aee 100644 (file)
@@ -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;
index bbc1fa78265722b13f7178c977fb86fa6936b151..24e2876e2706e034d147d1d1f77511a9842c0896 100644 (file)
     <!-- Default interceptor stack. -->
     <default-interceptor-ref name="defaultStack"/>
 
-    <!-- Action: Front page -->
-    <action name="index" class="org.apache.maven.repository.manager.web.action.BaseAction">
-      <result name="success" type="dispatcher">/WEB-INF/jsp/index.jsp</result>
+    <action name="index" class="baseAction">
+      <result name="success" type="dispatcher">/WEB-INF/jsp/quickSearch.jsp</result>
+    </action>
+
+    <action name="quickSearch" class="quickSearchAction">
+      <result name="success" type="dispatcher">/WEB-INF/jsp/results.jsp</result>
       <result name="error" type="dispatcher">/WEB-INF/jsp/index.jsp</result>
     </action>
 
+    <!-- TODO! old actions -->
+    <!--
+        <action name="index" class="org.apache.maven.repository.manager.web.action.BaseAction">
+          <result name="success" type="dispatcher">/WEB-INF/jsp/index.jsp</result>
+          <result name="error" type="dispatcher">/WEB-INF/jsp/index.jsp</result>
+        </action>
+    -->
+
     <action name="searchg" class="org.apache.maven.repository.manager.web.action.GeneralSearchAction">
       <result name="success" type="dispatcher">/WEB-INF/jsp/generalresults.jsp</result>
       <result name="error" type="dispatcher">/WEB-INF/jsp/index.jsp</result>
@@ -55,7 +66,7 @@
     <action name="configureScheduler" class="org.apache.maven.repository.manager.web.action.SchedulerConfigurationAction">
       <result name="success" type="dispatcher">/WEB-INF/jsp/indexConfigUpdateSuccess.jsp</result>
       <result name="error" type="dispatcher">/WEB-INF/jsp/index.jsp</result>
-    </action>    
+    </action>
 
   </package>
 </xwork>
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 (file)
index 0000000..b23a7a4
--- /dev/null
@@ -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.
+  --%>
+
+<html>
+<head><title>Quick Search</title></head>
+
+<body>
+
+<h1>Search</h1>
+
+<div id="contentArea">
+  <div id="searchBox">
+    <ww:form action="quickSearch.action">
+      <ww:textfield size="50" name="q" />
+      <ww:submit label="Go!" />
+    </ww:form>
+    <p>
+      Enter your search terms. A variety of data will be searched for your keywords.
+    </p>
+  </div>
+</div>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 0c4c135aca18a20c168178295c1156e967006a47..abdc15c25dcf5dc085b5c1b54c02921a55b8e0be 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -80,6 +80,7 @@
       <plugin>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-maven-plugin</artifactId>
+        <version>1.3-SNAPSHOT</version>
         <executions>
           <execution>
             <goals>
         <groupId>org.apache.maven.repository</groupId>
         <artifactId>maven-repository-converter</artifactId>
         <version>${pom.version}</version>
-      </dependency>      
+      </dependency>
     </dependencies>
   </dependencyManagement>
   <reporting>
       </build>
     </profile>
   </profiles>
+  <!-- TODO: remove, required only for plexus maven plugin -->
+  <pluginRepositories>
+    <pluginRepository>
+      <id>codehaus.snapshots</id>
+      <url>http://snapshots.repository.codehaus.org</url>
+    </pluginRepository>
+  </pluginRepositories>
 </project>