maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r569735 [1/4] - in /maven/sandbox/trunk/doxia/doxia-linkcheck: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/maven/ src/main/java/org/apache/maven/doxia/ src/main/java/org/apache/mave...
Date Sat, 25 Aug 2007 21:14:29 GMT
Author: ltheussl
Date: Sat Aug 25 14:14:27 2007
New Revision: 569735

URL: http://svn.apache.org/viewvc?rev=569735&view=rev
Log:
Adding a linkchecking tool. For now it's just a simple adaptation of the m1 linkcheck plugin (r535801) to make it usable stand-alone, adjusted code conventions, added javadocs. Needs some clean up and testing.

Added:
    maven/sandbox/trunk/doxia/doxia-linkcheck/
    maven/sandbox/trunk/doxia/doxia-linkcheck/pom.xml   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/FileToCheck.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckResult.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkMatcher.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/FileLinkValidator.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/HTTPLinkValidator.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationItem.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationResult.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidator.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidatorManager.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/MailtoLinkValidator.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OfflineHTTPLinkValidator.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OnlineHTTPLinkValidator.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/site/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/site/site.xml   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/site/xdoc/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/site/xdoc/index.xml   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/site/xdoc/usage.xml   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/org/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/org/apache/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/org/apache/maven/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/org/apache/maven/doxia/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/LinkCheckTest.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/validation/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/validation/HTTPLinkValidatorTest.java   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/resources/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/resources/index-all.html   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/resources/nolink.html   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/resources/test-resources/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/resources/test-resources/nolink.html   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/resources/test-resources/test1/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/resources/test-resources/test1/test1.html   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/resources/test-resources/test1/test2.html   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/resources/test1/
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/resources/test1/test1.html   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/resources/testA.html   (with props)
    maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/resources/testExcludes.html   (with props)

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/pom.xml?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/pom.xml (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/pom.xml Sat Aug 25 14:14:27 2007
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>doxia-sandbox</artifactId>
+    <groupId>org.apache.maven.doxia</groupId>
+    <version>1.0-alpha-9-SNAPSHOT</version>
+  </parent>
+  <artifactId>doxia-linkcheck</artifactId>
+  <name>Doxia Linkcheck</name>
+  <version>1.0-alpha-9-SNAPSHOT</version>
+  <dependencies>
+    <!-- compile dependencies -->
+    <dependency>
+      <groupId>commons-httpclient</groupId>
+      <artifactId>commons-httpclient</artifactId>
+      <version>3.0</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.0.4</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <!-- runtime dependencies -->
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+      <version>1.2</version>
+      <scope>runtime</scope>
+    </dependency>
+    <!-- test dependencies -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/FileToCheck.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/FileToCheck.java?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/FileToCheck.java (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/FileToCheck.java Sat Aug 25 14:14:27 2007
@@ -0,0 +1,329 @@
+package org.apache.maven.doxia.linkcheck;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.maven.doxia.linkcheck.validation.LinkValidationItem;
+import org.apache.maven.doxia.linkcheck.validation.LinkValidationResult;
+import org.apache.maven.doxia.linkcheck.validation.LinkValidatorManager;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * A file to be checked.
+ *
+ * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
+ * @version $Id$
+ */
+public final class FileToCheck
+{
+    /** Log for debug output. */
+    private static final Log LOG = LogFactory.getLog( FileToCheck.class );
+
+    /** Unknown validation status. Initialized as null. */
+    public static final String STATUS_UNKNOWN = null;
+
+    /** Validation status ok. */
+    public static final String STATUS_OK = "OK";
+
+    /** The base of this FileToCheck. */
+    private String base;
+
+    /** The File object of this FileToCheck. */
+    private File fileToCheck;
+
+    /** A list of links found in this FileToCheck. */
+    private List links = new LinkedList();
+
+    /** A message. */
+    private String message = "";
+
+    /** The status. */
+    private String status = STATUS_OK;
+
+    /** successful. */
+    private int successful;
+
+    /** unsuccessful. */
+    private int unsuccessful;
+
+    /**
+     * Returns the message.
+     *
+     * @return String
+     */
+    public String getMessage()
+    {
+        return this.message;
+    }
+
+    /**
+     * Returns the fileName.
+     *
+     * @return String
+     */
+    public String getName()
+    {
+        String fileName = this.fileToCheck.getAbsolutePath();
+        if ( fileName.startsWith( this.base ) )
+        {
+            fileName = fileName.substring( this.base.length() + 1 );
+        }
+
+        fileName = fileName.replace( '\\', '/' );
+        return fileName;
+    }
+
+    /**
+     * Returns the list of results.
+     *
+     * @return List
+     */
+    public List getResults()
+    {
+        return this.links;
+    }
+
+    /**
+     * Returns the status.
+     *
+     * @return int
+     */
+    // TODO: replace by LinkValidationResult status.
+    public String getStatus()
+    {
+        return this.status;
+    }
+
+    /**
+     * Returns the successful.
+     *
+     * @return int
+     */
+    public int getSuccessful()
+    {
+        return this.successful;
+    }
+
+    /**
+     * Returns the unsuccessful.
+     *
+     * @return int
+     */
+    public int getUnsuccessful()
+    {
+        return this.unsuccessful;
+    }
+
+    /**
+     * Constructor: initializes the basedir and fileToCheck.
+     *
+     * @param baseFile The base file.
+     * @param file The file to check.
+     */
+    public FileToCheck( File baseFile, File file )
+    {
+        this.base = baseFile.getAbsolutePath();
+        this.fileToCheck = file;
+    }
+
+    /**
+     * Validates this fileToCheck.
+     *
+     * @param lvm The LinkValidatorManager to use.
+     * @throws Exception if something goes wrong.
+     */
+    public void check( LinkValidatorManager lvm ) throws Exception
+    {
+        this.successful = 0;
+
+        this.unsuccessful = 0;
+
+        this.status = STATUS_OK;
+
+        this.message = "";
+
+        if ( LOG.isDebugEnabled() )
+        {
+            LOG.debug( "Validating " + getName() );
+        }
+
+        try
+        {
+            final Set hrefs;
+
+            try
+            {
+                hrefs = LinkMatcher.match( this.fileToCheck );
+            }
+            catch ( Throwable t )
+            {
+                // We catch Throwable, because there is a chance that the domReader will throw
+                // a stack overflow exception for some files
+
+                if ( LOG.isDebugEnabled() )
+                {
+                    LOG.error( "Received: [" + t + "] in page [" + getName() + "]", t );
+                }
+                else
+                {
+                    LOG.error( "Received: [" + t + "] in page [" + getName() + "]" );
+                }
+
+                LinkCheckResult lcr = new LinkCheckResult();
+
+                lcr.setStatus( "PARSE FAILURE" );
+
+                lcr.setTarget( "N/A" );
+
+                addResult( lcr );
+
+                return;
+            }
+
+            String href;
+
+            LinkCheckResult lcr;
+
+            LinkValidationItem lvi;
+
+            LinkValidationResult result;
+
+            for ( Iterator iter = hrefs.iterator(); iter.hasNext(); )
+            {
+                href = (String) iter.next();
+
+                lcr = new LinkCheckResult();
+
+                lvi = new LinkValidationItem( this.fileToCheck, href );
+
+                result = lvm.validateLink( lvi );
+
+                lcr.setTarget( href );
+
+                lcr.setErrorMessage( result.getErrorMessage() );
+
+                switch ( result.getStatus() )
+                {
+                    case LinkValidationResult.VALID:
+                        this.successful++;
+
+                        lcr.setStatus( "valid" );
+
+                        addResult( lcr ); // At some point we won't want to store valid links. The tests require that
+                        // we do at present
+
+                        break;
+                    case LinkValidationResult.ERROR:
+                        this.unsuccessful++;
+
+                        lcr.setStatus( "error" );
+
+                        addResult( lcr );
+
+                        break;
+                    case LinkValidationResult.WARNING:
+                        this.unsuccessful++;
+
+                        lcr.setStatus( "warning" );
+
+                        addResult( lcr );
+
+                        break;
+                    case LinkValidationResult.UNKNOWN:
+                    default:
+                        this.unsuccessful++;
+
+                        lcr.setStatus( "unknown" );
+
+                        addResult( lcr );
+
+                        break;
+                }
+            }
+
+            href = null;
+
+            lcr = null;
+
+            lvi = null;
+
+            result = null;
+
+        }
+        catch ( Exception e )
+        {
+            LOG.error( this.message );
+
+            throw e;
+        }
+    }
+
+    /**
+     * Returns an XML representation of the current linkcheck result.
+     * This is only available after {@link #check(LinkValidatorManager)} has been called.
+     *
+     * @return the XML linkcheck result as a string.
+     */
+    public String toXML()
+    {
+        StringBuffer buf = new StringBuffer();
+
+        buf.append( "  <file>" + LinkCheck.EOL );
+
+        buf.append( "    <name><![CDATA[" + getName() + "]]></name>" + LinkCheck.EOL );
+
+        buf.append( "    <successful>" + getSuccessful() + "</successful>" + LinkCheck.EOL );
+
+        buf.append( "    <unsuccessful>" + getUnsuccessful() + "</unsuccessful>" + LinkCheck.EOL );
+
+        Iterator iter = getResults().iterator();
+
+        LinkCheckResult result;
+
+        while ( iter.hasNext() )
+        {
+            result = (LinkCheckResult) iter.next();
+
+            buf.append( result.toXML() );
+        }
+
+        buf.append( "  </file>" + LinkCheck.EOL );
+
+        return buf.toString();
+    }
+
+    /**
+     * Adds the given LinkCheckResult to the list of results.
+     *
+     * @param lcr the LinkCheckResult to add.
+     */
+    private void addResult( LinkCheckResult lcr )
+    {
+        this.links.add( lcr );
+    }
+}

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/FileToCheck.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/FileToCheck.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java Sat Aug 25 14:14:27 2007
@@ -0,0 +1,513 @@
+package org.apache.maven.doxia.linkcheck;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.maven.doxia.linkcheck.validation.FileLinkValidator;
+import org.apache.maven.doxia.linkcheck.validation.LinkValidatorManager;
+import org.apache.maven.doxia.linkcheck.validation.MailtoLinkValidator;
+import org.apache.maven.doxia.linkcheck.validation.OfflineHTTPLinkValidator;
+import org.apache.maven.doxia.linkcheck.validation.OnlineHTTPLinkValidator;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * The main bean to be called whenever a set of documents should have their links checked.
+ * 
+ * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
+ * @version $Id$
+ */
+public final class LinkCheck
+{
+    /** Log. */
+    private static final Log LOG = LogFactory.getLog( LinkCheck.class );
+
+    /** The vm line separator. */
+    public static final String EOL = System.getProperty( "line.separator" );
+
+    /** FilenameFilter. */
+    private static final FilenameFilter CUSTOM_FF = new LinkCheck.CustomFilenameFilter();
+
+    /** One MegaByte. */
+    private static final long MEG = 1024 * 1024;
+
+    /** basedir. */
+    private File basedir;
+
+    /** cache. */
+    private String cache;
+
+    /** excludes. */
+    private String[] excludes = null;
+
+    /** method. */
+    private String method;
+
+    /** filesToCheck. */
+    private List filesToCheck = null;
+
+    /** LinkValidatorManager. */
+    private LinkValidatorManager lvm = null;
+
+    /** online mode. */
+    private boolean online;
+
+    /** Output file for xml document. */
+    private File output;
+
+    /** Output encoding for the xml document. */
+    private String outputEncoding;
+
+    /**
+     * Whether links are checked in online mode.
+     *
+     * @return online
+     */
+    public boolean isOnline()
+    {
+        return this.online;
+    }
+
+    /**
+     * Set the online mode.
+     *
+     * @param onLine online mode.
+     */
+    public void setOnline( boolean onLine )
+    {
+        this.online = onLine;
+    }
+
+
+    /**
+     * Get the base directory for the change log generator.
+     *
+     * @return the base directory
+     */
+    public File getBasedir()
+    {
+        return this.basedir;
+    }
+
+    /**
+     * Set the base directory for the change log generator.
+     *
+     * @param base the base directory
+     */
+    public void setBasedir( File base )
+    {
+        this.basedir = base;
+    }
+
+    /**
+     * Returns the cacheFile.
+     *
+     * @return String
+     */
+    public String getCache()
+    {
+        return this.cache;
+    }
+
+    /**
+     * Sets the cacheFile.
+     *
+     * @param cacheFile The cacheFile to set
+     */
+    public void setCache( String cacheFile )
+    {
+        this.cache = cacheFile;
+    }
+
+    /**
+     * Returns the excludes.
+     *
+     * @return String[]
+     */
+    public String[] getExcludes()
+    {
+        return this.excludes;
+    }
+
+    /**
+     * Sets the excludes, a String[] with exclude locations.
+     *
+     * @param excl The excludes to set
+     */
+    public void setExcludes( String[] excl )
+    {
+        this.excludes = excl;
+    }
+
+    /**
+     * The http method to use.
+     *
+     * @return the method
+     */
+    public String getMethod()
+    {
+        return this.method;
+    }
+
+    /**
+     * The http method to use. Currently supported are "get" and "head".
+     * 
+     * @param meth the method to set.
+     */
+    public void setMethod( String meth )
+    {
+        this.method = meth;
+    }
+
+
+    /**
+     * Returns a list of {@link org.apache.maven.doxia.linkcheck.FileToCheck files} that have been checked.
+     * This is only available after {@link #doExecute()} has been called.
+     *
+     * @return the list of files.
+     */
+    public List getFiles()
+    {
+        return this.filesToCheck;
+    }
+
+    /**
+     * Sets the LinkValidatorManager.
+     *
+     * @param validator the LinkValidatorManager to set
+     */
+    public void setLinkValidatorManager( LinkValidatorManager validator )
+    {
+        this.lvm = validator;
+    }
+
+
+    /**
+     * Returns the LinkValidatorManager.
+     * If this hasn't been set before with {@link #setLinkValidatorManager(LinkValidatorManager)}
+     * a default LinkValidatorManager will be returned.
+     *
+     * @return the LinkValidatorManager
+     */
+    public LinkValidatorManager getLinkValidatorManager()
+    {
+        if ( this.lvm == null )
+        {
+            initDefaultLinkValidatorManager();
+        }
+
+        return this.lvm;
+    }
+
+    /**
+     * Intializes the current LinkValidatorManager to a default value.
+     */
+    private void initDefaultLinkValidatorManager()
+    {
+        this.lvm = new LinkValidatorManager();
+
+        if ( this.excludes != null )
+        {
+            this.lvm.setExcludes( excludes );
+        }
+
+        this.lvm.addLinkValidator( new FileLinkValidator() );
+
+        if ( isOnline() )
+        {
+            this.lvm.addLinkValidator( new OnlineHTTPLinkValidator() );
+        }
+        else
+        {
+            this.lvm.addLinkValidator( new OfflineHTTPLinkValidator() );
+        }
+
+        this.lvm.addLinkValidator( new MailtoLinkValidator() );
+    }
+
+    /**
+     * Set the output file for the log.
+     *
+     * @param file the output file.
+     */
+    public void setOutput( File file )
+    {
+        this.output = file;
+    }
+
+    /**
+     * Returns the outputEncoding.
+     *
+     * @return String
+     */
+    public String getOutputEncoding()
+    {
+        return this.outputEncoding;
+    }
+
+    /**
+     * Sets the outputEncoding.
+     *
+     * @param encoding The outputEncoding to set.
+     */
+    public void setOutputEncoding( String encoding )
+    {
+        this.outputEncoding = encoding;
+    }
+
+    /**
+     * Recurses through the given base directory and adds
+     * files to the given list that pass through the current filter.
+     *
+     * @param allFiles the list to fill
+     * @param base the base directory to traverse.
+     */
+    public void findFiles( List allFiles, File base )
+    {
+        File[] f = base.listFiles( CUSTOM_FF );
+
+        if ( f != null )
+        {
+            File file;
+            for ( int i = 0; i < f.length; i++ )
+            {
+                file = f[i];
+
+                if ( file.isDirectory() )
+                {
+                    findFiles( allFiles, file );
+                }
+                else
+                {
+                    if ( LOG.isDebugEnabled() )
+                    {
+                        LOG.debug( " File - " + file );
+                    }
+
+                    allFiles.add( new FileToCheck( this.basedir, file ) );
+
+                    if ( allFiles.size() % 100 == 0 )
+                    {
+                        LOG.info( "Found " + allFiles.size() + " files so far." );
+                    }
+                }
+            }
+
+            file = null;
+        }
+
+        f = null;
+    }
+
+    /**
+     * Execute task.
+     *
+     * @throws IOException if there are problems
+     */
+    public void doExecute() throws IOException
+    {
+        if ( this.output == null )
+        {
+            throw new NullPointerException( "output must be set" );
+        }
+
+        if ( LOG.isDebugEnabled() )
+        {
+            displayMemoryConsumption();
+        }
+
+        LinkValidatorManager validator = getLinkValidatorManager();
+
+        this.filesToCheck = new LinkedList();
+
+        validator.loadCache( this.cache );
+
+        List files = new LinkedList();
+
+        LOG.debug( "Locating all files to be checked..." );
+
+        findFiles( files, this.basedir );
+
+        LOG.debug( "Located all files to be checked." );
+
+        LOG.info( "Found " + files.size() + " files to check." );
+
+        displayMemoryConsumption();
+
+        LOG.info( "Begin to check links in files..." );
+
+        Iterator fileIter = files.iterator();
+
+        FileToCheck flc;
+
+        while ( fileIter.hasNext() )
+        {
+            flc = (FileToCheck) fileIter.next();
+
+            try
+            {
+                this.filesToCheck.add( flc );
+                flc.check( validator );
+            }
+            catch ( Exception e )
+            {
+                LOG.error( "Error while checking : " + flc.getName(), e );
+            }
+        }
+
+        flc = null;
+
+        LOG.info( "Links checked." );
+
+        displayMemoryConsumption();
+
+        createDocument();
+
+        validator.saveCache( this.cache );
+
+        displayMemoryConsumption();
+    }
+
+    /**
+     * Returns an XML representation of the current linkcheck result.
+     *
+     * @return the XML linkcheck result as a string.
+     */
+    public String toXML()
+    {
+        StringBuffer buf = new StringBuffer();
+
+        buf.append( "<linkcheck>" + EOL );
+
+        FileToCheck ftc;
+
+        for ( Iterator iter = getFiles().iterator(); iter.hasNext(); )
+        {
+            ftc = (FileToCheck) iter.next();
+            buf.append( ftc.toXML() );
+        }
+
+        ftc = null;
+
+        buf.append( "</linkcheck>" + EOL );
+
+        return buf.toString();
+    }
+
+    /**
+     * Writes some memory data to the log (if debug enabled).
+     */
+    private void displayMemoryConsumption()
+    {
+        if ( LOG.isDebugEnabled() )
+        {
+            Runtime r = Runtime.getRuntime();
+            LOG.debug( "Memory: " + ( r.totalMemory() - r.freeMemory() ) / MEG + "M/" + r.totalMemory() / MEG
+                            + "M" );
+        }
+    }
+
+    /**
+     * Create the XML document from the currently available details.
+     *
+     * @throws FileNotFoundException
+     *             when the output file previously provided does not exist.
+     * @throws UnsupportedEncodingException
+     *             when the platform doesn't support the current encoding.
+     */
+    private void createDocument() throws FileNotFoundException, UnsupportedEncodingException
+
+    {
+        File dir = this.output.getParentFile();
+
+        if ( dir != null )
+        {
+            dir.mkdirs();
+        }
+
+        PrintWriter out;
+
+        String encoding = getOutputEncoding();
+
+        if ( encoding == null )
+        {
+            OutputStreamWriter osw = new OutputStreamWriter( new FileOutputStream( this.output ) );
+            out = new PrintWriter( osw );
+            encoding = osw.getEncoding();
+        }
+        else
+        {
+            out = new PrintWriter( new OutputStreamWriter( new FileOutputStream( this.output ), encoding ) );
+        }
+
+        StringBuffer buffer = new StringBuffer();
+
+        buffer.append( "<?xml version=\"1.0\" encoding=\"" ).append( encoding ).append( "\" ?>" + EOL );
+
+        out.write( buffer.toString() );
+
+        out.write( toXML() );
+
+        out.close();
+
+        out = null;
+
+        buffer = null;
+
+        dir = null;
+    }
+
+    /** Custom FilenameFilter used to search html files */
+    static class CustomFilenameFilter implements FilenameFilter
+    {
+        /** {@inheritDoc} */
+        public boolean accept( File dir, String name )
+        {
+            File n = new File( dir, name );
+
+            if ( n.isDirectory() )
+            {
+                return true;
+            }
+
+            if ( name.endsWith( ".html" ) || name.endsWith( ".htm" ) )
+            {
+                return true;
+            }
+
+            return false;
+        }
+    }
+
+}

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckResult.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckResult.java?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckResult.java (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckResult.java Sat Aug 25 14:14:27 2007
@@ -0,0 +1,123 @@
+package org.apache.maven.doxia.linkcheck;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.commons.lang.StringEscapeUtils;
+
+/**
+ * An class containing the results of a single check of a link.
+ * 
+ * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
+ * @version $Id$
+ */
+public final class LinkCheckResult
+{
+    /** status. */
+    private String status;
+
+    /** target. */
+    private String target;
+
+    /** errorMessage. */
+    private String errorMessage;
+
+    /**
+     * Returns the status.
+     *
+     * @return String
+     */
+    public String getStatus()
+    {
+        return this.status;
+    }
+
+    /**
+     * Sets the status.
+     *
+     * @param stat The status to set
+     */
+    public void setStatus( String stat )
+    {
+        this.status = stat;
+    }
+
+    /**
+     * Returns the target.
+     *
+     * @return String
+     */
+    public String getTarget()
+    {
+        return this.target;
+    }
+
+    /**
+     * Sets the target.
+     *
+     * @param targ The target to set
+     */
+    public void setTarget( String targ )
+    {
+        this.target = targ;
+    }
+
+    /**
+     * Returns the errorMessage.
+     *
+     * @return the errorMessage.
+     */
+    public String getErrorMessage()
+    {
+        return this.errorMessage;
+    }
+
+    /**
+    
+     * @param message The errorMessage to set.
+     */
+    public void setErrorMessage( String message )
+    {
+        this.errorMessage = message;
+    }
+
+    /**
+     * Creates an XML representation of this link check result
+     *
+     * @return xml fragment representation of this result
+     */
+    public String toXML()
+    {
+        StringBuffer buf = new StringBuffer();
+
+        buf.append( "    <result>" + LinkCheck.EOL );
+
+        buf.append( "      <target>" + StringEscapeUtils.escapeXml( getTarget() ) + "</target>" + LinkCheck.EOL );
+
+        buf.append( "      <status>" + getStatus() + "</status>" + LinkCheck.EOL );
+
+        buf.append( "      <errorMessage>" + StringEscapeUtils.escapeXml( getErrorMessage() ) + "</errorMessage>" + LinkCheck.EOL );
+
+        buf.append( "    </result>" + LinkCheck.EOL );
+
+        return buf.toString();
+    }
+
+}

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckResult.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkMatcher.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkMatcher.java?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkMatcher.java (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkMatcher.java Sat Aug 25 14:14:27 2007
@@ -0,0 +1,126 @@
+package org.apache.maven.doxia.linkcheck;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Link matcher. Reads the contents of a file and tries to match the following: <code>
+ * <a href=""....
+ * <link href=""....
+ * <img src=""....
+ * <script src=""....
+ * </code>
+ *
+ * @author <a href="mailto:mac@apache.org">Ignacio G. Mac Dowell </a>
+ * @version $Id$
+ */
+class LinkMatcher
+{
+
+    /** Regexp for link matching. */
+    private static final Pattern MATCH_PATTERN =
+        Pattern.compile( "<(?>link|a|img|script)[^>]*?(?>href|src)\\s*?=\\s*?[\\\"'](.*?)[\\\"'][^>]*?",
+                         Pattern.CASE_INSENSITIVE );
+
+    /** No need to create a new object each time a file is processed. Just clear it. */
+    private static final Set LINK_LIST = new TreeSet();
+
+    /**
+     * Reads a file and returns a StringBuffer with its contents.
+     *
+     * TODO: Check for encoding issues
+     *
+     * TODO: Better exception handling?
+     *
+     * @param file the file we are reading
+     * @return a StringBuffer with file's contents.
+     * @throws IOException if something goes wrong.
+     */
+    private static StringBuffer fileToStringBuffer( File file ) throws IOException
+    {
+        BufferedReader reader = null;
+
+        final StringBuffer pageBuffer = new StringBuffer();
+
+        try
+        {
+            reader = new BufferedReader( new FileReader( file ) );
+
+            String line;
+
+            while ( ( line = reader.readLine() ) != null )
+            {
+                pageBuffer.append( line );
+            }
+        }
+        finally
+        {
+            reader.close();
+        }
+
+        return pageBuffer;
+    }
+
+    /**
+     * Performs the actual matching.
+     *
+     * @param file the file to check
+     * @return a set with all links to check
+     * @throws IOException if something goes wrong
+     */
+    static Set match( File file ) throws IOException
+    {
+        LINK_LIST.clear();
+
+        final Matcher m = MATCH_PATTERN.matcher( fileToStringBuffer( file ) );
+
+        String link;
+
+        while ( m.find() )
+        {
+            link = m.group( 1 ).trim();
+
+            if ( link.length() < 1 )
+            {
+                continue;
+            }
+            else if ( link.toLowerCase().indexOf( "javascript" ) != -1 )
+            {
+                continue;
+            }
+            // else if (link.toLowerCase().indexOf("mailto:") != -1) {
+            // continue;
+            // }
+
+            LINK_LIST.add( link );
+        }
+
+        return LINK_LIST;
+    }
+
+}

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkMatcher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkMatcher.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/FileLinkValidator.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/FileLinkValidator.java?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/FileLinkValidator.java (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/FileLinkValidator.java Sat Aug 25 14:14:27 2007
@@ -0,0 +1,98 @@
+package org.apache.maven.doxia.linkcheck.validation;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 java.io.File;
+
+/**
+ * A link validator solely for files on the local filesystem.
+ *
+ * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
+ * @version $Id$
+ */
+public final class FileLinkValidator implements LinkValidator
+{
+    /** {@inheritDoc} */
+    public LinkValidationResult validateLink( LinkValidationItem lvi )
+    {
+        File f = getFile( lvi );
+
+        if ( f.exists() )
+        {
+            return new LinkValidationResult( LinkValidationResult.VALID, false, "" );
+        }
+        else
+        {
+            return new LinkValidationResult( LinkValidationResult.ERROR, false, "doesn't exist." );
+        }
+    }
+
+    /** {@inheritDoc} */
+    public Object getResourceKey( LinkValidationItem lvi )
+    {
+        String link = lvi.getLink();
+
+        // If we find an http(s) link or a mail link, it's not good
+        if ( link.startsWith( "http://" ) || link.startsWith( "https://" ) || link.indexOf( '@' ) != -1 )
+        {
+            return null;
+        }
+
+        return getFile( lvi ).getAbsolutePath();
+    }
+
+    /**
+     * Returns the link of the given LinkValidationItem as a File.
+     *
+     * @param lvi The LinkValidationItem.
+     * @return File the link as a File.
+     */
+    protected File getFile( LinkValidationItem lvi )
+    {
+        String link = lvi.getLink();
+
+        if ( link.indexOf( '#' ) != -1 )
+        {
+            link = link.substring( 0, link.indexOf( '#' ) );
+
+            // If the link was just #fred or similar, then the file is the file it came from
+            // XXX: Theoretically we could even validate the anchor tag?
+            if ( link.trim().length() == 0 )
+            {
+                return lvi.getSource();
+            }
+        }
+        if ( link.indexOf( '?' ) != -1 )
+        {
+            link = link.substring( 0, link.indexOf( '?' ) );
+
+            // If the link was just ?param=something or similar, then the file is the file it came from
+            // XXX: Theoretically we could even validate the anchor tag?
+            if ( link.trim().length() == 0 )
+            {
+                return lvi.getSource();
+            }
+        }
+
+        return new File( lvi.getSource().getParentFile(), link );
+    }
+
+}

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/FileLinkValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/FileLinkValidator.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/HTTPLinkValidator.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/HTTPLinkValidator.java?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/HTTPLinkValidator.java (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/HTTPLinkValidator.java Sat Aug 25 14:14:27 2007
@@ -0,0 +1,51 @@
+package org.apache.maven.doxia.linkcheck.validation;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * Checks links which are normal URLs
+ *
+ * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
+ * @version $Id$
+ */
+public abstract class HTTPLinkValidator implements LinkValidator
+{
+    /** {@inheritDoc} */
+    public Object getResourceKey( LinkValidationItem lvi )
+    {
+        String link = lvi.getLink();
+
+        if ( !link.startsWith( "http://" ) && !link.startsWith( "https://" ) )
+        {
+            return null;
+        }
+
+        int hashPos = link.indexOf( "#" );
+
+        if ( hashPos != -1 )
+        {
+            link = link.substring( 0, hashPos );
+        }
+
+        return link;
+    }
+
+}

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/HTTPLinkValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/HTTPLinkValidator.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationItem.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationItem.java?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationItem.java (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationItem.java Sat Aug 25 14:14:27 2007
@@ -0,0 +1,103 @@
+package org.apache.maven.doxia.linkcheck.validation;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 java.io.File;
+
+/**
+ * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
+ * @version $Id$
+ */
+public class LinkValidationItem
+{
+    /** The source. */
+    private final File source;
+
+    /** The link. */
+    private final String link;
+
+    /**
+     * Constructor: initializes the source and link.
+     *
+     * @param src The source, cannot be null.
+     * @param lnk The link, cannot be null.
+     */
+    public LinkValidationItem( File src, String lnk )
+    {
+        if ( src == null )
+        {
+            throw new NullPointerException( "source can't be null" );
+        }
+
+        if ( lnk == null )
+        {
+            throw new NullPointerException( "link can't be null" );
+        }
+
+        this.source = src;
+        this.link = lnk;
+    }
+
+    /**
+     * Returns the link.
+     *
+     * @return String
+     */
+    public String getLink()
+    {
+        return this.link;
+    }
+
+    /**
+     * Returns the source.
+     *
+     * @return File
+     */
+    public File getSource()
+    {
+        return this.source;
+    }
+
+    /** {@inheritDoc} */
+    public boolean equals( Object obj )
+    {
+        LinkValidationItem lvi = (LinkValidationItem) obj;
+
+        if ( !lvi.link.equals( this.link ) )
+        {
+            return false;
+        }
+
+        if ( !lvi.source.equals( this.source ) )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    public int hashCode()
+    {
+        return this.source.hashCode() ^ this.link.hashCode();
+    }
+
+}

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationItem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationItem.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationResult.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationResult.java?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationResult.java (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationResult.java Sat Aug 25 14:14:27 2007
@@ -0,0 +1,115 @@
+package org.apache.maven.doxia.linkcheck.validation;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 java.io.Serializable;
+
+/**
+ * <p>
+ * This class is used to return status responses from the validation handlers. A persistent result means that it can be
+ * stored in the persistent cache and used across runs.
+ * </p>
+ * 
+ * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
+ * @version $Id$
+ */
+public class LinkValidationResult implements Serializable
+{
+    /** serialVersionUID. */
+    private static final long serialVersionUID = -8346824125135406813L;
+
+    /** Validation result: not mine. */
+    public static final int NOTMINE = 0;
+
+    /** Validation result: error. */
+    public static final int ERROR = 1;
+
+    /** Validation result: valid. */
+    public static final int VALID = 2;
+
+    /** Validation result: unknown. */
+    public static final int UNKNOWN = 3;
+
+    /** Validation result: warning. */
+    public static final int WARNING = 4;
+
+    /** The persistent property. */
+    private final boolean persistent;
+
+    /** The status. */
+    private final int status;
+
+    /** The error message. */
+    private final String errorMessage;
+
+    /**
+     * Returns the persistent property.
+     *
+     * @return boolean
+     */
+    public boolean isPersistent()
+    {
+        return this.persistent;
+    }
+
+    /**
+     * Returns the status.
+     *
+     * @return int
+     */
+    public int getStatus()
+    {
+        return this.status;
+    }
+
+    /**
+     * Returns the errorMessage.
+     *
+     * @return the errorMessage.
+     */
+    public String getErrorMessage()
+    {
+        return this.errorMessage;
+    }
+
+    /**
+     * Constructor: initializes status, persistent and errorMessage.
+     *
+     * @param stat The status.
+     * @param pers The persistent.
+     * @param message The errorMessage.
+     */
+    public LinkValidationResult( int stat, boolean pers, String message )
+    {
+        this.status = stat;
+
+        this.persistent = pers;
+
+        this.errorMessage = message;
+    }
+
+    /** {@inheritDoc} */
+    public String toString()
+    {
+        return this.persistent + "/" + this.status + "/" + this.errorMessage;
+    }
+
+}

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidationResult.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidator.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidator.java?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidator.java (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidator.java Sat Aug 25 14:14:27 2007
@@ -0,0 +1,46 @@
+package org.apache.maven.doxia.linkcheck.validation;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
+ * @version $Id$
+ */
+public interface LinkValidator
+{
+    /**
+     * If getResourceKey(lvi) returned null, this will NOT be called.
+     *
+     * @param lvi The LinkValidationItem to validate.
+     * @return The LinkValidationResult.
+     * @throws Exception if something goes wrong.
+     */
+    LinkValidationResult validateLink( LinkValidationItem lvi ) throws Exception;
+
+    /**
+     * The resource key is used by the cache to determine if it really needs to validate the link. No actual validation
+     * should be done at this point.
+     *
+     * @param lvi The LinkValidationItem to validate.
+     * @return Object null if this validator should not be doing this work.
+     */
+    Object getResourceKey( LinkValidationItem lvi );
+}

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidator.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidatorManager.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidatorManager.java?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidatorManager.java (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidatorManager.java Sat Aug 25 14:14:27 2007
@@ -0,0 +1,323 @@
+package org.apache.maven.doxia.linkcheck.validation;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InvalidClassException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
+ * @version $Id$
+ */
+
+public class LinkValidatorManager implements Serializable
+{
+    /** serialVersionUID. */
+    private static final long serialVersionUID = 2467928182206500945L;
+
+    /** Log for debug output. */
+    private static final Log LOG = LogFactory.getLog( LinkValidatorManager.class );
+
+    /** validators. */
+    private List validators = new LinkedList();
+
+    /** excludes. */
+    private String[] excludes = new String[0];
+
+    /** cache. */
+    private Map cache = new HashMap();
+
+    /**
+     * Returns the list of validators.
+     *
+     * @return List
+     */
+    public List getValidators()
+    {
+        return this.validators;
+    }
+
+    /**
+     * Returns the excludes.
+     *
+     * @return String[]
+     */
+    public String[] getExcludes()
+    {
+        return this.excludes;
+    }
+
+    /**
+     * Sets the excludes.
+     *
+     * @param excl The excludes to set.
+     */
+    public void setExcludes( String[] excl )
+    {
+        this.excludes = excl;
+    }
+
+    /**
+     * Adds a LinkValidator to this manager.
+     *
+     * @param lv The LinkValidator to add.
+     */
+    public void addLinkValidator( LinkValidator lv )
+    {
+        this.validators.add( lv );
+    }
+
+    /**
+     * Validates the links of the given LinkValidationItem.
+     *
+     * @param lvi The LinkValidationItem to validate.
+     * @return A LinkValidationResult.
+     * @throws Exception if something goes wrong.
+     */
+    public LinkValidationResult validateLink( LinkValidationItem lvi ) throws Exception
+    {
+        {
+            LinkValidationResult status = getCachedResult( lvi );
+
+            if ( status != null )
+            {
+                return status;
+            }
+        }
+
+        for ( int i = 0; i < this.excludes.length; i++ )
+        {
+            if ( this.excludes[i] != null && lvi.getLink().startsWith( this.excludes[i] ) )
+            {
+                if ( LOG.isDebugEnabled() )
+                {
+                    LOG.debug( "Excluded " + lvi.getLink() );
+                }
+
+                return new LinkValidationResult( LinkValidationResult.VALID, false, "" );
+            }
+        }
+
+        Iterator iter = this.validators.iterator();
+
+        LinkValidator lv;
+
+        Object resourceKey;
+
+        LinkValidationResult lvr;
+
+        while ( iter.hasNext() )
+        {
+            lv = (LinkValidator) iter.next();
+
+            resourceKey = lv.getResourceKey( lvi );
+
+            if ( resourceKey != null )
+            {
+                if ( LOG.isDebugEnabled() )
+                {
+                    LOG.debug( lv.getClass().getName() + " - Checking link " + lvi.getLink() );
+                }
+
+                lvr = lv.validateLink( lvi );
+
+                if ( lvr.getStatus() == LinkValidationResult.NOTMINE )
+                {
+                    continue;
+                }
+
+                setCachedResult( resourceKey, lvr );
+
+                return lvr;
+            }
+        }
+
+        lv = null;
+
+        resourceKey = null;
+
+        lvr = null;
+
+        LOG.error( "Unable to validate link : " + lvi.getLink() );
+
+        return new LinkValidationResult( LinkValidationResult.UNKNOWN, false, "No validator found for this link" );
+    }
+
+    /**
+     * Loads a cache file.
+     *
+     * @param cacheFilename The name of the cache file.
+     */
+    public void loadCache( String cacheFilename )
+    {
+        try
+        {
+            File f = new File( cacheFilename );
+
+            if ( f.exists() )
+            {
+                ObjectInputStream is = new ObjectInputStream( new FileInputStream( cacheFilename ) );
+
+                this.cache = (Map) is.readObject();
+
+                is.close();
+            }
+        }
+        catch ( InvalidClassException e )
+        {
+            LOG.warn( "Your cache is incompatible with this new release of linkcheck. It will be recreated." );
+        }
+        catch ( Throwable t )
+        {
+            LOG.error( "Unable to load the cache: " + cacheFilename, t );
+        }
+    }
+
+    /**
+     * Saves a cache file.
+     *
+     * @param cacheFilename The name of the cache file.
+     */
+    public void saveCache( String cacheFilename )
+    {
+        try
+        {
+            // Remove non-persistent items from cache
+            Map persistentCache = new HashMap();
+
+            Iterator iter = this.cache.keySet().iterator();
+
+            Object resourceKey;
+
+            while ( iter.hasNext() )
+            {
+                resourceKey = iter.next();
+
+                if ( ( (LinkValidationResult) this.cache.get( resourceKey ) ).isPersistent() )
+                {
+                    persistentCache.put( resourceKey, this.cache.get( resourceKey ) );
+
+                    if ( LOG.isDebugEnabled() )
+                    {
+                        LOG.debug( "[" + resourceKey + "] with result [" + this.cache.get( resourceKey )
+                                        + "] is stored in the cache." );
+                    }
+                }
+            }
+
+            File cacheFile = new File( cacheFilename );
+
+            File dir = cacheFile.getParentFile();
+
+            if ( dir != null )
+            {
+                dir.mkdirs();
+            }
+
+            ObjectOutputStream os = new ObjectOutputStream( new FileOutputStream( cacheFilename ) );
+
+            os.writeObject( persistentCache );
+
+            os.close();
+
+            persistentCache = null;
+
+            iter = null;
+
+            resourceKey = null;
+
+            cacheFile = null;
+
+            dir = null;
+
+            os = null;
+        }
+        catch ( Throwable t )
+        {
+            LOG.error( "Unable to save the cache: " + cacheFilename, t );
+        }
+    }
+
+    /**
+     * Returns a LinkValidationResult for the given LinkValidationItem
+     * if it has been cached from a previous run, returns null otherwise.
+     *
+     * @param lvi The LinkValidationItem.
+     * @return LinkValidationResult
+     */
+    public LinkValidationResult getCachedResult( LinkValidationItem lvi )
+    {
+        Iterator iter = getValidators().iterator();
+
+        LinkValidator lv;
+
+        Object resourceKey;
+
+        while ( iter.hasNext() )
+        {
+            lv = (LinkValidator) iter.next();
+
+            resourceKey = lv.getResourceKey( lvi );
+
+            if ( resourceKey != null && this.cache.containsKey( resourceKey ) )
+            {
+                if ( LOG.isDebugEnabled() )
+                {
+                    LOG.debug( "The cache returns for [" + resourceKey + "] the result ["
+                                            + this.cache.get( resourceKey ) + "]." );
+                }
+
+                return (LinkValidationResult) this.cache.get( resourceKey );
+            }
+        }
+
+        lv = null;
+
+        resourceKey = null;
+
+        return null;
+    }
+
+    /**
+     * Puts the given LinkValidationResult into the cache.
+     *
+     * @param resourceKey The key to retrieve the result.
+     * @param lvr the LinkValidationResult to cache.
+     */
+    public void setCachedResult( Object resourceKey, LinkValidationResult lvr )
+    {
+        this.cache.put( resourceKey, lvr );
+    }
+}

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidatorManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidatorManager.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/MailtoLinkValidator.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/MailtoLinkValidator.java?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/MailtoLinkValidator.java (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/MailtoLinkValidator.java Sat Aug 25 14:14:27 2007
@@ -0,0 +1,53 @@
+package org.apache.maven.doxia.linkcheck.validation;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * Validates mailto links
+ *
+ * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
+ * @version $Id$
+ */
+public final class MailtoLinkValidator implements LinkValidator
+{
+    /** The (unique) LinkValidationResult to be returned by this LinkValidator. */
+    private static final LinkValidationResult LVR = new LinkValidationResult( LinkValidationResult.VALID, false, "" );
+
+    /** {@inheritDoc} */
+    public LinkValidationResult validateLink( LinkValidationItem lvi ) throws Exception
+    {
+        return LVR;
+    }
+
+    /** {@inheritDoc} */
+    public Object getResourceKey( LinkValidationItem lvi )
+    {
+        if ( lvi.getLink().indexOf( '@' ) != -1 )
+        {
+            return lvi.getLink();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+}

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/MailtoLinkValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/MailtoLinkValidator.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OfflineHTTPLinkValidator.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OfflineHTTPLinkValidator.java?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OfflineHTTPLinkValidator.java (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OfflineHTTPLinkValidator.java Sat Aug 25 14:14:27 2007
@@ -0,0 +1,37 @@
+package org.apache.maven.doxia.linkcheck.validation;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * Fake links check when maven is offline
+ *
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
+ * @version $Id$
+ */
+public final class OfflineHTTPLinkValidator extends HTTPLinkValidator
+{
+
+    /** {@inheritDoc} */
+    public LinkValidationResult validateLink( LinkValidationItem lvi )
+    {
+        return new LinkValidationResult( LinkValidationResult.WARNING, false, "Maven is offline. Link not checked." );
+    }
+
+}

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OfflineHTTPLinkValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OfflineHTTPLinkValidator.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OnlineHTTPLinkValidator.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OnlineHTTPLinkValidator.java?rev=569735&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OnlineHTTPLinkValidator.java (added)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OnlineHTTPLinkValidator.java Sat Aug 25 14:14:27 2007
@@ -0,0 +1,416 @@
+package org.apache.maven.doxia.linkcheck.validation;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 java.io.IOException;
+
+import java.net.URL;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.NTCredentials;
+import org.apache.commons.httpclient.StatusLine;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+/**
+ * Checks links which are normal URLs
+ *
+ * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
+ * @version $Id$
+ */
+public final class OnlineHTTPLinkValidator extends HTTPLinkValidator
+{
+    /** Log for debug output. */
+    private static final Log LOG = LogFactory.getLog( OnlineHTTPLinkValidator.class );
+
+    /** The maximum number of redirections for a link. */
+    private static final int MAX_NB_REDIRECT = 10;
+
+    /** Use the get method to test pages. */
+    private static final String GET_METHOD = "get";
+
+    /** Use the head method to test pages. */
+    private static final String HEAD_METHOD = "head";
+
+    /** The proxy host. */
+    private String proxyHost;
+
+    /** The proxy port. */
+    private int proxyPort;
+
+    /** The proxy user. */
+    private String proxyUser;
+
+    /** The proxy pass. */
+    private String proxyPass;
+
+    /** The proxy NtlmHost. */
+    private String proxyNtlmHost;
+
+    /** The proxy NtlmDomain. */
+    private String proxyNtlmDomain;
+
+    /** The http method to use. */
+    private String method = HEAD_METHOD;
+
+    /** The HttpClient. */
+    private transient HttpClient cl;
+
+    /**
+     * Constructor: initialize settings, use "head" method.
+     */
+    public OnlineHTTPLinkValidator()
+    {
+        this( HEAD_METHOD );
+    }
+
+    /**
+     * Constructor: initialize settings.
+     *
+     * @param meth The http method to use. Should be one of "head" or "get".
+     */
+    public OnlineHTTPLinkValidator( String meth )
+    {
+        this( meth, null, null, null, null, null, null );
+    }
+
+    /**
+     * Constructor: initialize settings.
+     *
+     * @param meth The http method to use. Should be one of "head" or "get".
+     * @param pHost The proxy host.
+     * @param pPort The proxy port.
+     * @param pUser The proxy user.
+     * @param pPass The proxy pass.
+     * @param pNtlmHost The proxy NtlmHost.
+     * @param pNtlmDomain The proxy NtlmDomain.
+     */
+    public OnlineHTTPLinkValidator( String meth, String pHost, String pPort, String pUser,
+                                    String pPass, String pNtlmHost, String pNtlmDomain )
+    {
+        if ( LOG.isDebugEnabled() )
+        {
+            LOG.debug( "Will use method : [" + meth + "]" );
+        }
+
+        this.method = meth;
+
+        if ( pHost == null || pHost.trim().equals( "" ) )
+        {
+            this.proxyHost = null;
+        }
+        else
+        {
+            this.proxyHost = pHost;
+
+            if ( pPort != null )
+            {
+                try
+                {
+                    this.proxyPort = Integer.parseInt( pPort );
+                }
+                catch ( NumberFormatException e )
+                {
+                    LOG.warn( "Invalid number for Proxy Port:" + pPort );
+                    LOG.warn( "Proxy Port won't be used." );
+                    this.proxyPort = -1;
+                }
+            }
+
+            this.proxyUser = pUser;
+
+            this.proxyPass = pPass;
+
+            if ( pNtlmHost != null && !pNtlmHost.trim().equals( "" ) )
+            {
+                this.proxyNtlmHost = pNtlmHost;
+                this.proxyNtlmDomain = pNtlmDomain;
+            }
+
+        }
+
+        initHttpClient();
+    }
+
+    /** {@inheritDoc} */
+    public LinkValidationResult validateLink( LinkValidationItem lvi )
+    {
+        if ( this.cl == null )
+        {
+            initHttpClient();
+        }
+
+        try
+        {
+            String link = lvi.getLink();
+
+            HttpMethod hm = null;
+
+            try
+            {
+                hm = checkLink( link, 0 );
+            }
+            catch ( Throwable t )
+            {
+                if ( LOG.isDebugEnabled() )
+                {
+                    LOG.error( "Received: [" + t + "] for [" + lvi.getLink() + "] in page [" + lvi.getSource() + "]", t );
+                }
+                else
+                {
+                    LOG.error( "Received: [" + t + "] for [" + lvi.getLink() + "] in page [" + lvi.getSource() + "]" );
+                }
+
+                return new LinkValidationResult( LinkValidationResult.ERROR, false, t.getClass().getName() + " : "
+                                + t.getMessage() );
+            }
+
+            if ( hm == null )
+            {
+                return new LinkValidationResult( LinkValidationResult.ERROR, false, "Cannot retreive HTTP Status" );
+            }
+
+            if ( hm.getStatusCode() == HttpStatus.SC_OK )
+            {
+                return new LinkValidationResult( LinkValidationResult.VALID, true, hm.getStatusCode() + " "
+                                + hm.getStatusText() );
+            }
+            else
+            {
+                // If there's a redirection ... add a warning
+                if ( hm.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY
+                                || hm.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY
+                                || hm.getStatusCode() == HttpStatus.SC_TEMPORARY_REDIRECT )
+                {
+                    LOG.warn( "Received: [" + hm.getStatusCode() + "] for [" + lvi.getLink() + "] in page ["
+                                    + lvi.getSource() + "]" );
+
+                    return new LinkValidationResult( LinkValidationResult.WARNING, true, hm.getStatusCode() + " "
+                                    + hm.getStatusText() );
+                }
+                else
+                {
+                    LOG.error( "Received: [" + hm.getStatusCode() + "] for [" + lvi.getLink() + "] in page ["
+                                    + lvi.getSource() + "]" );
+
+                    return new LinkValidationResult( LinkValidationResult.ERROR, false, hm.getStatusCode() + " "
+                                    + hm.getStatusText() );
+                }
+            }
+
+        }
+        catch ( Throwable t )
+        {
+            if ( LOG.isDebugEnabled() )
+            {
+                LOG.error( "Received: [" + t + "] for [" + lvi.getLink() + "] in page [" + lvi.getSource() + "]", t );
+            }
+            else
+            {
+                LOG.error( "Received: [" + t + "] for [" + lvi.getLink() + "] in page [" + lvi.getSource() + "]" );
+            }
+
+            return new LinkValidationResult( LinkValidationResult.ERROR, false, t.getMessage() );
+        }
+    }
+
+    /** Initialize the HttpClient. */
+    private void initHttpClient()
+    {
+        LOG.debug( "A new HttpClient instance is needed ..." );
+
+        // Some web servers don't allow the default user-agent sent by httpClient
+        System.setProperty( "httpclient.useragent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" );
+
+        this.cl = new HttpClient( new MultiThreadedHttpConnectionManager() );
+
+        HostConfiguration hc = new HostConfiguration();
+
+        HttpState state = new HttpState();
+
+        if ( this.proxyHost != null )
+        {
+            hc.setProxy( this.proxyHost, this.proxyPort );
+
+            if ( LOG.isDebugEnabled() )
+            {
+                LOG.debug( "Proxy Host:" + this.proxyHost );
+                LOG.debug( "Proxy Port:" + this.proxyPort );
+            }
+
+            if ( this.proxyUser != null && this.proxyPass != null )
+            {
+                if ( LOG.isDebugEnabled() )
+                {
+                    LOG.debug( "Proxy User:" + this.proxyUser );
+                }
+
+                Credentials credentials;
+
+                if ( this.proxyNtlmHost != null )
+                {
+                    credentials =
+                        new NTCredentials( this.proxyUser, this.proxyPass, this.proxyNtlmHost, this.proxyNtlmDomain );
+                }
+                else
+                {
+                    credentials = new UsernamePasswordCredentials( this.proxyUser, this.proxyPass );
+                }
+
+                state.setProxyCredentials( null, null, credentials );
+            }
+
+        }
+        else
+        {
+            LOG.debug( "Not using a proxy" );
+        }
+
+        this.cl.setHostConfiguration( hc );
+
+        this.cl.setState( state );
+
+        LOG.debug( "New HttpClient instance created." );
+    }
+
+    /**
+     * Checks the given link.
+     *
+     * @param link the link to check.
+     * @param nbRedirect the number of current redirects.
+     * @return HttpMethod
+     * @throws IOException if something goes wrong.
+     */
+    private HttpMethod checkLink( String link, int nbRedirect )
+        throws IOException
+    {
+        if ( nbRedirect > MAX_NB_REDIRECT )
+        {
+            throw new HttpException( "Maximum number of redirections (" + MAX_NB_REDIRECT + ") exceeded" );
+        }
+
+        HttpMethod hm;
+
+        if ( HEAD_METHOD.equals( this.method ) )
+        {
+            hm = new HeadMethod( link );
+        }
+        else if ( GET_METHOD.equals( this.method ) )
+        {
+            hm = new GetMethod( link );
+        }
+        else
+        {
+            LOG.error( "Unsupported method: " + method + ", using 'get'." );
+            hm = new GetMethod( link );
+        }
+
+        try
+        {
+            // We want to do it manually
+            hm.setFollowRedirects( false );
+
+            URL url = new URL( link );
+
+            cl.getHostConfiguration().setHost( url.getHost(), url.getPort(), url.getProtocol() );
+
+            cl.executeMethod( hm );
+
+            StatusLine sl = hm.getStatusLine();
+
+            if ( sl == null )
+            {
+                LOG.error( "Unknown error validating link : " + link );
+                return null;
+            }
+
+            if ( hm.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY
+                            || hm.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY
+                            || hm.getStatusCode() == HttpStatus.SC_TEMPORARY_REDIRECT )
+            {
+                Header locationHeader = hm.getResponseHeader( "location" );
+
+                if ( locationHeader == null )
+                {
+                    LOG.error( "Site sent redirect, but did not set Location header" );
+                    return hm;
+                }
+                else
+                {
+                    String newLink = locationHeader.getValue();
+
+                    // Be careful to absolute/relative links
+                    if ( !newLink.startsWith( "http://" ) && !newLink.startsWith( "https://" ) )
+                    {
+                        if ( newLink.startsWith( "/" ) )
+                        {
+                            URL oldUrl = new URL( link );
+
+                            newLink =
+                                oldUrl.getProtocol() + "://" + oldUrl.getHost()
+                                                + ( oldUrl.getPort() > 0 ? ":" + oldUrl.getPort() : "" ) + newLink;
+                        }
+                        else
+                        {
+                            newLink = link + newLink;
+                        }
+                    }
+
+                    HttpMethod oldHm = hm;
+
+                    LOG.info( "[" + link + "] is redirected to [" + newLink + "]" );
+
+                    oldHm.releaseConnection();
+
+                    hm = checkLink( newLink, nbRedirect + 1 );
+
+                    // Restore the hm to "Moved permanently" | "Moved temporarily" | "Temporary redirect"
+                    // if the new location is found to allow us to report it
+                    if ( hm.getStatusCode() == HttpStatus.SC_OK && nbRedirect == 0 )
+                    {
+                        return oldHm;
+                    }
+                }
+            }
+
+        }
+        finally
+        {
+            hm.releaseConnection();
+        }
+
+        return hm;
+    }
+
+}

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OnlineHTTPLinkValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/OnlineHTTPLinkValidator.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message