Writer2xhtml custom config ui
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@58 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
977a2f7d6b
commit
93d1e472c6
9 changed files with 229 additions and 20 deletions
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-03-31)
|
||||
* Version 1.2 (2010-04-12)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -79,6 +79,9 @@ public class Converter extends ConverterBase {
|
|||
|
||||
// The template
|
||||
private XhtmlDocument template = null;
|
||||
|
||||
// The included style sheet
|
||||
private CssDocument styleSheet = null;
|
||||
|
||||
// The xhtml output file(s)
|
||||
protected int nType = XhtmlDocument.XHTML10; // the doctype
|
||||
|
@ -104,16 +107,27 @@ public class Converter extends ConverterBase {
|
|||
this.nType = nType;
|
||||
}
|
||||
|
||||
// override
|
||||
public void readTemplate(InputStream is) throws IOException {
|
||||
// override methods to read templates and style sheets
|
||||
@Override public void readTemplate(InputStream is) throws IOException {
|
||||
template = new XhtmlDocument("Template",nType);
|
||||
template.read(is);
|
||||
}
|
||||
|
||||
public void readTemplate(File file) throws IOException {
|
||||
@Override public void readTemplate(File file) throws IOException {
|
||||
readTemplate(new FileInputStream(file));
|
||||
}
|
||||
|
||||
@Override public void readStyleSheet(InputStream is) throws IOException {
|
||||
if (styleSheet==null) {
|
||||
styleSheet = new CssDocument("styles.css");
|
||||
}
|
||||
styleSheet.read(is);
|
||||
}
|
||||
|
||||
@Override public void readStyleSheet(File file) throws IOException {
|
||||
readStyleSheet(new FileInputStream(file));
|
||||
}
|
||||
|
||||
protected StyleConverter getStyleCv() { return styleCv; }
|
||||
|
||||
protected TextConverter getTextCv() { return textCv; }
|
||||
|
@ -223,6 +237,11 @@ public class Converter extends ConverterBase {
|
|||
}
|
||||
}
|
||||
|
||||
// Add included style sheet, if any
|
||||
if (styleSheet!=null) {
|
||||
converterResult.addDocument(styleSheet);
|
||||
}
|
||||
|
||||
// Export styles (temp.)
|
||||
for (int i=0; i<=nOutFileIndex; i++) {
|
||||
Document dom = outFiles.get(i).getContentDOM();
|
||||
|
@ -564,6 +583,17 @@ public class Converter extends ConverterBase {
|
|||
}*/
|
||||
// Note: For single output file, styles are exported to the doc at the end.
|
||||
|
||||
// Add link to included style sheet
|
||||
if (styleSheet!=null) {
|
||||
Element sty = htmlDOM.createElement("link");
|
||||
sty.setAttribute("rel", "stylesheet");
|
||||
sty.setAttribute("type", "text/css");
|
||||
sty.setAttribute("media", "all");
|
||||
sty.setAttribute("href", styleSheet.getFileName());
|
||||
htmlDoc.getHeadNode().appendChild(sty);
|
||||
}
|
||||
|
||||
|
||||
// Recreate nested sections, if any
|
||||
if (!textCv.sections.isEmpty()) {
|
||||
Iterator<Node> iter = textCv.sections.iterator();
|
||||
|
|
95
source/java/writer2latex/xhtml/CssDocument.java
Normal file
95
source/java/writer2latex/xhtml/CssDocument.java
Normal file
|
@ -0,0 +1,95 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* CssDocument.java
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2010 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-04-12)
|
||||
*
|
||||
*/
|
||||
|
||||
package writer2latex.xhtml;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
import writer2latex.api.OutputFile;
|
||||
|
||||
/**
|
||||
* An implementation of <code>OutputFile</code> for CSS documents.
|
||||
* (Actually this is a trivial implementation which never parses the files)
|
||||
*/
|
||||
public class CssDocument implements OutputFile {
|
||||
|
||||
// Content
|
||||
private String sName;
|
||||
private String sContent;
|
||||
|
||||
/**
|
||||
* Constructor (creates an empty document)
|
||||
* @param name <code>Document</code> name.
|
||||
*/
|
||||
public CssDocument(String sName) {
|
||||
this.sName = sName;
|
||||
sContent = "";
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return sName;
|
||||
}
|
||||
|
||||
public String getMIMEType() {
|
||||
return "text/css";
|
||||
}
|
||||
|
||||
public boolean isMasterDocument() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void write(OutputStream os) throws IOException {
|
||||
OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
|
||||
osw.write(sContent);
|
||||
osw.flush();
|
||||
osw.close();
|
||||
}
|
||||
|
||||
public void read(InputStream is) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
|
||||
StringBuffer buf = new StringBuffer();
|
||||
String sLine;
|
||||
while ((sLine=reader.readLine())!=null) {
|
||||
buf.append(sLine).append('\n');
|
||||
}
|
||||
sContent = buf.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue