cleanup the checksum search

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@423825 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2006-07-20 08:38:56 +00:00
parent 154d0d416e
commit 9818d93f30
9 changed files with 192 additions and 145 deletions

View File

@ -21,6 +21,7 @@ import java.applet.Applet;
import java.awt.*; import java.awt.*;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.security.AccessController; import java.security.AccessController;
@ -65,28 +66,19 @@ public class ChecksumApplet
} }
catch ( NoSuchAlgorithmException e ) catch ( NoSuchAlgorithmException e )
{ {
return e; return "Error checksumming file: " + e.getMessage();
}
catch ( FileNotFoundException e )
{
return "Couldn't find the file. " + e.getMessage();
} }
catch ( IOException e ) catch ( IOException e )
{ {
return e; return "Error reading file: " + e.getMessage();
} }
} }
} ); } );
return (String) o;
//noinspection ChainOfInstanceofChecks
if ( o instanceof IOException )
{
throw (IOException) o;
}
else if ( o instanceof NoSuchAlgorithmException )
{
throw (NoSuchAlgorithmException) o;
}
else
{
return (String) o;
}
} }
protected String checksumFile( String file ) protected String checksumFile( String file )

View File

@ -1,112 +0,0 @@
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.repository.configuration.Configuration;
import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory;
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
import org.apache.maven.repository.indexing.RepositoryIndex;
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 org.apache.maven.repository.indexing.query.SinglePhraseQuery;
import java.io.File;
import java.net.MalformedURLException;
import java.util.List;
/**
* Search by package name.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.PackageSearchAction"
*/
public class PackageSearchAction
implements Action
{
private String packageName;
private String md5;
private List searchResult;
/**
* @plexus.requirement
*/
private RepositoryIndexingFactory factory;
/**
* @plexus.requirement
*/
private ConfiguredRepositoryFactory repositoryFactory;
/**
* @plexus.requirement
*/
private RepositoryIndexSearchLayer searchLayer;
public String execute()
throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
{
String searchTerm;
String key;
if ( packageName != null && packageName.length() != 0 )
{
searchTerm = packageName;
key = RepositoryIndex.FLD_PACKAGES;
}
else if ( md5 != null && md5.length() != 0 )
{
searchTerm = md5;
key = "md5";
}
else
{
return ERROR;
}
// TODO: better config - share with general [!]
Configuration configuration = new Configuration();
File indexPath = new File( configuration.getIndexPath() );
ArtifactRepository repository = repositoryFactory.createRepository( configuration );
ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository );
searchResult = searchLayer.searchAdvanced( new SinglePhraseQuery( key, searchTerm ), index );
return SUCCESS;
}
public void setPackageName( String packageName )
{
this.packageName = packageName;
}
public void setMd5( String md5 )
{
this.md5 = md5;
}
public List getSearchResult()
{
return searchResult;
}
}

View File

@ -27,6 +27,7 @@ import org.apache.maven.repository.indexing.RepositoryIndexException;
import org.apache.maven.repository.indexing.RepositoryIndexSearchException; import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer; import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer;
import org.apache.maven.repository.indexing.RepositoryIndexingFactory; import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
import java.io.File; import java.io.File;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -36,9 +37,9 @@ import java.util.Map;
/** /**
* Searches for searchString in all indexed fields. * Searches for searchString in all indexed fields.
* *
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="quickSearchAction" * @plexus.component role="com.opensymphony.xwork.Action" role-hint="searchAction"
*/ */
public class QuickSearchAction public class SearchAction
extends ActionSupport extends ActionSupport
{ {
/** /**
@ -46,6 +47,11 @@ public class QuickSearchAction
*/ */
private String q; private String q;
/**
* The MD5 to search by.
*/
private String md5;
/** /**
* Search results. * Search results.
*/ */
@ -76,7 +82,7 @@ public class QuickSearchAction
*/ */
private ConfigurationStore configurationStore; private ConfigurationStore configurationStore;
public String execute() public String quickSearch()
throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException, throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException,
ConfigurationStoreException ConfigurationStoreException
{ {
@ -84,12 +90,7 @@ public class QuickSearchAction
assert q != null && q.length() != 0; assert q != null && q.length() != 0;
Configuration configuration = configurationStore.getConfigurationFromStore(); ArtifactRepositoryIndex index = getIndex();
File indexPath = new File( configuration.getIndexPath() );
ArtifactRepository repository = repositoryFactory.createRepository( configuration );
ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository );
if ( !index.indexExists() ) if ( !index.indexExists() )
{ {
@ -102,6 +103,37 @@ public class QuickSearchAction
return SUCCESS; return SUCCESS;
} }
public String findArtifact()
throws ConfigurationStoreException, RepositoryIndexException, RepositoryIndexSearchException
{
// TODO: give action message if indexing is in progress
assert md5 != null && md5.length() != 0;
ArtifactRepositoryIndex index = getIndex();
if ( !index.indexExists() )
{
addActionError( "The repository is not yet indexed. Please wait, and then try again." );
return ERROR;
}
searchResults = searchLayer.searchAdvanced( new SinglePhraseQuery( "md5", md5 ), index );
return SUCCESS;
}
private ArtifactRepositoryIndex getIndex()
throws ConfigurationStoreException, RepositoryIndexException
{
Configuration configuration = configurationStore.getConfigurationFromStore();
File indexPath = new File( configuration.getIndexPath() );
ArtifactRepository repository = repositoryFactory.createRepository( configuration );
return factory.createArtifactRepositoryIndex( indexPath, repository );
}
public String doInput() public String doInput()
{ {
return INPUT; return INPUT;
@ -117,6 +149,16 @@ public class QuickSearchAction
this.q = q; this.q = q;
} }
public String getMd5()
{
return md5;
}
public void setMd5( String md5 )
{
this.md5 = md5;
}
public List getSearchResults() public List getSearchResults()
{ {
return searchResults; return searchResults;

View File

@ -0,0 +1,29 @@
<!--
~ 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.
-->
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="md5">
<field-validator type="requiredstring">
<message>
You must select a file, or enter the checksum. If the file was given and you receive this message,
there may have been an error generating the checksum.
</message>
</field-validator>
</field>
</validators>

View File

@ -41,16 +41,26 @@
<result name="config-needed" type="redirect">/admin/configure.action</result> <result name="config-needed" type="redirect">/admin/configure.action</result>
</global-results> </global-results>
<action name="index" class="quickSearchAction" method="input"> <action name="index" class="searchAction" method="input">
<result name="input">/WEB-INF/jsp/quickSearch.jsp</result> <result name="input">/WEB-INF/jsp/quickSearch.jsp</result>
</action> </action>
<action name="quickSearch" class="quickSearchAction"> <action name="quickSearch" class="searchAction" method="quickSearch">
<result name="input">/WEB-INF/jsp/quickSearch.jsp</result> <result name="input">/WEB-INF/jsp/quickSearch.jsp</result>
<result>/WEB-INF/jsp/results.jsp</result> <result>/WEB-INF/jsp/results.jsp</result>
<result name="error">/WEB-INF/jsp/quickSearch.jsp</result> <result name="error">/WEB-INF/jsp/quickSearch.jsp</result>
</action> </action>
<action name="findArtifact" class="searchAction" method="input">
<result name="input">/WEB-INF/jsp/findArtifact.jsp</result>
</action>
<action name="checksumSearch" class="searchAction" method="findArtifact">
<result name="input">/WEB-INF/jsp/findArtifact.jsp</result>
<result>/WEB-INF/jsp/results.jsp</result>
<result name="error">/WEB-INF/jsp/findArtifact.jsp</result>
</action>
<!-- TODO! old actions <!-- TODO! old actions
<action name="proxy" class="org.apache.maven.repository.proxy.web.action.RepositoryProxyAction"> <action name="proxy" class="org.apache.maven.repository.proxy.web.action.RepositoryProxyAction">
<result name="success" type="stream"> <result name="success" type="stream">

View File

@ -31,7 +31,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head> </head>
<body class="composite"> <body onload="<decorator:getProperty property="body.onload" />" class="composite">
<div id="banner"> <div id="banner">
<span id="bannerLeft"> <span id="bannerLeft">
<img src="http://www.apache.org/images/asf_logo_wide.gif" alt="" width="537" height="51" /> <img src="http://www.apache.org/images/asf_logo_wide.gif" alt="" width="537" height="51" />
@ -71,11 +71,11 @@
<my:currentWWUrl action="index" namespace="/">Search</my:currentWWUrl> <my:currentWWUrl action="index" namespace="/">Search</my:currentWWUrl>
</li> </li>
<%-- TODO <li class="none">
<li class="none"> <my:currentWWUrl action="findArtifact" namespace="/">Find Artifact</my:currentWWUrl>
<a href="#">Find Artifact</a> </li>
</li>
<%-- TODO
<li class="none"> <li class="none">
<a href="#">Browse</a> <a href="#">Browse</a>
</li> </li>

View File

@ -0,0 +1,86 @@
<%--
~ 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.
--%>
<%@ taglib prefix="ww" uri="/webwork" %>
<html>
<head>
<title>Find Artifact</title>
<ww:head />
</head>
<body onload="document.checksumSearch.file.disabled = false">
<h1>Find Artifact</h1>
<div id="contentArea">
<div id="searchBox">
<script type="text/javascript">
function generateMd5( file, defVal )
{
if ( file )
{
var s = document.ChecksumApplet.generateMd5(file);
// If there is a space, it's an error message, not a checksum
if ( s.indexOf(" ") >= 0 )
{
alert(s);
return "";
}
else
return s;
}
return defVal;
}
</script>
<noscript>
<span class="errorMessage">JavaScript is disabled: using the file browser will not work.</span>
</noscript>
<ww:form method="POST" action="checksumSearch" namespace="/"
onsubmit="this.md5.value = generateMd5(this.file.value,this.md5.value); this.file.disabled = true">
<tr>
<td class="tdLabel"><label for="checksumSearch_file" class="label">Search for:</label></td>
<td>
<input type="file" name="file" size="50" value="" id="checksumSearch_file" />
</td>
</tr>
<ww:textfield label="Checksum" size="50" name="md5" />
<ww:submit value="Go!" />
</ww:form>
<p>
Select the file you would like to locate in the remote repository.
The entire file will
<b>not</b>
be uploaded to the server. See the progress bar below for progress of
locally creating a checksum that is uploaded to the server after you hit "Go!".
<ww:actionerror />
</p>
<p>
<applet code="org/apache/maven/repository/applet/ChecksumApplet.class"
archive="maven-repository-artifact-applet.jar"
width="400" height="20" name="ChecksumApplet">
</applet>
</p>
</div>
</div>
</body>
</html>

View File

@ -1,4 +1,3 @@
<%@ taglib prefix="ww" uri="/webwork" %>
<%-- <%--
~ Copyright 2005-2006 The Apache Software Foundation. ~ Copyright 2005-2006 The Apache Software Foundation.
~ ~
@ -15,6 +14,7 @@
~ limitations under the License. ~ limitations under the License.
--%> --%>
<%@ taglib prefix="ww" uri="/webwork" %>
<html> <html>
<head> <head>
<title>Quick Search</title> <title>Quick Search</title>