diff options
author | Dirk Grobler <dg@openoffice.org> | 2001-06-19 15:43:22 +0000 |
---|---|---|
committer | Dirk Grobler <dg@openoffice.org> | 2001-06-19 15:43:22 +0000 |
commit | 8f83fd8b29b476da662da91c7da40b30607dc42d (patch) | |
tree | 00822bf149de1f8d927561a41ef6c1075c015b20 /officecfg/org | |
parent | a9676beaf91771752129e728e42e978ea90ef9ae (diff) |
TF_CFGDATA additional tools for generating xml instance and ldap data
Diffstat (limited to 'officecfg/org')
4 files changed, 616 insertions, 0 deletions
diff --git a/officecfg/org/openoffice/configuration/Generator.java b/officecfg/org/openoffice/configuration/Generator.java new file mode 100644 index 000000000000..7416235f61b2 --- /dev/null +++ b/officecfg/org/openoffice/configuration/Generator.java @@ -0,0 +1,97 @@ + +/** + * Title: Import of configuration schemas<p> + * Description: <p> + * Copyright: Copyright (c) <p> + * Company: <p> + * @author + * @version 1.0 + */ +package org.openoffice.configuration; + +import java.util.*; +import java.io.*; +import com.jclark.xsl.sax.Driver; + +public class Generator { + + public Generator() throws Exception + { + // set the driver for xt + System.setProperty("com.jclark.xsl.sax.parser", "com.sun.xml.parser.Parser"); + } + + /** + * creating a abs path of a source path + */ + static public String getAbsolutePath(String orgPath) throws IOException + { + String absolutePath = new String(); + if (orgPath.length() > 0) + { + StringTokenizer tokenizer = new StringTokenizer(orgPath, File.pathSeparator); + absolutePath = new File(tokenizer.nextToken()).getAbsoluteFile().toURL().toString(); + while (tokenizer.hasMoreTokens()) + { + absolutePath += File.pathSeparator; + absolutePath += tokenizer.nextToken(); + } + } + return absolutePath; + } + + public void generate(String argv []) throws Exception + { + try + { + // make sure that all directories exist + argv[2] = new File(argv[2]).getAbsoluteFile().toString(); + File path = new File(argv[2]).getParentFile().getAbsoluteFile(); + path.mkdirs(); + + Driver.main(argv); + + String[] args = new String[1]; + args[0] = argv[2]; + Trim.main(args); + } + catch (Exception e) + { + e.printStackTrace(); + throw e; + } + } + + public static void main (String argv []) + { + if (argv.length < 4) { + System.err.println ("Usage: cmd <filename> <xsl-file> <out-file> <include-path> [transformation parameters]"); + System.err.println ("<filename>: Configuration description file"); + System.err.println ("<xsl-file>: transformation file"); + System.err.println ("<out-file>: output file"); + System.err.println ("<include-path>: Path where to find imported configuration files"); + System.exit (1); + } + + try + { + Generator generator = new Generator(); + + String[] args = new String[argv.length + 1]; + for (int i = 0; i < argv.length; i++) + args[i] = argv[i]; + + // handle the path parameter for the source + args[3] = "path=" + getAbsolutePath(argv[3]); + args[argv.length] = "pathSeparator=" + File.pathSeparator; + + // create the instance file + generator.generate((String[])args.clone()); + } + catch (Exception pce) { + // Parser with specified options can't be built + pce.printStackTrace(); + System.exit (1); + } + } +} diff --git a/officecfg/org/openoffice/configuration/Inspector.java b/officecfg/org/openoffice/configuration/Inspector.java new file mode 100644 index 000000000000..11dc5ba41515 --- /dev/null +++ b/officecfg/org/openoffice/configuration/Inspector.java @@ -0,0 +1,205 @@ +/************************************************************************* + * + * $RCSfile: Inspector.java,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: dg $ $Date: 2001-06-19 16:43:08 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +package org.openoffice.configuration; + +import java.io.*; +import org.xml.sax.*; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; + +/** + * Title: Inspector + * Description: Validates an xml document against a dtd and retrieves the necessary + package and component informations<p> + */ +public class Inspector extends HandlerBase +{ + public java.lang.String componentName; + public java.lang.String packageName; + public java.lang.String transformationFile; + + public Inspector() + { + componentName = new String(); + packageName = new String(); + transformationFile = new String("instance.xsl"); + } + + //=========================================================== + // SAX DocumentHandler methods + //=========================================================== + public InputSource resolveEntity(java.lang.String publicId, + java.lang.String systemId) + throws SAXException + { + // take the transformation file 'instance2.xsl' if schema.description2.dtd is used + if (new File(systemId).getName().equalsIgnoreCase("schema.description2.dtd")) + transformationFile = "instance2.xsl"; + + return new InputSource(systemId); + } + + + //=========================================================== + // SAX DocumentHandler methods + //=========================================================== + + public void setDocumentLocator (Locator l) + { + // Save this to resolve relative URIs or to give diagnostics. + System.out.println ("** Start validating: " + l.getSystemId()); + } + + public void startElement(java.lang.String name, + AttributeList attributes) throws SAXException + { + if (componentName.length() == 0 && name == "schema:component") + { + componentName = attributes.getValue("cfg:name"); + packageName = attributes.getValue("cfg:package"); + } + } + + public void startDocument () + throws SAXException + { + } + + public void endDocument () + throws SAXException + { + System.out.println ("** Document is valid!"); + } + + //=========================================================== + // SAX ErrorHandler methods + //=========================================================== + + // treat validation errors as fatal + public void error (SAXParseException e) + throws SAXParseException + { + throw e; + } + + // dump warnings too + public void warning (SAXParseException err) + throws SAXParseException + { + System.out.println ("** Warning" + + ", line " + err.getLineNumber () + + ", uri " + err.getSystemId ()); + System.out.println(" " + err.getMessage ()); + } + + //=========================================================== + // Helpers ... + //=========================================================== + + public static void main (String argv []) + { + if (argv.length != 1) { + System.err.println ("Usage: cmd filename"); + System.exit (1); + } + // Use the validating parser + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setValidating(true); + try + { + // Parse the input + SAXParser saxParser = factory.newSAXParser(); + saxParser.parse( new File(argv [0]), new Inspector() ); + } + catch (SAXParseException spe) { + // Error generated by the parser + System.out.println ("\n** Parsing error" + + ", line " + spe.getLineNumber () + + ", uri " + spe.getSystemId ()); + System.out.println(" " + spe.getMessage() ); + System.exit (1); + } + catch (SAXException sxe) { + // Error generated by this application + // (or a parser-initialization error) + Exception x = sxe; + if (sxe.getException() != null) + x = sxe.getException(); + x.printStackTrace(); + System.exit (1); + } + catch (ParserConfigurationException pce) { + // Parser with specified options can't be built + pce.printStackTrace(); + System.exit (1); + + } + catch (IOException ioe) { + // I/O error + ioe.printStackTrace(); + System.exit (1); + } + + System.exit (0); + } + +} diff --git a/officecfg/org/openoffice/configuration/Trim.java b/officecfg/org/openoffice/configuration/Trim.java new file mode 100644 index 000000000000..b2d13f677670 --- /dev/null +++ b/officecfg/org/openoffice/configuration/Trim.java @@ -0,0 +1,50 @@ + +/** + * Title: Import of configuration schemas<p> + * Description: <p> + * Copyright: Copyright (c) <p> + * Company: <p> + * @author + * @version 1.0 + */ +package org.openoffice.configuration; + +import java.util.*; +import java.io.*; + +class Trim +{ + public static void main (String argv []) + { + try + { + BufferedReader reader = new BufferedReader(new FileReader(argv[0])); + FileWriter out = new FileWriter(argv[0] + ".trim" ,false); + String line = ""; + boolean hadLine = false; + while ((line = reader.readLine()) != null) + { + line = line.trim(); + if (line.length() > 0) + { + hadLine = true; + out.write(line); + out.write("\n"); + } + else if (hadLine) + { + out.write("\n"); + hadLine = false; + } + } + out.flush(); + out.close(); + reader.close(); + + new File(argv[0]).delete(); + new File(argv[0] + ".trim").renameTo(new File(argv[0])); + } + catch (Exception e) + {} + } +}
\ No newline at end of file diff --git a/officecfg/org/openoffice/configuration/XMLDefaultGenerator.java b/officecfg/org/openoffice/configuration/XMLDefaultGenerator.java new file mode 100644 index 000000000000..ca3b89d8c5fc --- /dev/null +++ b/officecfg/org/openoffice/configuration/XMLDefaultGenerator.java @@ -0,0 +1,264 @@ +/************************************************************************* + * + * $RCSfile: XMLDefaultGenerator.java,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: dg $ $Date: 2001-06-19 16:43:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +package org.openoffice.configuration; + +import org.xml.sax.*; +import org.w3c.dom.*; +import com.sun.xml.tree.XmlDocument; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.parsers.SAXParser; +import com.sun.xml.tree.*; +import java.util.*; +import java.io.*; +import com.jclark.xsl.sax.Driver; + +/** + * Title: XMLDefaultGenerator<p> + * Description: Tool for generating configuration default data<p> + */ +public class XMLDefaultGenerator { + + public static final String FILE_EXT = ".xml"; + + protected String packageName = null; + protected String componentName = null; + protected String transformationFile = null; + + /** + * construct the generator by validation of the source file + */ + public XMLDefaultGenerator(String sourceFile) throws Exception + { + // set the driver for xt + System.setProperty("com.jclark.xsl.sax.parser", "com.sun.xml.parser.Parser"); + evaluateSchema(sourceFile); + } + + public String getComponentName() {return componentName;} + public String getPackageName() {return packageName;} + + /** + * construct the generator by validation of the source file + */ + protected void evaluateSchema(String schemaFile) throws Exception + { + try + { + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setValidating(true); + + // Parse the input + SAXParser saxParser = factory.newSAXParser(); + Inspector inspector = new Inspector(); + saxParser.parse( new File(new File(schemaFile).getAbsolutePath()).toURL().toString(), inspector ); + + // get the necessary information for generation + packageName = inspector.packageName; + componentName = inspector.componentName; + transformationFile = inspector.transformationFile; + } + catch (SAXParseException spe) { + // Error generated by the parser + System.out.println ("\n** Parsing error" + + ", line " + spe.getLineNumber () + + ", uri " + spe.getSystemId ()); + System.out.println(" " + spe.getMessage() ); + throw spe; + } + catch (SAXException sxe) { + // Error generated by this application + // (or a parser-initialization error) + Exception x = sxe; + if (sxe.getException() != null) + x = sxe.getException(); + x.printStackTrace(); + throw sxe; + } + catch (IOException ioe) { + // I/O error + ioe.printStackTrace(); + throw ioe; + } + catch (Exception pce) { + // Parser with specified options can't be built + pce.printStackTrace(); + throw pce; + } + } + + /** + * creating the destination file name + */ + public String getTargetName(String aRoot, String aKind) throws Exception + { + String aRelPath = packageName.replace('.', File.separatorChar); + + // create the instance directory + File aFile = new File(aRoot + File.separatorChar + aKind + File.separatorChar + + aRelPath + File.separatorChar + componentName + FILE_EXT); + + return aFile.getPath(); + } + + /** + * generating the target document + */ + public void generate(String argv [], boolean asTemplate) throws Exception + { + // add the necessary transformation parameters + { + String[] args = new String[argv.length + 1]; + for (int i = 0; i < argv.length; i++) + args[i] = argv[i]; + + args[1] = argv[1] + File.separator + transformationFile; + + // handle the path parameter for the source + args[3] = "path=" + Generator.getAbsolutePath(argv[3]); + args[argv.length] = "pathSeparator=" + File.pathSeparator; + argv = args; + } + + try + { + // make sure that all directories exist + File path = new File(argv[2]).getParentFile(); + path.mkdirs(); + + String[] args = null; + // templates need a new argument, which is used for + // as parameter for the xsl translation + if (asTemplate) + { + args = new String[argv.length + 1]; + for (int i = 0; i < argv.length; i++) + args[i] = argv[i]; + + args[argv.length] = "templates=true"; + } + else + args = argv; + + Driver.main(args); + } + catch (Exception e) + { + e.printStackTrace(); + throw e; + } + } + + /** + * generating the instance document + */ + protected void generateInstanceFile(String argv []) throws Exception + { + argv[2] = getTargetName(argv[2], "instance"); + generate(argv, false); + } + + /** + * generating the template document + */ + protected void generateTemplateFile(String argv []) throws Exception + { + argv[2] = getTargetName(argv[2], "template"); + generate(argv, true); + } + + public static void main (String argv []) + { + if (argv.length < 4) { + System.err.println ("Usage: cmd <filename> <xsldir> <outdir> <include-path> [transformation parameters]"); + System.err.println ("<filename>: Configuration description file"); + System.err.println ("<xsldir>: Directory where to locate the transformation files used"); + System.err.println ("<outdir>: Directory where to generate the output files"); + System.err.println ("<include-path>: Path where to find imported configuration files"); + System.exit (1); + } + + try + { + XMLDefaultGenerator XMLDefaultGenerator = new XMLDefaultGenerator(argv [0]); + + String[] args = new String[argv.length + 1]; + for (int i = 0; i < argv.length; i++) + args[i] = argv[i]; + + String url = new File(argv[2] + File.separator + "template") + .getAbsoluteFile().toURL().toString(); + args[argv.length] = "templateURL=" + url; + + // create the instance file + XMLDefaultGenerator.generateInstanceFile((String[])args.clone()); + + // create the template file + XMLDefaultGenerator.generateTemplateFile((String[])args.clone()); + } + catch (Exception pce) { + // Parser with specified options can't be built + pce.printStackTrace(); + System.exit (1); + } + } +} |