diff options
author | Svante Schubert <sus@openoffice.org> | 2001-02-08 17:25:07 +0000 |
---|---|---|
committer | Svante Schubert <sus@openoffice.org> | 2001-02-08 17:25:07 +0000 |
commit | 9bdee5cfcedb108b5a4abc1f2d934a48071772b5 (patch) | |
tree | 47948fd3e0a982ec896ececde8a750485524b670 /officecfg | |
parent | f4079ff69acb688bf35fa952e75500c95bb19d71 (diff) |
#82641# workaround for a xslt bug with default namespaces
Diffstat (limited to 'officecfg')
-rw-r--r-- | officecfg/org/openoffice/helper/DefaultNamespaceRemover.java | 96 | ||||
-rw-r--r-- | officecfg/org/openoffice/helper/makefile.mk | 13 |
2 files changed, 103 insertions, 6 deletions
diff --git a/officecfg/org/openoffice/helper/DefaultNamespaceRemover.java b/officecfg/org/openoffice/helper/DefaultNamespaceRemover.java new file mode 100644 index 000000000000..47747b701084 --- /dev/null +++ b/officecfg/org/openoffice/helper/DefaultNamespaceRemover.java @@ -0,0 +1,96 @@ +/** + * Title: workaround for xslt bug with default namespaces + * Description: removes the first default namespace from a given xml file<p> + * Copyright: null<p> + * Company: null<p> + * @author Svante Schubert + * @version 1.0 + */ +package org.openoffice.helper; + +import java.io.*; + + +public class DefaultNamespaceRemover +{ + private static final boolean debug = false; + + public static void main (String argv []) + { + + if (argv.length != 2){ + System.err.println("Usage: "); + System.err.println("DefaultNamespaceRemover <inputfile> <outputfile>"); + System.exit(1); + } + + //****************************** + //parse and write the html file + //****************************** + try{ + + BufferedReader in = new BufferedReader(new InputStreamReader (new FileInputStream (argv[0]), "UTF8")); + BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(argv[1]), "UTF8")); + String sLine = null; + StringBuffer sBuffer = null; + boolean isNamespaceRemoved = false; + int nodeIndex1 = -1; + int nodeIndex2 = -1; + int delimiterIndex1 = -1; + int delimiterIndex2 = -1; + String lineEnd = System.getProperty("line.separator"); + + while((sLine = in.readLine()) != null) + { + // as long the namespace has to be removed + if(isNamespaceRemoved){ + out.write(sLine + lineEnd); + if(debug) System.out.println(sLine + lineEnd); + }else{ + //see if a defaultnamespace exists in the input line + if((nodeIndex1 = sLine.indexOf("xmlns=")) != -1 || (nodeIndex2 = sLine.indexOf("xmlns =")) != -1) + { + // take the valid starting point of the default namespace node + if(nodeIndex1 == -1) + nodeIndex1 = nodeIndex2; + + // for possible delimiter " see if it exist after default namespace node, then get the next + if((delimiterIndex1 = sLine.indexOf('\"', nodeIndex1)) != -1) + delimiterIndex1 = sLine.indexOf('\"', delimiterIndex1 + 1); + + // for possible delimiter ' see if it exist after default namespace node, then get the next + if((delimiterIndex2 = sLine.indexOf('\'', nodeIndex2)) != -1) + delimiterIndex2 = sLine.indexOf('\'', delimiterIndex2 + 1); + + // if the first delimiter ('"') does not exist in string, take the other for granted + if(delimiterIndex1 == -1) + delimiterIndex1 = delimiterIndex2; + // otherwise both delimiters exist, so get the first + else if(delimiterIndex2 != -1) + if(delimiterIndex2 < delimiterIndex1) + delimiterIndex1 = delimiterIndex2; + + sBuffer = new StringBuffer(sLine); + // +2 for the delimiter itself and the following space + sBuffer.delete(nodeIndex1, delimiterIndex1 + 2); + out.write(new String(sBuffer) + lineEnd); + if(debug) System.out.println(new String(sBuffer) + lineEnd); + isNamespaceRemoved = true; + }else{ + out.write(sLine + lineEnd); + if(debug) System.out.println(sLine + lineEnd); + } + } + } + in.close(); + out.flush(); + if(out != null) + out.close(); + } + catch(Exception e) + { + System.out.println("Error by parsing the html file: "+e.getMessage()); + e.printStackTrace(); + } + } +} diff --git a/officecfg/org/openoffice/helper/makefile.mk b/officecfg/org/openoffice/helper/makefile.mk index d4641cea7657..a742a74367f9 100644 --- a/officecfg/org/openoffice/helper/makefile.mk +++ b/officecfg/org/openoffice/helper/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.4 $ +# $Revision: 1.5 $ # -# last change: $Author: svesik $ $Date: 2000-10-27 16:08:36 $ +# last change: $Author: sus $ $Date: 2001-02-08 18:25:07 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -74,7 +74,8 @@ PACKAGE=org$/openoffice$/helper EXTRAJARFILES = jaxp.jar parser.jar -JAVACLASSFILES= \ +JAVACLASSFILES= \ + $(CLASSDIR)$/$(PACKAGE)$/DefaultNamespaceRemover.class \ $(CLASSDIR)$/$(PACKAGE)$/Validator.class \ $(CLASSDIR)$/$(PACKAGE)$/PrettyPrinter.class @@ -82,9 +83,9 @@ JAVAFILES= $(subst,$(CLASSDIR)$/$(PACKAGE)$/, $(subst,.class,.java $(JAVACLASSFI RC_SUBDIRSDEPS=$(JAVATARGET) -JARCLASSDIRS = $(PACKAGE) -JARTARGET = $(TARGET).jar -JARCOMPRESS = TRUE +JARCLASSDIRS = $(PACKAGE) +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE # --- Targets ------------------------------------------------------ |