Various work on w2l 1.2

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@17 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2009-04-23 10:53:07 +00:00
parent 6f3a08b4f6
commit c410adda52
17 changed files with 202 additions and 60 deletions

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2009 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-11-24)
* Version 1.2 (2009-04-23)
*
*/
@ -132,38 +132,34 @@ public abstract class ExportFilterBase implements
return name;
}
public String replace(String origString, String origChar, String replaceChar){
String tmp="";
int index=origString.indexOf(origChar);
if(index !=-1){
while (index !=-1){
String first =origString.substring(0,index);
first=first.concat(replaceChar);
tmp=tmp.concat(first);
origString=origString.substring(index+1,origString.length());
index=origString.indexOf(origChar);
if(index==-1) {
tmp=tmp.concat(origString);
}
}
}
return tmp;
}
public String needsMask(String origString) {
if (origString.indexOf("&")!=-1){
origString=replace(origString,"&","&");
}
if (origString.indexOf("\"")!=-1){
origString=replace(origString,"\"",""");
}
if (origString.indexOf("<")!=-1){
origString=replace(origString,"<","&lt;");
}
if (origString.indexOf(">")!=-1){
origString=replace(origString,">","&gt;");
}
return origString;
StringBuffer buf = new StringBuffer();
int nLen = origString.length();
for (int i=0; i<nLen; i++) {
char c = origString.charAt(i);
if (c=='&'){
buf.append("&amp;");
}
if (c=='\"'){
buf.append("&quot;");
}
if (c=='<'){
buf.append("&lt;");
}
if (c=='>'){
buf.append("&gt;");
}
else if (c=='\u0009' || c=='\n' || c=='\r' || (c>='\u0020' && c<='\uD7FF') || (c>='\uE000' && c<'\uFFFD')) {
// Valid characters found at xml.com
// Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
buf.append(c);
}
else {
// Found illegal character
System.out.println("Illegal character : "+Integer.toHexString(c));
}
}
return buf.toString();
}
@ -233,7 +229,7 @@ public abstract class ExportFilterBase implements
// Implementation of XDocumentHandler:
// Flat xml is created by the sax events and passed through the pipe
// created by exporter()
public void startDocument () {
//Do nothing
}
@ -301,6 +297,7 @@ public abstract class ExportFilterBase implements
}
public void characters(String str){
str=needsMask(str);
try{
xOutStream.writeBytes(str.getBytes("UTF-8"));
}
@ -370,12 +367,12 @@ public abstract class ExportFilterBase implements
converter.setGraphicConverter(new GraphicConverterImpl(xComponentContext));
ConverterResult dataOut = null;
try {
//try {
dataOut = converter.convert(xis,sName);
}
catch (IOException e) {
//}
//catch (IOException e) {
// Fail silently
}
//}
// Write out files
Iterator<OutputFile> docEnum = dataOut.iterator();

View file

@ -20,14 +20,16 @@
*
* All Rights Reserved.
*
* Version 1.2 (2009-03-30)
* Version 1.2 (2009-04-23)
*
*/
package org.openoffice.da.comp.writer4latex;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Vector;
import com.sun.star.awt.XControl;
import com.sun.star.awt.XControlContainer;
@ -199,32 +201,99 @@ public final class ConfigurationDialog
}
return true;
}
private boolean autoConfigure(XWindow xWindow) {
externalApps.setApplication(ExternalApps.LATEX, "latex", "--interaction=batchmode %s");
externalApps.setApplication(ExternalApps.PDFLATEX, "pdflatex", "--interaction=batchmode %s");
externalApps.setApplication(ExternalApps.XELATEX, "xelatex", "--interaction=batchmode %s");
externalApps.setApplication(ExternalApps.DVIPS, "dvips", "%s");
externalApps.setApplication(ExternalApps.BIBTEX, "bibtex", "%s");
externalApps.setApplication(ExternalApps.MAKEINDEX, "makeindex", "%s");
externalApps.setApplication(ExternalApps.OOLATEX, "oolatex", "%s");
// Unix: Test to determine wether a certain application is available in the OS
// Requires "which", hence unix only
private boolean hasApp(String sAppName) {
try {
Vector<String> command = new Vector<String>();
command.add("which");
command.add(sAppName);
ProcessBuilder pb = new ProcessBuilder(command);
Process proc = pb.start();
// Gobble the error stream of the application
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR");
// Gooble the output stream of the application
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUTPUT");
errorGobbler.start();
outputGobbler.start();
// The application exists if the process exits with 0
return proc.waitFor()==0;
}
catch (InterruptedException e) {
return false;
}
catch (IOException e) {
return false;
}
}
// Unix: Configure a certain application testing the availability
private boolean configureApp(String sName, String sAppName, String sArguments) {
if (hasApp(sAppName)) {
externalApps.setApplication(sName, sAppName, sArguments);
return true;
}
else {
externalApps.setApplication(sName, "???", "???");
return false;
}
}
// Unix: Configure a certain application testing the availability
// This variant uses an array of potential apps
private boolean configureApp(String sName, String[] sAppNames, String sArguments) {
for (String sAppName : sAppNames) {
if (configureApp(sName, sAppName, sArguments)) { return true; }
}
return false;
}
// Configure the applications automatically (OS dependent)
private boolean autoConfigure(XWindow xWindow) {
String sOsName = System.getProperty("os.name");
if ("Linux".equals(sOsName)) {
// TODO: Search for applications (which...)
// Viewers may be evince, okular, xdvi, xpdf, ghostview or...
externalApps.setApplication(ExternalApps.DVIVIEWER, "evince", "%s");
externalApps.setApplication(ExternalApps.PDFVIEWER, "evince", "%s");
externalApps.setApplication(ExternalApps.POSTSCRIPTVIEWER, "evince", "%s");
configureApp(ExternalApps.LATEX, "latex", "--interaction=batchmode %s");
configureApp(ExternalApps.PDFLATEX, "pdflatex", "--interaction=batchmode %s");
configureApp(ExternalApps.XELATEX, "xelatex", "--interaction=batchmode %s");
configureApp(ExternalApps.DVIPS, "dvips", "%s");
configureApp(ExternalApps.BIBTEX, "bibtex", "%s");
configureApp(ExternalApps.MAKEINDEX, "makeindex", "%s");
configureApp(ExternalApps.OOLATEX, "oolatex", "%s");
// We have several possible viewers
String[] sDviViewers = {"evince", "okular", "xdvi"};
configureApp(ExternalApps.DVIVIEWER, sDviViewers, "%s");
String[] sPdfViewers = {"evince", "okular", "xpdf"};
configureApp(ExternalApps.PDFVIEWER, sPdfViewers, "%s");
String[] sPsViewers = {"evince", "okular", "ghostview"};
configureApp(ExternalApps.POSTSCRIPTVIEWER, sPsViewers, "%s");
}
else if ("Windows".equals(sOsName)) {
// TODO: Get information from the windows registry
// Assume MikTeX
externalApps.setApplication(ExternalApps.LATEX, "latex", "--interaction=batchmode %s");
externalApps.setApplication(ExternalApps.PDFLATEX, "pdflatex", "--interaction=batchmode %s");
externalApps.setApplication(ExternalApps.XELATEX, "xelatex", "--interaction=batchmode %s");
externalApps.setApplication(ExternalApps.DVIPS, "dvips", "%s");
externalApps.setApplication(ExternalApps.BIBTEX, "bibtex", "%s");
externalApps.setApplication(ExternalApps.MAKEINDEX, "makeindex", "%s");
externalApps.setApplication(ExternalApps.OOLATEX, "oolatex", "%s");
externalApps.setApplication(ExternalApps.DVIVIEWER, "yap", "--single-instance %s");
// And assume gsview for pdf and ps
// gsview32 may not be in the path, but at least this helps a bit
externalApps.setApplication(ExternalApps.PDFVIEWER, "gsview32.exe", "-e \"%s\"");
externalApps.setApplication(ExternalApps.POSTSCRIPTVIEWER, "gsview32.exe", "-e \"%s\"");
}
else {
// Unsupported OS
}
changeApplication(xWindow);
return true;
}