Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (c) 2011, REMPL.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1) Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3) Neither the name of the REMPL.com nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.rempl.readers.pdd;
// REMPL API classes
import com.rempl.api.Logger;
import com.rempl.api.Model;
import com.rempl.api.Reader;
import com.rempl.api.Rempler;
// file management
import java.io.File;
// collection management
import java.util.Iterator;
// files manipulation
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
// string manipulation
import org.apache.commons.lang.StringUtils;
/**
* Reader of PDD puzzles.
*
* @author Yegor Bugayenko ([email protected])
* @version $Id: PDDReader.java 795 2011-03-19 10:17:23Z [email protected] $
*/
public final class PDDReader implements Reader {
/**
* The {@link Rempler} we're working for.
* @see #setRempler(Rempler)
*/
private Rempler rempler;
/**
* Public ctor.
*/
public PDDReader() {
this.rempler = null;
}
/**
* {@inheritDoc}
*/
@Override
public void setRempler(final Rempler rpr) {
this.rempler = rpr;
}
/**
* {@inheritDoc}
*/
@Override
public boolean read(final Model model) throws java.io.IOException {
if (Logger.isTraceEnabled(this)) {
Logger.trace(this, "#read(model)");
}
final File dir = new File(
this.rempler.configuration().get("/*/sources/directory/text()")
);
if (Logger.isDebugEnabled(this)) {
Logger.debug(this, "#read(): reading from %s", dir.getPath());
}
final String include = this.rempler.configuration()
.get("/*/pdd/include/text()");
final String[] includes = StringUtils.stripAll(
StringUtils.split(include, ",")
);
if (Logger.isDebugEnabled(this)) {
Logger.debug(
this,
"#read(): including wildcards (%s)",
StringUtils.join(includes, ", ")
);
}
final Iterator files = FileUtils.iterateFiles(
dir,
// @see http://download.oracle.com/javase/6/docs/api/java/util/Collection.html#toArray(T[])
new WildcardFileFilter(includes),
DirectoryFileFilter.INSTANCE
);
while (files.hasNext()) {
model.transform(new FilePuzzles(files.next()).uml());
}
return false;
}
}