incubator-rat-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r636144 [3/7] - in /incubator/rat/import: ./ rat/ rat/src/ rat/src/java/ rat/src/java/rat/ rat/src/java/rat/analysis/ rat/src/java/rat/analysis/generation/ rat/src/java/rat/analysis/license/ rat/src/java/rat/analysis/util/ rat/src/java/rat/...
Date Tue, 11 Mar 2008 23:09:27 GMT
Added: incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDirectory.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDirectory.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDirectory.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDirectory.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.document.impl.zip;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.zip.ZipEntry;
+
+class ZipDirectory extends ZipDocumentCollection {
+
+    private final ZipEntry entry;
+    public ZipDirectory(final ZipEntry entry, final Collection subdirectorires, final Collection documents) {
+        super(subdirectorires, documents);
+        this.entry = entry;
+    }
+
+    public String getName() {
+        return ZipUtils.getName(entry);
+    }
+
+    public String getURL() {
+        return ZipUtils.getUrl(entry);
+    }
+
+    void addSubDirectories(Collection directories) {
+        final String stem = getStem();
+        for (Iterator it=directories.iterator();it.hasNext();) {
+            ZipDirectory directory = (ZipDirectory) it.next();
+            if (!directory.equals(this)) {
+                final String otherStem = directory.getStem();
+                if (stem.equals(otherStem)) {
+                    add(directory);
+                }
+            }
+        } 
+    }
+
+    public String getStem() {
+        return ZipUtils.getStem(entry);
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDocument.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDocument.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDocument.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDocument.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.document.impl.zip;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import rat.document.IDocument;
+import rat.document.IDocumentCollection;
+import rat.document.UnreadableArchiveException;
+
+class ZipDocument implements IDocument {
+
+    private final ZipEntry entry;
+    private final ZipFile zipFile;
+    
+    public ZipDocument(final ZipEntry entry, final ZipFile zipFile) {
+        super();
+        this.entry = entry;
+        this.zipFile = zipFile;
+    }
+
+    public Reader reader() throws IOException {
+        final InputStream input = zipFile.getInputStream(entry);
+        final InputStreamReader result = new InputStreamReader(input);
+        return result;
+    }
+
+    public String getName() {
+        return ZipUtils.getName(entry);
+    }
+
+    public String getURL() {
+        return ZipUtils.getUrl(entry);
+    }
+
+    public String toString() {
+        final StringBuffer buffer = new StringBuffer("[ZipDocument '");
+        buffer.append(getName());
+        buffer.append("']");
+        return buffer.toString();
+    }
+
+    public IDocumentCollection readArchive() throws IOException {
+        throw new UnreadableArchiveException();
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDocumentCollection.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDocumentCollection.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDocumentCollection.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDocumentCollection.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.document.impl.zip;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import rat.document.IDocumentCollection;
+
+abstract class ZipDocumentCollection  implements IDocumentCollection {
+
+    private final Collection subdirectories;
+    private final Collection documents;
+
+    public ZipDocumentCollection(final Collection subdirectorires, final Collection documents) {
+        super();
+        this.subdirectories = subdirectorires;
+        this.documents = documents;
+    }
+
+    public Iterator documentIterator() {
+        return documents.iterator();
+    }
+
+    public Iterator subcollectionIterator() {
+        return subdirectories.iterator();
+    }
+
+    void add(ZipDirectory directory) {
+        subdirectories.add(directory);
+    }
+    
+    public String toString() {
+        final StringBuffer buffer = new StringBuffer("[ZipDocumentCollection '"); 
+        buffer.append(getName());
+        buffer.append("' documents: ");
+        buffer.append(documents);
+        buffer.append(", directories: ");
+        buffer.append(subdirectories);
+        buffer.append("]");
+        return buffer.toString();
+    }
+}
\ No newline at end of file

Added: incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDocumentFactory.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDocumentFactory.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDocumentFactory.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipDocumentFactory.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.document.impl.zip;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.apache.commons.collections.EnumerationUtils;
+
+import rat.document.IDocumentCollection;
+
+public class ZipDocumentFactory {
+
+    public static final IDocumentCollection load(File file) throws IOException {
+        ZipFile zip = null;
+        try {
+            zip = new ZipFile(file);
+            final Collection documents = new ArrayList();
+            final Collection subdirectories = new ArrayList();
+
+            final Collection directories = new ArrayList();
+            final List entries = EnumerationUtils.toList(zip.entries());
+            for (Iterator it=entries.iterator();it.hasNext();) {
+                final ZipEntry entry = (ZipEntry) it.next();
+                final boolean isDirectory = entry.isDirectory();
+                final boolean topLevel = ZipUtils.isTopLevel(entry);
+                if (isDirectory) {
+                    ZipDirectory directory = createDirectory(entry, entries, directories, zip);
+                    if (topLevel) {
+                        subdirectories.add(directory);
+                    }
+                    directories.add(directory);
+                } else if (topLevel){
+                    documents.add(new ZipDocument(entry, zip));
+                }
+            }
+            for (Iterator it=directories.iterator();it.hasNext();) {
+                ZipDirectory directory = (ZipDirectory) it.next();
+                directory.addSubDirectories(directories);
+            }
+
+            final IDocumentCollection result = new ZipRootDirectory(zip, subdirectories, documents);
+            return result;
+        } finally {
+            if (zip != null) {
+                zip.close();
+            }
+        }
+    }
+
+    private static ZipDirectory createDirectory(ZipEntry entry, 
+            List entries, Collection directories, ZipFile zip) {
+        final String stem = ZipUtils.getStem(entry);
+        final Collection subdirectories = new ArrayList();
+        final Collection documents = new ArrayList();
+        
+        for(Iterator it=entries.iterator();it.hasNext();) {
+            ZipEntry otherEntry = (ZipEntry) it.next();
+            if (!otherEntry.equals(entry))
+            {
+                final String otherStem = ZipUtils.getStem(otherEntry);
+                if (stem.equals(otherStem)) {
+                    if (otherEntry.isDirectory()) {
+                        ZipDirectory subDirectory 
+                            = createDirectory(otherEntry, entries,directories, zip);
+                        subdirectories.add(subDirectory);
+                        directories.add(subDirectory);
+                    } else {
+                        ZipDocument document = new ZipDocument(otherEntry, zip);
+                        documents.add(document);
+                    }
+                }
+            }
+        }
+        
+        final ZipDirectory result = new ZipDirectory(entry, subdirectories, documents);
+        return result;
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipFileDocument.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipFileDocument.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipFileDocument.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipFileDocument.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.document.impl.zip;
+
+import java.io.File;
+import java.io.IOException;
+
+import rat.document.IDocumentCollection;
+import rat.document.impl.CompositeDocument;
+
+/**
+ * Document which is a zip file.
+ *
+ */
+public class ZipFileDocument extends CompositeDocument {
+
+    private final File file;
+    private IDocumentCollection contents;
+    
+    public ZipFileDocument(final File file) {
+        super(file.getPath());
+        this.file = file;
+    }
+    
+    public synchronized IDocumentCollection readArchive() throws IOException {
+        if (contents == null) {
+            contents = ZipDocumentFactory.load(file);
+        }
+        return contents;
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipFileUnarchiver.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipFileUnarchiver.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipFileUnarchiver.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipFileUnarchiver.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.document.impl.zip;
+
+import java.io.File;
+import java.io.IOException;
+
+import rat.document.IDocumentCollection;
+import rat.document.IFileUnarchiver;
+
+public class ZipFileUnarchiver implements IFileUnarchiver {
+
+    public IDocumentCollection unarchive(File file) throws IOException {
+        final IDocumentCollection result = ZipDocumentFactory.load(file);
+        return result;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipRootDirectory.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipRootDirectory.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipRootDirectory.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipRootDirectory.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.document.impl.zip;
+
+import java.util.Collection;
+import java.util.zip.ZipFile;
+
+public class ZipRootDirectory extends ZipDocumentCollection {
+
+    private final ZipFile zipFile;
+    
+    public ZipRootDirectory(final ZipFile zipFile, final Collection subdirectorires, final Collection documents) {
+        super(subdirectorires, documents);
+        this.zipFile = zipFile;
+    }
+
+    public String getName() {
+        return zipFile.getName();
+    }
+
+    public String getURL() {
+        return zipFile.getName();
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipUtils.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipUtils.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipUtils.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/zip/ZipUtils.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.document.impl.zip;
+
+import java.util.zip.ZipEntry;
+
+final class ZipUtils {
+
+    public static String getStem(final ZipEntry entry) {
+        final String name = entry.getName();
+        final int lastIndexOfForwardSlash = name.lastIndexOf('/');
+        final int lastIndexOfBackSlash = name.lastIndexOf('\\');
+        final int index = Math.max(lastIndexOfBackSlash, lastIndexOfForwardSlash);
+        String result = "";
+        if (index >= 0) {
+            result = name.substring(0, index);
+        }
+        return result;
+    }
+    
+    public static String getName(final ZipEntry entry) {
+        String name = entry.getName();
+        if (name.endsWith("/") || name.endsWith("\\")) {
+            name = name.substring(0, name.length() - 1);
+        }
+        final int lastIndexOfForwardSlash = name.lastIndexOf('/');
+        final int lastIndexOfBackSlash = name.lastIndexOf('\\');
+        final int index = Math.max(lastIndexOfBackSlash, lastIndexOfForwardSlash);
+        String result = name;
+        if (index >= 0) {
+            final int length = name.length();
+            result = name.substring(index + 1, length);
+        }
+        return result;
+    }
+    
+    public static String getUrl(final ZipEntry entry) {
+        return "zip:" + entry.getName();
+    }
+    
+    public static boolean isTopLevel(final ZipEntry entry) {
+        final String name = entry.getName();
+        final int lastPosition = name.length() - 1;
+        final int indexOfForwardSlash = name.indexOf('/');
+        final int indexOfBackSlash = name.indexOf('\\');
+        final boolean result = (indexOfForwardSlash < 0 || indexOfForwardSlash == lastPosition) 
+                        && (indexOfBackSlash < 0 || indexOfBackSlash == lastPosition);
+        return result;
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/header/ArrayCharFilter.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/header/ArrayCharFilter.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/header/ArrayCharFilter.java (added)
+++ incubator/rat/import/rat/src/java/rat/header/ArrayCharFilter.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.header;
+
+class ArrayCharFilter implements CharFilter {
+
+    private final char[] filtered;
+    private final int length;
+    
+    protected ArrayCharFilter(final char[] filtered) {
+        super();
+        this.filtered = filtered;
+        length = filtered.length;
+    }
+
+    public boolean isFilteredOut(char character) {
+        boolean result = false;
+        for(int i=0; i<length ;i++) {
+            if (character == filtered[i]) {
+                result = true;
+                break;
+            }
+        }
+        return result;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/header/CharFilter.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/header/CharFilter.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/header/CharFilter.java (added)
+++ incubator/rat/import/rat/src/java/rat/header/CharFilter.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.header;
+
+interface CharFilter {
+
+    /**
+     * Is the given character filtered out?
+     * @param character character to be filtered
+     * @return true if this character should be filtered out,
+     * false if this character should be filtered in
+     */
+    public boolean isFilteredOut(char character);
+}

Added: incubator/rat/import/rat/src/java/rat/header/FilteringSequenceFactory.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/header/FilteringSequenceFactory.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/header/FilteringSequenceFactory.java (added)
+++ incubator/rat/import/rat/src/java/rat/header/FilteringSequenceFactory.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.header;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.CharBuffer;
+
+class FilteringSequenceFactory {
+    
+    private static final int BUFFER_CAPACITY = 5000;
+    
+    private final CharBuffer buffer;
+    private final CharFilter filter;
+    
+    public FilteringSequenceFactory(final CharFilter filter) {
+        this(BUFFER_CAPACITY, filter);
+    }
+    
+    public FilteringSequenceFactory(final int capacity, final CharFilter filter) {
+        this.buffer = CharBuffer.allocate(capacity);
+        this.filter = filter;
+    }
+
+    public CharSequence filter(Reader reader) throws IOException {
+        buffer.clear();
+        boolean eof = false;
+        while(!eof) {
+            final int next = reader.read();
+            if (next == -1 || !buffer.hasRemaining()) {
+                eof = true;
+            } else {
+                final char character = (char) next;
+                if (!filter.isFilteredOut(character))
+                {
+                    buffer.put(character); 
+                }
+            }
+        }
+        buffer.limit(buffer.position()).rewind();
+        return buffer;
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/header/HeaderBean.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/header/HeaderBean.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/header/HeaderBean.java (added)
+++ incubator/rat/import/rat/src/java/rat/header/HeaderBean.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.header;
+
+import java.util.regex.Pattern;
+
+public class HeaderBean {
+
+    private Pattern headerPattern;
+    private boolean match;
+    
+    public HeaderBean() {
+        super();
+    }
+    
+    public HeaderBean(Pattern headerPattern, boolean match) {
+        super();
+        this.headerPattern = headerPattern;
+        this.match = match;
+    }
+
+    /**
+     * Gets the header pattern to be matched.
+     * @return <code>Patter</code>
+     * or null when no match is to be made
+     */
+    public Pattern getHeaderPattern() {
+        return headerPattern;
+    }
+    
+    /**
+     * Sets the header pattern to be matched.
+     * @param <code>Patter</code>
+     * or null when no match is to be made
+     */
+    public void setHeaderPattern(Pattern headerPattern) {
+        this.headerPattern = headerPattern;
+    }
+    
+    public boolean isMatch() {
+        return match;
+    }
+    public void setMatch(boolean match) {
+        this.match = match;
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/header/HeaderMatcher.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/header/HeaderMatcher.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/header/HeaderMatcher.java (added)
+++ incubator/rat/import/rat/src/java/rat/header/HeaderMatcher.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.header;
+
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.Reader;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * <p>Matches headers.</p>
+ * <p><strong>Usage:</strong></p>
+ * <ol>
+ * <li>{@link #read(Reader)} content</li>
+ * <li>{@link #matches(Pattern)} against filtered content</li>
+ * </ol>
+ * <p><strong>Note:</strong> use only from a single thread.</p>
+ *
+ */
+public class HeaderMatcher {
+
+    private final FilteringSequenceFactory factory;
+    private final HeaderBean[] headers;
+    private CharSequence read;
+    private int lines;
+    
+    public HeaderMatcher(final CharFilter filter, final int capacity) {
+        this(filter, capacity, null);
+    }
+    
+    public HeaderMatcher(final CharFilter filter, final int capacity, final HeaderBean[] headers) {
+        factory = new FilteringSequenceFactory(capacity, filter);
+        read = null;
+        this.headers = headers;
+    }
+    
+    public void read(Reader reader) throws IOException {
+        final LineNumberReader lineNumberReader = new LineNumberReader(reader);
+        read = factory.filter(lineNumberReader);
+        if (lineNumberReader.read() == -1) {
+            lines = lineNumberReader.getLineNumber();
+        } else {
+            lines = -1;
+        }
+        if (headers != null) {
+            final int length = headers.length;
+            for (int i=0;i<length;i++) {
+                final HeaderBean headerBean = headers[i];
+                if (headerBean != null) {
+                    final Pattern headerPattern = headerBean.getHeaderPattern();
+                    if (headerPattern != null) {
+                        final boolean matches = matches(headerPattern);
+                        headerBean.setMatch(matches);
+                    }
+                }
+            }
+        }
+    }
+    
+    /**
+     * <p>Seeks a match in the last headers read.</p>
+     * <p><strong>Note</strong> that this pattern
+     * must not contain filtered characters.
+     * </p>
+     * @param pattern <code>Pattern</code> to match
+     * @return true if the pattern matches,
+     * false otherwise or if {@link #read()} has not been
+     * called
+     */
+    public boolean matches(Pattern pattern) {
+        boolean result = false;
+        if (read != null) {
+            final Matcher matcher = pattern.matcher(read);
+            result = matcher.matches();
+        }
+        return result;
+    }
+    
+    /**
+     * Number of lines read.
+     * @return the number of lines in the file
+     * or -1 if the file has more lines than were read
+     */
+    public int lines() {
+        return lines;
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/license/AcademicFree21LicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/license/AcademicFree21LicenseFamily.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/license/AcademicFree21LicenseFamily.java (added)
+++ incubator/rat/import/rat/src/java/rat/license/AcademicFree21LicenseFamily.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.license;
+
+public class AcademicFree21LicenseFamily implements ILicenseFamily {
+
+    public static final String ACADEMIC_FREE_LICENSE_FAMILY = "Academic Free License, Version 2.1";
+
+    public String getFamilyName() {
+        return ACADEMIC_FREE_LICENSE_FAMILY;
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/license/Apache20LicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/license/Apache20LicenseFamily.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/license/Apache20LicenseFamily.java (added)
+++ incubator/rat/import/rat/src/java/rat/license/Apache20LicenseFamily.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.license;
+
+public final class Apache20LicenseFamily implements ILicenseFamily {
+
+    public static final String APACHE_SOFTWARE_LICENSE_NAME = "Apache License Version 2.0";
+
+    public String getFamilyName() {
+        return APACHE_SOFTWARE_LICENSE_NAME;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/license/ILicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/license/ILicenseFamily.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/license/ILicenseFamily.java (added)
+++ incubator/rat/import/rat/src/java/rat/license/ILicenseFamily.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.license;
+
+public interface ILicenseFamily {
+    public String getFamilyName();
+}

Added: incubator/rat/import/rat/src/java/rat/license/ModifiedBSDLicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/license/ModifiedBSDLicenseFamily.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/license/ModifiedBSDLicenseFamily.java (added)
+++ incubator/rat/import/rat/src/java/rat/license/ModifiedBSDLicenseFamily.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.license;
+
+public class ModifiedBSDLicenseFamily implements ILicenseFamily {
+
+    public static final String MODIFIED_BSD_LICENSE_NAME = "Modified BSD License";
+
+    public String getFamilyName() {
+        return MODIFIED_BSD_LICENSE_NAME;
+    }
+
+    
+}

Added: incubator/rat/import/rat/src/java/rat/license/OASISLicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/license/OASISLicenseFamily.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/license/OASISLicenseFamily.java (added)
+++ incubator/rat/import/rat/src/java/rat/license/OASISLicenseFamily.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.license;
+
+public final class OASISLicenseFamily implements ILicenseFamily {
+
+    public static final String OASIS_OPEN_LICENSE_NAME = "OASIS Open License";
+
+    public String getFamilyName() {
+        return OASIS_OPEN_LICENSE_NAME;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/license/W3CDocumentLicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/license/W3CDocumentLicenseFamily.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/license/W3CDocumentLicenseFamily.java (added)
+++ incubator/rat/import/rat/src/java/rat/license/W3CDocumentLicenseFamily.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.license;
+
+public class W3CDocumentLicenseFamily implements ILicenseFamily {
+
+    public static final String W3C_DOCUMENT_COPYRIGHT_NAME = "W3C Document Copyright";
+
+    public String getFamilyName() {
+        return W3C_DOCUMENT_COPYRIGHT_NAME;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/license/W3CSoftwareLicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/license/W3CSoftwareLicenseFamily.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/license/W3CSoftwareLicenseFamily.java (added)
+++ incubator/rat/import/rat/src/java/rat/license/W3CSoftwareLicenseFamily.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.license;
+
+public class W3CSoftwareLicenseFamily implements ILicenseFamily {
+
+    public static final String W3C_SOFTWARE_COPYRIGHT_NAME = "W3C Software Copyright";
+
+    public String getFamilyName() {
+        return W3C_SOFTWARE_COPYRIGHT_NAME;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/plain-rat.xsl
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/plain-rat.xsl?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/plain-rat.xsl (added)
+++ incubator/rat/import/rat/src/java/rat/plain-rat.xsl Tue Mar 11 16:08:58 2008
@@ -0,0 +1,78 @@
+<?xml version='1.0' ?>
+<!--
+ Copyright 2006 Robert Burrell Donkin
+ 
+ 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.
+-->
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:output method='text'/>
+<xsl:template match='/'>
+*****************************************************
+Summary
+-------
+Notes: <xsl:value-of select='count(descendant::type[attribute::name="notice"])'/>
+Binaries: <xsl:value-of select='count(descendant::type[attribute::name="binary"])'/>
+Archives: <xsl:value-of select='count(descendant::type[attribute::name="archive"])'/>
+Standards: <xsl:value-of select='count(descendant::type[attribute::name="standard"])'/>
+
+Apache Licensed: <xsl:value-of select='count(descendant::header-type[attribute::name="AL   "])'/>
+Generated Documents: <xsl:value-of select='count(descendant::header-type[attribute::name="GEN  "])'/>
+
+JavaDocs are generated and so license header is optional
+Generated files do not required license headers
+
+<xsl:value-of select='count(descendant::header-type[attribute::name="?????"])'/> Unknown Licenses
+
+*******************************
+
+Archives (+ indicates readable, $ unreadable): 
+
+ <xsl:for-each select='descendant::resource[type/@name="archive"]'>
+ <xsl:choose><xsl:when test='archive-type/@name="readable"'>+ </xsl:when><xsl:otherwise>$ </xsl:otherwise></xsl:choose><xsl:value-of select='@name'/>
+ <xsl:text>
+ </xsl:text>
+ </xsl:for-each>
+*****************************************************
+  Files with AL headers will be marked L
+  Binary files (which do not require AL headers) will be marked B
+  Compressed archives will be marked A
+  Notices, licenses etc will be marked N
+ <xsl:for-each select='descendant::resource'>
+  <xsl:choose>
+	 <xsl:when test='license-approval/@name="false"'>!</xsl:when>
+	 <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
+ </xsl:choose>
+ <xsl:choose>
+	 <xsl:when test='type/@name="notice"'>N    </xsl:when>
+	 <xsl:when test='type/@name="archive"'>A    </xsl:when>
+	 <xsl:when test='type/@name="binary"'>B    </xsl:when>
+	 <xsl:when test='type/@name="standard"'><xsl:value-of select='header-type/@name'/></xsl:when>
+	 <xsl:otherwise>!!!!!</xsl:otherwise>
+ </xsl:choose>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select='@name'/>
+ <xsl:text>
+ </xsl:text>
+ </xsl:for-each>
+ *****************************************************
+ Printing headers for files without AL header...
+ 
+ <xsl:for-each select='descendant::resource[header-type/@name="?????"]'>
+ =======================================================================
+ ==<xsl:value-of select='@name'/>
+ =======================================================================
+ <xsl:value-of select='header-sample'/>
+ </xsl:for-each>
+</xsl:template>
+</xsl:stylesheet>
\ No newline at end of file

Added: incubator/rat/import/rat/src/java/rat/policy/DefaultPolicy.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/policy/DefaultPolicy.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/policy/DefaultPolicy.java (added)
+++ incubator/rat/import/rat/src/java/rat/policy/DefaultPolicy.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.policy;
+
+import java.util.Arrays;
+
+import rat.analysis.Claims;
+import rat.license.Apache20LicenseFamily;
+import rat.license.ILicenseFamily;
+import rat.license.ModifiedBSDLicenseFamily;
+import rat.license.OASISLicenseFamily;
+import rat.license.W3CDocumentLicenseFamily;
+import rat.license.W3CSoftwareLicenseFamily;
+import rat.report.RatReportFailedException;
+import rat.report.claim.IClaimReporter;
+
+public class DefaultPolicy implements IClaimReporter {
+
+    private static final String[] APPROVED_LICENSES = {
+        Apache20LicenseFamily.APACHE_SOFTWARE_LICENSE_NAME, OASISLicenseFamily.OASIS_OPEN_LICENSE_NAME, 
+        W3CSoftwareLicenseFamily.W3C_SOFTWARE_COPYRIGHT_NAME, W3CDocumentLicenseFamily.W3C_DOCUMENT_COPYRIGHT_NAME,
+        ModifiedBSDLicenseFamily.MODIFIED_BSD_LICENSE_NAME
+    };
+    
+    private static final String[] toNames(final ILicenseFamily[] approvedLicenses) {
+        String[] results = null;
+        if (approvedLicenses != null) {
+            final int length = approvedLicenses.length;
+            results = new String[length];
+            for (int i=0;i<length;i++) {
+                results[i] = approvedLicenses[i].getFamilyName();
+            }
+        }
+        return results;
+    }
+    
+    private final IClaimReporter reporter;
+    private final String[] approvedLicenseNames;
+    
+    public DefaultPolicy(final IClaimReporter reporter) {
+        this(reporter, APPROVED_LICENSES);
+    }
+    
+    public DefaultPolicy(final IClaimReporter reporter, final ILicenseFamily[] approvedLicenses) {
+        this(reporter, toNames(approvedLicenses));
+    }
+    
+    public DefaultPolicy(final IClaimReporter reporter, final String[] approvedLicenseNames) {
+        super();
+        this.reporter = reporter;
+        if (approvedLicenseNames == null) {
+            this.approvedLicenseNames = APPROVED_LICENSES;
+        } else {
+            final int length = approvedLicenseNames.length;
+            this.approvedLicenseNames = new String[length];
+            System.arraycopy(approvedLicenseNames, 0, this.approvedLicenseNames, 0, length);
+        }
+        Arrays.sort(this.approvedLicenseNames);
+    }
+
+    public void claim(CharSequence subject, CharSequence predicate,
+            CharSequence object, boolean isLiteral)
+            throws RatReportFailedException {
+        if (Claims.LICENSE_FAMILY_PREDICATE.equals(predicate)) {
+            final boolean isApproved = Arrays.binarySearch(approvedLicenseNames, object) >= 0;
+            Claims.reportLicenseApprovalClaim(subject, isApproved, reporter);
+        }
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/report/IReportable.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/IReportable.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/IReportable.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/IReportable.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report;
+
+public interface IReportable {
+
+    public void run(RatReport report) throws RatReportFailedException;
+}

Added: incubator/rat/import/rat/src/java/rat/report/RatReport.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/RatReport.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/RatReport.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/RatReport.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report;
+
+import rat.document.IDocument;
+
+public interface RatReport {
+
+    public void startReport() throws RatReportFailedException;
+    
+    public void report(IDocument document) throws RatReportFailedException;
+    
+    public void endReport() throws RatReportFailedException;
+}

Added: incubator/rat/import/rat/src/java/rat/report/RatReportFailedException.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/RatReportFailedException.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/RatReportFailedException.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/RatReportFailedException.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report;
+
+import org.apache.commons.lang.exception.NestableException;
+
+public class RatReportFailedException extends NestableException {
+
+    private static final long serialVersionUID = 4940711222435919034L;
+
+    public RatReportFailedException() {
+        super();
+    }
+
+    public RatReportFailedException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public RatReportFailedException(String message) {
+        super(message);
+    }
+
+    public RatReportFailedException(Throwable cause) {
+        super(cause);
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/report/analyser/AbstractSingleClaimAnalyser.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/analyser/AbstractSingleClaimAnalyser.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/analyser/AbstractSingleClaimAnalyser.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/analyser/AbstractSingleClaimAnalyser.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report.analyser;
+
+import rat.document.IDocument;
+import rat.document.IDocumentAnalyser;
+import rat.document.RatDocumentAnalysisException;
+import rat.report.RatReportFailedException;
+import rat.report.claim.IClaimReporter;
+
+public abstract class AbstractSingleClaimAnalyser implements IDocumentAnalyser {
+
+    private final IClaimReporter reporter;
+    private final CharSequence predicate;
+    private final boolean isLiteral;
+    
+    public AbstractSingleClaimAnalyser(final IClaimReporter reporter, final CharSequence predicate, 
+            final boolean isLiteral) {
+        super();
+        this.reporter = reporter;
+        this.predicate = predicate;
+        this.isLiteral = isLiteral;
+    }
+
+    public void analyse(IDocument document) throws RatDocumentAnalysisException {
+        final String name = document.getName();
+        try {
+            final CharSequence object = toObject(document);
+            reporter.claim(name, predicate, object, isLiteral);
+        } catch (RatReportFailedException e) {
+            throw new RatReportAnalysisResultException(e);
+        }
+    }
+    
+    protected abstract CharSequence toObject(final IDocument document) throws RatDocumentAnalysisException;
+}

Added: incubator/rat/import/rat/src/java/rat/report/analyser/ConstantClaimAnalyser.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/analyser/ConstantClaimAnalyser.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/analyser/ConstantClaimAnalyser.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/analyser/ConstantClaimAnalyser.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report.analyser;
+
+import rat.document.IDocument;
+import rat.document.RatDocumentAnalysisException;
+import rat.report.claim.IClaimReporter;
+
+public class ConstantClaimAnalyser extends AbstractSingleClaimAnalyser {
+
+    private final CharSequence object;
+    public ConstantClaimAnalyser(final IClaimReporter reporter, final CharSequence predicate, 
+            final CharSequence object, final boolean isLiteral) {
+        super(reporter, predicate, isLiteral);
+        this.object = object;
+    }
+
+    protected CharSequence toObject(IDocument document) throws RatDocumentAnalysisException {
+        return object;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/report/analyser/DefaultAnalyserFactory.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/analyser/DefaultAnalyserFactory.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/analyser/DefaultAnalyserFactory.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/analyser/DefaultAnalyserFactory.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report.analyser;
+
+import rat.analysis.IHeaderMatcher;
+import rat.document.IDocumentAnalyser;
+import rat.document.IDocumentMatcher;
+import rat.document.impl.guesser.ArchiveGuesser;
+import rat.document.impl.guesser.BinaryGuesser;
+import rat.document.impl.guesser.NoteGuesser;
+import rat.document.impl.util.ConditionalAnalyser;
+import rat.document.impl.util.DocumentAnalyserMultiplexer;
+import rat.document.impl.util.DocumentMatcherMultiplexer;
+import rat.document.impl.util.MatchNegator;
+import rat.report.claim.IClaimReporter;
+
+/**
+ * Creates default analysers.
+ *
+ */
+public class DefaultAnalyserFactory {
+    
+    public static final IDocumentAnalyser createArchiveTypeAnalyser(final IClaimReporter reporter) {
+        final AbstractSingleClaimAnalyser constantClaimAnalyser = new ConstantClaimAnalyser(reporter, "type", "archive", false);
+        return constantClaimAnalyser;
+    }
+    
+    public static final IDocumentAnalyser createNoticeTypeAnalyser(final IClaimReporter reporter) {
+        final AbstractSingleClaimAnalyser constantClaimAnalyser = new ConstantClaimAnalyser(reporter, "type", "notice", false);
+        return constantClaimAnalyser;
+    }
+    
+    public static final IDocumentAnalyser createBinaryTypeAnalyser(final IClaimReporter reporter) {
+        final AbstractSingleClaimAnalyser constantClaimAnalyser = new ConstantClaimAnalyser(reporter, "type", "binary", false);
+        return constantClaimAnalyser;
+    }
+    
+    public static final IDocumentAnalyser createStandardTypeAnalyser(final IClaimReporter reporter) {
+        final AbstractSingleClaimAnalyser constantClaimAnalyser = new ConstantClaimAnalyser(reporter, "type", "standard", false);
+        return constantClaimAnalyser;
+    }
+    
+    public static final IDocumentAnalyser createDefaultBinaryAnalyser(final IClaimReporter reporter) {
+        final IDocumentAnalyser result = createBinaryTypeAnalyser(reporter);
+        return result;
+    }
+    
+    public static final IDocumentAnalyser createDefaultNoticeAnalyser(final IClaimReporter reporter) {
+        final IDocumentAnalyser result = createNoticeTypeAnalyser(reporter);
+        return result;
+    }
+    
+    public static final IDocumentAnalyser createDefaultArchiveAnalyser(final IClaimReporter reporter) {
+        final IDocumentAnalyser[] components = {
+                createArchiveTypeAnalyser(reporter),
+                new ReadableArchiveAnalyser(reporter)
+        };
+        final DocumentAnalyserMultiplexer result = new DocumentAnalyserMultiplexer(components);
+        return result;
+    }
+    
+    public static final IDocumentAnalyser createDefaultStandardAnalyser(final IClaimReporter reporter, 
+            final IHeaderMatcher matcher) {
+        final IDocumentAnalyser[] components = {
+                createStandardTypeAnalyser(reporter),
+                new DocumentHeaderAnalyser(matcher, reporter)
+        };
+        final DocumentAnalyserMultiplexer result = new DocumentAnalyserMultiplexer(components);
+        return result;
+    }
+    
+    public static final IDocumentAnalyser createDefaultAnalyser(final IClaimReporter reporter, 
+            final IHeaderMatcher matcher) {
+        
+        final IDocumentAnalyser binaryAnalyser = createDefaultBinaryAnalyser(reporter);
+        final IDocumentAnalyser archiveAnalyser = createDefaultArchiveAnalyser(reporter);
+        final IDocumentAnalyser noticeAnalyser = createDefaultNoticeAnalyser(reporter);
+        final IDocumentAnalyser standardAnalyser = createDefaultStandardAnalyser(reporter, matcher);
+        
+        return createDefaultAnalyser(binaryAnalyser, archiveAnalyser, noticeAnalyser, standardAnalyser);
+    }
+
+    public static IDocumentAnalyser createDefaultAnalyser(final IDocumentAnalyser binaryAnalyser, final IDocumentAnalyser archiveAnalyser, final IDocumentAnalyser noticeAnalyser, final IDocumentAnalyser standardAnalyser) {
+        final IDocumentMatcher binaryGuesser = new BinaryGuesser();
+        final IDocumentMatcher archiveGuesser = new ArchiveGuesser();
+        final IDocumentMatcher noteGuesser = new NoteGuesser();
+        
+        return createDefaultAnalyser(binaryAnalyser, archiveAnalyser, noticeAnalyser, standardAnalyser, binaryGuesser, archiveGuesser, noteGuesser);
+    }
+
+    public static IDocumentAnalyser createDefaultAnalyser(final IDocumentAnalyser binaryAnalyser, final IDocumentAnalyser archiveAnalyser, final IDocumentAnalyser noticeAnalyser, final IDocumentAnalyser standardAnalyser, final IDocumentMatcher binaryGuesser, final IDocumentMatcher archiveGuesser, final IDocumentMatcher noteGuesser) {
+        final IDocumentMatcher binaryMatcher = new ConditionalAnalyser(binaryGuesser, binaryAnalyser);
+        final IDocumentMatcher noticeMatcher = new ConditionalAnalyser(noteGuesser, noticeAnalyser);
+        final IDocumentMatcher archiveMatcher = new ConditionalAnalyser(archiveGuesser, archiveAnalyser);
+        final IDocumentMatcher[] matchers = {noticeMatcher, archiveMatcher, binaryMatcher};
+        final IDocumentMatcher specialDocumentMatcher = new DocumentMatcherMultiplexer(matchers);
+        final IDocumentMatcher documentMatcher = new MatchNegator(specialDocumentMatcher);
+        
+        final ConditionalAnalyser result = new ConditionalAnalyser(documentMatcher, standardAnalyser);
+        return result;
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/report/analyser/DocumentHeaderAnalyser.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/analyser/DocumentHeaderAnalyser.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/analyser/DocumentHeaderAnalyser.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/analyser/DocumentHeaderAnalyser.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report.analyser;
+
+import java.io.IOException;
+import java.io.Reader;
+
+import rat.analysis.IHeaderMatcher;
+import rat.analysis.RatHeaderAnalysisException;
+import rat.document.IDocument;
+import rat.document.IDocumentAnalyser;
+import rat.document.RatDocumentAnalysisException;
+import rat.report.claim.IClaimReporter;
+
+public class DocumentHeaderAnalyser implements IDocumentAnalyser {
+
+    private final IHeaderMatcher matcher;
+    // TODO: coupling to unknown license should be replaced
+    private final IClaimReporter reporter;
+    
+    public DocumentHeaderAnalyser(final IHeaderMatcher matcher, final IClaimReporter reporter) {
+        super();
+        this.matcher = matcher;
+        this.reporter = reporter;
+    }
+
+    public void analyse(IDocument document) throws RatDocumentAnalysisException {
+        Reader reader = null;
+        try {
+            reader = document.reader();
+            final String name = document.getName();
+            // TODO: worker function should be moved into this class
+            HeaderCheckWorker worker = new HeaderCheckWorker(reader, matcher, reporter, name);
+            worker.read();
+        } catch (IOException e) {
+            throw new RatDocumentAnalysisException("Cannot read header", e);
+        } catch (RatHeaderAnalysisException e) {
+            throw new RatDocumentAnalysisException("Cannot analyse header", e);
+        } finally {
+            if (reader != null) {
+                try {
+                    reader.close();
+                } catch (IOException e) {
+                    // SWALLOW
+                }
+            }
+        }
+     }
+
+}

Added: incubator/rat/import/rat/src/java/rat/report/analyser/HeaderCheckWorker.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/analyser/HeaderCheckWorker.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/analyser/HeaderCheckWorker.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/analyser/HeaderCheckWorker.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,120 @@
+package rat.report.analyser;
+/*
+ *     Copyright 2006 Robert Burrell Donkin
+ *  
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *  
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ */
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+
+import rat.analysis.Claims;
+import rat.analysis.IHeaderMatcher;
+import rat.analysis.RatHeaderAnalysisException;
+import rat.report.RatReportFailedException;
+import rat.report.claim.IClaimReporter;
+
+/**
+ * <p>Reads from a stream to check license.</p>
+ * <p><strong>Note</strong> that this class is not thread safe.</p> 
+ */
+class HeaderCheckWorker {
+
+    public static final int DEFAULT_NUMBER_OF_RETAINED_HEADER_LINES = 50;
+	
+	private final int numberOfRetainedHeaderLines;
+	private final BufferedReader reader;
+	private final IHeaderMatcher matcher;
+	private final IClaimReporter reporter;
+    private final String name;
+    
+	private boolean match = false;
+	
+	private int headerLinesToRead;
+	private boolean finished = false;
+
+	public HeaderCheckWorker(Reader reader, int numberOfRetainedHeaderLine, 
+            final IHeaderMatcher matcher, final IClaimReporter reporter, final String name) {
+		this(new BufferedReader(reader), numberOfRetainedHeaderLine, matcher, reporter, name);
+	}
+	
+	
+	/**
+	 * Convenience constructor wraps given <code>Reader</code> 
+	 * in a <code>BufferedReader</code>.
+	 * @param name the name of the checked content, possibly null
+	 * @param reader a <code>Reader</code> for the content, not null
+	 */
+	public HeaderCheckWorker(Reader reader, final IHeaderMatcher matcher, final IClaimReporter reporter, final String name) {
+		this(new BufferedReader(reader), matcher, reporter, name);
+	}
+	
+	public HeaderCheckWorker(BufferedReader reader, final IHeaderMatcher matcher,
+            final IClaimReporter reporter, final String name) {
+		this(reader, DEFAULT_NUMBER_OF_RETAINED_HEADER_LINES, matcher, reporter, name);
+	}
+	
+	public HeaderCheckWorker(BufferedReader reader, int numberOfRetainedHeaderLine, final IHeaderMatcher matcher,
+            final IClaimReporter reporter, final String name) {
+		this.reader = reader;
+		this.numberOfRetainedHeaderLines = numberOfRetainedHeaderLine;
+		this.matcher = matcher;
+        this.reporter = reporter;
+        this.name = name;
+	}	
+	
+	public boolean isFinished() {
+		return finished;
+	}
+
+	public void read() throws RatHeaderAnalysisException {
+		if (!finished) {
+			final StringBuffer headers = new StringBuffer();
+			headerLinesToRead = numberOfRetainedHeaderLines;
+			try {
+				while(readLine(headers));
+				if (!match) {
+					final String notes = headers.toString();
+                    // TODO: this should be factored into a header matcher
+                    Claims.reportStandardClaims(name, notes, "?????", "UNKNOWN", reporter);
+				}
+			} catch (IOException e) {
+                throw new RatHeaderAnalysisException("Cannot read header for " + name, e);
+			} catch (RatReportFailedException e) {
+                throw new RatHeaderAnalysisException("Cannot write claim for " + name, e);
+            }
+			try {
+				reader.close();
+			} catch (IOException e) {
+				// swallow
+			}
+            matcher.reset();
+		}
+		finished = true;
+	}
+	
+	boolean readLine(StringBuffer headers) throws IOException, RatHeaderAnalysisException {
+		String line = reader.readLine();
+		boolean result = line != null;
+		if (result) {
+			if (headerLinesToRead-- > 0) {
+				headers.append(line);
+				headers.append('\n');
+			}
+            match = matcher.match(name, line, reporter);
+			result = !match;
+		}
+		return result;
+	}
+}

Added: incubator/rat/import/rat/src/java/rat/report/analyser/RatReportAnalysisResultException.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/analyser/RatReportAnalysisResultException.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/analyser/RatReportAnalysisResultException.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/analyser/RatReportAnalysisResultException.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report.analyser;
+
+import rat.document.RatDocumentAnalysisException;
+import rat.report.RatReportFailedException;
+
+public class RatReportAnalysisResultException extends RatDocumentAnalysisException {
+    
+    private static final long serialVersionUID = 4018716722707721989L;
+    private static final String MESSAGE = "Could not report results of analysis";
+    
+    public RatReportAnalysisResultException() {
+        super(MESSAGE);
+    }
+
+    public RatReportAnalysisResultException(RatReportFailedException cause) {
+        super(MESSAGE, cause);
+    }
+
+    public RatReportAnalysisResultException(String msg, RatReportFailedException cause) {
+        super(msg, cause);
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/report/analyser/ReadableArchiveAnalyser.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/analyser/ReadableArchiveAnalyser.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/analyser/ReadableArchiveAnalyser.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/analyser/ReadableArchiveAnalyser.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report.analyser;
+
+import java.io.IOException;
+
+import rat.document.IDocument;
+import rat.document.IDocumentCollection;
+import rat.document.RatDocumentAnalysisException;
+import rat.report.claim.IClaimReporter;
+
+public final class ReadableArchiveAnalyser extends AbstractSingleClaimAnalyser {
+
+    public static final String READABLE_ARCHIVE_VALUE = "readable";
+    public static final String UNREADABLE_ARCHIVE_VALUE = "unreadable";
+    
+    
+    public ReadableArchiveAnalyser(IClaimReporter reporter) {
+        super(reporter, "archive-type", false);
+    }
+
+    protected CharSequence toObject(IDocument document) throws RatDocumentAnalysisException {
+        boolean readable = false;
+        try {
+            final IDocumentCollection contents = document.readArchive();
+            if (contents != null) {
+                readable = true;
+            }
+        } catch (IOException e) {
+            readable = false;
+        }
+        String result = UNREADABLE_ARCHIVE_VALUE;
+        if (readable) {
+            result = READABLE_ARCHIVE_VALUE;
+        }
+        return result;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/report/claim/IClaimReporter.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/claim/IClaimReporter.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/claim/IClaimReporter.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/claim/IClaimReporter.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report.claim;
+
+import rat.report.RatReportFailedException;
+
+public interface IClaimReporter {
+
+    /**
+     * States a claim.
+     * @param subject subject of this claim, not null
+     * @param predicate predicate claimed, not null
+     * @param object object of this claim, not null
+     * @param isLiteral <code>true</code> is the object of this claim is a literal,
+     * <code>false</code> if the object of this claim is an identifier
+     */
+    public void claim(CharSequence subject, CharSequence predicate, CharSequence object, boolean isLiteral)
+        throws RatReportFailedException;
+}

Added: incubator/rat/import/rat/src/java/rat/report/claim/impl/xml/SimpleXmlClaimReporter.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/claim/impl/xml/SimpleXmlClaimReporter.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/claim/impl/xml/SimpleXmlClaimReporter.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/claim/impl/xml/SimpleXmlClaimReporter.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report.claim.impl.xml;
+
+import java.io.IOException;
+
+import rat.report.RatReportFailedException;
+import rat.report.claim.IClaimReporter;
+import rat.report.xml.writer.IXmlWriter;
+
+public class SimpleXmlClaimReporter implements IClaimReporter {
+
+    private static final String NAME = "name";
+    private final IXmlWriter writer;
+    private CharSequence lastSubject;
+    
+    public SimpleXmlClaimReporter(final IXmlWriter writer) {
+        this.writer = writer;
+    }
+    
+    public void claim(CharSequence subject, CharSequence predicate,
+            CharSequence object, boolean isLiteral) throws RatReportFailedException {
+        try {
+            if (!(subject.equals(lastSubject))) {
+                if (lastSubject != null) {
+                    writer.closeElement();
+                }
+                writer.openElement("resource").attribute(NAME, subject);
+            }
+            if (isLiteral) {
+                writer.openElement(predicate).content(object).closeElement();
+            } else {
+                writer.openElement(predicate).attribute(NAME, object).closeElement();
+            }
+            lastSubject = subject;
+        } catch (IOException e) {
+            throw new RatReportFailedException("XML writing failure: " + e.getMessage() + " subject: " + subject + " predicate: " + predicate, e);
+        }
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/report/claim/util/ClaimReporterMultiplexer.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/claim/util/ClaimReporterMultiplexer.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/claim/util/ClaimReporterMultiplexer.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/claim/util/ClaimReporterMultiplexer.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report.claim.util;
+
+import rat.report.RatReportFailedException;
+import rat.report.claim.IClaimReporter;
+
+public class ClaimReporterMultiplexer implements IClaimReporter {
+
+    private final IClaimReporter[] reporters;
+        
+    public ClaimReporterMultiplexer(final IClaimReporter[] reporters) {
+        super();
+        this.reporters = reporters;
+    }
+
+    public void claim(CharSequence subject, CharSequence predicate,
+            CharSequence object, boolean isLiteral)
+            throws RatReportFailedException {
+        final int length = reporters.length;
+        for (int i=0;i<length;i++) {
+            reporters[i].claim(subject, predicate, object, isLiteral);
+        }
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/report/xml/XmlReport.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/xml/XmlReport.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/xml/XmlReport.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/xml/XmlReport.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report.xml;
+
+import java.io.IOException;
+
+import rat.document.IDocument;
+import rat.document.IDocumentAnalyser;
+import rat.document.RatDocumentAnalysisException;
+import rat.report.RatReport;
+import rat.report.RatReportFailedException;
+import rat.report.xml.writer.IXmlWriter;
+
+class XmlReport implements RatReport {
+   
+    private final IDocumentAnalyser analyser;
+    private final IXmlWriter writer;
+    
+    public XmlReport(final IXmlWriter writer, IDocumentAnalyser analyser) {
+        this.analyser = analyser;
+        this.writer = writer;
+    }
+
+    public void startReport() throws RatReportFailedException {
+        try {
+            writer.openElement("rat-report");
+        } catch (IOException e) {
+            throw new RatReportFailedException("Cannot open start element", e);
+        }
+    }
+
+    public void endReport() throws RatReportFailedException {
+        try {
+            writer.closeDocument();
+        } catch (IOException e) {
+            throw new RatReportFailedException("Cannot close last element", e);
+        }
+    }
+
+    public void report(IDocument document) throws RatReportFailedException {
+        try {
+            analyser.analyse(document);
+        } catch (RatDocumentAnalysisException e) {
+            throw new RatReportFailedException("Analysis failed", e);
+        }
+    }    
+}

Added: incubator/rat/import/rat/src/java/rat/report/xml/XmlReportFactory.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/report/xml/XmlReportFactory.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/report/xml/XmlReportFactory.java (added)
+++ incubator/rat/import/rat/src/java/rat/report/xml/XmlReportFactory.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * 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 rat.report.xml;
+
+import rat.analysis.IHeaderMatcher;
+import rat.document.IDocumentAnalyser;
+import rat.license.ILicenseFamily;
+import rat.policy.DefaultPolicy;
+import rat.report.RatReport;
+import rat.report.analyser.DefaultAnalyserFactory;
+import rat.report.claim.IClaimReporter;
+import rat.report.claim.impl.xml.SimpleXmlClaimReporter;
+import rat.report.claim.util.ClaimReporterMultiplexer;
+import rat.report.xml.writer.IXmlWriter;
+
+/**
+ * Creates reports.
+ *
+ */
+public class XmlReportFactory {
+    
+    public static final RatReport createStandardReport(final IXmlWriter writer, 
+            final IHeaderMatcher matcher) {
+        return createStandardReport(writer, matcher, null);
+    }
+    
+    public static final RatReport createStandardReport(final IXmlWriter writer, 
+            final IHeaderMatcher matcher, final ILicenseFamily[] approvedLicenses) {
+        // TODO: this isn't very elegant :-/
+        // TODO: should really pass in analysers but this means injecting reporter
+        final SimpleXmlClaimReporter reporter = new SimpleXmlClaimReporter(writer);
+        final DefaultPolicy policy = new DefaultPolicy(reporter, approvedLicenses);
+        final IClaimReporter[] reporters = {reporter, policy};
+        final ClaimReporterMultiplexer multiplexer = new ClaimReporterMultiplexer(reporters);
+        
+        final IDocumentAnalyser analyser = 
+            DefaultAnalyserFactory.createDefaultAnalyser(multiplexer, matcher);
+        
+        final RatReport result = new XmlReport(writer, analyser);
+        return result;
+    }
+}



Mime
View raw message