1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one * 3 * or more contributor license agreements. See the NOTICE file * 4 * distributed with this work for additional information * 5 * regarding copyright ownership. The ASF licenses this file * 6 * to you under the Apache License, Version 2.0 (the * 7 * "License"); you may not use this file except in compliance * 8 * with the License. You may obtain a copy of the License at * 9 * * 10 * http://www.apache.org/licenses/LICENSE-2.0 * 11 * * 12 * Unless required by applicable law or agreed to in writing, * 13 * software distributed under the License is distributed on an * 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 15 * KIND, either express or implied. See the License for the * 16 * specific language governing permissions and limitations * 17 * under the License. * 18 */ 19 20 package org.apache.rat.walker; 21 22 import java.util.SortedSet; 23 24 import org.apache.rat.api.Document; 25 import org.apache.rat.api.RatException; 26 import org.apache.rat.report.RatReport; 27 28 /** 29 * Walks directories. 30 */ 31 public class DirectoryWalker extends Walker { 32 33 /** 34 * Constructs a directory walker. 35 * 36 * @param document the document to process. 37 */ 38 public DirectoryWalker(final Document document) { 39 super(document); 40 } 41 42 /** 43 * Run a report over all files and directories in this DirectoryWalker, 44 * ignoring any files/directories set to be ignored. 45 * 46 * @param report the defined RatReport to run on this Directory walker. 47 * @throws RatException on error 48 */ 49 public void run(final RatReport report) throws RatException { 50 process(report, getDocument()); 51 } 52 53 /** 54 * Process a directory, ignoring any files/directories set to be ignored. 55 * 56 * @param report the report to use in processing 57 * @param document the document to run the report against 58 * @throws RatException on error 59 */ 60 protected void process(final RatReport report, final Document document) throws RatException { 61 final SortedSet<Document> documents = document.listChildren(); 62 if (documents != null) { 63 for (final Document doc : documents) { 64 if (doc.isIgnored() || !doc.isDirectory()) { 65 report.report(doc); 66 } else { 67 process(report, doc); 68 } 69 } 70 } 71 } 72 }