You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@creadur.apache.org by jo...@apache.org on 2008/05/12 22:12:49 UTC

svn commit: r655625 [2/8] - in /incubator/rat/main/trunk/rat: ./ rat-anttasks/ rat-anttasks/src/ rat-anttasks/src/main/ rat-anttasks/src/main/java/ rat-anttasks/src/main/java/org/ rat-anttasks/src/main/java/org/apache/ rat-anttasks/src/main/java/org/ap...

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/ReportTransformer.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/ReportTransformer.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/ReportTransformer.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/ReportTransformer.java Mon May 12 13:12:44 2008
@@ -0,0 +1,67 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.Writer;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+
+class ReportTransformer implements Runnable {
+
+    private final Writer out;
+    private final Transformer transformer;
+    private final Reader in;
+    
+    public ReportTransformer(final Writer out, final Reader style, 
+            final Reader in) throws TransformerConfigurationException {
+        this.out = out;
+        transformer = TransformerFactory.newInstance().newTransformer(
+                new StreamSource(style));
+        this.in = in;
+    }
+    
+    public ReportTransformer(final Writer out, final InputStream style, 
+            final Reader in) throws TransformerConfigurationException {
+        this.out = out;
+        transformer = TransformerFactory.newInstance().newTransformer(
+                new StreamSource(style));
+        this.in = in;
+    }
+    
+    public void run() {
+        try {
+            transform();
+        } catch (TransformerException e) {
+            throw new ReportFailedRuntimeException(e.getMessage(), e);
+        }
+    }
+
+    public void transform() throws TransformerException {
+        transformer.transform(new StreamSource(in), new StreamResult(out));
+    }
+
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/Claims.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/Claims.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/Claims.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/Claims.java Mon May 12 13:12:44 2008
@@ -0,0 +1,70 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.analysis;
+
+import org.apache.rat.report.RatReportFailedException;
+import org.apache.rat.report.claim.IClaimReporter;
+
+public class Claims {
+
+    public static final String LICENSE_APPROVAL_PREDICATE = "license-approval";
+    public static final String LICENSE_FAMILY_PREDICATE = "license-family";
+    public static final String HEADER_SAMPLE_PREDICATE = "header-sample";
+    public static final String HEADER_TYPE_PREDICATE = "header-type";
+    
+    public static void reportHeaderSampleClaim(final String sample, final String subject, IClaimReporter reporter) throws RatReportFailedException {
+        reporter.claim(subject, HEADER_SAMPLE_PREDICATE, sample, true);
+    }
+    
+    public static void reportGeneratedHeaderTypeClaim(final String subject, IClaimReporter reporter) throws RatReportFailedException {
+        reportHeaderTypeClaim("GEN  ", subject, reporter);
+    }
+    
+    public static void reportHeaderTypeClaim(final String type, final String subject, IClaimReporter reporter) throws RatReportFailedException {
+        reporter.claim(subject, HEADER_TYPE_PREDICATE, type, false);
+    }
+    
+    public static void reportGeneratedClaims(final String subject, final String notes, final IClaimReporter reporter) throws RatReportFailedException {
+        Claims.reportHeaderSampleClaim(notes, subject, reporter);
+        Claims.reportGeneratedHeaderTypeClaim(subject, reporter);
+    }
+    
+    public static void reportStandardClaims(final String subject, final String notes, final String code, final String name, final IClaimReporter reporter) throws RatReportFailedException {
+        Claims.reportHeaderTypeClaim(code, subject, reporter);
+        Claims.reportHeaderSampleClaim(notes, subject, reporter);
+
+        reporter.claim(subject, LICENSE_FAMILY_PREDICATE, name, false);
+    }
+    
+    public static void reportLicenseApprovalClaim(final CharSequence subject, final boolean isAcceptable, final IClaimReporter reporter) throws RatReportFailedException {
+        // TODO: replace with more finely grained system
+        final String approvalValue = Boolean.toString(isAcceptable);
+        // TODO: not very readable; 
+        // TODO: replace when license approval factored into separate phase
+        // TODO: probably name='ASF'
+        reporter.claim(subject, LICENSE_APPROVAL_PREDICATE, approvalValue, false);
+    }
+
+    public static final String ASL_CODE = "AL   ";
+    public static final String OASIS_CODE = "OASIS";
+    public static final String W3CD_CODE = "W3CD ";
+    public static final String W3C_CODE = "W3C  ";
+    public static final String DOJO = "DOJO ";
+    public static final String TMF854 = "TMF  ";
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/IHeaderMatcher.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/IHeaderMatcher.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/IHeaderMatcher.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/IHeaderMatcher.java Mon May 12 13:12:44 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.analysis;
+
+import org.apache.rat.report.claim.IClaimReporter;
+
+/**
+ * Matches text headers to known licenses.
+ *
+ */
+public interface IHeaderMatcher {
+
+	/**
+	 * Resets this matches.
+	 * Subsequent calls to {@link #match} will accumulate new text.
+	 */
+	public void reset();
+	
+	/**
+	 * Matches the text accumulated to licenses.
+     * TODO probably a poor design choice - hope to fix later
+	 * @param subject TODO
+	 * @param line next line of text, not null
+	 * @param reporter TODO
+	 * @return TODO
+	 */
+	public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException;
+	
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/RatHeaderAnalysisException.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/RatHeaderAnalysisException.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/RatHeaderAnalysisException.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/RatHeaderAnalysisException.java Mon May 12 13:12:44 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.analysis;
+
+import org.apache.commons.lang.exception.NestableException;
+
+/**
+ * Indicates exceptional condition during header analysis.
+ *
+ */
+public class RatHeaderAnalysisException extends NestableException {
+
+    private static final long serialVersionUID = 7613577476983281387L;
+
+    public RatHeaderAnalysisException() {
+        super();
+    }
+
+    public RatHeaderAnalysisException(String msg, Throwable cause) {
+        super(msg, cause);
+    }
+
+    public RatHeaderAnalysisException(String msg) {
+        super(msg);
+    }
+
+    public RatHeaderAnalysisException(Throwable cause) {
+        super(cause);
+    }
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/generation/GeneratedLicenseNotRequired.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/generation/GeneratedLicenseNotRequired.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/generation/GeneratedLicenseNotRequired.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/generation/GeneratedLicenseNotRequired.java Mon May 12 13:12:44 2008
@@ -0,0 +1,91 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.analysis.generation;
+
+import java.util.regex.Pattern;
+
+import org.apache.rat.analysis.Claims;
+import org.apache.rat.analysis.IHeaderMatcher;
+import org.apache.rat.analysis.RatHeaderAnalysisException;
+import org.apache.rat.report.RatReportFailedException;
+import org.apache.rat.report.claim.IClaimReporter;
+
+public class GeneratedLicenseNotRequired implements IHeaderMatcher {
+
+    private static final Pattern[] DEFAULT_PATTERNS = {Pattern.compile(".*generated by Cayenne.*"),
+        Pattern.compile(".*Generated By:JJTree:.*"),
+        Pattern.compile(".*Generated By:JavaCC:.*"),
+        Pattern.compile(".*THIS FILE IS AUTOMATICALLY GENERATED.*"),
+        Pattern.compile(".*NOTE: this file is autogenerated by XBeans.*"),
+        Pattern.compile(".*This file was automatically generated by .*"),
+        Pattern.compile(".*# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!.*"),
+        Pattern.compile(".*# Microsoft Developer Studio Generated NMAKE File.*"),
+        Pattern.compile(".*# Microsoft Developer Studio Generated Build File.*"),
+        Pattern.compile(".*Generated from configure.ac by autoheader.*"),
+        Pattern.compile(".*generated automatically by aclocal.*"),
+        Pattern.compile(".*build.xml generated by maven from project.xml.*"),
+        Pattern.compile(".*This file was generated by.*"),
+        Pattern.compile(".*This file has been automatically generated..*"),
+        Pattern.compile(".*Automatically generated - do not modify!.*"),
+        Pattern.compile(".*Javadoc style sheet.*"),
+        Pattern.compile(".*SOURCE FILE GENERATATED.*"),
+        Pattern.compile(".*Generated by the Batik.*"),
+        Pattern.compile(".*this file is autogenerated.*"),
+        Pattern.compile(".*This class was autogenerated.*"),
+        Pattern.compile(".*Generated by Maven.*"),
+        Pattern.compile(".*This class was generated by.*")};
+    
+    
+    private final Pattern[] linePatterns;
+    private final int numberOfPatterns;
+    
+    public GeneratedLicenseNotRequired() {
+        this(DEFAULT_PATTERNS);
+    }
+    
+    public GeneratedLicenseNotRequired(final Pattern[] linePatterns) {
+        this.linePatterns = linePatterns;
+        this.numberOfPatterns = linePatterns.length;
+    }
+
+    public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        boolean result = false;
+        for (int i=0;i<numberOfPatterns;i++) {
+            if (linePatterns[i].matcher(line).matches()) {
+                result = true;
+                reportOnLicense(subject, reporter);
+                break;
+            }
+        }
+        return result;
+    }
+
+    private void reportOnLicense(String subject, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        try {
+            Claims.reportGeneratedClaims(subject, "Generated files do not required license headers", reporter);
+        } catch (RatReportFailedException e) {
+            throw new RatHeaderAnalysisException("Cannot write claims", e);
+        }
+    }
+
+    public void reset() {
+        // stateless
+    }
+
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/generation/JavaDocLicenseNotRequired.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/generation/JavaDocLicenseNotRequired.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/generation/JavaDocLicenseNotRequired.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/generation/JavaDocLicenseNotRequired.java Mon May 12 13:12:44 2008
@@ -0,0 +1,58 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.analysis.generation;
+
+import java.util.regex.Pattern;
+
+import org.apache.rat.analysis.Claims;
+import org.apache.rat.analysis.IHeaderMatcher;
+import org.apache.rat.analysis.RatHeaderAnalysisException;
+import org.apache.rat.report.RatReportFailedException;
+import org.apache.rat.report.claim.IClaimReporter;
+
+/**
+ * JavaDocs are generated and so no license is required.
+ * It is useful to not these separately.
+ */
+public class JavaDocLicenseNotRequired implements IHeaderMatcher {
+
+    private static final String JAVADOC_REGEX_DEFN = ".*Generated by javadoc.*";
+    
+    private static final Pattern JAVADOC_REGEX = Pattern.compile(JAVADOC_REGEX_DEFN);
+    
+    public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        boolean result = JAVADOC_REGEX.matcher(line).matches();
+        if (result) {
+            reportOnLicense(subject, reporter);
+        }
+        return result;
+    }
+
+    private void reportOnLicense(String subject, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        try {
+            Claims.reportGeneratedClaims(subject, "JavaDocs are generated and so license header is optional", reporter);
+        } catch (RatReportFailedException e) {
+            throw new RatHeaderAnalysisException("Cannot write claims", e);
+        }
+    }
+    
+    public void reset() {
+        // stateless
+    }
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/ApacheSoftwareLicense20.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/ApacheSoftwareLicense20.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/ApacheSoftwareLicense20.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/ApacheSoftwareLicense20.java Mon May 12 13:12:44 2008
@@ -0,0 +1,56 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.analysis.license;
+
+import org.apache.rat.analysis.Claims;
+import org.apache.rat.analysis.IHeaderMatcher;
+import org.apache.rat.analysis.RatHeaderAnalysisException;
+import org.apache.rat.license.Apache20LicenseFamily;
+import org.apache.rat.report.claim.IClaimReporter;
+
+/**
+ * Matches Apache Software License, Version 2.0
+ *
+ */
+public final class ApacheSoftwareLicense20 extends BaseLicense implements
+		IHeaderMatcher {
+
+	public static final String FIRST_LICENSE_LINE = "Licensed under the Apache License, Version 2.0 (the \"License\")";
+	public static final String LICENSE_REFERENCE_LINE = "http://www.apache.org/licenses/LICENSE-2.0";
+	
+	public ApacheSoftwareLicense20() {
+		super(Claims.ASL_CODE, Apache20LicenseFamily.APACHE_SOFTWARE_LICENSE_NAME, "");
+	}
+	
+	public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        final boolean result = matches(line);
+		if (result) {
+			reportOnLicense(subject, reporter);
+		}
+        return result;
+	}
+
+	boolean matches(String line) {
+		return line.indexOf(FIRST_LICENSE_LINE, 0) >= 0 
+		|| line.indexOf(LICENSE_REFERENCE_LINE, 0) >= 0;
+	}
+	
+	public void reset() {	
+	}
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java Mon May 12 13:12:44 2008
@@ -0,0 +1,62 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.analysis.license;
+
+import org.apache.rat.analysis.Claims;
+import org.apache.rat.analysis.RatHeaderAnalysisException;
+import org.apache.rat.report.RatReportFailedException;
+import org.apache.rat.report.claim.IClaimReporter;
+
+public class BaseLicense {
+	private final String code;
+	private final String name;
+	private final String notes;
+	
+	public BaseLicense(final String code, final String name, final String notes)
+	{
+		this.code = code;
+		this.name = name;
+		this.notes = notes;
+	}
+    
+    public final void reportOnLicense(String subject, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        final String name = getName();
+        final String code = getCode();
+        final String notes = getNotes();
+        try {
+            Claims.reportStandardClaims(subject, notes, code, name, reporter);
+
+        } catch (RatReportFailedException e) {
+            // Cannot recover
+            throw new RatHeaderAnalysisException("Cannot report on license information", e);
+        }
+    }
+
+    public String getCode() {
+		return code;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public String getNotes() {
+		return notes;
+	}
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/DojoLicenseHeader.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/DojoLicenseHeader.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/DojoLicenseHeader.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/DojoLicenseHeader.java Mon May 12 13:12:44 2008
@@ -0,0 +1,65 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.analysis.license;
+
+import org.apache.rat.analysis.Claims;
+import org.apache.rat.analysis.IHeaderMatcher;
+import org.apache.rat.analysis.RatHeaderAnalysisException;
+import org.apache.rat.license.ModifiedBSDLicenseFamily;
+import org.apache.rat.report.claim.IClaimReporter;
+
+
+public class DojoLicenseHeader extends BaseLicense implements IHeaderMatcher {
+    
+    private static final String LICENSE_URL 
+    = "http://dojotoolkit.org/community/licensing.shtml";
+    
+    //  Copyright (c) 2004-2006, The Dojo Foundation
+    // All Rights Reserved.
+    //
+    // Licensed under the Academic Free License version 2.1 or above OR the
+    // modified BSD license. For more information on Dojo licensing, see:
+    //
+    //    http://dojotoolkit.org/community/licensing.shtml
+
+    public DojoLicenseHeader() {
+        // TODO: support for dual licensing
+        // TODO: support for or higher clauses
+        super(Claims.DOJO, ModifiedBSDLicenseFamily.MODIFIED_BSD_LICENSE_NAME, "Dual license AFL/BSD");
+    }
+
+
+    public void reset() {
+
+    }
+
+    public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        final boolean result = matches(line);
+        if (result) {
+            reportOnLicense(subject, reporter);
+        }
+        return result;
+    }
+
+    boolean matches(String line) {
+        boolean result = (line != null && line.indexOf(LICENSE_URL) != -1);
+        return result;
+    }
+    
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/OASISLicense.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/OASISLicense.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/OASISLicense.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/OASISLicense.java Mon May 12 13:12:44 2008
@@ -0,0 +1,84 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.analysis.license;
+
+import java.util.regex.Pattern;
+
+import org.apache.rat.analysis.Claims;
+import org.apache.rat.analysis.IHeaderMatcher;
+import org.apache.rat.analysis.RatHeaderAnalysisException;
+import org.apache.rat.license.OASISLicenseFamily;
+import org.apache.rat.report.claim.IClaimReporter;
+
+/**
+ * Looks for documents contain the OASIS copyright claim plus derivative work clause.
+ * Perhaps need to match more.
+ */
+public class OASISLicense extends BaseLicense implements IHeaderMatcher {
+
+    private static final String COPYRIGHT_PATTERN_DEFN = ".*Copyright.*OASIS Open.*";
+    private static final String CLAUSE_DEFN
+    = ".*thisdocumentandtranslationsofitmaybecopiedandfurnishedtoothersandderivativeworks" +
+            "thatcommentonorotherwiseexplainitorassistinitsimplementationmaybeprepared" +
+            "copiedpublishedanddistributed.*";
+    
+    private static final Pattern COPYRIGHT_PATTERN = Pattern.compile(COPYRIGHT_PATTERN_DEFN);
+    private static final Pattern CLAUSE_PATTERN = Pattern.compile(CLAUSE_DEFN);
+
+    boolean copyrightMatch = false;
+    final StringBuffer buffer = new StringBuffer();
+    
+    public OASISLicense() {
+        super(Claims.OASIS_CODE, OASISLicenseFamily.OASIS_OPEN_LICENSE_NAME, "No modifications allowed");
+    }
+
+    public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        boolean result = false;
+        if (copyrightMatch) {
+            line = line.toLowerCase();
+            buffer.append(line);
+            prune(buffer); 
+            final boolean clauseMatch = CLAUSE_PATTERN.matcher(buffer).matches();
+            if (clauseMatch) {
+                result = true;
+                reportOnLicense(subject, reporter);
+            }
+            
+        } else {
+            copyrightMatch = COPYRIGHT_PATTERN.matcher(line).matches();
+        }
+        return result;
+    }
+    
+    private void prune(final StringBuffer buffer) {
+        final int length = buffer.length();
+        for (int i=length;i>0;) {
+            char at = buffer.charAt(--i);
+            if (at < 'a' || at > 'z')
+            {
+                buffer.deleteCharAt(i);
+            }
+        }
+    }
+
+    public void reset() {
+        copyrightMatch = false;
+        buffer.delete(0, buffer.length());
+    }
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/TMF854LicenseHeader.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/TMF854LicenseHeader.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/TMF854LicenseHeader.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/TMF854LicenseHeader.java Mon May 12 13:12:44 2008
@@ -0,0 +1,57 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.analysis.license;
+
+import org.apache.rat.analysis.Claims;
+import org.apache.rat.analysis.IHeaderMatcher;
+import org.apache.rat.analysis.RatHeaderAnalysisException;
+import org.apache.rat.license.ModifiedBSDLicenseFamily;
+import org.apache.rat.report.claim.IClaimReporter;
+
+
+public class TMF854LicenseHeader extends BaseLicense implements IHeaderMatcher {
+    
+    private static final String COPYRIGHT_HEADER 
+    = "TMF854 Version 1.0 - Copyright TeleManagement Forum";
+    
+    //  TMF854 Version 1.0 - Copyright TeleManagement Forum 
+
+    public TMF854LicenseHeader() {
+        super(Claims.TMF854, ModifiedBSDLicenseFamily.MODIFIED_BSD_LICENSE_NAME, "BSD");
+    }
+
+
+    public void reset() {
+
+    }
+
+    public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        final boolean result = matches(line);
+        if (result) {
+            reportOnLicense(subject, reporter);
+        }
+        return result;
+    }
+
+    boolean matches(String line) {
+        boolean result = (line != null && line.indexOf(COPYRIGHT_HEADER) != -1);
+        return result;
+    }
+    
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/W3CDocLicense.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/W3CDocLicense.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/W3CDocLicense.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/W3CDocLicense.java Mon May 12 13:12:44 2008
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2006 Guillaume Nodet
+ *
+ * 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.
+ */ 
+package org.apache.rat.analysis.license;
+
+import org.apache.rat.analysis.Claims;
+import org.apache.rat.analysis.IHeaderMatcher;
+import org.apache.rat.analysis.RatHeaderAnalysisException;
+import org.apache.rat.license.W3CDocumentLicenseFamily;
+import org.apache.rat.report.claim.IClaimReporter;
+
+public class W3CDocLicense extends BaseLicense implements IHeaderMatcher {
+
+    private static final String NOTES 
+        = "Note that W3CD does not allow modifications. See http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231.";
+    private static final String COPYRIGHT_URL 
+    = "http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231";
+    
+    public W3CDocLicense() {
+        super(Claims.W3CD_CODE, W3CDocumentLicenseFamily.W3C_DOCUMENT_COPYRIGHT_NAME,  NOTES);
+        
+    }
+
+    public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        boolean result = line != null && line.indexOf(COPYRIGHT_URL) != -1;
+        if (result) {
+            reportOnLicense(subject, reporter);
+        }
+        return result;
+    }
+
+    public void reset() {
+        // Matcher is not stateful 
+    }
+
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/W3CLicense.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/W3CLicense.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/W3CLicense.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/license/W3CLicense.java Mon May 12 13:12:44 2008
@@ -0,0 +1,51 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.analysis.license;
+
+import org.apache.rat.analysis.Claims;
+import org.apache.rat.analysis.IHeaderMatcher;
+import org.apache.rat.analysis.RatHeaderAnalysisException;
+import org.apache.rat.license.W3CSoftwareLicenseFamily;
+import org.apache.rat.report.claim.IClaimReporter;
+
+public class W3CLicense extends BaseLicense implements IHeaderMatcher {
+
+    private static final String NOTES 
+        = "Note that W3C requires a NOTICE. All modifications require notes. See http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231.";
+    private static final String COPYRIGHT_URL 
+    = "http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231";
+    
+    public W3CLicense() {
+        super(Claims.W3C_CODE, W3CSoftwareLicenseFamily.W3C_SOFTWARE_COPYRIGHT_NAME,  NOTES);
+        
+    }
+
+    public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        boolean result = line != null && line.indexOf(COPYRIGHT_URL) != -1;
+        if (result) {
+            reportOnLicense(subject, reporter);
+        }
+        return result;
+    }
+
+    public void reset() {
+        // Matcher is not stateful 
+    }
+
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/util/HeaderMatcherMultiplexer.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/util/HeaderMatcherMultiplexer.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/util/HeaderMatcherMultiplexer.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/analysis/util/HeaderMatcherMultiplexer.java Mon May 12 13:12:44 2008
@@ -0,0 +1,56 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.analysis.util;
+
+import org.apache.rat.analysis.IHeaderMatcher;
+import org.apache.rat.analysis.RatHeaderAnalysisException;
+import org.apache.rat.report.claim.IClaimReporter;
+
+/**
+ * Delegates to an ordered set of matchers.
+ *
+ */
+public final class HeaderMatcherMultiplexer implements IHeaderMatcher {
+
+	private final IHeaderMatcher[] matchers;
+	private final int numberOfMatchers;
+	
+	public HeaderMatcherMultiplexer(final IHeaderMatcher[] matchers) {
+		this.matchers = matchers;
+		numberOfMatchers = matchers.length;
+	}
+	
+	public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        boolean result = false;
+		for (int i=0;i<numberOfMatchers;i++) {
+			result = matchers[i].match(subject, line, reporter);
+            if (result) {
+                break;
+            }
+		}
+        return result;
+	}
+
+	public void reset() {
+		for (int i=0;i<numberOfMatchers;i++) {
+			matchers[i].reset();
+		}
+	}
+
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/CompositeDocumentException.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/CompositeDocumentException.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/CompositeDocumentException.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/CompositeDocumentException.java Mon May 12 13:12:44 2008
@@ -0,0 +1,39 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document;
+
+import java.io.IOException;
+
+/**
+ * Indicates that the document is a composite archive 
+ * and cannot be read.
+ */
+public class CompositeDocumentException extends IOException {
+
+    private static final long serialVersionUID = -8874256971728263295L;
+
+    public CompositeDocumentException() {
+        super("This document must be read as an archive.");
+    }
+
+    public CompositeDocumentException(String s) {
+        super(s);
+    }
+
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/DocumentUtils.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/DocumentUtils.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/DocumentUtils.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/DocumentUtils.java Mon May 12 13:12:44 2008
@@ -0,0 +1,59 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.Transformer;
+
+public final class DocumentUtils {
+
+    private static final Transformer TO_NAME_TRANSFORMER = new ToNameTransformer();
+    
+    public static final Transformer toNameTransformer() {
+        return TO_NAME_TRANSFORMER;
+    }
+    
+    /**
+     * Collects all the documents contained in the collection tree.
+     * @param documentCollection <code>IDocumentCollection</code>, not null
+     * @return <code>Collection</code> of <code>IDocument</code>
+     */
+    public static final Collection documentsContained(IDocumentCollection documentCollection) {
+        final Collection results = new ArrayList();
+        addContents(documentCollection, results);
+        return results;
+    }
+    
+    /**
+     * Depth first traversal.
+     * @param documentCollection <code>IDocumentCollection</code>, not null
+     * @param contents <code>Collection</code> of <code>IDocument</code>'s, not null
+     */
+    private static final void addContents(IDocumentCollection documentCollection, Collection contents) {
+        for (Iterator it=documentCollection.subcollectionIterator();it.hasNext();) {
+            IDocumentCollection subCollection = (IDocumentCollection) it.next();
+            addContents(subCollection, contents);
+        }
+        CollectionUtils.addAll(contents, documentCollection.documentIterator());
+    }
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocument.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocument.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocument.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocument.java Mon May 12 13:12:44 2008
@@ -0,0 +1,43 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document;
+
+import java.io.IOException;
+import java.io.Reader;
+
+public interface IDocument extends IResource {
+
+    /**
+     * Reads the content of this document.
+     * @return <code>Reader</code> not null
+     * @throws IOException if this document cannot be read
+     * @throws CompositeDocumentException if this document can only be read as
+     * a composite archive
+     */
+	public Reader reader() throws IOException;
+    
+    /**
+     * Reads contents of composite document.
+     * @return <code>IDocumentCollection</code>, not null
+     * @throws IOException if the document cannot be read
+     * @throws UnreadableArchiveException if this document is not an archive
+     * or if this document is unreadable
+     */
+    public IDocumentCollection readArchive() throws IOException;
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocumentAnalyser.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocumentAnalyser.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocumentAnalyser.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocumentAnalyser.java Mon May 12 13:12:44 2008
@@ -0,0 +1,25 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document;
+
+
+public interface IDocumentAnalyser {
+
+    public void analyse(IDocument document) throws RatDocumentAnalysisException;
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocumentCollection.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocumentCollection.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocumentCollection.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocumentCollection.java Mon May 12 13:12:44 2008
@@ -0,0 +1,40 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document;
+
+import java.util.Iterator;
+
+/**
+ * Collects documents.
+ * May contain subcollections.
+ */
+public interface IDocumentCollection extends IResource {
+
+	/**
+	 * Iterates <code>IDocument</code>'s contained.
+	 * @return <code>Iterator</code>, not null
+	 */
+	public Iterator documentIterator();
+	
+	/**
+	 * Iterates <code>IDocumentCollection</code>'s contained.
+	 * @return <code>Iterator</code>, not null
+	 */
+	public Iterator subcollectionIterator();
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocumentMatcher.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocumentMatcher.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocumentMatcher.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IDocumentMatcher.java Mon May 12 13:12:44 2008
@@ -0,0 +1,25 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document;
+
+
+public interface IDocumentMatcher {
+
+    public boolean matches(final IDocument document) throws RatDocumentAnalysisException;
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IFileUnarchiver.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IFileUnarchiver.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IFileUnarchiver.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IFileUnarchiver.java Mon May 12 13:12:44 2008
@@ -0,0 +1,38 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Reads documents from file archives.
+ *
+ */
+public interface IFileUnarchiver {
+
+    /**
+     * Unarchives the file.
+     * @param file <code>File</code>, not null
+     * @return <code>IDocumentCollection</code> describing the archived
+     * documents contained
+     * @throws UnreadableArchiveException if the file cannot be unarchived
+     */
+    public IDocumentCollection unarchive(File file) throws IOException;
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IResource.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IResource.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IResource.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/IResource.java Mon May 12 13:12:44 2008
@@ -0,0 +1,25 @@
+/*
+ * 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.                                           *
+ */
+package org.apache.rat.document;
+
+public interface IResource {
+
+	public String getName();
+
+}
\ No newline at end of file

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/RatDocumentAnalysisException.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/RatDocumentAnalysisException.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/RatDocumentAnalysisException.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/RatDocumentAnalysisException.java Mon May 12 13:12:44 2008
@@ -0,0 +1,42 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document;
+
+import org.apache.commons.lang.exception.NestableException;
+
+public class RatDocumentAnalysisException extends NestableException {
+
+    private static final long serialVersionUID = 2339068944003517510L;
+
+    public RatDocumentAnalysisException() {
+    }
+
+    public RatDocumentAnalysisException(String msg) {
+        super(msg);
+    }
+
+    public RatDocumentAnalysisException(Throwable cause) {
+        super(cause);
+    }
+
+    public RatDocumentAnalysisException(String msg, Throwable cause) {
+        super(msg, cause);
+    }
+
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/ToNameTransformer.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/ToNameTransformer.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/ToNameTransformer.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/ToNameTransformer.java Mon May 12 13:12:44 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document;
+
+import org.apache.commons.collections.Transformer;
+
+class ToNameTransformer implements Transformer {
+
+    public Object transform(Object subject) {
+        Object result = null;
+        if (subject != null && subject instanceof IResource) {
+            IResource location = (IResource) subject;
+            result = location.getName();
+        }
+        return result;
+    }
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/UnreadableArchiveException.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/UnreadableArchiveException.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/UnreadableArchiveException.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/UnreadableArchiveException.java Mon May 12 13:12:44 2008
@@ -0,0 +1,122 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
+import org.apache.commons.lang.exception.Nestable;
+import org.apache.commons.lang.exception.NestableDelegate;
+
+/**
+ * Indicates that an archive is unreadable.
+ *
+ */
+public class UnreadableArchiveException extends IOException implements Nestable {
+
+    private static final String MESSAGE = "Archive is unreadable";
+
+    private static final long serialVersionUID = -1556313036805276658L;
+
+    private final NestableDelegate delegate = new NestableDelegate(this);
+    private final Throwable cause;
+    
+    public UnreadableArchiveException() {
+        this(MESSAGE, null);
+    }
+
+    public UnreadableArchiveException(String s) {
+        this(s, null);
+    }
+    
+    public UnreadableArchiveException(Throwable cause) {
+        this(MESSAGE, cause);
+    }
+    
+    public UnreadableArchiveException(String s, Throwable cause) {
+        super(s);
+        this.cause = cause;
+    }
+    
+    public Throwable getCause() {
+        return cause;
+    }
+    
+    public String getMessage() {
+        final String result = super.getMessage();
+        return result;
+    }
+    
+    public String getMessage(int index) {
+        String result = null;
+        if (index == 0) {
+            result = getMessage();
+        } else {
+            result = delegate.getMessage(index);
+        }
+        return result;
+    }
+
+    public String[] getMessages() {
+        final String[] messages = delegate.getMessages();
+        return messages;
+    }
+
+    public Throwable getThrowable(int index) {
+        final Throwable result = delegate.getThrowable(index);
+        return result;
+    }
+
+    public int getThrowableCount() {
+        final int throwableCount = delegate.getThrowableCount();
+        return throwableCount;
+    }
+
+    public Throwable[] getThrowables() {
+        final Throwable[] throwables = delegate.getThrowables();
+        return throwables;
+    }
+
+    public int indexOfThrowable(Class type) {
+        final int result = delegate.indexOfThrowable(type, 0);
+        return result;
+    }
+
+    public int indexOfThrowable(Class type, int fromIndex) {
+        final int result = delegate.indexOfThrowable(type, fromIndex);
+        return result;
+    }
+
+    public void printStackTrace() {
+        delegate.printStackTrace();
+    }
+
+    public void printStackTrace(PrintStream s) {
+        delegate.printStackTrace(s);
+    }
+
+    public void printStackTrace(PrintWriter s) {
+        delegate.printStackTrace(s);
+    }
+
+    public void printPartialStackTrace(PrintWriter out) {
+        super.printStackTrace(out);
+    }
+}    

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/UnsuitableDocumentException.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/UnsuitableDocumentException.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/UnsuitableDocumentException.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/UnsuitableDocumentException.java Mon May 12 13:12:44 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document;
+
+/**
+ * Indicates that the document was unsuitable for analysis.
+ *
+ */
+public class UnsuitableDocumentException extends RatDocumentAnalysisException {
+
+    private static final long serialVersionUID = 4202800209654402733L;
+
+    public UnsuitableDocumentException() {
+        super("This document is unsuitable for analysis");
+    }
+
+    public UnsuitableDocumentException(String msg, Throwable cause) {
+        super(msg, cause);
+    }
+
+    public UnsuitableDocumentException(String msg) {
+        super(msg);
+    }
+
+    public UnsuitableDocumentException(Throwable cause) {
+        super(cause);
+    }
+
+    
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/AbstractMonolithicDocument.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/AbstractMonolithicDocument.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/AbstractMonolithicDocument.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/AbstractMonolithicDocument.java Mon May 12 13:12:44 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document.impl;
+
+import java.io.IOException;
+
+import org.apache.rat.document.IDocument;
+import org.apache.rat.document.IDocumentCollection;
+import org.apache.rat.document.UnreadableArchiveException;
+
+
+/**
+ * Abstract base class for monolithic documents.
+ */
+public abstract class AbstractMonolithicDocument implements IDocument {
+	private final String name;
+
+	public AbstractMonolithicDocument(String pName) {
+		name = pName;
+	}
+
+	public IDocumentCollection readArchive() throws IOException {
+        throw new UnreadableArchiveException("This file is not an archive");
+    }
+
+	public String getName() {
+		return name;
+	}
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/CompositeDocument.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/CompositeDocument.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/CompositeDocument.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/CompositeDocument.java Mon May 12 13:12:44 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document.impl;
+
+import java.io.IOException;
+import java.io.Reader;
+
+import org.apache.rat.document.CompositeDocumentException;
+import org.apache.rat.document.IDocument;
+
+/**
+ * Composed from a set of archived documents.
+ *
+ */
+public abstract class CompositeDocument implements IDocument {
+
+    private final String name;
+    
+    public CompositeDocument(final String name) {
+        super();
+        this.name = name;
+    }
+
+    public Reader reader() throws IOException {
+        throw new CompositeDocumentException();
+    }
+
+    public String getName() {
+        return name;
+    }
+
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/DocumentImplUtils.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/DocumentImplUtils.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/DocumentImplUtils.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/DocumentImplUtils.java Mon May 12 13:12:44 2008
@@ -0,0 +1,31 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document.impl;
+
+import java.io.File;
+
+public class DocumentImplUtils {
+
+    public final static String toName(File file) {
+        String path = file.getPath();
+        String normalisedPath = path.replace('\\', '/');
+        return normalisedPath;
+    }
+
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/FileDocument.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/FileDocument.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/FileDocument.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/FileDocument.java Mon May 12 13:12:44 2008
@@ -0,0 +1,61 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document.impl;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+
+import org.apache.rat.document.IDocument;
+import org.apache.rat.document.IDocumentCollection;
+import org.apache.rat.document.IFileUnarchiver;
+
+/**
+ * Document wrapping a file of undetermined composition.
+ *
+ */
+public class FileDocument implements IDocument {
+
+    private final File file;
+    private final String name;
+    private IFileUnarchiver unarchiver;
+    
+    public FileDocument(final File file, IFileUnarchiver unarchiver) {
+        super();
+        this.file = file;
+        this.unarchiver = unarchiver;
+        name = DocumentImplUtils.toName(file);
+    }
+
+    public IDocumentCollection readArchive() throws IOException {
+        final IDocumentCollection result = unarchiver.unarchive(file);
+        return result;
+    }
+
+    public Reader reader() throws IOException {
+        return new FileReader(file);
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/MonolithicFileDocument.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/MonolithicFileDocument.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/MonolithicFileDocument.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/MonolithicFileDocument.java Mon May 12 13:12:44 2008
@@ -0,0 +1,64 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document.impl;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+
+import org.apache.rat.document.IDocument;
+import org.apache.rat.document.IDocumentCollection;
+import org.apache.rat.document.UnreadableArchiveException;
+
+
+public class MonolithicFileDocument extends AbstractMonolithicDocument {
+	private final File file;
+
+    /**
+     * Creates a new instance. The document is read from the
+     * given URL.
+     */
+    public static IDocument newInstance(final URL url) {
+    	if ("file".equals(url.getProtocol())) {
+    		final File f = new File(url.getFile());
+    		return new MonolithicFileDocument(f);
+    	}
+    	return new AbstractMonolithicDocument(url.toExternalForm()){
+			public Reader reader() throws IOException {
+				return new InputStreamReader(url.openStream(), "UTF-8");
+			}
+    	};
+    }
+
+    public MonolithicFileDocument(final File file) {
+    	super(DocumentImplUtils.toName(file));
+        this.file = file;
+    }
+
+    public IDocumentCollection readArchive() throws IOException {
+        throw new UnreadableArchiveException("This file is not an archive");
+    }
+
+    public Reader reader() throws IOException {
+        return new FileReader(file);
+    }
+}

Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/ArchiveGuesser.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/ArchiveGuesser.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/ArchiveGuesser.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/ArchiveGuesser.java Mon May 12 13:12:44 2008
@@ -0,0 +1,55 @@
+/*
+ * 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.                                           *
+ */ 
+package org.apache.rat.document.impl.guesser;
+
+import java.util.Locale;
+
+import org.apache.rat.document.IDocument;
+import org.apache.rat.document.IDocumentMatcher;
+
+public class ArchiveGuesser implements IDocumentMatcher {
+    
+    public static final String[] ARCHIVE_EXTENSIONS = {
+        "jar", "gz",
+        "zip", "tar",
+        "bz", "bz2",
+        "rar", "war",
+    };
+
+    public boolean matches(final IDocument document) {
+        
+        final String name = document.getName();
+        final boolean result = isArchive(name);
+        return result;
+    }
+
+    /**
+     * Is a file by that name an archive?
+     */
+    public static final boolean isArchive(final String name) {
+        if (name == null) {return false;}
+        String nameToLower = name.toLowerCase(Locale.US);
+        boolean result = false;
+        for (int i = 0; !result && i < ArchiveGuesser.ARCHIVE_EXTENSIONS.length; i++) {
+            result = nameToLower.endsWith("." + ArchiveGuesser.ARCHIVE_EXTENSIONS[i]);
+        }
+        return result;
+    }
+
+}