diff options
author | Ivo Hinkelmann <ihi@openoffice.org> | 2010-05-28 13:51:26 +0200 |
---|---|---|
committer | Ivo Hinkelmann <ihi@openoffice.org> | 2010-05-28 13:51:26 +0200 |
commit | 126d4b4f8dde5f4f7588a9c49043f9c90fe86ebb (patch) | |
tree | 2e779c325265d6635d54fbd8029161b30b5578b8 /l10ntools/java | |
parent | 834f4bd699643b9297a14cbc1eb1ef65dbdf0862 (diff) |
l10ntooling17: #i100845# add support for java properties
Diffstat (limited to 'l10ntools/java')
-rwxr-xr-x | l10ntools/java/jpropex/build.xml | 169 | ||||
-rw-r--r-- | l10ntools/java/jpropex/java/JPropEx.java | 428 | ||||
-rw-r--r-- | l10ntools/java/jpropex/java/Main.java | 38 | ||||
-rw-r--r-- | l10ntools/java/jpropex/java/NoLocalizeFilter.java | 56 | ||||
-rw-r--r-- | l10ntools/java/jpropex/java/OrderedHashMap.java | 96 | ||||
-rw-r--r-- | l10ntools/java/jpropex/java/SdfData.java | 109 | ||||
-rw-r--r-- | l10ntools/java/jpropex/java/SdfEntity.java | 254 | ||||
-rwxr-xr-x | l10ntools/java/jpropex/jpropex | 10 | ||||
-rwxr-xr-x | l10ntools/java/jpropex/jpropex.MF | 1 | ||||
-rwxr-xr-x | l10ntools/java/jpropex/makefile.mk | 36 |
10 files changed, 1197 insertions, 0 deletions
diff --git a/l10ntools/java/jpropex/build.xml b/l10ntools/java/jpropex/build.xml new file mode 100755 index 000000000000..d74fb3975d0f --- /dev/null +++ b/l10ntools/java/jpropex/build.xml @@ -0,0 +1,169 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + + Copyright 2000, 2010 Oracle and/or its affiliates. + + OpenOffice.org - a multi-platform office productivity suite + + This file is part of OpenOffice.org. + + OpenOffice.org is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + OpenOffice.org is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details + (a copy is included in the LICENSE file that accompanied this code). + + You should have received a copy of the GNU Lesser General Public License + version 3 along with OpenOffice.org. If not, see + <http://www.openoffice.org/license.html> + for a copy of the LGPLv3 License. + +--> +<project name="jpropex" default="main" basedir="."> + + <!-- ================================================================= --> + <!-- settings --> + <!-- ================================================================= --> + + <!-- name of this sub target used in recursive builds --> + <property name="target" value="jpropex"/> + + <!-- name of jar file created, without .jar extension --> + <property name="jarname" value="jpropex"/> + + <!-- relative path to project directory --> + <property name="prj" value="."/> + + <!-- build output directory --> + <property name="out" value="build"/> + + <!-- build directories --> + <property name="build.dir" value="${out}"/> + <property name="build.class" value="${build.dir}/class/jpropex"/> + <property name="build.misc" value="${build.dir}/misc/jpropex"/> + + <!-- start of java source code package structure --> + <property name="java.dir" value="java"/> + + <!-- define how to handle CLASSPATH environment --> + <property name="build.sysclasspath" value="ignore"/> + + <!-- classpath settings for compile and javadoc tasks --> + <path id="classpath"> + <pathelement location="."/> + <pathelement location="${build.class}"/> + </path> + + <!-- name to display in documentation --> + <!-- <property name="docname" value="l10n converter"/> --> + + <!-- set "modern" java compiler --> + <property name="build.compiler" value="modern"/> + + <!-- set wether we want to compile with debug information --> + <property name="debug" value="on"/> + + <!-- set wether we want to compile with optimisation --> + <property name="optimize" value="off"/> + + <!-- set wether we want to compile with or without deprecation --> + <property name="deprecation" value="on"/> + + <target name="info"> + <echo message="--------------------"/> + <echo message="${target}"/> + <echo message="--------------------"/> + </target> + + <!-- ================================================================= --> + <!-- custom targets --> + <!-- ================================================================= --> + + <!-- the main target, called in recursive builds --> + <target name="main" depends="info,prepare,compile,jar"/> + + <!-- prepare output directories --> + <target name="prepare"> + <mkdir dir="${build.dir}"/> + <mkdir dir="${build.class}"/> + <mkdir dir="${build.misc}"/> + </target> + + + <target name="res" depends="prepare"> + <copy todir="${build.class}"> + <fileset dir="${java.dir}"> + <include name="**/*.properties"/> + <include name="**/*.css"/> + <include name="**/*.dtd"/> + <include name="**/*.form"/> + <include name="**/*.gif "/> + <include name="**/*.htm"/> + <include name="**/*.html"/> + <include name="**/*.js"/> + <include name="**/*.mod"/> + <include name="**/*.sql"/> + <include name="**/*.xml"/> + <include name="**/*.xsl"/> + <include name="**/*.map"/> + + </fileset> + </copy> + </target> + + + <target name="compile" depends="prepare,res"> + <javac destdir="${build.class}" + debug="${debug}" + deprecation="${deprication}" + optimize="${optimize}" + classpathref="classpath"> + <src path="${java.dir}"/> + <include name="**/*.java"/> + </javac> + </target> + + <!-- clean up --> + <target name="clean" depends="prepare"> + <delete includeEmptyDirs="true"> + <fileset dir="${build.class}"> + <patternset> + <include name="${package}/**/*.class"/> + </patternset> + </fileset> + </delete> + </target> + + <!-- create jar file --> + <target name="jar" depends="prepare,compile" if="build.class"> + <jar jarfile="${build.class}/${jarname}.jar" + basedir="${build.class}" + manifest="${jarname}.MF"> + <include name="**/*.class"/> + <include name="**/*.properties"/> + <include name="**/*.css"/> + <include name="**/*.dtd"/> + <include name="**/*.form"/> + <include name="**/*.gif "/> + <include name="**/*.htm"/> + <include name="**/*.html"/> + <include name="**/*.js"/> + <include name="**/*.mod"/> + <include name="**/*.sql"/> + <include name="**/*.xml"/> + <include name="**/*.xsl"/> + <include name="**/*.map"/> + </jar> + </target> + + <target name="test" depends="prepare"> + </target> + +</project> + diff --git a/l10ntools/java/jpropex/java/JPropEx.java b/l10ntools/java/jpropex/java/JPropEx.java new file mode 100644 index 000000000000..a4a17060d1f8 --- /dev/null +++ b/l10ntools/java/jpropex/java/JPropEx.java @@ -0,0 +1,428 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +import java.util.*; +import java.io.*; + +public class JPropEx +{ + private String inputFileArg = ""; + private String outputFileArg = ""; + private String pathPrefixArg = ""; + private String pathPostfixArg = ""; + private String projectArg = ""; + private String rootArg = ""; + private Vector forcedLangsArg; + private Vector langsArg; + private String inputSdfFileArg = ""; + private boolean isQuiet = false; + private final String resourceType = "javaproperties"; + private final String sourceLanguage = "en-US"; + //private SdfData data; + + public JPropEx() + { + //data = new SdfData(); + } + + public JPropEx( String args[] ) + { + super(); + parseArguments( args ); + testCL(); + //testArguments(); + if( inputSdfFileArg != null && inputSdfFileArg.length() > 0 ) + merge(); + else + extract(); + } + + private String getSimpleArg( String[] args , int x ) + { + if( x < args.length ) x++; + else + { + System.err.println("ERROR: Missing arg for "+args[ x ]+"\n"); + help(); + } + return args[ x ]; + } + private Vector getComplexArg( String[] args , int x ) + { + if( x < args.length ) x++; + else + { + System.err.println("ERROR: Missing arg for "+args[ x ]+"\n"); + help(); + } + String value = args[ x ]; + Vector values = new Vector( Arrays.asList( value.split(",") ) ); + return values; + } + + private void testCL() + { + if( inputFileArg.length()>0 && ( ( pathPrefixArg.length()>0 && pathPostfixArg.length()>0 ) || outputFileArg.length()>0 ) && projectArg.length()>0 && rootArg.length()>0 && langsArg.size()>0 ) + if( ( inputSdfFileArg.length()>0 && ( outputFileArg.length()>0 || ( pathPrefixArg.length()>0 && pathPostfixArg.length()>0 ) ) ) || ( inputFileArg.length()>0 && outputFileArg.length()>0 ) ) + return; + System.out.println("ERROR: Strange parameters!"); + help(); + System.exit( -1 ); + } + private void help() + { + System.out.println("jpropex -> extract / merge java properties files"); + System.out.println("Example:\ncd /data/cws/l10ntooling17/DEV300/ooo/reportbuilder/java/com/sun/star/report/function/metadata"); + System.out.println("Extract:\njpropex -p reportbuilder -r ../../../../../../.. -i Title-Function.properties -o new.sdf -l en-US"); + System.out.println("Merge: use either ( -x path -y more_path ) or ( -o ) and ( -i filename ) or ( -i @filename )"); + System.out.println("jpropex -p reportbuilder -r ../../../../../../.. -x ../../../../../../../unxlngx6.pro/class/com/sun/star/report/function/metadata -y ivo -i @abc -l all -lf en-US,de,fr,pt -m ../../../../../../../common.pro/misc/reportbuilder/java/com/sun/star/report/function/metadata/localize.sdf"); + System.out.println("jpropex -p reportbuilder -r ../../../../../../.. -x ../../../../../../../unxlngx6.pro/class/com/sun/star/report/function/metadata -y ivo -i @abc -l all -lf en-US,de,fr,pt -m ../../../../../../../common.pro/misc/reportbuilder/java/com/sun/star/report/function/metadata/localize.sdf"); + System.out.println("jpropex -p reportbuilder -r ../../../../../../.. -o ../../../../../../../unxlngx6.pro/class/com/sun/star/report/function/metadata/ -i Title-Function.properties -l all -lf en-US,de,fr,pt -m ../../../../../../../common.pro/misc/reportbuilder/java/com/sun/star/report/function/metadata/localize.sdf"); + System.out.println("jpropex -p reportbuilder -r ../../../../../../.. -x ../../../../../../../unxlngx6.pro/class/com/sun/star/report/function/metadata -y ivooo -i Title-Function.properties -l all -lf en-US,de,fr,pt -m ../../../../../../../common.pro/misc/reportbuilder/java/com/sun/star/report/function/metadata/localize.sdf"); + System.exit( -1 ); + } + + private void extract() + { + SdfData data = new SdfData(); + java.util.Properties prop = loadProp( inputFileArg ); + + // Get a prototype that already contains the most common settings + SdfEntity dolly = prepareSdfObj( inputFileArg ); + String key; + SdfEntity currentStr; + String value; + for( Enumeration e = prop.propertyNames() ; e.hasMoreElements() ; ) + { + key = (String) e.nextElement(); + currentStr = (SdfEntity) dolly.clone(); + // Set the new LID and the string text + currentStr.setLid( key ); + value = prop.getProperty( key , "" ); + //if( value.equals("") ) System.err.println("Warning: in file "+inputFileArg+" the string with the key "+key+" has a empty string!"); + currentStr.setText( (prop.getProperty( key )).replaceAll("\t" , " " ) ); // TODO: Quoting!!!! + data.add( currentStr ); + } + data.write( outputFileArg ); + } + + private SdfEntity prepareSdfObj( String filename ) + { + String path = makeAbs( filename ); + //String path = makeAbs( inputFileArg ); + path = path.replace( rootArg + "/" , "" ); + path = path.replace("/","\\"); + return new SdfEntity( projectArg , path , "" /* dummy1 */ , resourceType , "", "" , "" , "" , "" /* dummy2 */ , + sourceLanguage , "", "" , "" , "" , "2002-02-02 02:02:02" ); + } + + private void merge() + { + SdfData data = getSdfData(); + if( inputFileArg.startsWith("@") ) + { + // Read files + Vector fileList = readFileList( inputFileArg ); + for( Enumeration e = fileList.elements(); e.hasMoreElements(); ) + mergeFile( (String) e.nextElement() , data , false ); + } + else + { + // Single file + mergeFile( inputFileArg , data , true ); + } + } + + private Vector readFileList( String filename ) + { + Vector lines = new Vector(); + try + { + BufferedReader in = new BufferedReader( new FileReader( filename.substring( 1 ) ) ); + while( in.ready() ) + lines.add( in.readLine() ); + } + catch( IOException e ) + { + System.out.println("ERROR: Can't open file '"+filename.substring( 1 )+"'"); + System.exit( -1 ); + } + return lines; + } + + private void mergeFile( String filename , SdfData data , boolean isSingleFile ) + { + java.util.Properties sourceProp = loadProp( filename ); + Vector langs = getLanguages( data ); + HashMap props = new HashMap(); + // Create a properties object for every language + for( Enumeration e = langs.elements(); e.hasMoreElements();) + { + props.put( (String)e.nextElement() , new java.util.Properties() ); + } + // Get a prototype that already contains the most common settings + + SdfEntity dolly = prepareSdfObj( filename ); + String key; + String sourceString; + SdfEntity curStr; + SdfEntity curEntity; + SdfEntity mergedEntity; + String curLang; + for( Enumeration e = sourceProp.propertyNames() ; e.hasMoreElements() ; ) // For all property keys + { + key = (String) e.nextElement(); + sourceString = sourceProp.getProperty( key ); + curStr = (SdfEntity) dolly.clone(); + curStr.setLid( key ); + for( Enumeration lang = langs.elements(); lang.hasMoreElements(); ) // merge in every language + { + curEntity = (SdfEntity) curStr.clone(); + curLang = (String) lang.nextElement(); + curEntity.setLangid( curLang ); + mergedEntity = data.get( curEntity ); + if( mergedEntity == null ) + { + // if case there is not translation the fallback to the en-US source string + ( (java.util.Properties) props.get( curLang )).setProperty( curEntity.getLid() , sourceString ); + } + else + { + // Set the merged text from the sdf file + ( (java.util.Properties) props.get( curLang )).setProperty( mergedEntity.getLid() , mergedEntity.getText() ); // TODO: Quoting ??? + } + } + + } + // Now write them out + String lang; + for( Iterator i = props.keySet().iterator() ; i.hasNext() ; ) + { + lang = (String) i.next(); + writeSinglePropertiesFile( filename , (java.util.Properties) props.get( lang ) , lang , isSingleFile ); + } + } + private void writeSinglePropertiesFile( String filename , java.util.Properties prop , String lang , boolean isSingleFile ) + { + // Prepare path to file + int filenameIdx = filename.lastIndexOf( "/" ) > 0 ? filename.lastIndexOf( "/" )+1 : 0 ; + String path = new String(); + String name = new String(); + String lcLang = lang.toLowerCase(); + // use of -x <path> -y <more_path> + // -> <path>/<lang>/<more_path> + if( pathPrefixArg != null && pathPrefixArg.length()>0 && pathPostfixArg != null && pathPostfixArg.length()>0 ) + { + path = new StringBuffer().append( pathPrefixArg ).append( "/" ).append( lcLang ).append( "/" ).append( pathPostfixArg ).append( "/" ).toString(); + name = new StringBuffer().append( filename.substring( filenameIdx , filename.lastIndexOf( ".properties" ) ) ) + .append( "_" ).append( lcLang.replaceAll("-","_") ).append( ".properties" ).toString(); + } + //use of -i <one_filename> + else if( !isSingleFile && outputFileArg != null && outputFileArg.length()>0 ) + { + name = outputFileArg; + name += new StringBuffer().append( filename.substring( filenameIdx , filename.lastIndexOf( ".properties" ) ) ) + .append( "_" ).append( lcLang.replaceAll("-","_") ).append( ".properties" ).toString(); + //name = outputFileArg; + } + //use of -i @<file_containing_many_filenames> + else if( isSingleFile && outputFileArg != null && outputFileArg.length()>0 ) + { + name = outputFileArg; + name += new StringBuffer().append( inputFileArg.substring( filenameIdx , filename.lastIndexOf( ".properties" ) ) ) + .append( "_" ).append( lcLang.replaceAll("-","_") ).append( ".properties" ).toString(); + //name = outputFileArg; + } + else + { + System.err.println("ERROR: No outputfile specified .. either -o or -x -y !"); + System.exit( -1 ); + } + + File dir = new File( path ); + try + { + if( !dir.exists() && path.length()>0 ) + { + if( !dir.mkdirs() ) + { + System.out.println("ERROR: Can't create directory '"+path+"' !!!"); + System.exit( -1 ); + } + } + } + catch( SecurityException e ) + { + System.out.println("ERROR: Can't create directory '"+path+"'!!!Wrong Permissions?"); + System.exit( -1 ); + } + path += name; + // Write the properties file + System.out.println("DBG: Writing to "+path); + try{ + BufferedOutputStream out = new BufferedOutputStream( new FileOutputStream( path ) ); + if( prop == null ) + System.out.println("DBG: prop == null!!!"); + prop.store( out , "" ); // Legal headers? + } + catch( IOException e ) + { + System.out.println("ERROR: Can't write file '"+path+"' !!!!"); + System.exit( -1 ); + } + } + + private SdfData getSdfData() + { + SdfData data = new SdfData( inputSdfFileArg ); + data.read(); + return data; + } + private Vector getLanguages( SdfData data ) + { + Vector langs = new Vector(); + + if( ((String)langsArg.get( 0 )).equalsIgnoreCase( "all" ) ) // for "-l all" use all languages found in the -m sdf file + langs.addAll( data.getLanguages() ); + else + langs.addAll( langsArg ); // use the langs giving by -l + + if( forcedLangsArg != null ) + langs.addAll( forcedLangsArg ); + + return removeDupes( langs ); + } + private Vector removeDupes( Vector vec ) + { + Collection coll = new LinkedHashSet( vec ); + return new Vector( coll ); + } + private java.util.Properties loadProp( String filename ) + { + java.util.Properties prop = new java.util.Properties(); + try + { + prop.load( new BufferedInputStream( new NoLocalizeFilter( new FileInputStream( filename ) ) ) ); + } + catch( IOException e ) + { + System.err.println("ERROR: Can't read file '"+filename+"'!!!"); + } + return prop; + } + private void parseArguments( String[] args ) + { + + if( args.length == 0 ) + { + System.out.println("ERROR: No args???"); + help(); + System.exit( -1 ); + } + for( int x = 0; x < args.length ; x++ ) + { + if( args[ x ].equalsIgnoreCase("-i") ) + { + // Input resource file + inputFileArg = getSimpleArg( args , x ); + } + else if( args[ x ].equalsIgnoreCase("-o") ) + { + // Output sdf file + outputFileArg = getSimpleArg( args , x ); + } + else if( args[ x ].equalsIgnoreCase("-x") ) + { + // path prefix + pathPrefixArg = getSimpleArg( args , x ); + } + else if( args[ x ].equalsIgnoreCase("-y") ) + { + // path postfix + pathPostfixArg = getSimpleArg( args , x ); + } + else if( args[ x ].equalsIgnoreCase("-p") ) + { + // project + projectArg = getSimpleArg( args , x ); + } + else if( args[ x ].equalsIgnoreCase("-r") ) + { + // root + rootArg = getSimpleArg( args , x ); + rootArg = makeAbs( rootArg ); + } + else if( args[ x ].equalsIgnoreCase("-lf") ) + { + // forced langs + forcedLangsArg = getComplexArg( args , x ); + } + else if( args[ x ].equalsIgnoreCase("-l") ) + { + // langs + langsArg = getComplexArg( args , x ); + } + else if( args[ x ].equalsIgnoreCase("-m") ) + { + // input sdf file + inputSdfFileArg = getSimpleArg( args , x ); + } + else if( args[ x ].equalsIgnoreCase("-qq") ) + { + isQuiet = true; + } + } + } + private String makeAbs( String path ) + { + File file; + try + { + file = new File( path ); + return file.getCanonicalPath(); + }catch( IOException e ) + { + e.printStackTrace(); + System.exit( -1 ); + } + return null; + } +/* private boolean testArguments() + { + // nice merge + if( inputSdfFileArg != null && inputSdfFileArg.length()>0 ) + // nice merge + return projectArg != null && rootArg != null && inputFileArg != null && pathPrefixArg != null && pathPostfixArg != null && langsArg != null && + projectArg.length()>0 && rootArg.length()>0 && inputFileArg.length()>0 && pathPrefixArg.length()>0 && pathPostfixArg.length()>0 && langsArg.size()>0 ; + else + // nice extract + return projectArg != null && rootArg != null && inputFileArg != null && outputFileArg != null && langsArg != null && + projectArg.length()>0 && rootArg.length()>0 && inputFileArg.length()>0 && outputFileArg.length()>0 && langsArg.size()>0; + } +*/ +} diff --git a/l10ntools/java/jpropex/java/Main.java b/l10ntools/java/jpropex/java/Main.java new file mode 100644 index 000000000000..23dc477ddec3 --- /dev/null +++ b/l10ntools/java/jpropex/java/Main.java @@ -0,0 +1,38 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +class Main +{ + + public static void main( String args[] ) + { + JPropEx jpropex = new JPropEx( args ); + //jpropex.init(); + } +} + diff --git a/l10ntools/java/jpropex/java/NoLocalizeFilter.java b/l10ntools/java/jpropex/java/NoLocalizeFilter.java new file mode 100644 index 000000000000..3bfa53df2296 --- /dev/null +++ b/l10ntools/java/jpropex/java/NoLocalizeFilter.java @@ -0,0 +1,56 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +import java.io.*; +import java.util.regex.*; + +// exit if the sequence x-no-localize is found in stream! +public class NoLocalizeFilter extends FilterInputStream +{ + InputStream in; + Pattern p = Pattern.compile("#[\\s]*x-no-translate"); + + public NoLocalizeFilter( InputStream in ) { + super(in); + this.in = in; + } + public int read(byte[] b, int off, int len) throws IOException + { + String search = new String( b ); + Matcher m = p.matcher( search ); + if( m.find() ) + //if( search.contains("x-no-translate" ) ) // TODO: fixme! + { + System.out.println("found x-no-translate"); + in.close(); + close(); + System.exit( 0 ); + } + return in.read( b , off , len ); + } +} diff --git a/l10ntools/java/jpropex/java/OrderedHashMap.java b/l10ntools/java/jpropex/java/OrderedHashMap.java new file mode 100644 index 000000000000..a462d598b307 --- /dev/null +++ b/l10ntools/java/jpropex/java/OrderedHashMap.java @@ -0,0 +1,96 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +import java.util.*; + +// LinkedHashMap implrementation +public class OrderedHashMap +{ + private HashMap hm = new HashMap(); + private LinkedList list = new LinkedList(); + + public Iterator iterator() { return list.iterator(); } + + public boolean isEmpty() { return hm.isEmpty(); } + public Object get( Object key ) { return hm.get( key ); } + public Object get( int index ) { return hm.get( list.get( index ) ); } + public Iterator keys() { return list.iterator(); } + public Object add( Object key , Object value ) + { + list.add( key ); + return hm.put( key, value ); + } + public Object add( int index , Object key , Object value ) + { + list.add( index , key ); + return hm.put( key, value ); + } + public Object remove( Object key ) + { + list.remove( list.indexOf( key ) ); + return hm.remove( key ); + } + public void move( int idxFrom , int idxTo ) + { + Object key = list.get( idxFrom ); + list.remove( idxFrom ); + list.add( idxTo , key ); + } + public void move( Object key , int idxTo ) + { + move( list.indexOf( key ) , idxTo ); + } + public int size() + { + return hm.size(); + } + public Enumeration elements() + { + return new OHMenum( this ); + } +} + +final class OHMenum implements Enumeration +{ + OrderedHashMap ohm; + int index = 0; + + private OHMenum(){}; + public OHMenum( OrderedHashMap ohm ){ + this.ohm = ohm ; + } + + public boolean hasMoreElements() + { + return index < ohm.size(); + } + public Object nextElement() + { + return ohm.get( index++ ); + } +} diff --git a/l10ntools/java/jpropex/java/SdfData.java b/l10ntools/java/jpropex/java/SdfData.java new file mode 100644 index 000000000000..80b8ea890f26 --- /dev/null +++ b/l10ntools/java/jpropex/java/SdfData.java @@ -0,0 +1,109 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +import java.util.*; +import java.io.*; + +public class SdfData +{ + private String filename; + private OrderedHashMap ohm; + private LinkedHashSet languagesFound; + + public SdfData() + { + languagesFound = new LinkedHashSet(); + ohm = new OrderedHashMap(); + languagesFound = new LinkedHashSet(); + } + public SdfData( String filename ) + { + this(); + this.filename = filename; + } + + public LinkedHashSet getLanguages() + { + return languagesFound; + } + public SdfEntity get( SdfEntity obj ) + { + return (SdfEntity) ohm.get( (String)obj.getId() ); + } + public SdfEntity get( String key ){ + return (SdfEntity) ohm.get( key ); + } + public void add( SdfEntity obj ) + { + ohm.add( obj.getId() , obj ); + } + + public void read() + { + BufferedReader in; + try + { + in = new BufferedReader( new FileReader( filename ) ); + SdfEntity entity; + while( in.ready() ) + { + String line = in.readLine(); + if( line.length() > 0 ) + { + entity = new SdfEntity( line ); + ohm.add( entity.getId() , entity ); // test if is valid + languagesFound.add( entity.getLangid() ); + } + } + in.close(); + } + catch( IOException e ) + { + System.out.println("Error: reading file " + filename); + System.exit( -1 ); + } + } + public void write( String filename ) + { + FileWriter out; + try + { + out = new FileWriter( filename , true ); // Always append + for( Enumeration e = ohm.elements(); e.hasMoreElements(); ) + { + out.write( ( (SdfEntity) e.nextElement() ).toString() + "\n" ); + } + out.close(); + } + catch( IOException e ) + { + System.out.println("Error: Can't write to file " + filename); + System.exit( -1 ); + } + } +} diff --git a/l10ntools/java/jpropex/java/SdfEntity.java b/l10ntools/java/jpropex/java/SdfEntity.java new file mode 100644 index 000000000000..52dc61ca40ca --- /dev/null +++ b/l10ntools/java/jpropex/java/SdfEntity.java @@ -0,0 +1,254 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +public class SdfEntity implements Cloneable{ + private String project = new String(""); + private String source_file = new String(""); + private String dummy1 = new String(""); + private String resource_type= new String(""); + private String gid = new String(""); + private String lid = new String(""); + private String helpid = new String(""); + private String platform = new String(""); + private String dummy2 = new String(""); + private String langid = new String(""); + private String text = new String(""); + private String helptext = new String(""); + private String quickhelptext= new String(""); + private String title = new String(""); + private String date = new String(""); + + public static int PROJECT_POS = 0; + public static int SOURCE_FILE_POS = 1; + public static int DUMMY1_POS = 2; + public static int RESOURCE_TYPE_POS = 3; + public static int GID_POS = 4; + public static int LID_POS = 5; + public static int HELPID_POS = 6; + public static int PLATFORM_POS = 7; + public static int DUMMY2_POS = 8; + public static int LANGID_POS = 9; + public static int TEXT_POS = 10; + public static int HELPTEXT_POS = 11; + public static int QUICKHELPTEXT_POS = 12; + public static int TITLE_POS = 13; + public static int DATE_POS = 14; + + public Object clone() + { + try + { + return super.clone(); + } + catch( CloneNotSupportedException e ) + { + System.out.println("ERROR: Can not clone, something is broken here ...."); + System.exit( -1 ); + } + return null; // dummy + } + + public SdfEntity( String line ){ + // isValid? + setProperties( line ) ; + } + public SdfEntity(String project, String source_file, String dummy1, String resource_type, String gid, String lid, String helpid, String platform, String dummy2, String langid, String text, String helptext, String quickhelptext, String title , String date) { + super(); + this.project = project; + this.source_file = source_file; + this.dummy1 = dummy1; + this.resource_type = resource_type; + this.gid = gid; + this.lid = lid; + this.helpid = helpid; + this.platform = platform; + this.dummy2 = dummy2; + this.langid = langid; + this.text = text; + this.helptext = helptext; + this.quickhelptext = quickhelptext; + this.title = title; + this.date = date; + } + + public void setProperties( String line ){ + + String[] splitted = line.split("\t"); + + setProject( splitted[ SdfEntity.PROJECT_POS ] ); + setSource_file( splitted[ SdfEntity.SOURCE_FILE_POS ] ); + setDummy1( splitted[ SdfEntity.DUMMY1_POS ] ); + setResource_type( splitted[ SdfEntity.RESOURCE_TYPE_POS ] ); + setGid( splitted[ SdfEntity.GID_POS ] ); + setLid( splitted[ SdfEntity.LID_POS ] ); + setHelpid( splitted[ SdfEntity.HELPID_POS ] ); + setPlatform( splitted[ SdfEntity.PLATFORM_POS ] ); + setDummy2( splitted[ SdfEntity.DUMMY2_POS ] ); + setLangid( splitted[ SdfEntity.LANGID_POS ] ); + setText( splitted[ SdfEntity.TEXT_POS ] ); + setHelptext( splitted[ SdfEntity.HELPTEXT_POS ] ); + setQuickhelptext( splitted[ SdfEntity.QUICKHELPTEXT_POS ] ); + setTitle( splitted[ SdfEntity.TITLE_POS ] ); + setDate( splitted[ SdfEntity.DATE_POS ] ); + } + + public String getFileId(){ + return project+"\\"+source_file; + } + public String getResourcePath(){ + return source_file.substring(0 , source_file.lastIndexOf( "\\" )-1 ); + } + public String toString(){ + return new StringBuffer( project ).append( "\t" ).append( source_file ).append( "\t" ).append( dummy1 ).append( "\t" ).append( resource_type ).append( "\t" ).append( gid ).append( "\t" ) + .append( lid ).append( "\t" ).append( helpid ).append( "\t" ).append( platform ).append( "\t" ).append( dummy2 ).append( "\t" ).append( langid ).append( "\t" ) + .append( text ).append( "\t" ).append( helptext ).append( "\t" ).append( quickhelptext ).append( "\t" ).append( title ).append( "\t" ).append( date ).toString(); + } + public String getId(){ + return new StringBuffer( project ).append( gid ).append( lid ).append( source_file ).append( resource_type ).append( platform ).append( helpid ).append( langid ).toString(); + } + + public String getDummy1() { + return dummy1; + } + + public void setDummy1(String dummy1) { + this.dummy1 = dummy1; + } + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getDummy2() { + return dummy2; + } + + public void setDummy2(String dummy2) { + this.dummy2 = dummy2; + } + + public String getGid() { + return gid; + } + + public void setGid(String gid) { + this.gid = gid; + } + + public String getHelpid() { + return helpid; + } + + public void setHelpid(String helpid) { + this.helpid = helpid; + } + + public String getHelptext() { + return helptext; + } + + public void setHelptext(String helptext) { + this.helptext = helptext; + } + + public String getLangid() { + return langid; + } + + public void setLangid(String langid) { + this.langid = langid; + } + + public String getLid() { + return lid; + } + + public void setLid(String lid) { + this.lid = lid; + } + + public String getProject() { + return project; + } + + public void setProject(String project) { + this.project = project; + } + + public String getQuickhelptext() { + return quickhelptext; + } + + public void setQuickhelptext(String quickhelptext) { + this.quickhelptext = quickhelptext; + } + + public String getResource_type() { + return resource_type; + } + + public void setResource_type(String resource_type) { + this.resource_type = resource_type; + } + + public String getSource_file() { + return source_file; + } + + public void setSource_file(String source_file) { + this.source_file = source_file; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + public String getDate() { + return date; + } + public void setDate(String date) { + this.date = date; + } + + +} diff --git a/l10ntools/java/jpropex/jpropex b/l10ntools/java/jpropex/jpropex new file mode 100755 index 000000000000..2d62d13b093e --- /dev/null +++ b/l10ntools/java/jpropex/jpropex @@ -0,0 +1,10 @@ +#!/bin/sh +if [ x${SOLARENV}x = xx ]; then + echo No environment found, please use 'configure' or 'setsolar' + exit 1 +fi +if [ x${JAVA_HOME}x = xx ]; then + echo No Java found! + exit 1 +fi +exec java -DSOLARSRC=${SOLARSRC} -DWORK_STAMP=${WORK_STAMP} -DUSE_SHELL= -jar ${SOLARVER}/${INPATH}/bin${UPDMINOREXT}/jpropex.jar "$@" diff --git a/l10ntools/java/jpropex/jpropex.MF b/l10ntools/java/jpropex/jpropex.MF new file mode 100755 index 000000000000..3e22e7e9bfbf --- /dev/null +++ b/l10ntools/java/jpropex/jpropex.MF @@ -0,0 +1 @@ +Main-Class: Main diff --git a/l10ntools/java/jpropex/makefile.mk b/l10ntools/java/jpropex/makefile.mk new file mode 100755 index 000000000000..f86d2c830025 --- /dev/null +++ b/l10ntools/java/jpropex/makefile.mk @@ -0,0 +1,36 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + + +PRJ=../.. +PRJNAME=transex3 +TARGET=jpropex + +.INCLUDE : ant.mk + +ALLTAR : ANTBUILD + |