filter: use python version of FCFGMerge

Change-Id: I23124b919359c1217529724338b8d4906e051306
This commit is contained in:
Matúš Kukan
2013-03-09 12:34:34 +01:00
parent 77e21bb36a
commit 17b2ace79b
16 changed files with 1 additions and 5430 deletions

View File

@@ -746,7 +746,6 @@ $(eval $(call gb_Helper_register_jars,URE, \
$(eval $(call gb_Helper_register_jars,OOO, \
ConnectivityTools \
FCFGMerge \
HelloWorld \
Highlight \
MemoryUsage \

View File

@@ -21,16 +21,11 @@
# most of the rules here use some weird merge program, and this is sort of
# semi-integrated with the stuff from Configuration.mk; not exactly pretty...
ifeq ($(SOLAR_JAVA),)
filter_MERGE_TARGET := $(call gb_ExternalExecutable_get_dependencies,python) \
$(SRCDIR)/filter/source/config/tools/merge/pyAltFCFGMerge
filter_MERGE := $(call gb_ExternalExecutable_get_command,python) \
$(SRCDIR)/filter/source/config/tools/merge/pyAltFCFGMerge
else # SOLAR_JAVA
filter_MERGE_TARGET := $(OUTDIR_FOR_BUILD)/bin/FCFGMerge.jar
filter_MERGE := $(JAVAINTERPRETER) $(JAVAIFLAGS) -jar $(filter_MERGE_TARGET)
endif
filter_MERGE_CONFIG_TARGET := $(OUTDIR_FOR_BUILD)/inc/l10ntools/FCFGMerge.cfg
filter_MERGE_CONFIG_TARGET := $(SRCDIR)/filter/source/config/tools/merge/FCFGMerge.cfg
### filter configuration rules: generic stuff #######################

View File

@@ -1,48 +0,0 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
# Version: MPL 1.1 / GPLv3+ / LGPLv3+
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License or as specified alternatively below. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# Major Contributor(s):
# Copyright (C) 2012 David Ostrovsky <d.ostrovsky@gmx.de> (initial developer)
#
# All Rights Reserved.
#
# For minor contributions see the git repository.
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 3 or later (the "GPLv3+"), or
# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
# instead of those above.
$(eval $(call gb_Jar_Jar,FCFGMerge))
$(eval $(call gb_Jar_set_packageroot,FCFGMerge,com))
$(eval $(call gb_Jar_set_manifest,FCFGMerge,$(SRCDIR)/l10ntools/source/filter/merge/Manifest.mf))
$(eval $(call gb_Jar_add_sourcefiles,FCFGMerge,\
l10ntools/source/filter/merge/FCFGMerge \
l10ntools/source/filter/merge/Merger \
l10ntools/source/filter/utils/AnalyzeStartupLog \
l10ntools/source/filter/utils/Cache \
l10ntools/source/filter/utils/ConfigHelper \
l10ntools/source/filter/utils/FileHelper \
l10ntools/source/filter/utils/Logger \
l10ntools/source/filter/utils/MalformedCommandLineException \
l10ntools/source/filter/utils/XMLHelper \
))
$(eval $(call gb_Jar_add_packagefile,FCFGMerge,\
com/sun/star/filter/config/tools/merge/FCFGMerge.cfg,\
$(SRCDIR)/l10ntools/source/filter/merge/FCFGMerge.cfg \
))

View File

@@ -43,10 +43,4 @@ $(eval $(call gb_Module_add_targets,l10ntools,\
Package_ulfconv \
))
ifneq ($(SOLAR_JAVA),)
$(eval $(call gb_Module_add_targets,l10ntools,\
Jar_FCFGMerge \
))
endif
# vim:set noet sw=4 ts=4:

View File

@@ -29,7 +29,5 @@ $(eval $(call gb_Package_Package,l10ntools_inc,$(SRCDIR)/l10ntools))
$(eval $(call gb_Package_add_file,l10ntools_inc,inc/l10ntools/export.hxx,inc/export.hxx))
$(eval $(call gb_Package_add_file,l10ntools_inc,inc/l10ntools/directory.hxx,inc/l10ntools/directory.hxx))
$(eval $(call gb_Package_add_file,l10ntools_inc,inc/l10ntools/file.hxx,inc/l10ntools/file.hxx))
$(eval $(call gb_Package_add_file,l10ntools_inc,inc/l10ntools/FCFGMerge.cfg,source/filter/merge/FCFGMerge.cfg))
# vim: set noet sw=4 ts=4:

View File

@@ -1,112 +0,0 @@
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file incorporates work covered by the following license notice:
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed
# with this work for additional information regarding copyright
# ownership. The ASF licenses this file to you under the Apache
# License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
#
#************************************************
# Specify the verbose mode of this tool.
# 1 = show errors only
# 2 = show errors/warnings (default)
# 3 = show errors/warnings and some generic infos
# 4 = show anything (including detailed infos)
#
# [OPTIONAL]
#************************************************
loglevel = 2
#************************************************
# This extension is used for all XML files. It doesnt
# matter if its used for reading fragments or writing
# XML packages.
# Must be given without any additional signes like "."
# or "*."!
#
# [REQUIRED]
#************************************************
extension_xcu=xcu
#************************************************
# This extension is used for all Package files. It doesnt
# matter if its used for reading such files or writing
# it.
# Must be given without any additional signes like "."
# or "*."!
#
# [REQUIRED]
#************************************************
extension_pkg=pkg
#************************************************
# These values are used to generate a correct XML
# header.
# Note: The property "xmlpackage" must be specified
# via command line. There exists more then one
# possible value.
#
# [REQUIRED]
#************************************************
xmlversion = 1.0
xmlencoding = UTF-8
xmlpath = org.openoffice.TypeDetection
#xmlpackage =
#************************************************
# These values are used to name the configuration
# sets inside the generated XCM file for different
# item groups like e.g. types, filters etcpp.
#
# [REQUIRED]
#************************************************
setname_types = Types
setname_filters = Filters
setname_frameloaders = FrameLoaders
setname_contenthandlers = ContentHandlers
subdir_types = types
subdir_filters = filters
subdir_frameloaders = frameloaders
subdir_contenthandlers = contenthandlers
#************************************************
# This delimiter is used to split every
# item list of the package configuration files
# (which are temp. created by the make proccess)
# into its tokens.
#
# [REQUIRED]
#************************************************
delimiter=,
#************************************************
# Enable/disable removing of leading/trailing withespaces
# during splitting stringlists.
#
# [REQUIRED]
#************************************************
trim=true
#************************************************
# Enable/disable removing of leading/trailing "-signs
# during splitting stringlists.
#
# [REQUIRED]
#************************************************
decode=false

View File

@@ -1,114 +0,0 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
package com.sun.star.filter.config.tools.merge;
import java.lang.*;
import java.util.*;
import java.io.*;
import com.sun.star.filter.config.tools.utils.*;
/**
* Its a simple command line tool, which can merge different XML fragments
* together. Such fragments must exist as files on disk, will be moved into
* one file together on disk.
*
*
*/
public class FCFGMerge
{
private static final java.lang.String CFGFILE = "com/sun/star/filter/config/tools/merge/FCFGMerge.cfg";
private static final java.lang.String PROP_LOGLEVEL = "loglevel";
//___________________________________________
// main
public static void main(java.lang.String[] sCmdLine)
{
// create log object in default mode "WARNINGS"
// If a command line parameter indicates another
// level - change it!
Logger aLog = new Logger();
try
{
// merge config file and overwrite properties
// via command line
ConfigHelper aCfg = null;
aCfg = new ConfigHelper(CFGFILE, sCmdLine);
// update log level
int nLogLevel = aCfg.getInt(PROP_LOGLEVEL, Logger.LEVEL_WARNINGS);
aLog = new Logger(nLogLevel);
// help requested?
if (aCfg.isHelp())
{
FCFGMerge.printCopyright();
FCFGMerge.printHelp();
System.exit(-1);
}
// create new merge object and start operation
Merger aMerger = new Merger(aCfg, aLog);
aMerger.merge();
}
catch(java.lang.Throwable ex)
{
aLog.setException(ex);
System.exit(-1);
}
System.exit(0);
}
//___________________________________________
/** prints out a copyright message on stdout.
*/
private static void printCopyright()
{
java.lang.StringBuffer sOut = new java.lang.StringBuffer(256);
sOut.append("FCFGMerge (LibreOffice)\n\n");
sOut.append("Copyright (C) 2003 Sun Microsystems, Inc.\n");
sOut.append("Copyright (C) 2012 The Document Foundation\n");
sOut.append("License LGPLv3: GNU LGPL version 3 <http://www.gnu.org/licenses/lgpl.html>.\n");
sOut.append("This is free software: you are free to change and redistribute it.\n");
sOut.append("There is NO WARRANTY, to the extent permitted by law.\n");
System.out.println(sOut.toString());
}
//___________________________________________
/** prints out a help message on stdout.
*/
private static void printHelp()
{
java.lang.StringBuffer sOut = new java.lang.StringBuffer(256);
sOut.append("____________________________________________________________\n");
sOut.append("usage: FCFGMerge cfg=<file name>\n" );
sOut.append("parameters:\n" );
sOut.append("\tcfg=<file name>\n" );
sOut.append("\t\tmust point to a system file, which contains\n" );
sOut.append("\t\tall neccessary configuration data for the merge process.\n");
sOut.append("\n\tFurther cou can specify every parameter allowed in the\n" );
sOut.append("\n\tconfig file as command line parameter too, to overwrite\n" );
sOut.append("\n\tthe value from the file.\n" );
System.out.println(sOut.toString());
}
}

View File

@@ -1 +0,0 @@
Main-Class: com.sun.star.filter.config.tools.merge.FCFGMerge

View File

@@ -1,345 +0,0 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
package com.sun.star.filter.config.tools.merge;
import java.lang.*;
import java.util.*;
import java.io.*;
import com.sun.star.filter.config.tools.utils.*;
/** can merge different xml fragments together.
*
*
*/
public class Merger
{
private static final java.lang.String PROP_XMLVERSION = "xmlversion" ; // <= global cfg file
private static final java.lang.String PROP_XMLENCODING = "xmlencoding" ; // <= global cfg file
private static final java.lang.String PROP_XMLPATH = "xmlpath" ; // <= global cfg file
private static final java.lang.String PROP_XMLPACKAGE = "xmlpackage" ; // <= global cfg file
private static final java.lang.String PROP_SETNAME_TYPES = "setname_types" ; // <= global cfg file
private static final java.lang.String PROP_SETNAME_FILTERS = "setname_filters" ; // <= global cfg file
private static final java.lang.String PROP_SETNAME_LOADERS = "setname_frameloaders" ; // <= global cfg file
private static final java.lang.String PROP_SETNAME_HANDLERS = "setname_contenthandlers" ; // <= global cfg file
private static final java.lang.String PROP_SUBDIR_TYPES = "subdir_types" ; // <= global cfg file
private static final java.lang.String PROP_SUBDIR_FILTERS = "subdir_filters" ; // <= global cfg file
private static final java.lang.String PROP_SUBDIR_LOADERS = "subdir_frameloaders" ; // <= global cfg file
private static final java.lang.String PROP_SUBDIR_HANDLERS = "subdir_contenthandlers" ; // <= global cfg file
private static final java.lang.String PROP_EXTENSION_XCU = "extension_xcu" ; // <= global cfg file
private static final java.lang.String PROP_EXTENSION_PKG = "extension_pkg" ; // <= global cfg file
private static final java.lang.String PROP_DELIMITER = "delimiter" ; // <= global cfg file
private static final java.lang.String PROP_TRIM = "trim" ; // <= global cfg file
private static final java.lang.String PROP_DECODE = "decode" ; // <= global cfg file
private static final java.lang.String PROP_FRAGMENTSDIR = "fragmentsdir" ; // <= cmdline
private static final java.lang.String PROP_TEMPDIR = "tempdir" ; // <= cmdline
private static final java.lang.String PROP_OUTDIR = "outdir" ; // <= cmdline
private static final java.lang.String PROP_PKG = "pkg" ; // <= cmdline
private static final java.lang.String PROP_DEBUG = "debug" ; // <= cmdline
private static final java.lang.String PROP_TCFG = "tcfg" ; // <= cmdline
private static final java.lang.String PROP_FCFG = "fcfg" ; // <= cmdline
private static final java.lang.String PROP_LCFG = "lcfg" ; // <= cmdline
private static final java.lang.String PROP_CCFG = "ccfg" ; // <= cmdline
private static final java.lang.String PROP_LANGUAGEPACK = "languagepack" ; // <= cmdline
private static final java.lang.String PROP_ITEMS = "items" ; // <= pkg cfg files!
//___________________________________________
// member
//-------------------------------------------
/** TODO */
private ConfigHelper m_aCfg;
//-------------------------------------------
/** TODO */
private Logger m_aLog;
//-------------------------------------------
/** TODO */
private java.io.File m_aFragmentsDir;
//-------------------------------------------
/** TODO */
private java.io.File m_aTempDir;
//-------------------------------------------
/** TODO */
private java.io.File m_aOutDir;
//-------------------------------------------
/** TODO */
private java.util.Vector m_lTypes;
private java.util.Vector m_lFilters;
private java.util.Vector m_lLoaders;
private java.util.Vector m_lHandlers;
//___________________________________________
// interface
//-------------------------------------------
/** initialize a new instance of this class and
* try to get all needed resources from the config module.
*
* @param aCfg
* provides access to all values of the global
* config file and to the command line.
*
* @param aLog
* can be used to print out log informations.
*/
public Merger(ConfigHelper aCfg,
Logger aLog)
throws java.lang.Exception
{
m_aCfg = aCfg;
m_aLog = aLog;
m_aFragmentsDir = new java.io.File(m_aCfg.getString(PROP_FRAGMENTSDIR));
m_aTempDir = new java.io.File(m_aCfg.getString(PROP_TEMPDIR ));
// m_aOutDir = new java.io.File(m_aCfg.getString(PROP_OUTDIR ));
java.lang.String sDelimiter = m_aCfg.getString(PROP_DELIMITER);
boolean bTrim = m_aCfg.getBoolean(PROP_TRIM);
boolean bDecode = m_aCfg.getBoolean(PROP_DECODE);
try
{
ConfigHelper aFcfg = new ConfigHelper(m_aCfg.getString(PROP_TCFG), null);
m_lTypes = aFcfg.getStringList(PROP_ITEMS, sDelimiter, bTrim, bDecode);
}
catch(java.util.NoSuchElementException ex1)
{
m_lTypes = new java.util.Vector();
//m_aLog.setWarning("Fragment list of types is missing. Parameter \"items\" seems to be invalid.");
}
try
{
ConfigHelper aFcfg = new ConfigHelper(m_aCfg.getString(PROP_FCFG), null);
m_lFilters = aFcfg.getStringList(PROP_ITEMS, sDelimiter, bTrim, bDecode);
}
catch(java.util.NoSuchElementException ex1)
{
m_lFilters = new java.util.Vector();
//m_aLog.setWarning("Fragment list of filters is missing. Parameter \"items\" seems to be invalid.");
}
try
{
ConfigHelper aFcfg = new ConfigHelper(m_aCfg.getString(PROP_LCFG), null);
m_lLoaders = aFcfg.getStringList(PROP_ITEMS, sDelimiter, bTrim, bDecode);
}
catch(java.util.NoSuchElementException ex1)
{
m_lLoaders = new java.util.Vector();
//m_aLog.setWarning("Fragment list of frame loader objects is missing. Parameter \"items\" seems to be invalid.");
}
try
{
ConfigHelper aFcfg = new ConfigHelper(m_aCfg.getString(PROP_CCFG), null);
m_lHandlers = aFcfg.getStringList(PROP_ITEMS, sDelimiter, bTrim, bDecode);
}
catch(java.util.NoSuchElementException ex1)
{
m_lHandlers = new java.util.Vector();
//m_aLog.setWarning("Fragment list of content handler objects is missing. Parameter \"items\" seems to be invalid.");
}
}
//-------------------------------------------
/** TODO */
public synchronized void merge()
throws java.lang.Exception
{
java.lang.StringBuffer sBuffer = new java.lang.StringBuffer(1000000);
java.lang.String sPackage = m_aCfg.getString(PROP_PKG);
m_aLog.setGlobalInfo("create package \""+sPackage+"\" ...");
m_aLog.setDetailedInfo("generate package header ... ");
sBuffer.append(
XMLHelper.generateHeader(
m_aCfg.getString (PROP_XMLVERSION ),
m_aCfg.getString (PROP_XMLENCODING ),
m_aCfg.getString (PROP_XMLPATH ),
m_aCfg.getString (PROP_XMLPACKAGE ),
m_aCfg.getBoolean(PROP_LANGUAGEPACK, false)));
// counts all transferred fragments
// Can be used later to decide, if a generated package file
// contains "nothing"!
int nItemCount = 0;
for (int i=0; i<4; ++i)
{
java.lang.String sSetName = null;
java.lang.String sSubDir = null;
java.util.Vector lFragments = null;
try
{
switch(i)
{
case 0: // types
{
m_aLog.setDetailedInfo("generate set for types ... ");
sSetName = m_aCfg.getString(PROP_SETNAME_TYPES);
sSubDir = m_aCfg.getString(PROP_SUBDIR_TYPES );
lFragments = m_lTypes;
}
break;
case 1: // filters
{
m_aLog.setDetailedInfo("generate set for filter ... ");
sSetName = m_aCfg.getString(PROP_SETNAME_FILTERS);
sSubDir = m_aCfg.getString(PROP_SUBDIR_FILTERS );
lFragments = m_lFilters;
}
break;
case 2: // loaders
{
m_aLog.setDetailedInfo("generate set for frame loader ... ");
sSetName = m_aCfg.getString(PROP_SETNAME_LOADERS);
sSubDir = m_aCfg.getString(PROP_SUBDIR_LOADERS );
lFragments = m_lLoaders;
}
break;
case 3: // handlers
{
m_aLog.setDetailedInfo("generate set for content handler ... ");
sSetName = m_aCfg.getString(PROP_SETNAME_HANDLERS);
sSubDir = m_aCfg.getString(PROP_SUBDIR_HANDLERS );
lFragments = m_lHandlers;
}
break;
}
nItemCount += lFragments.size();
getFragments(
new java.io.File(m_aFragmentsDir, sSubDir),
sSetName,
lFragments,
1,
sBuffer);
}
catch(java.util.NoSuchElementException exIgnore)
{ continue; }
}
m_aLog.setDetailedInfo("generate package footer ... ");
sBuffer.append(XMLHelper.generateFooter());
// Attention!
// If the package seem to be empty, it make no sense to generate a corresponding
// xml file. We should suppress writing of this file on disk completely ...
if (nItemCount < 1)
{
m_aLog.setWarning("Package is empty and will not result into a xml file on disk!? Please check configuration file.");
return;
}
m_aLog.setGlobalInfo("package contains "+nItemCount+" items");
java.io.File aPackage = new File(sPackage);
m_aLog.setGlobalInfo("write temp package \""+aPackage.getPath()); // TODO encoding must be readed from the configuration
FileHelper.writeEncodedBufferToFile(aPackage, "UTF-8", false, sBuffer); // check for success is done inside this method!
}
//-------------------------------------------
/** TODO */
private void getFragments(java.io.File aDir ,
java.lang.String sSetName ,
java.util.Vector lFragments ,
int nPrettyTabs,
java.lang.StringBuffer sBuffer )
throws java.lang.Exception
{
if (lFragments.size()<1)
{
// m_aLog.setWarning("List of fragments is empty!? Will be ignored ...");
return;
}
java.util.Enumeration pFragments = lFragments.elements();
java.lang.String sExtXcu = m_aCfg.getString(PROP_EXTENSION_XCU);
for (int tabs=0; tabs<nPrettyTabs; ++tabs)
sBuffer.append("\t");
sBuffer.append("<node oor:name=\""+sSetName+"\">\n");
++nPrettyTabs;
// special mode for generating language packs.
// In such case we must live with some missing fragment files.
// Reason behind; Not all filters are realy localized.
// But we dont use a different fragment list. We try to locate
// any fragment file in its language-pack version ...
boolean bHandleLanguagePacks = m_aCfg.getBoolean(PROP_LANGUAGEPACK, false);
boolean bDebug = m_aCfg.getBoolean(PROP_DEBUG , false);
java.lang.String sEncoding = "UTF-8";
if (bDebug)
sEncoding = "UTF-8Special";
while(pFragments.hasMoreElements())
{
java.lang.String sFragment = (java.lang.String)pFragments.nextElement();
java.io.File aFragment = new java.io.File(aDir, sFragment+"."+sExtXcu);
// handle simple files only and check for existence!
if (!aFragment.exists())
{
if (bHandleLanguagePacks)
{
m_aLog.setWarning("language fragment \""+aFragment.getPath()+"\" does not exist. Will be ignored.");
continue;
}
else
throw new java.io.IOException("fragment \""+aFragment.getPath()+"\" does not exists.");
}
if (!aFragment.isFile())
{
m_aLog.setWarning("fragment \""+aFragment.getPath()+"\" seem to be not a valid file.");
continue;
}
// copy file content of original fragment
// Note: A FileNotFoundException will be thrown automaticly by the
// used reader objects. Let it break this method too. Our calli is interested
// on such errors :-)
m_aLog.setDetailedInfo("merge fragment \""+aFragment.getPath()+"\" ...");
FileHelper.readEncodedBufferFromFile(aFragment, sEncoding, sBuffer);
sBuffer.append("\n");
}
--nPrettyTabs;
for (int tabs=0; tabs<nPrettyTabs; ++tabs)
sBuffer.append("\t");
sBuffer.append("</node>\n");
}
}

View File

@@ -1,316 +0,0 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
package com.sun.star.filter.config.tools.utils;
//_______________________________________________
// imports
import java.util.*;
import java.lang.*;
//_______________________________________________
// implementation
public class AnalyzeStartupLog
{
private class OperationTime
{
/** name the measured operation. */
public java.lang.String sOperation;
/** contains the time value, when this operation was started. */
public long nStartTime;
/** contains the time value, when this operation was finished. */
public long nEndTime;
/** text inside log file, which identifies the start time value. */
public java.lang.String sStartMsg;
/** text inside log file, which identifies the end time value. */
public java.lang.String sEndMsg;
}
//_________________________________
// main
public static void main(java.lang.String[] lCmdLine)
{
int nExit = 0;
try
{
// analyze command line
ConfigHelper aCmdLine = new ConfigHelper("", lCmdLine);
java.lang.String sLogDir = aCmdLine.getString("logdir" );
java.lang.String sDataFile = aCmdLine.getString("datafile");
if (sLogDir == null || sDataFile == null)
{
System.err.println("AnalyzeStartupLog lodir=<dir> datafile=<file>");
System.err.println("E.g.: AnalyzeStartupLog lodir=c:\\temp\\logs datafile=c:\\temp\\data.csv");
System.exit(--nExit);
}
// get list of all log files
boolean bRecursive = true;
java.util.Vector lLogs = FileHelper.getSystemFilesFromDir(new java.io.File(sLogDir), bRecursive);
if (lLogs == null || lLogs.isEmpty())
{
System.err.println("log dir is empty");
System.exit(--nExit);
}
// analyze it
java.lang.StringBuffer sOut = new java.lang.StringBuffer(1000);
sOut.append("log;t_cfg_start;t_cfg_end;t_fwk_start;t_fwk_end;t_sfx_start;t_sfx_end;t_types_start;t_types_end;t_filters_start;t_filters_end;");
sOut.append("t_filters_swriter_start;t_filters_swriter_end;t_filters_sweb_start;t_filters_sweb_end;t_filters_sglobal_start;t_filters_sglobal_end;t_filters_scalc_start;t_filters_scalc_end;t_filters_sdraw_start;t_filters_sdraw_end;t_filters_simpress_start;t_filters_simpress_end;t_filters_schart_start;t_filters_schart_end;t_filters_smath_start;t_filters_smath_end;");
sOut.append("t_others_start;t_others_end;d_cfg;d_fwk;d_sfx;d_types;d_filters;d_others;d_complete\n");
java.util.Enumeration aIt = lLogs.elements();
while (aIt.hasMoreElements())
{
java.io.File aLog = (java.io.File)aIt.nextElement();
java.io.FileReader aReader = new java.io.FileReader(aLog);
java.io.BufferedReader aBuffer = new java.io.BufferedReader(aReader);
long t_cfg_start = 0;
long t_cfg_end = 0;
long t_fwk_start = 0;
long t_fwk_end = 0;
long t_sfx_start = 0;
long t_sfx_end = 0;
long t_types_start = 0;
long t_types_end = 0;
long t_filters_start = 0;
long t_filters_end = 0;
long t_filters_swriter_start = 0;
long t_filters_swriter_end = 0;
long t_filters_sweb_start = 0;
long t_filters_sweb_end = 0;
long t_filters_sglobal_start = 0;
long t_filters_sglobal_end = 0;
long t_filters_scalc_start = 0;
long t_filters_scalc_end = 0;
long t_filters_sdraw_start = 0;
long t_filters_sdraw_end = 0;
long t_filters_simpress_start = 0;
long t_filters_simpress_end = 0;
long t_filters_schart_start = 0;
long t_filters_schart_end = 0;
long t_filters_smath_start = 0;
long t_filters_smath_end = 0;
long t_others_start = 0;
long t_others_end = 0;
while (true)
{
java.lang.String sLine = aBuffer.readLine();
if (sLine == null)
break;
if (sLine.endsWith("| framework (as96863) ::FilterCache::FilterCache : { creation ConfigItem [file=standard, version=6, mode=3]"))
t_cfg_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("| framework (as96863) ::FilterCache::FilterCache : } creation ConfigItem"))
t_cfg_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("| framework (as96863) ::FilterCache::FilterCache : { reading TypeDetection.xml"))
t_fwk_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("| framework (as96863) ::FilterCache::FilterCache : } reading TypeDetection.xml"))
t_fwk_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("{ framework (as96863) ::FilterCFGAccess::impl_loadTypes"))
t_types_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("} framework (as96863) ::FilterCFGAccess::impl_loadTypes"))
t_types_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("{ framework (as96863) ::FilterCFGAccess::impl_loadFilters"))
t_filters_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("} framework (as96863) ::FilterCFGAccess::impl_loadFilters"))
t_filters_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("{ reading FilterGroup [swriter]"))
t_filters_swriter_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("} reading FilterGroup [swriter]"))
t_filters_swriter_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("{ reading FilterGroup [sweb]"))
t_filters_sweb_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("} reading FilterGroup [sweb]"))
t_filters_sweb_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("{ reading FilterGroup [sglobal]"))
t_filters_sglobal_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("} reading FilterGroup [sglobal]"))
t_filters_sglobal_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("{ reading FilterGroup [scalc]"))
t_filters_scalc_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("} reading FilterGroup [scalc]"))
t_filters_scalc_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("{ reading FilterGroup [sdraw]"))
t_filters_sdraw_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("} reading FilterGroup [sdraw]"))
t_filters_sdraw_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("{ reading FilterGroup [simpress]"))
t_filters_simpress_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("} reading FilterGroup [simpress]"))
t_filters_simpress_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("{ reading FilterGroup [schart]"))
t_filters_schart_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("} reading FilterGroup [schart]"))
t_filters_schart_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("{ reading FilterGroup [smath]"))
t_filters_smath_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("} reading FilterGroup [smath]"))
t_filters_smath_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("{ framework (as96863) ::FilterCFGAccess::impl_loadDetectors"))
t_others_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("} framework (as96863) ::FilterCFGAccess::impl_loadContentHandlers"))
t_others_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("} framework (as96863) ::FilterCache::FilterCache"))
t_sfx_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
else
if (sLine.endsWith("} desktop (lo119109) OfficeWrapper::OfficeWrapper"))
t_sfx_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
}
sOut.append(aLog.getName() );
sOut.append(";" );
sOut.append(t_cfg_start );
sOut.append(";" );
sOut.append(t_cfg_end );
sOut.append(";" );
sOut.append(t_fwk_start );
sOut.append(";" );
sOut.append(t_fwk_end );
sOut.append(";" );
sOut.append(t_sfx_start );
sOut.append(";" );
sOut.append(t_sfx_end );
sOut.append(";" );
sOut.append(t_types_start );
sOut.append(";" );
sOut.append(t_types_end );
sOut.append(";" );
sOut.append(t_filters_start );
sOut.append(";" );
sOut.append(t_filters_end );
sOut.append(";" );
sOut.append(t_filters_swriter_start );
sOut.append(";" );
sOut.append(t_filters_swriter_end );
sOut.append(";" );
sOut.append(t_filters_sweb_start );
sOut.append(";" );
sOut.append(t_filters_sweb_end );
sOut.append(";" );
sOut.append(t_filters_sglobal_start );
sOut.append(";" );
sOut.append(t_filters_sglobal_end );
sOut.append(";" );
sOut.append(t_filters_scalc_start );
sOut.append(";" );
sOut.append(t_filters_scalc_end );
sOut.append(";" );
sOut.append(t_filters_sdraw_start );
sOut.append(";" );
sOut.append(t_filters_sdraw_end );
sOut.append(";" );
sOut.append(t_filters_simpress_start );
sOut.append(";" );
sOut.append(t_filters_simpress_end );
sOut.append(";" );
sOut.append(t_filters_schart_start );
sOut.append(";" );
sOut.append(t_filters_schart_end );
sOut.append(";" );
sOut.append(t_filters_smath_start );
sOut.append(";" );
sOut.append(t_filters_smath_end );
sOut.append(";" );
sOut.append(t_others_start );
sOut.append(";" );
sOut.append(t_others_end );
sOut.append(";" );
sOut.append(t_cfg_end -t_cfg_start );
sOut.append(";" );
sOut.append(t_fwk_end -t_fwk_start );
sOut.append(";" );
sOut.append(t_sfx_end -t_sfx_start );
sOut.append(";" );
sOut.append(t_types_end -t_types_start );
sOut.append(";" );
sOut.append(t_filters_end-t_filters_start);
sOut.append(";" );
sOut.append(t_others_end -t_others_start );
sOut.append(";" );
sOut.append(t_others_end -t_cfg_start );
sOut.append("\n" );
aBuffer.close();
}
java.io.FileWriter aCSV = new java.io.FileWriter(sDataFile);
java.lang.String sData = sOut.toString();
aCSV.write(sData, 0, sData.length());
aCSV.flush();
aCSV.close();
}
catch(java.lang.Throwable exAny)
{
System.err.println(exAny.getMessage());
exAny.printStackTrace();
System.exit(--nExit);
}
System.exit(0);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,291 +0,0 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
package com.sun.star.filter.config.tools.utils;
//_______________________________________________
// imports
import java.lang.*;
import java.util.*;
import java.io.*;
//_______________________________________________
// definition
/** can be used to analyze command line parameters
* and merge it together with might existing config
* files. That provides the possibility to overwrite
* config values via command line parameter.
*
*
*/
public class ConfigHelper extends java.util.Properties
{
//___________________________________________
// member
/** indicates an empty command line. */
private boolean m_bEmpty = true;
//___________________________________________
// ctor
//-------------------------------------------
/** initialize a new helper with the list of
* command line parameters and bind this new instance
* to a property file on disk.
*
* @param sPropFile
* name of the property file.
* If its set to null or an empty value
* it will be ignored.
*
* @param lCommandLineArgs
* the list of original command line arguments.
*
* @throws [Exception]
* in case the command line contains an unknown
* schema for specifiying parameters or the
* specified property file does not exists
* or seem to be corrupted.
*/
public ConfigHelper(java.lang.String sPropFile ,
java.lang.String[] lCommandLineArgs)
throws java.lang.Exception
{
// first load prop file, so its values can be overwritten
// by command line args later
// Do it only, if a valid file name was given.
// But in case this file name is wrong, throw an exception.
// So the outside code can react!
if (
(sPropFile != null) &&
(sPropFile.length() > 0 )
)
{
java.lang.ClassLoader aLoader = getClass().getClassLoader();
java.io.InputStream aStream = aLoader.getResourceAsStream(sPropFile);
if (aStream == null)
aStream = new java.io.FileInputStream(sPropFile);
load(aStream);
}
int count = 0;
if (lCommandLineArgs != null)
count = lCommandLineArgs.length;
m_bEmpty = (count < 1);
for (int arg=0; arg<count; ++arg)
{
// is it a named-value argument?
// Note: We ignores double "=" signs! => search from left to right
int len = lCommandLineArgs[arg].length();
int pos = lCommandLineArgs[arg].indexOf('=');
if (pos != -1)
{
java.lang.String sArg = lCommandLineArgs[arg].substring(0,pos);
java.lang.String sValue = lCommandLineArgs[arg].substring(pos+1);
setProperty(sArg, sValue);
continue;
}
// is it a boolean argument?
// Note: Because "--" and "-" will be interpreted as the same
// we search from right to left!
pos = lCommandLineArgs[arg].lastIndexOf('-');
if (pos == -1)
pos = lCommandLineArgs[arg].lastIndexOf('/');
if (pos != -1)
{
java.lang.String sArg = lCommandLineArgs[arg].substring(pos+1);
setProperty(sArg, java.lang.String.valueOf(true));
continue;
}
// There is an unknown format used by this argument ...
throw new MalformedCommandLineException("Invalid command line detected. The argument \""+lCommandLineArgs[arg]+"\" use an unsupported format.");
}
}
//-------------------------------------------
/** indicates if the given command line includes
* a help request.
*
* @return True if there was an explicit help request.
*/
public synchronized boolean isHelp()
{
return (
(containsKey("help")) ||
(containsKey("?") ) ||
(containsKey("h") )
);
}
//-------------------------------------------
/** indicates if the gioven command line was empty.
*
* @return True if there was an empty command line.
*/
public synchronized boolean isEmpty()
{
return m_bEmpty;
}
//-------------------------------------------
/** returns the value of sProp as boolean value.
*
* @param sProp
* the name of the parameter.
*
* @return The boolean value of the requested property.
*
* @throw [NoSuchElementException]
* if the requested property does not exists.
*/
public synchronized boolean getBoolean(java.lang.String sProp)
throws java.util.NoSuchElementException
{
java.lang.String sValue = getProperty(sProp);
if (sValue == null)
throw new java.util.NoSuchElementException("The requested config value \""+sProp+"\" does not exists!");
return new java.lang.Boolean(sValue).booleanValue();
}
public synchronized boolean getBoolean(java.lang.String sProp ,
boolean bDefault)
{
java.lang.String sDefault = java.lang.String.valueOf(bDefault);
java.lang.String sValue = getProperty(sProp, sDefault);
return new java.lang.Boolean(sValue).booleanValue();
}
//-------------------------------------------
/** returns the value of sProp as int value.
*
* @param sProp
* the name of the parameter.
*
* @return The int value of the requested property.
*
* @throw [NoSuchElementException]
* if the requested property does not exists.
*/
public synchronized int getInt(java.lang.String sProp)
throws java.util.NoSuchElementException
{
java.lang.String sValue = getProperty(sProp);
if (sValue == null)
throw new java.util.NoSuchElementException("The requested config value \""+sProp+"\" does not exists!");
return new java.lang.Integer(sValue).intValue();
}
public synchronized int getInt(java.lang.String sProp ,
int nDefault)
{
java.lang.String sDefault = java.lang.String.valueOf(nDefault);
java.lang.String sValue = getProperty(sProp, sDefault);
return new java.lang.Integer(sValue).intValue();
}
//-------------------------------------------
/** returns the value of sProp as string value.
*
* @param sProp
* the name of the parameter.
*
* @return The string value of the requested property.
*
* @throw [NoSuchElementException]
* if the requested property does not exists.
*/
public synchronized java.lang.String getString(java.lang.String sProp)
throws java.util.NoSuchElementException
{
java.lang.String sValue = getProperty(sProp);
if (sValue == null)
throw new java.util.NoSuchElementException("The requested config value \""+sProp+"\" does not exists!");
return sValue;
}
//-------------------------------------------
/** returns the value of sProp as string list value!
*
* @descr The delimiter must be well known and
* it must be clear if trailing/leading
* whitespaces must be ignored or not.
*
* @param sProp
* the name of the parameter.
*
* @param sDelim
* the delimiter, which must be used to split
* the config string value into an array.
*
* @param bTrim
* if its set to true, trailing and leading whitespace
* characters will be ommited.
*
* @param bDecode
* if its set to TRUE all liste items will be
* interpreted as "<xxx>" and converted to <xxx>!
*
* @return The string list value of the requested property.
*
* @throw [NoSuchElementException]
* if the requested property does not exists.
*/
public synchronized java.util.Vector getStringList(java.lang.String sProp ,
java.lang.String sDelimiter,
boolean bTrim ,
boolean bDecode )
throws java.util.NoSuchElementException
{
java.lang.String sValue = getProperty(sProp);
if (sValue == null)
throw new java.util.NoSuchElementException("The requested config value \""+sProp+"\" does not exists!");
java.util.Vector lValue = new java.util.Vector();
try
{
java.util.StringTokenizer lTokens = new java.util.StringTokenizer(sValue, sDelimiter);
while(lTokens.hasMoreTokens())
{
java.lang.String sToken = lTokens.nextToken();
// remove trailing/leading whitespaces
if (bTrim)
sToken = sToken.trim();
// remove ""
if (
(bDecode ) &&
(sToken.indexOf("\"") == 0 ) &&
(sToken.lastIndexOf("\"") == sToken.length()-1)
)
{
sToken = sToken.substring(1, sToken.length()-1);
}
lValue.add(sToken);
}
}
catch(java.lang.Throwable ex)
{ lValue.clear(); }
return lValue;
}
}

View File

@@ -1,754 +0,0 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
package com.sun.star.filter.config.tools.utils;
// __________ Imports __________
import java.io.*;
import java.lang.*;
import java.net.*;
import java.util.*;
// __________ Implementation __________
/**
* It collects some static helper functons to handle file system specific problems.
* Sometimes it's neccessary to convert URL from/to system paths;
* or from string notation to structural versions (e.g. com.sun.star.util.URL).
* And sometimes java had another notation then the office it has.
* Further it provides functionality to work easiear with the java.io.File class of java.
*
*
*/
public class FileHelper
{
// ____________________
/**
* Because the office need URLs for loading/saving documents
* we must convert used system paths.
* And java use another notation for file URLs ... correct it.
*
* @param aSystemPath
* represent the file in system notation
*
* @return [String]
* a file url which represent the given system path
*/
public static java.lang.String getFileURLFromSystemPath(java.io.File aSystemPath)
{
System.out.println("TODO: must be adapted to java 1.3 :-(");
System.exit(-1);
/*TODO_JAVA
try
{
sFileURL = aSystemPath.toURI().toURL().toString();
}
catch( MalformedURLException exWrong )
{
sFileURL = null;
}
*/
java.lang.String sFileURL = null;
// problem of java: file URL's are coded with 1 slash instead of 2 or 3 ones!
// => correct this problem first, otherwise office can't use these URL's
if(
(sFileURL != null ) &&
(sFileURL.startsWith("file:/")) &&
(!sFileURL.startsWith("file://"))
)
{
java.lang.StringBuffer sWorkBuffer = new java.lang.StringBuffer(sFileURL);
sWorkBuffer.insert(6,"//");
sFileURL = sWorkBuffer.toString();
}
return sFileURL;
}
// ____________________
/**
* The same as getFileURLFromSystemPath() before but uses string parameter instead
* of a java.io.File type. It exist to supress converting of neccessary parameters in the
* outside code. But of course getFileURLFromSystemPath(File) will be a little bit faster
* then this method ...
*
* @param sSystemPath
* represent the file in system notation
*
* @return [String]
* a file url which represent the given system path
*/
public static java.lang.String getFileURLFromSystemPath(java.lang.String sSystemPath)
{
return getFileURLFromSystemPath(new java.io.File(sSystemPath));
}
// ____________________
/**
* Does the same as getFileURLFromSystemPath() before ... but uses
* the given protocol string (e.g."http://") instead of "file:///".
*
* @param aSystemPath
* represent the file in system notation
*
* @param aBasePath
* define the base path of the aSystemPath value,
* which must be replaced with the value of "sServerPath".
*
* @param sServerURL
* Will be used to replace sBasePath.
*
* @example
* System Path = "d:\test\file.txt"
* Base Path = "d:\test"
* Server Path = "http://alaska:8000"
* => "http://alaska:8000/file.txt"
*
* @return [String]
* an url which represent the given system path
* and uses the given protocol
*/
public static java.lang.String getURLWithProtocolFromSystemPath(java.io.File aSystemPath,
java.io.File aBasePath ,
java.lang.String sServerURL )
{
System.out.println("TODO: must be adapted to java 1.3 :-(");
System.exit(-1);
java.lang.String sFileURL = FileHelper.getFileURLFromSystemPath(aSystemPath);
java.lang.String sBaseURL = FileHelper.getFileURLFromSystemPath(aBasePath );
// cut last '/'!
if (sBaseURL.lastIndexOf('/')==(sBaseURL.length()-1))
sBaseURL = sBaseURL.substring(0,sBaseURL.length()-1);
// cut last '/'!
if (sServerURL.lastIndexOf('/')==(sServerURL.length()-1))
sServerURL = sServerURL.substring(0,sServerURL.length()-1);
//TODO_JAVA java.lang.String sURL = sFileURL.replaceFirst(sBaseURL,sServerURL);
java.lang.String sURL = null;
return sURL;
}
// ____________________
/**
* The same as getURLWithProtocolFromSystemPath() before but uses string parameter instead
* of a java.io.File types. It exist to supress converting of neccessary parameters in the
* outside code. But of course getURLWithProtocolFromSystemPath(File,File,String) will be
* a little bit faster then this method ...
*
* @param sSystemPath
* represent the file in system notation
*
* @param sBasePath
* define the base path of the aSystemPath value,
* which must be replaced with the value of "sServerPath".
*
* @param sServerPath
* Will be used to replace sBasePath.
*
* @example
* System Path = "d:\test\file.txt"
* Base Path = "d:\test"
* Server Path = "http://alaska:8000"
* => "http://alaska:8000/file.txt"
*
* @return [String]
* an url which represent the given system path
* and uses the given protocol
*/
public static java.lang.String getURLWithProtocolFromSystemPath(java.lang.String sSystemPath,
java.lang.String sBasePath ,
java.lang.String sServerPath)
{
return getURLWithProtocolFromSystemPath(new java.io.File(sSystemPath), new java.io.File(sBasePath), sServerPath);
}
//_________________________________
/**
* Return a list of all available files of a directory.
* We filter sub directories. All other files
* are returned. So they can be used for further purposes.
* One parameter define the start directory,
* another one enable/disable recursive search into sub directories.
*
* @param aRoot
* the start directory, which should be analyzed.
*
* @param bRecursive
* enable/disable search in sub directories.
*
* @return [Vector]
* a filtered list of java java.io.File objects of all available files
* of the start dir (and may of its sub directories).
*/
public static java.util.Vector getSystemFilesFromDir(java.io.File aRoot ,
boolean bRecursive)
{
java.io.File[] lAllFiles = aRoot.listFiles();
if (lAllFiles == null)
return null;
int c = lAllFiles.length;
java.util.Vector lFilteredFiles = new java.util.Vector(c);
for (int i=0; i<c; ++i)
{
// simple files!
if (lAllFiles[i].isFile())
lFilteredFiles.add(lAllFiles[i]);
else
// recursion?
if (bRecursive && lAllFiles[i].isDirectory())
{
java.util.Vector lSubFiles = FileHelper.getSystemFilesFromDir(lAllFiles[i],bRecursive);
if (lSubFiles != null)
{
java.util.Enumeration aSnapshot = lSubFiles.elements();
while (aSnapshot.hasMoreElements())
lFilteredFiles.add(aSnapshot.nextElement());
}
}
}
return lFilteredFiles;
}
//_________________________________
/** it converts the given name (e.g. an internal type name) to
* an usable system file name.
*
* Do so some special characters (e.g. "/") must be replaced with other ones.
*
* @param sName
* the name, which should be analyzed and converted.
*
* @return A valid system file name, which should be similar to the
* given name, but does not contain special characters any longer.
*/
public static java.lang.String convertName2FileName(String sName)
{
int i = 0;
int nLength = sName.length();
char[] lBuffer = sName.toCharArray();
java.lang.StringBuffer sNewName = new java.lang.StringBuffer(nLength);
for (i=0; i<nLength; ++i)
{
char c = lBuffer[i];
if (
c>=48 && c<=57 // 0-9
&&
c>=97 && c<=122 // a-z
&&
c>=65 && c<=90 // A-Z
)
{
sNewName.append(c);
}
else
{
sNewName.append("_");
}
}
return sNewName.toString();
}
//___________________________________________
/** it removes all child nodes of a file system directory.
*
* @param aDirectory
* points to the directory, which should be made empty.
*
* @param bFilesOnly
* force deletion of files only. If its set to TRUE,
* no subdirectory will be removed.
*
* @throw [java.io.IOException]
* if some of the child nodes couldn't be removed.
*/
public static void makeDirectoryEmpty(java.io.File aDirectory,
boolean bFilesOnly)
throws java.io.IOException
{
if (!aDirectory.isDirectory())
throw new java.io.FileNotFoundException("\""+aDirectory.toString()+"\" is not a directory.");
java.io.File[] lChildren = aDirectory.listFiles();
for (int f=0; f<lChildren.length; ++f)
{
if (lChildren[f].isDirectory())
{
FileHelper.makeDirectoryEmpty(lChildren[f], bFilesOnly);
if (!bFilesOnly)
{
if (!lChildren[f].delete())
throw new java.io.IOException("\""+lChildren[f].toString()+"\" could not be deleted.");
}
}
else
{
if (!lChildren[f].delete())
throw new java.io.IOException("\""+lChildren[f].toString()+"\" could not be deleted.");
}
}
}
//___________________________________________
/** it try to generate a new file with a unique ID
* inside given directory.
*
* Call this method with a directory and a base name for
* a file. It will be used to generate a new files inside
* the directory. Existing files will be checked and new file
* name will be tested till a non existing file name would be found.
*
* @param aBaseDir
* must be a system path
* e.g.: "c:\temp"
*
* @param sBaseName
* must be a system file name without extensions.
* e.g.: "myfile_"
*
* @param sExtension
* the whished extension.
* e.g.: "dat"
*
* @return A valid file object, if an unique file could be created -
* Null otherwise.
* e.g.: "c:\temp\myfile_1.dat"
*/
public static java.io.File createUniqueFile(java.io.File aBaseDir ,
java.lang.String sBaseName ,
java.lang.String sExtension)
{
java.io.File aBaseFile = new java.io.File(aBaseDir, sBaseName);
java.io.File aFile = null;
long nr = 0;
while (aFile == null && nr < java.lang.Long.MAX_VALUE)
{
java.lang.String sFileName = aBaseFile.getPath() + java.lang.String.valueOf(nr) + "." + sExtension;
aFile = new java.io.File(sFileName);
if (aFile.exists())
aFile=null;
++nr;
}
return aFile;
}
//___________________________________________
/** reads the complete file, using the right encoding,
* into the given string buffer.
*
* @param aFile
* must point to a system file, which must exist.
* e.g.: "c:\temp\test.txt"
* "/tmp/test.txt"
*
* @param sEncoding
* will be used to encode the string content
* inside the file.
* e.g.: "UTF8"
*
* @param sBuffer
* used to return the file content.
*
* @throw [IOException]
* - if the file couldnt be opened
* - if the file does not use the right encoding
*/
public static void readEncodedBufferFromFile(java.io.File aFile ,
java.lang.String sEncoding,
java.lang.StringBuffer sBuffer )
throws java.io.IOException
{
if (sEncoding.equals("UTF-8Special"))
{
FileHelper.readAndCheckUTF8File(aFile,sBuffer);
return;
}
java.io.FileInputStream aByteStream = new java.io.FileInputStream(aFile.getAbsolutePath());
java.io.InputStreamReader aEncodedReader = new java.io.InputStreamReader(aByteStream, sEncoding);
char[] aEncodedBuffer = new char[4096];
int nReadCount = 0;
while((nReadCount=aEncodedReader.read(aEncodedBuffer))>0)
sBuffer.append(aEncodedBuffer, 0, nReadCount);
aEncodedReader.close();
}
//___________________________________________
private static void logEncodingData(java.lang.StringBuffer sLog ,
int nUTF8 ,
int nByteOrg1 ,
int nByteOrg2 ,
int nByteOrg3 ,
int nByteOrg4 ,
int nByte1 ,
int nByte2 ,
int nByte3 ,
int nByte4 ,
int nEncodingType)
{
sLog.append("["+nEncodingType+"]\t");
sLog.append((int)nUTF8+"\t=");
sLog.append("\t"+nByteOrg1+"/"+nByte1);
sLog.append("\t"+nByteOrg2+"/"+nByte2);
sLog.append("\t"+nByteOrg3+"/"+nByte3);
sLog.append("\t"+nByteOrg4+"/"+nByte4);
sLog.append("\n");
}
//___________________________________________
private static char impl_convertBytesToChar(int nByte1, int nByte2, int nByte3, int nByte4)
{
return (char)((nByte1*0x40000)+(nByte2*0x1000)+(nByte3*0x40)+nByte4);
}
//___________________________________________
private static int impl_readAndCheckNextByte(byte[] aBuffer ,
int nBufPos ,
int nBufLength ,
int nMinRange ,
int nMaxRange )
throws java.lang.Exception
{
if (nBufPos>=nBufLength)
throw new java.lang.Exception("impl_readAndCheckNextByte()\nEnd of buffer reached.");
int nByte = aBuffer[nBufPos] & 0xFF;
if (
(nByte < nMinRange) ||
(nByte > nMaxRange)
)
{
throw new java.lang.Exception("impl_readAndCheckNextByte()\nByte does not fit the specified range.");
}
return nByte;
}
//___________________________________________
public static void readAndCheckUTF8File(java.io.File aFile ,
java.lang.StringBuffer sBuffer)
throws java.io.IOException
{
java.io.FileInputStream aByteStream = new java.io.FileInputStream(aFile.getAbsolutePath());
byte[] aBuffer = new byte[4096];
int nReadCount = 0;
int nByteOrg_1 = 0;
int nByteOrg_2 = 0;
int nByteOrg_3 = 0;
int nByteOrg_4 = 0;
int nByte_1 = 0;
int nByte_2 = 0;
int nByte_3 = 0;
int nByte_4 = 0;
char nUTF8 = 0;
int i = 0;
int nEncodingType = 0;
java.lang.StringBuffer sLog = new java.lang.StringBuffer();
try
{
while((nReadCount=aByteStream.read(aBuffer))>0)
{
i=0;
while (i<nReadCount)
{
nByteOrg_1 = 0;
nByteOrg_2 = 0;
nByteOrg_3 = 0;
nByteOrg_4 = 0;
nByte_1 = 0;
nByte_2 = 0;
nByte_3 = 0;
nByte_4 = 0;
nUTF8 = 0;
nEncodingType = 0;
nByteOrg_1 = aBuffer[i++] & 0xFF;
nByte_1 = nByteOrg_1;
/*
Table 3-6. Well-Formed UTF-8 Byte Sequences
============================================================================
Nr. Code Points 1st Byte 2nd Byte 3rd Byte 4th Byte
============================================================================
01 U+ 0..U+ 7F 00..7F
02 U+ 80..U+ 7FF C2..DF 80..BF
03 U+ 800..U+ FFF E0 A0..BF 80..BF
04 U+ 1000..U+ CFFF E1..EC 80..BF 80..BF
05 U+ D000..U+ D7FF ED 80..9F 80..BF
06 U+ E000..U+ FFFF EE..EF 80..BF 80..BF
07 U+ 10000..U+ 3FFFF F0 90..BF 80..BF 80..BF
08 U+ 40000..U+ FFFFF F1..F3 80..BF 80..BF 80..BF
09 U+100000..U+10FFFF F4 80..8F 80..BF 80..BF
*/
// ------------------------------------------------------------
// 01
// 1 byte: 0xxxxxxx
// ------------------------------------------------------------
if (
(nByteOrg_1 >= 0x00) &&
(nByteOrg_1 <= 0x7F)
)
{
nEncodingType = 1;
nUTF8 = (char)nByte_1;
}
// ------------------------------------------------------------
// 02
// 1 byte: 110xxxxx
// 2 byte: 101xxxxx
// ------------------------------------------------------------
else
if (
(nByteOrg_1 >= 0xC2) &&
(nByteOrg_1 <= 0xDF)
)
{
nEncodingType = 2;
nByteOrg_2 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByte_1 = nByteOrg_1-0xC2;
nByte_2 = nByteOrg_2-0x80;
nUTF8 = FileHelper.impl_convertBytesToChar(0,0,nByte_1, nByte_2);
}
// ------------------------------------------------------------
// 03
// 1 byte: 11100000
// 2 byte: 101xxxxx
// 3 byte: 10xxxxxx
// ------------------------------------------------------------
else
if (nByteOrg_1 == 0xE0)
{
nEncodingType = 3;
nByteOrg_2 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0xA0, 0xBF);
nByteOrg_3 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByte_2 = nByteOrg_2-0xA0;
nByte_3 = nByteOrg_3-0x80;
nUTF8 = FileHelper.impl_convertBytesToChar(0,0,nByte_2, nByte_3);
}
// ------------------------------------------------------------
// 04
// 1 byte: 111xxxxx
// 2 byte: 10xxxxxx
// 3 byte: 10xxxxxx
// ------------------------------------------------------------
else
if (
(nByteOrg_1 >= 0xE1) &&
(nByteOrg_1 <= 0xEC)
)
{
nEncodingType = 4;
nByteOrg_2 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByteOrg_3 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByte_1 = nByteOrg_1-0xE1;
nByte_2 = nByteOrg_2-0x80;
nByte_3 = nByteOrg_3-0x80;
nUTF8 = FileHelper.impl_convertBytesToChar(0,nByte_1, nByte_2, nByte_3);
}
// ------------------------------------------------------------
// 05
// 1 byte: 11101101
// 2 byte: 10xxxxxx
// 3 byte: 10xxxxxx
// ------------------------------------------------------------
else
if (nByteOrg_1 == 0xED)
{
nEncodingType = 5;
nByteOrg_2 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0x9F);
nByteOrg_3 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByte_2 = nByteOrg_2-0x80;
nByte_3 = nByteOrg_3-0x80;
nUTF8 = FileHelper.impl_convertBytesToChar(0,0, nByte_2, nByte_3);
}
// ------------------------------------------------------------
// 06
// 1 byte: 1110111x
// 2 byte: 10xxxxxx
// 3 byte: 10xxxxxx
// ------------------------------------------------------------
else
if (
(nByteOrg_1 >= 0xEE) &&
(nByteOrg_1 <= 0xEF)
)
{
nEncodingType = 6;
nByteOrg_2 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByteOrg_3 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByte_1 = nByteOrg_1-0xEE;
nByte_2 = nByteOrg_2-0x80;
nByte_3 = nByteOrg_3-0x80;
nUTF8 = FileHelper.impl_convertBytesToChar(0,nByte_1, nByte_2, nByte_3);
}
// ------------------------------------------------------------
// 07
// 1 byte: 11110000
// 2 byte: 1001xxxx
// 3 byte: 10xxxxxx
// 4 byte: 10xxxxxx
// ------------------------------------------------------------
else
if (nByteOrg_1 == 0xF0)
{
nEncodingType = 7;
nByteOrg_2 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x90, 0xBF);
nByteOrg_3 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByteOrg_4 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByte_2 = nByteOrg_2-0x90;
nByte_3 = nByteOrg_3-0x80;
nByte_4 = nByteOrg_4-0x80;
nUTF8 = FileHelper.impl_convertBytesToChar(0, nByte_2, nByte_3, nByte_4);
}
// ------------------------------------------------------------
// 08
// 1 byte: 111100xx
// 2 byte: 10xxxxxx
// 3 byte: 10xxxxxx
// 3 byte: 10xxxxxx
// ------------------------------------------------------------
else
if (
(nByteOrg_1 >= 0xF1) &&
(nByteOrg_1 <= 0xF3)
)
{
nEncodingType = 8;
nByteOrg_2 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByteOrg_3 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByteOrg_4 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByte_1 = nByteOrg_1-0xF1;
nByte_2 = nByteOrg_2-0x80;
nByte_3 = nByteOrg_3-0x80;
nByte_4 = nByteOrg_4-0x80;
nUTF8 = FileHelper.impl_convertBytesToChar(nByte_1, nByte_2, nByte_3, nByte_4);
}
// ------------------------------------------------------------
// 09
// 1 byte: 11110100
// 2 byte: 10xxxxxx
// 3 byte: 10xxxxxx
// 4 byte: 10xxxxxx
// ------------------------------------------------------------
else
if (nByteOrg_1 == 0xF0)
{
nEncodingType = 9;
nByteOrg_2 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByteOrg_3 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByteOrg_4 = FileHelper.impl_readAndCheckNextByte(aBuffer, i++, nReadCount, 0x80, 0xBF);
nByte_2 = nByteOrg_2-0x80;
nByte_3 = nByteOrg_3-0x80;
nByte_4 = nByteOrg_4-0x80;
nUTF8 = FileHelper.impl_convertBytesToChar(0, nByte_2, nByte_3, nByte_4);
}
// wrong encoding ?
else
{
throw new java.lang.Exception("Non well formed UTF-8 encoding.");
}
sBuffer.append(nUTF8);
// -> DEBUG !
FileHelper.logEncodingData(sLog, nUTF8, nByteOrg_1, nByteOrg_2, nByteOrg_3, nByteOrg_4, nByte_1, nByte_2, nByte_3, nByte_4, nEncodingType);
// <- DEBUG !
}
}
}
catch(java.lang.Throwable ex)
{
// -> DEBUG !
FileHelper.logEncodingData(sLog, nUTF8, nByteOrg_1, nByteOrg_2, nByteOrg_3, nByteOrg_4, nByte_1, nByte_2, nByte_3, nByte_4, nEncodingType);
java.io.File aDir = new java.io.File(aFile.getParent());
java.lang.String sDump = aFile.getName();
java.io.File aDump = FileHelper.createUniqueFile(aDir, sDump, "dump");
FileHelper.writeEncodedBufferToFile(aDump, "UTF-8", false, sLog);
// <- DEBUG !
java.lang.String sMsg = "File '"+aFile.getPath()+"' is not encoded right as UTF-8.";
throw new java.io.IOException(sMsg);
}
aByteStream.close();
}
//___________________________________________
/** writes the given string buffer into the specified file
* using the specified encoding.
*
* Further it can be set, if the file should be expanded
* or replaced by this new string buffer.
*
* @param aFile
* must point to a system file. It can already exist!
* e.g.: "c:\temp\test.txt"
* "/tmp/test.txt"
*
* @param sEncoding
* will be used to encode the string content inside the file.
* e.g.: "UTF8"
*
* @param bAppend
* specify if an already existing file will be
* expanded or replaced.
*
* @param sBuffer
* the new string content for this file.
*/
public static void writeEncodedBufferToFile(java.io.File aFile ,
java.lang.String sEncoding,
boolean bAppend ,
java.lang.StringBuffer sBuffer )
throws java.io.IOException
{
java.io.FileOutputStream aByteStream = new java.io.FileOutputStream(aFile.getAbsolutePath(), bAppend);
java.io.OutputStreamWriter aEncodedWriter = new java.io.OutputStreamWriter(aByteStream, sEncoding);
java.lang.String sTemp = sBuffer.toString();
aEncodedWriter.write(sTemp, 0, sTemp.length());
aEncodedWriter.flush();
aEncodedWriter.close();
if (!aFile.exists())
throw new java.io.IOException("File \""+aFile.getAbsolutePath()+"\" not written correctly.");
}
}

View File

@@ -1,156 +0,0 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
package com.sun.star.filter.config.tools.utils;
import java.lang.*;
import java.util.*;
/** can be used to print out some debug messages
* and group it into warnings/errors or info statements.
*
*
*/
public class Logger
{
/** only error message will be shown. */
public static final int LEVEL_ERRORS = 1;
/** only errors and warnings will be shown. */
public static final int LEVEL_WARNINGS = 2;
/** enable errors/warnings and some global info
* message. */
public static final int LEVEL_GLOBALINFOS = 3;
/** enable anything! */
public static final int LEVEL_DETAILEDINFOS = 4;
//___________________________________________
// member
/** enable/disable different output level.
* e.g. warnings/errors/infos */
private int m_nLevel;
//___________________________________________
// ctor
/** initialize new debug object with the specified
* debug level.
*
* @param nLevel
* the new debug level.
* See const values LEVEL_xxx too.
*/
public Logger(int nLevel)
{
m_nLevel = nLevel;
}
//___________________________________________
// interface
/** initialize new debug object with a default
* debug level.
*/
public Logger()
{
m_nLevel = LEVEL_DETAILEDINFOS;
}
//___________________________________________
// interface
/** prints out an exception ... if the right level is set.
*
* @param ex
* the exception object
*/
public synchronized void setException(java.lang.Throwable ex)
{
if (m_nLevel >= LEVEL_ERRORS)
{
System.err.println("Exception:\n");
ex.printStackTrace();
}
}
//___________________________________________
// interface
/** prints out an error ... if the right level is set.
*
* @param sError
* the error message.
*/
public synchronized void setError(java.lang.String sError)
{
if (m_nLevel >= LEVEL_ERRORS)
System.err.println("Error :\t\""+sError+"\"");
}
//___________________________________________
// interface
/** prints out a warning ... if the right level is set.
*
* @param sWarning
* the warning message.
*/
public synchronized void setWarning(java.lang.String sWarning)
{
if (m_nLevel >= LEVEL_WARNINGS)
System.err.println("Warning :\t\""+sWarning+"\"");
}
//___________________________________________
// interface
/** prints out a global info message ... if the right level is set.
*
* Global infos should be used to describe a complex operation.
* E.g.: loading of a document.
* But not for every sub operation like e.g. analyzing lines
* during loading the document!
*
* @param sInfo
* the info message.
*/
public synchronized void setGlobalInfo(java.lang.String sInfo)
{
if (m_nLevel >= LEVEL_GLOBALINFOS)
System.out.println("Info :\t\""+sInfo+"\"");
}
//___________________________________________
// interface
/** prints out a mode detailed info message ... if the right level is set.
*
* Such detailed message are e.g. "analyze line [n] of file ...".
*
* @param sInfo
* the info message.
*/
public synchronized void setDetailedInfo(java.lang.String sInfo)
{
if (m_nLevel >= LEVEL_DETAILEDINFOS)
System.out.println("Detail :\t\""+sInfo+"\"");
}
}

View File

@@ -1,38 +0,0 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
package com.sun.star.filter.config.tools.utils;
//_______________________________________________
// imports
import java.lang.*;
//___________________________________________
// types
/** indicates a malformed command line.
*
* E.g. it must be thrown if the command line contains one item more then once,
* or use unsupported format.
*/
public class MalformedCommandLineException extends java.lang.Exception
{
public MalformedCommandLineException() {}
public MalformedCommandLineException(java.lang.String sMsg) { super(sMsg); }
}

View File

@@ -1,812 +0,0 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
package com.sun.star.filter.config.tools.utils;
//_______________________________________________
import java.lang.*;
import java.util.*;
import java.io.*;
//_______________________________________________
/**
* It provides some constant values and some static helper routines
* which are neccessary to work with a xml file - especialy
* the filter configuration.
*
*
*/
public class XMLHelper
{
/** its a possible value of the xml attribute "oor:type" and identify an integer type. */
public static final java.lang.String XMLTYPE_INTEGER = "xs:int";
/** its a possible value of the xml attribute "oor:type" and identify an boolean type. */
public static final java.lang.String XMLTYPE_BOOLEAN = "xs:boolean";
/** its a possible value of the xml attribute "oor:type" and identify an string type. */
public static final java.lang.String XMLTYPE_STRING = "xs:string";
/** its a possible value of the xml attribute "oor:type" and identify an string list type. */
public static final java.lang.String XMLTYPE_STRINGLIST = "oor:string-list";
/** its a xml attribute, which specify a property name. */
public static final java.lang.String XMLATTRIB_OOR_NAME = "oor:name";
/** its a xml attribute, which specify a property type. */
public static final java.lang.String XMLATTRIB_OOR_TYPE = "oor:type";
/** its a xml attribute, which specify a list separator. */
public static final java.lang.String XMLATTRIB_OOR_SEPARATOR = "oor:separator";
/** its a xml attribute, which specify a localized value. */
public static final java.lang.String XMLATTRIB_OOR_LOCALIZED = "oor:localized";
/** its a xml attribute, which specify a merge operation for cfg layering. */
public static final java.lang.String XMLATTRIB_OOR_OP = "oor:op";
/** can be used as value for XMLATTRIB_OOR_OP. */
public static final java.lang.String XMLATTRIB_OP_REPLACE = "replace";
/** its a xml attribute, which specify a locale value. */
public static final java.lang.String XMLATTRIB_XML_LANG = "xml:lang";
/** its the tag name of a <value ...> entry. */
public static final java.lang.String XMLTAG_VALUE = "value";
/** its the tag name of a <prop ...> entry. */
public static final java.lang.String XMLTAG_PROP = "prop";
/** its the tag name of a <node ...> entry. */
public static final java.lang.String XMLTAG_NODE = "node";
//___________________________________________
// private const
/** a static list of all possible separators, which can be used for configuration type string-list. */
private static final java.lang.String[] DELIMS = {" ", ",", ";", ".", ":", "-", "_", "#", "'", "+", "*", "~", "=", "?"};
/** index of the default separator inside list DELIMS.
* Its neccessary to know such default separator; because it can
* be supressed as xml attribute of the corresponding value tag. */
private static final int DEFAULT_SEPARATOR = 0;
//___________________________________________
/** analyze the structures of the given XML node and
* return a property set of all found sub nodes.
*
* Such properties are organized as [name, value] pairs.
* The type of a xml node will be detected automaticly.
* Following types are supported:
* xs:int => java.lang.Integer
* xs:bool => java.lang.Boolean
* xs:string => java.lang.String
* oor:string-list => java.util.LinkedList[java.lang.String]
* oor:set => java.util.Vector[java.lang.Object]
* oor:localized => java.util.HashMap[java.lang.Object]
*
* @param aNode
* points directly to the xml node, where we should analyze
* the children nodes.
*
* @return [java.util.HashMap]
* contains every node name as key and its string(!) as value.
*/
public static java.util.HashMap convertNodeToPropSet(org.w3c.dom.Node aNode)
throws java.lang.Exception
{
java.util.HashMap aPropSet = new java.util.HashMap();
// get all child nodes, which seems to be properties
java.util.Vector lChildNodes = XMLHelper.extractChildNodesByTagName(aNode, XMLTAG_PROP);
java.util.Enumeration en1 = lChildNodes.elements();
while(en1.hasMoreElements())
{
org.w3c.dom.Node aChildNode = (org.w3c.dom.Node)en1.nextElement();
// read its name
java.lang.String sChildName = XMLHelper.extractNodeAttribByName(aChildNode, XMLATTRIB_OOR_NAME);
if (sChildName == null)
throw new java.io.IOException("unsupported format: could not extract child node name");
// read its type info
java.lang.String sChildType = XMLHelper.extractNodeAttribByName(aChildNode, XMLATTRIB_OOR_TYPE);
if (sChildType == null)
{
/** Special patch:
* If an xml tag has no type information set ... we can restore it
* by analyzing the already readed tag name :-)
* Not very nice - but it can help to read stripped xml files too. */
sChildType = XMLHelper.getTypeForTag(sChildName);
if (sChildType == null)
throw new java.io.IOException("unsupported format: could not extract child node type");
}
// read its value(s?)
java.util.Vector lChildValues = XMLHelper.extractChildNodesByTagName(aChildNode, XMLTAG_VALUE);
java.util.Enumeration en2 = lChildValues.elements();
int nValue = 0;
java.lang.Object aValue = null;
while(en2.hasMoreElements())
{
org.w3c.dom.Node aValueNode = (org.w3c.dom.Node)en2.nextElement();
java.lang.String sChildLocale = XMLHelper.extractNodeAttribByName(aValueNode, XMLATTRIB_XML_LANG);
boolean bLocalized = (sChildLocale != null);
++nValue;
if (sChildType.equals(XMLTYPE_INTEGER))
{
if (!bLocalized && nValue > 1)
throw new java.io.IOException("unsupported format: more then one value for non localized but atomic type detected");
java.lang.String sData = ((org.w3c.dom.CharacterData)aValueNode.getFirstChild()).getData();
aValue = new java.lang.Integer(sData);
}
else
if (sChildType.equals(XMLTYPE_BOOLEAN))
{
if (!bLocalized && nValue > 1)
throw new java.io.IOException("unsupported format: more then one value for non localized but atomic type detected");
java.lang.String sData = ((org.w3c.dom.CharacterData)aValueNode.getFirstChild()).getData();
aValue = new java.lang.Boolean(sData);
}
else
if (sChildType.equals(XMLTYPE_STRING))
{
if (!bLocalized && nValue > 1)
throw new java.io.IOException("unsupported format: more then one value for non localized but atomic type detected");
java.lang.String sData = ((org.w3c.dom.CharacterData)aValueNode.getFirstChild()).getData();
java.util.HashMap lLocalized = null;
if (bLocalized)
{
if (aValue == null)
aValue = new java.util.HashMap();
lLocalized = (java.util.HashMap)aValue;
lLocalized.put(sChildLocale, sData);
}
else
aValue = sData;
}
else
if (sChildType.equals(XMLTYPE_STRINGLIST))
{
if (!bLocalized && nValue > 1)
throw new java.io.IOException("unsupported format: more then one value for non localized but atomic type detected");
java.lang.String sSeparator = XMLHelper.extractNodeAttribByName(aChildNode, XMLATTRIB_OOR_SEPARATOR);
if (sSeparator == null)
sSeparator = " ";
java.lang.String sData = ((org.w3c.dom.CharacterData)aValueNode.getFirstChild()).getData();
sData = sData.replace('\t', ' ');
sData = sData.replace('\n', ' ');
java.util.StringTokenizer aTokenizer = new java.util.StringTokenizer(sData, sSeparator);
java.util.Vector lList = new java.util.Vector();
while(aTokenizer.hasMoreTokens())
{
java.lang.String sToken = (java.lang.String)aTokenizer.nextToken();
sToken.trim();
if (sToken.length() < 1)
continue;
lList.add(sToken);
}
aValue = lList;
}
aPropSet.put(sChildName, aValue);
}
}
return aPropSet;
}
//___________________________________________
private static java.lang.String getTypeForTag(java.lang.String sTag)
{
java.lang.String sType = null;
if (
(sTag.equals(Cache.PROPNAME_DATA )) ||
(sTag.equals(Cache.PROPNAME_NAME )) ||
(sTag.equals(Cache.PROPNAME_UINAME )) ||
(sTag.equals(Cache.PROPNAME_MEDIATYPE )) ||
(sTag.equals(Cache.PROPNAME_CLIPBOARDFORMAT )) ||
(sTag.equals(Cache.PROPNAME_PREFERREDFILTER )) ||
(sTag.equals(Cache.PROPNAME_DETECTSERVICE )) ||
(sTag.equals(Cache.PROPNAME_FRAMELOADER )) ||
(sTag.equals(Cache.PROPNAME_CONTENTHANDLER )) ||
(sTag.equals(Cache.PROPNAME_DOCUMENTSERVICE )) ||
(sTag.equals(Cache.PROPNAME_FILTERSERVICE )) ||
(sTag.equals(Cache.PROPNAME_TEMPLATENAME )) ||
(sTag.equals(Cache.PROPNAME_TYPE )) ||
(sTag.equals(Cache.PROPNAME_UICOMPONENT ))
)
sType = XMLTYPE_STRING;
else
if (
(sTag.equals(Cache.PROPNAME_PREFERRED )) ||
(sTag.equals("Installed" ))
)
sType = XMLTYPE_BOOLEAN;
else
if (
(sTag.equals(Cache.PROPNAME_UIORDER )) ||
(sTag.equals(Cache.PROPNAME_DOCUMENTICONID )) ||
(sTag.equals(Cache.PROPNAME_FILEFORMATVERSION))
)
sType = XMLTYPE_INTEGER;
else
if (
(sTag.equals(Cache.PROPNAME_URLPATTERN )) ||
(sTag.equals(Cache.PROPNAME_EXTENSIONS )) ||
(sTag.equals(Cache.PROPNAME_USERDATA )) ||
(sTag.equals(Cache.PROPNAME_FLAGS )) ||
(sTag.equals(Cache.PROPNAME_TYPES ))
)
sType = XMLTYPE_STRINGLIST;
if (sType == null)
System.err.println("getTypeForTag("+sTag+") = "+sType);
return sType;
}
//___________________________________________
/** return a xml representation of the given property set.
*
* @param aPropSet
* a set of <name,value> pairs, which should be translated to xml
*
* @return [java.lang.String]
* the xml string representation.
*
* @throws [java.lang.Exception]
* if anything during convertion fill fail.
*/
public static java.lang.String convertPropSetToXML(java.util.HashMap aPropSet ,
int nPrettyTabs)
throws java.lang.Exception
{
java.lang.StringBuffer sXML = new java.lang.StringBuffer(256);
java.util.Iterator it1 = aPropSet.keySet().iterator();
while(it1.hasNext())
{
java.lang.String sProp = (java.lang.String)it1.next();
java.lang.Object aVal = aPropSet.get(sProp);
sProp = encodeHTMLSigns(sProp);
// is it a simple type?
if (
(aVal instanceof java.lang.Integer) ||
(aVal instanceof java.lang.Boolean) ||
(aVal instanceof java.lang.String )
)
{
sXML.append(XMLHelper.convertSimpleObjectToXML(sProp, aVal, nPrettyTabs));
continue;
}
// no!
// is it a list value?
if (aVal instanceof java.util.Vector)
{
java.util.Vector lVal = (java.util.Vector)aVal;
sXML.append(XMLHelper.convertListToXML(sProp, lVal, nPrettyTabs));
continue;
}
// its a localized value?
if (aVal instanceof java.util.HashMap)
{
java.util.HashMap lVal = (java.util.HashMap)aVal;
sXML.append(XMLHelper.convertLocalizedValueToXML(sProp, lVal, nPrettyTabs));
continue;
}
// unknown type!
java.lang.StringBuffer sMsg = new java.lang.StringBuffer(256);
sMsg.append("unsupported object type detected.");
sMsg.append("\ttype ? : \""+sProp+"\" = "+aVal);
sMsg.append("\tprop set: \""+aPropSet );
throw new java.lang.Exception(sMsg.toString());
}
return sXML.toString();
}
public static java.lang.String encodeHTMLSigns(java.lang.String sValue)
{
java.lang.StringBuffer sSource = new java.lang.StringBuffer(sValue);
java.lang.StringBuffer sDestination = new java.lang.StringBuffer(1000 );
for (int i=0; i<sSource.length(); ++i)
{
char c = sSource.charAt(i);
if (c == '&')
sDestination.append("&amp;");
else
sDestination.append(c);
}
java.lang.String sReturn = sDestination.toString();
if (!sReturn.equals(sValue))
System.out.println("encode \""+sValue+"\" => \""+sReturn+"\"");
return sReturn;
}
//___________________________________________
/** return a xml representation of an atomic property.
*
* Atomic property types are e.g. Integer, Boolean, String.
*
* @param sName
* the name of the property.
* @param aValue
* the value of the property.
*
* @param nPrettyTabs
* count of tab signs for pretty format the xml code :-)
*
* @return [java.lang.String]
* the xml string representation.
*
* @throws [java.lang.Exception]
* if anything during convertion fill fail.
*/
private static java.lang.String convertSimpleObjectToXML(java.lang.String sName ,
java.lang.Object aValue ,
int nPrettyTabs)
throws java.lang.Exception
{
java.lang.StringBuffer sXML = new java.lang.StringBuffer(256);
for (int t=0; t<nPrettyTabs; ++t)
sXML.append("\t");
if (aValue instanceof java.lang.Integer)
{
sXML.append("<prop "+XMLATTRIB_OOR_NAME+"=\""+sName+"\">");
sXML.append("<value>"+aValue.toString()+"</value>");
sXML.append("</prop>\n");
}
else
if (aValue instanceof java.lang.Boolean)
{
sXML.append("<prop "+XMLATTRIB_OOR_NAME+"=\""+sName+"\">");
sXML.append("<value>"+aValue.toString()+"</value>");
sXML.append("</prop>\n");
}
else
if (aValue instanceof java.lang.String)
{
sXML.append("<prop "+XMLATTRIB_OOR_NAME+"=\""+sName+"\"");
java.lang.String sValue = (java.lang.String)aValue;
sValue = encodeHTMLSigns(sValue);
if (sValue.length() < 1)
sXML.append("/>\n");
else
{
sXML.append("><value>"+sValue+"</value>");
sXML.append("</prop>\n");
}
}
else
{
System.err.println("name = "+sName);
System.err.println("value = "+aValue);
// ! can be used outside to detect - that it was not a simple type :-)
throw new java.lang.Exception("not an atomic type.");
}
return sXML.toString();
}
//___________________________________________
/** return a xml representation of a string-list property.
*
* @param sName
* the name of the property.
* @param aValue
* the value of the property.
*
* @param nPrettyTabs
* count of tab signs for pretty format the xml code :-)
*
* @return [java.lang.String]
* the xml string representation.
*
* @throws [java.lang.Exception]
* if anything during convertion fill fail.
*/
private static java.lang.String convertListToXML(java.lang.String sName ,
java.util.Vector aValue ,
int nPrettyTabs)
throws java.lang.Exception
{
java.lang.StringBuffer sXML = new java.lang.StringBuffer(256);
for (int t=0; t<nPrettyTabs; ++t)
sXML.append("\t");
int c = aValue.size();
if (c < 1)
{
sXML.append("<prop "+XMLATTRIB_OOR_NAME+"=\""+sName+"\"/>\n");
return sXML.toString();
}
// step over all list items and add it to a string buffer
// Every item will be separated by a default separator "\n" first.
// Because "\n" is not a valid separator at all and can`t occure inside
// our list items. During we step over all items, we check if our current separator
// (we use a list of possible ones!) clash with an item.
// If it clash - we step to the next possible separator.
// If our list of possible separator values runs out of range we throw
// an exception :-) Its better then generating of wrong values
// If we found a valid seperator - we use it to replace our "\n" place holder
// at the end of the following loop ...
int d = 0;
java.lang.StringBuffer sValBuff = new java.lang.StringBuffer(256);
for (int i=0; i<c; ++i)
{
// get the next list item
java.lang.Object aItem = aValue.get(i);
if (!(aItem instanceof java.lang.String))
throw new java.lang.Exception("Current implementation supports string-list only!");
java.lang.String sValue = (java.lang.String)aItem;
sValue = encodeHTMLSigns(sValue);
// append item with default separator, which isn a valid separator at all
// But supress adding of the separator if last element is reached.
sValBuff.append(sValue);
if (i<(c-1))
sValBuff.append("\n");
// check for delim clash
// Attention: An empty (means default) element forbid using
// of a whitespace character as separator!
while(true)
{
if (d >= DELIMS.length)
throw new java.lang.Exception("No valid separator found for a string list item.");
if (sValue.length() < 1 && DELIMS[d].equals(" "))
{
++d;
continue;
}
if (sValue.indexOf(DELIMS[d]) != -1)
{
++d;
continue;
}
break;
}
}
// replace default separator with right one
System.out.println("TODO: must be adapted to java 1.3 :-(");
System.exit(-1);
//TODO_JAVA java.lang.String sListVal = sValBuff.toString().replaceAll("\n", DELIMS[d]);
java.lang.String sListVal = null;
sXML.append("<prop "+XMLATTRIB_OOR_NAME+"=\""+sName+"\">");
if (d == DEFAULT_SEPARATOR)
sXML.append("<value>");
else
sXML.append("<value "+XMLATTRIB_OOR_SEPARATOR+"=\""+DELIMS[d]+"\">");
sXML.append(sListVal);
sXML.append("</value>");
sXML.append("</prop>\n");
return sXML.toString();
}
//___________________________________________
/** return a xml representation of a localized property.
*
* @param sName
* the name of the property.
* @param aValue
* the value of the property.
*
* @param nPrettyTabs
* count of tab signs for pretty format the xml code :-)
*
* @return [java.lang.String]
* the xml string representation.
*
* @throws [java.lang.Exception]
* if anything during convertion fill fail.
*/
private static java.lang.String convertLocalizedValueToXML(java.lang.String sName ,
java.util.HashMap aValue ,
int nPrettyTabs)
throws java.lang.Exception
{
java.lang.StringBuffer sXML = new java.lang.StringBuffer(256);
int c = aValue.size();
if (c < 1)
throw new java.lang.Exception("Cant detect type of localized values. Because the given list is empty.");
for (int t=0; t<nPrettyTabs; ++t)
sXML.append("\t");
// !Our localized values must be formated at a deeper coloum
// then its property name!
++nPrettyTabs;
sXML.append("<prop "+XMLATTRIB_OOR_NAME+"=\""+sName+"\">\n");
java.util.Iterator it = aValue.keySet().iterator();
// boolean bTypeKnown = false;
while(it.hasNext())
{
java.lang.String sLocale = (java.lang.String)it.next();
java.lang.Object aLocalizedValue = aValue.get(sLocale);
/*
if (!bTypeKnown)
{
bTypeKnown = true;
if (aLocalizedValue instanceof java.lang.Integer)
sXML.append(" "+XMLATTRIB_OOR_TYPE+"=\""+XMLTYPE_INTEGER+"\">\n");
else
if (aLocalizedValue instanceof java.lang.Boolean)
sXML.append(" "+XMLATTRIB_OOR_TYPE+"=\""+XMLTYPE_BOOLEAN+"\">\n");
else
if (aLocalizedValue instanceof java.lang.String)
sXML.append(" "+XMLATTRIB_OOR_TYPE+"=\""+XMLTYPE_STRING+"\">\n");
else
throw new java.lang.Exception("Unsupported type for localized value detected.");
}
*/
java.lang.String sLocValue = aLocalizedValue.toString();
java.lang.String sValue = encodeHTMLSigns(sLocValue);
for (int t=0; t<nPrettyTabs; ++t)
sXML.append("\t");
sXML.append("<value "+XMLATTRIB_XML_LANG+"=\""+sLocale+"\">"+sValue+"</value>\n");
}
--nPrettyTabs;
for (int t=0; t<nPrettyTabs; ++t)
sXML.append("\t");
sXML.append("</prop>\n");
return sXML.toString();
}
//___________________________________________
/** returns the value of an attribute of the given node.
*
* If the given node represent an lement node, may it supports some attributes.
* Then this method search for an attribute with the specified name and return it's value.
* If nothing could be found ... or the given node isn't a suitable node ... it returns null.
*
* @param aNode
* the node, which should be analyzed.
*
* @param sAttrib
* name of the attribute, which should be searched.
*
* @return The value of the specified attribute if it could be found at the given node.
* Can be null if node doesn't support attributes or the searched one does not exist there.
*/
public static java.lang.String extractNodeAttribByName(org.w3c.dom.Node aNode ,
java.lang.String sAttrib)
throws java.lang.Exception
{
// We can get valid attributes for element nodes only!
if (aNode.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
{
// System.err.println("not an element node");
return null;
}
// may it supports attributes in general ... but doesn't have anyone realy.
org.w3c.dom.NamedNodeMap lAttribs = aNode.getAttributes();
if (lAttribs==null)
{
// System.err.println("no attributes at all");
return null;
}
// step over the attribute list and search for the requested one
for (int i=0; i<lAttribs.getLength(); ++i)
{
org.w3c.dom.Attr aAttrib = (org.w3c.dom.Attr)lAttribs.item(i);
if (aAttrib.getName().equals(sAttrib))
{
java.lang.String sValue = aAttrib.getValue();
return sValue;
}
}
// the searched attribute was not found!
// System.err.println("required attribute \""+sAttrib+"\" does not exist for node ["+aNode.toString()+"]");
return null;
}
//___________________________________________
/** returns a list of children, which are ELEMENT_NODES and have the right tag name.
*
* It analyze the list of all possible child nodes. Only ELEMENT_NODES are candidates.
* All other ones will be ignored. Further these element nodes are compared by it's tag
* names. If it match with the specified value it's added to the return list.
* So the return list includes references to the DOM tree nodes only, which are child
* element nodes with the right tag name.
*
* @param aNode
* provides access to the child nodes, which should be analyzed
*
* @param sTag
* the searched tag name.
*
* @return A list of child nodes, which are element nodes and have the right tag name.
*/
public static java.util.Vector extractChildNodesByTagName(org.w3c.dom.Node aNode,
java.lang.String sTag )
{
// extract first all ELEMENT_NODES of he given parent
// Such nodes only provide tag names.
java.util.Vector lChildren = XMLHelper.extractChildNodesByType(aNode,org.w3c.dom.Node.ELEMENT_NODE);
java.util.Vector lExtractedChildren = new java.util.Vector(lChildren.size());
// step over the list and search for the right tags using the specified name
java.util.Enumeration en = lChildren.elements();
while (en.hasMoreElements())
{
org.w3c.dom.Node aChild = (org.w3c.dom.Node)en.nextElement();
if (aChild.getNodeName().equals(sTag))
lExtractedChildren.add(aChild);
}
// pack(!) and return the list
lExtractedChildren.trimToSize();
return lExtractedChildren;
}
//___________________________________________
/** returns a list of children, which supports the right node type.
*
* It analyze the list of all possible child nodes. If a node represent the right node type
* it is added to the return list. Otherwhise it will be ignored.
*
* @param aNode
* provides access to the list of possible children nodes.
*
* @param nType
* represent the searched node type.
* Possible values are constant fields of a org.w3c.dom.Node - e.g. org.w3c.dom.Node.ELEMENT_NODE.
*
* @return A list of child nodes, which provides the right node type.
*/
public static java.util.Vector extractChildNodesByType(org.w3c.dom.Node aNode,
short nType)
{
// get list of all possibe children and reserve enough space for our return list
// Attention: A null pointer is not allowed for return! (means lExtractedChildren)
org.w3c.dom.NodeList lChildren = aNode.getChildNodes();
int c = lChildren.getLength();
java.util.Vector lExtractedChildren = new java.util.Vector(c);
// step of these children and select only needed ones
for (int i=0; i<c; ++i)
{
org.w3c.dom.Node aChild = lChildren.item(i);
if (aChild.getNodeType() == nType)
lExtractedChildren.add(aChild);
}
// pack(!) and return the list
lExtractedChildren.trimToSize();
return lExtractedChildren;
}
//___________________________________________
/** generates an xml header, using parameters.
*
* @param sVersion
* number of the xml version.
*
* @param sEncoding
* used file encoding.
*
* @param sPath
* name of the configuration root.
*
* @param sPackage
* name of the configuration package.
*
* @param bLanguagepack
* force creation of a special header,
* which is needed for language packs only.
*
* @return [java.lang.String]
* the generated xml header.
*/
public static java.lang.String generateHeader(java.lang.String sVersion ,
java.lang.String sEncoding ,
java.lang.String sPath ,
java.lang.String sPackage ,
boolean bLanguagePack)
{
java.lang.StringBuffer sHeader = new java.lang.StringBuffer(256);
if (bLanguagePack)
{
sHeader.append("<?xml version=\"");
sHeader.append(sVersion);
sHeader.append("\" encoding=\"");
sHeader.append(sEncoding);
sHeader.append("\"?>\n");
sHeader.append("<oor:component-data oor:package=\"");
sHeader.append(sPath);
sHeader.append("\" oor:name=\"");
sHeader.append(sPackage);
sHeader.append("\" xmlns:install=\"http://openoffice.org/2004/installation\"");
sHeader.append(" xmlns:oor=\"http://openoffice.org/2001/registry\"");
sHeader.append(" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"");
sHeader.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n");
}
else
{
sHeader.append("<?xml version=\"");
sHeader.append(sVersion);
sHeader.append("\" encoding=\"");
sHeader.append(sEncoding);
sHeader.append("\"?>\n");
sHeader.append("<oor:component-data xmlns:oor=\"http://openoffice.org/2001/registry\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" oor:package=\"");
sHeader.append(sPath);
sHeader.append("\" oor:name=\"");
sHeader.append(sPackage);
sHeader.append("\">\n");
}
return sHeader.toString();
}
public static java.lang.String generateFooter()
{
return "</oor:component-data>\n";
}
}