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 [3/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/document/impl/guesser/BinaryGuesser.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/BinaryGuesser.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/BinaryGuesser.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/BinaryGuesser.java Mon May 12 13:12:44 2008
@@ -0,0 +1,287 @@
+/*
+ * 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.io.IOException;
+import java.io.Reader;
+import java.util.Locale;
+
+import org.apache.rat.document.IDocument;
+import org.apache.rat.document.IDocumentMatcher;
+
+/**
+ * TODO: factor into MIME guesser and MIME->binary guesser
+ */
+public class BinaryGuesser implements IDocumentMatcher {
+
+ private static boolean isBinary(IDocument document) {
+ boolean result = false;
+ Reader reader = null;
+ try
+ {
+ reader = document.reader();
+ result = isBinary(reader);
+ }
+ catch (IOException e)
+ {
+ result = false;
+ }
+ finally
+ {
+ try
+ {
+ if (reader != null)
+ {
+ reader.close();
+ }
+ }
+ catch (IOException e)
+ {
+ // SWALLOW
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Do the first few bytes of the stream hint at a binary file?
+ */
+ public static boolean isBinary(Reader in) {
+ boolean result = false;
+ char[] taste = new char[100];
+ try {
+ int bytesRead = in.read(taste);
+ if (bytesRead > 0) {
+ int highBytes = 0;
+ for (int i=0;i<bytesRead;i++) {
+ if (taste[i] > BinaryGuesser.NON_ASCII_THREASHOLD
+ || taste[i] <= BinaryGuesser.ASCII_CHAR_THREASHOLD) {
+ highBytes++;
+ }
+ }
+ if (highBytes * BinaryGuesser.HIGH_BYTES_RATIO
+ > bytesRead * BinaryGuesser.TOTAL_READ_RATIO) {
+ result = true;
+ }
+ }
+ } catch (IOException e) {
+ // SWALLOW
+ }
+ return result;
+ }
+
+ public static final boolean isBinaryData(final String name) {
+ return extensionMatches(name, DATA_EXTENSIONS);
+ }
+
+ /**
+ * Is a file by that name a known non-binary file?
+ */
+ public static final boolean isNonBinary(final String name) {
+ if (name == null) {return false;}
+ return extensionMatches(name.toUpperCase(Locale.US),
+ BinaryGuesser.NON_BINARY_EXTENSIONS);
+ }
+
+ public static final boolean isExecutable(final String name) {
+ return name.equals(BinaryGuesser.JAVA) || extensionMatches(name, EXE_EXTENSIONS)
+ || containsExtension(name, EXE_EXTENSIONS);
+ }
+
+ public static boolean containsExtension(final String name,
+ final String[] exts) {
+ boolean result = false;
+ for (int i = 0; !result && i < exts.length; i++) {
+ result = name.indexOf("." + exts[i] + ".") >= 0;
+ }
+ return result;
+ }
+
+ public static boolean extensionMatches(final String name,
+ final String[] exts) {
+ boolean result = false;
+ for (int i = 0; !result && i < exts.length; i++) {
+ result = name.endsWith("." + exts[i]);
+ }
+ return result;
+ }
+
+ public static boolean isBytecode(final String name) {
+ return BinaryGuesser.extensionMatches(name, BYTECODE_EXTENSIONS);
+ }
+
+ public static final boolean isImage(final String name) {
+ return BinaryGuesser.extensionMatches(name, IMAGE_EXTENSIONS);
+ }
+
+ public static final boolean isKeystore(final String name) {
+ return BinaryGuesser.extensionMatches(name, KEYSTORE_EXTENSIONS);
+ }
+
+ /**
+ * Is a file by that name a known binary file?
+ */
+ public static final boolean isBinary(final String name) {
+ if (name == null) {return false;}
+ String normalisedName = GuessUtils.normalise(name);
+ return BinaryGuesser.JAR_MANIFEST.equals(name) || BinaryGuesser.isImage(normalisedName)
+ || BinaryGuesser.isKeystore(normalisedName) || BinaryGuesser.isBytecode(normalisedName)
+ || BinaryGuesser.isBinaryData(normalisedName) || BinaryGuesser.isExecutable(normalisedName);
+ }
+
+ public static final String[] DATA_EXTENSIONS = {
+ "DAT", "DOC",
+ "NCB", "IDB",
+ "SUO", "XCF",
+ "RAJ", "CERT",
+ "KS", "TS",
+ };
+ public static final String[] EXE_EXTENSIONS = {
+ "EXE", "DLL",
+ "LIB", "SO",
+ "A", "EXP",
+ };
+ public static final String[] KEYSTORE_EXTENSIONS = {
+ "JKS", "KEYSTORE", "PEM", "CRL"
+ };
+ public static final String[] IMAGE_EXTENSIONS = {
+ "PNG", "PDF",
+ "GIF", "GIFF",
+ "TIF", "TIFF",
+ "JPG", "JPEG",
+ "ICO",
+ };
+ public static final String[] BYTECODE_EXTENSIONS = {
+ "CLASS", "PYD",
+ "OBJ", "PYC",
+ };
+
+ /**
+ * Based on http://www.apache.org/dev/svn-eol-style.txt
+ */
+ public static final String[] NON_BINARY_EXTENSIONS = {
+ "AART",
+ "AC",
+ "AM",
+ "BAT",
+ "C",
+ "CAT",
+ "CGI",
+ "CLASSPATH",
+ "CMD",
+ "CONFIG",
+ "CPP",
+ "CSS",
+ "CWIKI",
+ "DATA",
+ "DCL",
+ "DTD",
+ "EGRM",
+ "ENT",
+ "FT",
+ "FN",
+ "FV",
+ "GRM",
+ "G",
+ "H",
+ "HTACCESS",
+ "HTML",
+ "IHTML",
+ "IN",
+ "JAVA",
+ "JMX",
+ "JSP",
+ "JS",
+ "JUNIT",
+ "JX",
+ "MANIFEST",
+ "M4",
+ "MF",
+ "MF",
+ "META",
+ "MOD",
+ "N3",
+ "PEN",
+ "PL",
+ "PM",
+ "POD",
+ "POM",
+ "PROJECT",
+ "PROPERTIES",
+ "PY",
+ "RB",
+ "RDF",
+ "RNC",
+ "RNG",
+ "RNX",
+ "ROLES",
+ "RSS",
+ "SH",
+ "SQL",
+ "SVG",
+ "TLD",
+ "TXT",
+ "TYPES",
+ "VM",
+ "VSL",
+ "WSDD",
+ "WSDL",
+ "XARGS",
+ "XCAT",
+ "XCONF",
+ "XEGRM",
+ "XGRM",
+ "XLEX",
+ "XLOG",
+ "XMAP",
+ "XML",
+ "XROLES",
+ "XSAMPLES",
+ "XSD",
+ "XSL",
+ "XSLT",
+ "XSP",
+ "XUL",
+ "XWEB",
+ "XWELCOME",
+ };
+ public static final String JAR_MANIFEST = "MANIFEST.MF";
+ public static final String JAVA = "JAVA";
+ public static final int HIGH_BYTES_RATIO = 100;
+ public static final int TOTAL_READ_RATIO = 30;
+ public static final int NON_ASCII_THREASHOLD = 256;
+ public static final int ASCII_CHAR_THREASHOLD = 8;
+
+ public boolean matches(final IDocument document) {
+ // TODO: reimplement the binary test algorithm?
+ // TODO: more efficient to move into standard analysis
+ // TODO: then use binary as default
+ final String name = document.getName();
+ boolean result = isBinary(name);
+ if (!result)
+ {
+ // try a taste
+ result = isBinary(document);
+ }
+ return result;
+ }
+
+
+
+}
Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/GuessUtils.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/GuessUtils.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/GuessUtils.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/GuessUtils.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.impl.guesser;
+
+import java.util.Locale;
+
+import org.apache.commons.lang.StringUtils;
+
+public class GuessUtils {
+
+ private static final String[] SEPARATORS = {"/", "\\"};
+
+ /**
+ * Converts name to upper case and strips any path.
+ * @param name
+ * @return
+ */
+ public static final String normalise(final String name) {
+ String result = name.toUpperCase(Locale.US);
+ final int lastSeparatorIndex = StringUtils.lastIndexOfAny(result, SEPARATORS);
+ final int length = result.length();
+ if (lastSeparatorIndex >= 0 && lastSeparatorIndex < length) {
+ result = result.substring(lastSeparatorIndex + 1);
+ }
+ return result;
+ }
+}
Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/NoteGuesser.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/NoteGuesser.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/NoteGuesser.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/guesser/NoteGuesser.java Mon May 12 13:12:44 2008
@@ -0,0 +1,76 @@
+/*
+ * 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.Arrays;
+import java.util.List;
+
+import org.apache.rat.document.IDocument;
+import org.apache.rat.document.IDocumentMatcher;
+
+public class NoteGuesser implements IDocumentMatcher {
+
+
+ public static final String[] NOTE_FILE_NAMES = {
+ "NOTICE", "LICENSE",
+ "LICENSE.TXT", "NOTICE.TXT",
+ "INSTALL", "INSTALL.TXT",
+ "README", "README.TXT",
+ "NEWS", "NEWS.TXT",
+ "AUTHOR", "AUTHOR.TXT",
+ "AUTHORS", "AUTHORS.txt",
+ "CHANGELOG", "CHANGELOG.TXT",
+ "DISCLAIMER", "DISCLAIMER.TXT",
+ "KEYS", "KEYS.TXT",
+ "RELEASE-NOTES", "RELEASE-NOTES.TXT",
+ "RELEASE_NOTES", "RELEASE_NOTES.TXT",
+ "UPGRADE", "UPGRADE.TXT",
+ "STATUS", "STATUS.TXT",
+ "THIRD_PARTY_NOTICES", "THIRD_PARTY_NOTICES.TXT",
+ "COPYRIGHT", "COPYRIGHT.TXT",
+ "BUILDING", "BUILDING.TXT",
+ };
+ public static final String[] NOTE_FILE_EXTENSIONS = {
+ "LICENSE", "LICENSE.TXT",
+ "NOTICE", "NOTICE.TXT",
+ };
+
+ /**
+ * Is a file by that name a note file?
+ */
+ public static final boolean isNote(final String name) {
+ if (name == null) {return false;}
+
+ List l = Arrays.asList(NoteGuesser.NOTE_FILE_NAMES);
+ String normalisedName = GuessUtils.normalise(name);
+
+ boolean result = l.contains(name) || l.contains(normalisedName);
+ for (int i = 0; !result && i < NoteGuesser.NOTE_FILE_EXTENSIONS.length; i++) {
+ result = normalisedName.endsWith("." + NoteGuesser.NOTE_FILE_EXTENSIONS[i]);
+ }
+ return result;
+ }
+
+ public boolean matches(final IDocument document) {
+ final String name = document.getName();
+ final boolean result = isNote(name);
+ return result;
+ }
+
+}
Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/ConditionalAnalyser.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/ConditionalAnalyser.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/ConditionalAnalyser.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/ConditionalAnalyser.java Mon May 12 13:12:44 2008
@@ -0,0 +1,52 @@
+/*
+ * 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.util;
+
+import org.apache.rat.document.IDocument;
+import org.apache.rat.document.IDocumentAnalyser;
+import org.apache.rat.document.IDocumentMatcher;
+import org.apache.rat.document.RatDocumentAnalysisException;
+
+/**
+ * Analyses documents matching given condition.
+ *
+ */
+public class ConditionalAnalyser implements IDocumentMatcher, IDocumentAnalyser {
+
+ private final IDocumentMatcher matcher;
+ private final IDocumentAnalyser analyser;
+
+ public ConditionalAnalyser(final IDocumentMatcher matcher, final IDocumentAnalyser analyser) {
+ super();
+ this.matcher = matcher;
+ this.analyser = analyser;
+ }
+
+ public boolean matches(final IDocument document) throws RatDocumentAnalysisException {
+ final boolean result = matcher.matches(document);
+ if (result) {
+ analyser.analyse(document);
+ }
+ return result;
+ }
+
+ public void analyse(final IDocument document) throws RatDocumentAnalysisException {
+ matches(document);
+ }
+}
Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/DocumentAnalyserMultiplexer.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/DocumentAnalyserMultiplexer.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/DocumentAnalyserMultiplexer.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/DocumentAnalyserMultiplexer.java Mon May 12 13:12:44 2008
@@ -0,0 +1,41 @@
+/*
+ * 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.util;
+
+import org.apache.rat.document.IDocument;
+import org.apache.rat.document.IDocumentAnalyser;
+import org.apache.rat.document.RatDocumentAnalysisException;
+
+public class DocumentAnalyserMultiplexer implements IDocumentAnalyser {
+
+ private final IDocumentAnalyser[] analysers;
+
+ public DocumentAnalyserMultiplexer(final IDocumentAnalyser[] analysers) {
+ super();
+ this.analysers = analysers;
+ }
+
+ public void analyse(IDocument document) throws RatDocumentAnalysisException {
+ final int length = analysers.length;
+ for (int i=0;i<length;i++) {
+ analysers[i].analyse(document);
+ }
+ }
+
+}
Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/DocumentMatcherMultiplexer.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/DocumentMatcherMultiplexer.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/DocumentMatcherMultiplexer.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/DocumentMatcherMultiplexer.java Mon May 12 13:12:44 2008
@@ -0,0 +1,50 @@
+/*
+ * 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.util;
+
+import org.apache.rat.document.IDocument;
+import org.apache.rat.document.IDocumentMatcher;
+import org.apache.rat.document.RatDocumentAnalysisException;
+
+/**
+ * Calls all the matchers in turn until one returns true.
+ *
+ */
+public class DocumentMatcherMultiplexer implements IDocumentMatcher {
+
+ private final IDocumentMatcher[] matchers;
+
+ public DocumentMatcherMultiplexer(final IDocumentMatcher[] matchers) {
+ super();
+ this.matchers = matchers;
+ }
+
+ public boolean matches(IDocument document) throws RatDocumentAnalysisException {
+ boolean result = false;
+ final int length = matchers.length;
+ for (int i=0;i<length;i++) {
+ if (matchers[i].matches(document)) {
+ result = true;
+ break;
+ }
+ }
+ return result;
+ }
+
+}
Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/MatchNegator.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/MatchNegator.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/MatchNegator.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/util/MatchNegator.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.impl.util;
+
+import org.apache.rat.document.IDocument;
+import org.apache.rat.document.IDocumentMatcher;
+import org.apache.rat.document.RatDocumentAnalysisException;
+
+/**
+ * Negatives the result of the given matcher.
+ *
+ */
+public final class MatchNegator implements IDocumentMatcher {
+
+ private final IDocumentMatcher matcher;
+
+ public MatchNegator(final IDocumentMatcher matcher) {
+ super();
+ this.matcher = matcher;
+ }
+
+ public boolean matches(IDocument document) throws RatDocumentAnalysisException {
+ return !matcher.matches(document);
+ }
+
+}
Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDirectory.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDirectory.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDirectory.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDirectory.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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDocument.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDocument.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDocument.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDocument.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.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 org.apache.rat.document.IDocument;
+import org.apache.rat.document.IDocumentCollection;
+import org.apache.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDocumentCollection.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDocumentCollection.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDocumentCollection.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDocumentCollection.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.impl.zip;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDocumentFactory.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDocumentFactory.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDocumentFactory.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipDocumentFactory.java Mon May 12 13:12:44 2008
@@ -0,0 +1,101 @@
+/*
+ * 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.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 org.apache.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipFileDocument.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipFileDocument.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipFileDocument.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipFileDocument.java Mon May 12 13:12:44 2008
@@ -0,0 +1,47 @@
+/*
+ * 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.zip;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.rat.document.IDocumentCollection;
+import org.apache.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipFileUnarchiver.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipFileUnarchiver.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipFileUnarchiver.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipFileUnarchiver.java Mon May 12 13:12:44 2008
@@ -0,0 +1,34 @@
+/*
+ * 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.zip;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.rat.document.IDocumentCollection;
+import org.apache.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipRootDirectory.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipRootDirectory.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipRootDirectory.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipRootDirectory.java Mon May 12 13:12:44 2008
@@ -0,0 +1,41 @@
+/*
+ * 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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipUtils.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipUtils.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipUtils.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/document/impl/zip/ZipUtils.java Mon May 12 13:12:44 2008
@@ -0,0 +1,66 @@
+/*
+ * 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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/ArrayCharFilter.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/ArrayCharFilter.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/ArrayCharFilter.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/ArrayCharFilter.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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/CharFilter.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/CharFilter.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/CharFilter.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/CharFilter.java Mon May 12 13:12:44 2008
@@ -0,0 +1,30 @@
+/*
+ * 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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/FilteringSequenceFactory.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/FilteringSequenceFactory.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/FilteringSequenceFactory.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/FilteringSequenceFactory.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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/HeaderBean.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/HeaderBean.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/HeaderBean.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/HeaderBean.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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/HeaderMatcher.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/HeaderMatcher.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/HeaderMatcher.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/header/HeaderMatcher.java Mon May 12 13:12:44 2008
@@ -0,0 +1,104 @@
+/*
+ * 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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/AcademicFree21LicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/AcademicFree21LicenseFamily.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/AcademicFree21LicenseFamily.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/AcademicFree21LicenseFamily.java Mon May 12 13:12:44 2008
@@ -0,0 +1,28 @@
+/*
+ * 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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/Apache20LicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/Apache20LicenseFamily.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/Apache20LicenseFamily.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/Apache20LicenseFamily.java Mon May 12 13:12:44 2008
@@ -0,0 +1,29 @@
+/*
+ * 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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/ILicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/ILicenseFamily.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/ILicenseFamily.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/ILicenseFamily.java Mon May 12 13:12:44 2008
@@ -0,0 +1,23 @@
+/*
+ * 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.license;
+
+public interface ILicenseFamily {
+ public String getFamilyName();
+}
Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/ModifiedBSDLicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/ModifiedBSDLicenseFamily.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/ModifiedBSDLicenseFamily.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/ModifiedBSDLicenseFamily.java Mon May 12 13:12:44 2008
@@ -0,0 +1,30 @@
+/*
+ * 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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/OASISLicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/OASISLicenseFamily.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/OASISLicenseFamily.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/OASISLicenseFamily.java Mon May 12 13:12:44 2008
@@ -0,0 +1,29 @@
+/*
+ * 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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/W3CDocumentLicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/W3CDocumentLicenseFamily.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/W3CDocumentLicenseFamily.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/W3CDocumentLicenseFamily.java Mon May 12 13:12:44 2008
@@ -0,0 +1,29 @@
+/*
+ * 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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/W3CSoftwareLicenseFamily.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/W3CSoftwareLicenseFamily.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/W3CSoftwareLicenseFamily.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/license/W3CSoftwareLicenseFamily.java Mon May 12 13:12:44 2008
@@ -0,0 +1,29 @@
+/*
+ * 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.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/plain-rat.xsl
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/plain-rat.xsl?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/plain-rat.xsl (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/plain-rat.xsl Mon May 12 13:12:44 2008
@@ -0,0 +1,81 @@
+<?xml version='1.0' ?>
+<!--
+ 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. *
+-->
+<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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/policy/DefaultPolicy.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/policy/DefaultPolicy.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/policy/DefaultPolicy.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/policy/DefaultPolicy.java Mon May 12 13:12:44 2008
@@ -0,0 +1,86 @@
+/*
+ * 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.policy;
+
+import java.util.Arrays;
+
+import org.apache.rat.analysis.Claims;
+import org.apache.rat.license.Apache20LicenseFamily;
+import org.apache.rat.license.ILicenseFamily;
+import org.apache.rat.license.ModifiedBSDLicenseFamily;
+import org.apache.rat.license.OASISLicenseFamily;
+import org.apache.rat.license.W3CDocumentLicenseFamily;
+import org.apache.rat.license.W3CSoftwareLicenseFamily;
+import org.apache.rat.report.RatReportFailedException;
+import org.apache.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/main/trunk/rat/rat-core/src/main/java/org/apache/rat/report/IReportable.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/report/IReportable.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/report/IReportable.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/report/IReportable.java Mon May 12 13:12:44 2008
@@ -0,0 +1,24 @@
+/*
+ * 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.report;
+
+public interface IReportable {
+
+ public void run(RatReport report) throws RatReportFailedException;
+}
Added: incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/report/RatReport.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/report/RatReport.java?rev=655625&view=auto
==============================================================================
--- incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/report/RatReport.java (added)
+++ incubator/rat/main/trunk/rat/rat-core/src/main/java/org/apache/rat/report/RatReport.java Mon May 12 13:12:44 2008
@@ -0,0 +1,30 @@
+/*
+ * 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.report;
+
+import org.apache.rat.document.IDocument;
+
+public interface RatReport {
+
+ public void startReport() throws RatReportFailedException;
+
+ public void report(IDocument document) throws RatReportFailedException;
+
+ public void endReport() throws RatReportFailedException;
+}