org.wings.template.FileTemplateSource Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2000,2005 wingS development team.
*
* This file is part of wingS (http://wingsframework.org).
*
* wingS is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* Please see COPYING for the complete licence.
*/
package org.wings.template;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
/**
* A FileDataSource
implements a TemplateSource
* for a file.
*
* @author Henner Zeller
*/
public class FileTemplateSource implements TemplateSource, Serializable {
private File file;
protected String canonicalName = null;
public FileTemplateSource(File f) {
this.file = f;
if (file != null) {
try {
canonicalName = "file:" + file.getCanonicalPath();
} catch (IOException e) {
// should never happen for files ..
}
}
}
/**
* Returns a canonical name of this DataSource.
*/
@Override
public String getCanonicalName() {
return canonicalName;
}
/**
* Returns the time the content of this File
* was last modified.
*
* The return value is used to decide whether to reparse a
* Source or not. Reparsing is done if the value returned
* here differs from the value returned at the last processing
* time.
*
* @return long a modification time
*/
@Override
public long lastModified() {
return file.lastModified();
}
/**
* Gets an InputStream of the File.
*/
@Override
public InputStream getInputStream()
throws IOException {
return new FileInputStream(file);
}
}