org.archive.crawler.restlet.EditRepresentation Maven / Gradle / Ivy
The newest version!
/*
* This file is part of the Heritrix web crawler (crawler.archive.org).
*
* Licensed to the Internet Archive (IA) by one or more individual
* contributors.
*
* The IA 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.archive.crawler.restlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import org.apache.commons.lang.StringEscapeUtils;
import org.restlet.data.CharacterSet;
import org.restlet.data.MediaType;
import org.restlet.data.Reference;
import org.restlet.representation.CharacterRepresentation;
import org.restlet.representation.FileRepresentation;
/**
* Representation wrapping a FileRepresentation, displaying its contents
* in a TextArea for editing.
*
* @author gojomo
*/
public class EditRepresentation extends CharacterRepresentation {
protected FileRepresentation fileRepresentation;
protected EnhDirectoryResource dirResource;
public EditRepresentation(FileRepresentation representation, EnhDirectoryResource resource) {
super(MediaType.TEXT_HTML);
fileRepresentation = representation;
dirResource = resource;
// TODO: remove if not necessary in future?
setCharacterSet(CharacterSet.UTF_8);
}
@Override
public Reader getReader() throws IOException {
StringWriter writer = new StringWriter((int)fileRepresentation.getSize()+100);
write(writer);
return new StringReader(writer.toString());
}
protected String getStaticRef(String resource) {
String rootRef = dirResource.getRequest().getRootRef().toString();
return rootRef + "/engine/static/" + resource;
}
@Override
public void write(Writer writer) throws IOException {
PrintWriter pw = new PrintWriter(writer);
pw.println("");
pw.println("");
pw.println(""+fileRepresentation.getFile().getName()+" ");
pw.println("");
pw.println("");
pw.println("");
pw.println("");
pw.println("");
pw.println("");
pw.println("");
pw.println("");
pw.println("");
pw.println("");
pw.println("");
pw.println("");
}
public FileRepresentation getFileRepresentation() {
return fileRepresentation;
}
}