
com.itextpdf.tool.itextdoc.site.SiteWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of itextdoc Show documentation
Show all versions of itextdoc Show documentation
This maven plugin main purpose is to pars html files defined in an xml file, that's in itextdoc.xsd style, to one PDF.
The newest version!
/*
*
* This file is part of the iText (R) project.
* Copyright (c) 1998-2011 1T3XT BVBA
* Authors: Balder Van Camp, et al.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3
* as published by the Free Software Foundation with the addition of the
* following permission added to Section 15 as permitted in Section 7(a):
* FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY 1T3XT,
* 1T3XT DISCLAIMS THE WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, see http://www.gnu.org/licenses or write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA, 02110-1301 USA, or download the license from the following URL:
* http://itextpdf.com/terms-of-use/
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License.
*
* In accordance with Section 7(b) of the GNU Affero General Public License,
* a covered work must retain the producer line in every PDF that is created
* or manipulated using iText.
*
* You can be released from the requirements of the license by purchasing
* a commercial license. Buying such a license is mandatory as soon as you
* develop commercial activities involving the iText software without
* disclosing the source code of your own applications.
* These activities include: offering paid services to customers as an ASP,
* serving PDFs on the fly in a web application, shipping iText with a closed
* source product.
*
* For more information, please contact iText Software Corp. at this
* address: [email protected]
*/
package com.itextpdf.tool.itextdoc.site;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import com.itextpdf.tool.xml.Experimental;
/**
* @author redlab_b http://www.redlab.be/
*
*/
@Experimental
public class SiteWriter {
/**
*
*/
public SiteWriter() {
}
/**
* Writes something like
*
*
* <?xml version="1.0" encoding="ISO-8859-1" ?>
* <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
* <html xmlns="http://www.w3.org/1999/xhtml">
* <head>
* <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
*
*
* @param out the OutputStream to write to.
* @param encoding the encoding to use
* @return this the instance of SiteWriter
* @throws IOException if something could not be written
*/
public SiteWriter writeHeadOpen(final OutputStream out, final String encoding) throws IOException {
write(out, "")
.
writeLF(out)
.
write(out,
"")
.writeLF(out).
write(
out,
"").writeLF(out)
.write(out, "").writeLF(out);
return this;
}
/**
* @param out the OutputStream to write to.
* @param title the title of the site
* @return this this instance of XMLWorker
* @throws IOException if something could not be written
*/
public SiteWriter writeTitle(final OutputStream out, final String title) throws IOException {
write(out, "").write(out, title).write(out, " ").writeLF(out);
return this;
}
/**
* Writes a linefeed/carriage return
*
* @param out the OutputStream to write to.
* @return this this instance of XMLWorker
* @throws IOException if something could not be written
*/
public SiteWriter writeLF(final OutputStream out) throws IOException {
write(out, "\n");
return this;
}
/**
* @param out the OutputStream to write to.
* @param str the String to write
* @return this this instance of XMLWorker
* @throws IOException if something could not be written
*/
public SiteWriter write(final OutputStream out, final String str) throws IOException {
out.write(str.getBytes());
return this;
}
/**
* @param out the OutputStream to write to.
* @param src the link to the JavaScript file
* @return this this instance of XMLWorker
* @throws IOException if something could not be written
*/
public SiteWriter writeScript(final OutputStream out, final String src) throws IOException {
write(out, "").writeLF(out);
return this;
}
/**
* @param out the OutputStream to write to.
* @param href the link to the stylesheet file
* @return this this instance of XMLWorker
* @throws IOException if something could not be written
*/
public SiteWriter writeStyleLink(final OutputStream out, final String href) throws IOException {
write(out, "").writeLF(out);
return this;
}
/**
* @param out the OutputStream to write to.
* @return this this instance of XMLWorker
* @throws IOException if something could not be written
*/
public SiteWriter writeHeadCloseBodyOpen(final OutputStream out) throws IOException {
write(out, "").writeLF(out);
return this;
}
/**
* @param out the OutputStream to write to.
* @param in content
* @param wrapId the id of the div used for wrapping, if null, no wrapping
* is done
* @return this this instance of XMLWorker
* @throws IOException if something could not be written
*/
public SiteWriter writeDivContent(final OutputStream out, final InputStream in, final String wrapId)
throws IOException {
if (null != wrapId) {
write(out, "");
}
writeContent(out, in);
if (null != wrapId) {
write(out, "");
}
return this;
}
/**
* @param out the OutputStream to write to.
* @param in the InputStream to read content from, it's closed after use.
* @return this this instance of XMLWorker
* @throws IOException if something could not be written
*/
public SiteWriter writeContent(final OutputStream out, final InputStream in) throws IOException {
try {
int length = -1;
byte[] b = new byte[2048];
while (-1 != (length = in.read(b))) {
out.write(b, 0, length);
}
} finally {
in.close();
}
return this;
}
/**
* @param out the OutputStream to write to.
* @return this this instance of XMLWorker
* @throws IOException if something could not be written
*/
public SiteWriter writeBodyClose(final OutputStream out) throws IOException {
write(out, "").writeLF(out);
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy