Kaydet (Commit) 53bf1040 authored tarafından Andras Timar's avatar Andras Timar

remove unused l10ntools

üst 99dd0380
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* 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.
*
************************************************************************/
// global includes
#include <rtl/textcvt.h>
#include <tools/string.hxx>
//
// class UTF8Converter
//
class UTF8Converter
{
private:
static void Convert( ByteString &rBuffer, rtl_TextEncoding nSourceENC, rtl_TextEncoding nDestENC );
public:
static ByteString ConvertToUTF8( const ByteString &rASCII, rtl_TextEncoding nEncoding );
static ByteString ConvertFromUTF8( const ByteString &rUTF8, rtl_TextEncoding nEncoding );
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<?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>
This diff is collapsed.
/*************************************************************************
*
* 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();
}
}
/*************************************************************************
*
* 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() )
{
in.close();
close();
System.exit( 0 );
}
return in.read( b , off , len );
}
}
/*************************************************************************
*
* 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++ );
}
}
/*************************************************************************
*
* 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 InputStreamReader( new FileInputStream( filename ), "UTF-8" ) );
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("Warning: can not read file " + filename);
}
}
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 );
}
}
}
/*************************************************************************
*
* 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 ){
if( line != null )
{
String[] splitted = line.split("\t",15);
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;
}
}
#!/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 ERROR: No java found
exit 1
fi
exec java -DSOLARSRC=${SOLARSRC} -DWORK_STAMP=${WORK_STAMP} -DUSE_SHELL= -jar ${SOLARVER}/${INPATH}/bin/jpropex.jar "$@"
@echo off
if "x%SOLARENV%x" EQU "xx" (
echo No environment found, please use 'configure' or 'setsolar'
exit
)
if "x%JAVA_HOME%x" EQU "xx" (
echo echo ERROR: No java found
exit
)
java -DSOLARSRC=%SOLARSRC% -DWORK_STAMP=%WORK_STAMP% -DUSE_SHELL= -jar %SOLARVER%\%INPATH%\bin\jpropex.jar %*
#*************************************************************************
#
# 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
<?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="l10nconv" default="main" basedir=".">
<!-- ================================================================= -->
<!-- settings -->
<!-- ================================================================= -->
<!-- name of this sub target used in recursive builds -->
<property name="target" value="l10nconv"/>
<!-- name of jar file created, without .jar extension -->
<property name="jarname" value="converter"/>
<!-- 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/converter"/>
<property name="build.misc" value="${build.dir}/misc/converter"/>
<!-- 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,javadoc,zipdoc"/>
<!-- prepare output directories -->
<target name="prepare">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.dir}/doc"/>
<mkdir dir="${build.dir}/doc/javadoc"/>
<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>
<!-- check if javadoc is up to date -->
<target name="javadoc_check" depends="prepare" if="build.dir">
<uptodate property="javadocBuild.notRequired" value="true"
targetfile="${build.dir}/doc/converter_javadoc.zip">
<srcfiles dir="${java.dir}" includes="**/*.java"/>
</uptodate>
</target>
<!-- generate java documentation -->
<target name="javadoc" depends="prepare,javadoc_check,compile"
unless="javadocBuild.notRequired"
if="build.dir">
<javadoc destdir="${build.dir}/doc/javadoc"
verbose="false"
author="false"
nodeprecated="true"
nodeprecatedlist="true"
use="true"
Doctitle="${docname}"
windowtitle="${docname}"
classpathref="classpath">
<packageset dir="${java.dir}" defaultexcludes="yes">
<include name="com/**"/>
</packageset>
<link offline="true" href="http://java.sun.com/j2se/1.4.2/docs/api"
packagelistLoc="${common.doc}/jdk1.4.2"/>
<link offline="true"
href="http://java.sun.com/products/servlet/2.3/javadoc"
packagelistLoc="${common.doc}/servlet2.3"/>
<link offline="true"
href="http://logging.apache.org/log4j/docs/api"
packagelistLoc="${common.doc}/log4j-1.2.8"/>
<link offline="true"
href="http://java.sun.com/products/javabeans/glasgow/javadocs"
packagelistLoc="${common.doc}/jaf-1.0.2"/>
<link offline="true"
href="http://java.sun.com/products/javamail/javadocs"
packagelistLoc="${common.doc}/javamail-1.3.1"/>
<link offline="true"
href="http://ws.apache.org/soap/docs"
packagelistLoc="${common.doc}/soap-2.3.1"/>
<bottom>&lt;i&gt;Copyright &amp;#169; 2004 Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, CA 94303 USA&lt;/i&gt;</bottom>
<header>${docname}</header>
</javadoc>
</target>
<!-- zip documentation and store in build/misc -->
<target name="zipdoc" depends="javadoc" if="build.dir" unless="javadocBuild.notRequired">
<zip zipfile="${build.dir}/doc/converter_javadoc.zip"
basedir="${build.dir}/doc/javadoc"
update="true"/>
</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>
Main-Class: com.sun.star.tooling.converter.Convert
/*************************************************************************
*
* 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.
*
************************************************************************/
/*
* Created on 2005
* by Christian Schmidt
*/
package com.sun.star.tooling.DirtyTags;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class DirtyTagWrapCheck {
static String line="";
public static void main(String[] args) {
try {
File fi = new File("D:\\Testfiles\\KID_helpcontent.sdf");//Copy of
FileReader fr = new FileReader(fi);
BufferedReader br = new BufferedReader(fr);
int readCounter=0;
int missCounter=0;
int lineErrorCounter=0;
while((line=br.readLine())!=null){
readCounter++;
String [] split = line.split("\t");
if(split.length<15){
lineErrorCounter++;
continue;
}
String string = split[10];
String wrapped = DirtyTagWrapper.wrapString(string);
String unwrapped=DirtyTagWrapper.unwrapString(wrapped);
if(!string.equals(unwrapped)){
missCounter++;
System.out.println(""+readCounter+"\n"+string+"\n"+unwrapped+"\n"+wrapped+"\n");
}
}
System.out.println("Fertig "+readCounter+" "+missCounter+" "+lineErrorCounter);
} catch (FileNotFoundException e) {
//
e.printStackTrace();
} catch (IOException e) {
//
e.printStackTrace();
} catch (DirtyTagWrapper.TagWrapperException e) {
System.out.println(e.getMessage()+"\n"+line+"\n");
}
}
}
/*************************************************************************
*
* 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.
*
************************************************************************/
/*
* Created on 2005
* by Christian Schmidt
*/
package com.sun.star.tooling.DirtyTags;
import java.io.IOException;
import java.util.ArrayList;
/**
* Solves the problem with translating strings from the
* Star-Office Help. This Strings contain XML snippets
* (that means parts of an xml dokument). I call them 'dirty'
* because the start of a tag (<) and the and of an tag (>)
* are quoted by a single backslash(\<.....\>). This is done
* because the text out of th tags should not contain '<' and '>'
* as Entity references (&lt; or &gt;) but as readable signs.
* This is for translation purposes.
* Because translators get mad while find out the really translatable
* parts between all the markup information, the XLIFF Specification
* allows to wrap parts of a String that should not be translated by
* special tags (<ept>, <bpt>).
* This Class has two static methods that do the wrapping and unwrapping
* NOTE: this won't work with not 'dirty' Strings.
*
* @author Christian Schmidt 2005
*
*/
public class DirtyTagWrapper {
private static boolean doWrap=true;
public static void setWrapping(boolean doWrap){
DirtyTagWrapper.doWrap=doWrap;
}
/**
* Unwraps the 'dirty' parts of a String from ept and bpt tags
*
* @param checkString The String to unwrap
* @return the unwrapped String
*/
public static String unwrapString(String checkString){
//remove the ept and bpt tags
String[] splitted =checkString.split("(<ept ([^<>])*>)|(</ept>)|(<bpt ([^<>])*>)|(</bpt>)|(<sub([^<>])*>)|(</sub>)|(<ex ([^<>])*/>)");
StringBuffer workBuffer= new StringBuffer();
for(int i=0;i<splitted.length;i++){
workBuffer.append(splitted[i]);
}
String string = new String(workBuffer);
//replace Entity references
string=string.replaceAll( "&amp;","&").replaceAll( "&lt;","<").replaceAll( "&gt;",">").replaceAll( "&quot;","\"").replaceAll( "&apos;","'");
//remove the nsub tags
splitted =string.split("(<sub([^<>])*>)|(</sub>)");
StringBuffer returnBuffer= new StringBuffer();
for(int i=0;i<splitted.length;i++){
returnBuffer.append(splitted[i]);
}
String returnString = new String(returnBuffer);
return returnString;
}
/**
* Wrap the dirty parts of a string
*
* @param checkString The String to check if there are dirty Parts to wrap
* @return A String with wrapped dirty parts
* @throws TagWrapperException
* @throws IOException
*/
public static String wrapString(String checkString) throws TagWrapperException, IOException {
// if no wrapping should be done return the given string
if(!doWrap) return checkString;
// let's wrap
String[] parts=null;
int idx=0;
//split the string at tag ends
String[] parts2 = checkString.split("\\\\>");
ArrayList tagString =new ArrayList();
// put the while splitting lost parts to the end of the single strings
for(int j=0;j<parts2.length-1;j++){
parts2[j]+="\\>";
}
// same for the last string
if (checkString.endsWith("\\>")){
parts2[parts2.length-1]+="\\>";
}
// split the leading text from the real tag string (<...>)
for(int j=0;j<parts2.length;j++){
//is it just a tag
if(parts2[j].startsWith("\\<")){
tagString.add(parts2[j]);
// or is it a tag with leading text?
}else if((idx=parts2[j].indexOf("\\<"))>0&&parts2[j].indexOf("\\>")>0){
//...then split it in two parts
// the leading text
tagString.add(parts2[j].substring(0,(parts2[j].indexOf("\\<"))));
// ...and the tag
tagString.add(parts2[j].substring(parts2[j].indexOf("\\<")));
}else{
//no tag...must be text only
tagString.add(parts2[j]);
}
}
ArrayList tagNames=new ArrayList();
String item="";
for(int i=0;i<tagString.size();i++){
item=((String)tagString.get(i));
int start=item.indexOf("\\<")+2;
// check if we have an index that is ok
if(start==1) start=-1;
int end=item.lastIndexOf("\\>");
if(start>=0&&end>0){
boolean isStandalone=false;
if(item.endsWith("/\\>")){
// this is a standalone tag
isStandalone=true;
}
item=item.substring(start,end);
if(item.indexOf(" ")>0){
item=item.substring(0,item.indexOf(" "));
}
if(isStandalone){
item=item+"/";
}
tagNames.add(item);
}else{
tagNames.add("");
}
}
ArrayList tagType=new ArrayList();
for(int i=0;i<tagNames.size();i++){
if(((String)tagNames.get(i)).equals("")){
tagType.add("Text");
}else if(((String)tagNames.get(i)).startsWith("/")){
tagType.add("EndTag");
}else if(((String)tagNames.get(i)).endsWith("/")){
tagType.add("StartAndEndTag");
}else {
tagType.add("StartTag");
}
}
ArrayList tagList=new ArrayList();
for(int i=0;i<tagNames.size();i++){
tagList.add(new Tag(
(String)tagType.get(i),
(String)tagNames.get(i),
(String)tagString.get(i)));
}
tagType=null;
tagNames=null;
tagString=null;
TagPair start;
StringBuffer returnBuffer=new StringBuffer();
while(tagList.size()>0){
try{
start=new TagPair(tagList);
returnBuffer.append(start.getWrapped());
}catch(TagPair.TagPairConstructionException e){
throw (new DirtyTagWrapper()).new TagWrapperException(e);
}
}
TagPair.resetCounter();
return new String(returnBuffer);
}
/**
* @author Christian Schmidt 2005
*
*/
public class TagWrapperException extends Exception {
/**
* Create a new Instance of TagWrapperException
*
*
*/
public TagWrapperException() {
super();
//
}
/**
* Create a new Instance of TagWrapperException
*
* @param arg0
*/
public TagWrapperException(String arg0) {
super(arg0);
//
}
/**
* Create a new Instance of TagWrapperException
*
* @param arg0
* @param arg1
*/
public TagWrapperException(String arg0, Throwable arg1) {
super(arg0, arg1);
//
}
/**
* Create a new Instance of TagWrapperException
*
* @param arg0
*/
public TagWrapperException(Throwable arg0) {
super(arg0);
//
}
}
}
/*************************************************************************
*
* 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.
*
************************************************************************/
/*
* Created on 2005
* by Christian Schmidt
*/
package com.sun.star.tooling.DirtyTags;
import java.io.IOException;
import java.util.Map;
import com.sun.star.tooling.converter.ExtMap;
/**
* @author Christian Schmidt 2005
*
*/
public class Tag {
private static int indent=0;
Map tagNames;
private String tagType;
private String tagName;
private String tagString;
public static Tag EMPTYTAG=new Tag("","","");
/**
* Create a new Instance of Tag
*
* @param tagType
* @param tagName
* @param tagString
*/
public Tag(String tagType, String tagName, String tagString) {
this.tagType=tagType;
this.tagName=tagName;
this.tagString=tagString;
tagNames=new ExtMap();
tagNames.put("link","name");
tagNames.put("caption","xml-lang");
tagNames.put("alt","xml-lang");
}
public String getWrappedTagString() throws IOException{
if(this.canHaveTranslateableContent()){
return this.wrapTagStringIntern();
}else{
return xmlString(this.tagString);
}
}
private final String xmlString( final String string) throws java.io.IOException {
if (string == null)
return string; // ""
String str = string;
for(int i=0;i<str.length();i++){
if(str.charAt(i)=='&'){
str=str.substring(0, i)+"&amp;"+str.substring(i+1);
continue;
}
if(str.charAt(i)=='<'){
str=str.substring(0, i)+"&lt;"+str.substring(i+1);
continue;
}
if(str.charAt(i)=='>'){
str=str.substring(0, i)+"&gt;"+str.substring(i+1);
continue;
}
if(str.charAt(i)=='"'){
str=str.substring(0, i)+"&quot;"+str.substring(i+1);
continue;
}
if(str.charAt(i)=='\''){
str=str.substring(0, i)+"&apos;"+str.substring(i+1);
continue;
}
}
return str;
}
/**
* @return
*/
private boolean canHaveTranslateableContent() {
return (tagNames.containsKey(this.tagName));
}
/**
* @throws IOException
*
*/
private String wrapTagStringIntern() throws IOException {
String[] split=this.tagString.split("=");
int length=split.length;
// no attribute found;
if (length==0) return xmlString(tagString);
else{
int i=0;
while(i<length-1/*the last part can only contain an attribute value*/){
String attributeName = split[i].trim();
if(split[i]. indexOf("</sub>")<0) split[i]=xmlString(split[i]);
i++;
String value;
attributeName=(attributeName.substring(attributeName.lastIndexOf(" ")).trim());
if((value=translateableAttributeValue(this.tagName)).equals(attributeName)){
int valueStart=0;
int valueEnd=0;
// get the value to the found attribute name
// it must either be surrounded by '"'...
if((valueStart=split[i].indexOf('"'))>=0){
valueEnd = split[i].lastIndexOf('"');
//...or surrounded by "'"
}else if((valueStart=split[i].indexOf("'"))>=0){
valueEnd = split[i].lastIndexOf("'");
}else{
// there seems to be an error,
// we found an '=' (we split there) but no '"' or '''
// but although we don't check the syntax
// we just continue
continue;
}
//ok we found the border of a value that might be translated
//now we wrap it with the tags
split[i]=xmlString(split[i].substring(0,valueStart+1))+"<sub>"+xmlString(split[i].substring(valueStart+1,valueEnd))+"</sub>"+xmlString(split[i].substring(valueEnd));
}
}
String wrappedString="";
// we have the wrapped parts, now we put them together
int j=0;
for(j=0;j<split.length-1;j++){
wrappedString+=(split[j]+"=");
}
wrappedString+=split[j];
// System.out.println(this.tagString);
// System.out.println(wrappedString);
return wrappedString;
}
}
/**
* @param tagName the name of the tag to check
* @return the name of the attribute that can contain translateable value
*/
private String translateableAttributeValue(String tagName) {
return (String)this.tagNames.get(tagName);
}
/**
* Create a new Instance of Tag
*
*
*/
public Tag(String tagString) {
this(extractTagType(extractTagName(tagString)),extractTagName(tagString),tagString);
}
private static String extractTagName(String tagString){
int start=tagString.indexOf('<')+1;
int end=tagString.lastIndexOf('\\');
if(start>=0&&end>0){
tagString=tagString.substring(start,end);
if(tagString.indexOf(" ")>0){
tagString=tagString.substring(0,tagString.indexOf(" "));
}
return tagString;
}else{
return "";
}
}
private static String extractTagType(String tagName){
if(tagName.equals("")){
return "Text";
}else if(tagName.startsWith("/")){
return "EndTag";
}else if(tagName.endsWith("/")){
return "StartAndEndTag";
}else {
return "StartTag";
}
}
/**
* @return Returns the tagName.
*/
public String getTagName() {
return this.tagName;
}
/**
* @return Returns the tagString.
*/
public String getTagString() {
return this.tagString;
}
/**
* @return Returns the tagType.
*/
public String getTagType() {
return this.tagType;
}
}
/*************************************************************************
*
* 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.
*
************************************************************************/
/*
* a simple exception
* just to seperate
* it from other
* exceptions
*/
package com.sun.star.tooling.converter;
/**
* @author Christian Schmidt
*
* Thrown if an error occurs during converting from one file format to another
* that does not belong to an other exception
*/
public class ConverterException extends Exception {
/**
*
*/
public ConverterException() {
super();
}
/**
* @param arg0
*/
public ConverterException(String arg0) {
super(arg0);
}
/**
* @param arg0
*/
public ConverterException(Throwable arg0) {
super(arg0);
}
/**
* @param arg0
* @param arg1
*/
public ConverterException(String arg0, Throwable arg1) {
super(arg0, arg1);
}
}
\ No newline at end of file
/*************************************************************************
*
* 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.
*
************************************************************************/
/*
* DataHandler.java
*
* take the data from the reader
* and put it to the Writer
*
*/
package com.sun.star.tooling.converter;
import java.util.*;
/**
* Handle the Data to get it from the Source
* readable to the Target
*
* @author Christian Schmidt
*/
public class DataHandler {
/**
* An arrays that holds the names that will be
* keys for the HashMap containing the data
*
*/
private final String[] dataNames = { "BlockNr", "Project",
"SourceFile", "Dummy", "ResType", "GID", "LID", "HID", "Platform",
"Width", "SourceLanguageID", "SourceText", "SourceHText",
"SourceQText", "SourceTitle", "TargetLanguageID", "TargetText",
"TargetHText", "TargetQText", "TargetTitle", "TimeStamp" };
private static final String EMPTY = new String("");
/**
* The HashMap containing the data
*/
private final Map data = new ExtMap(dataNames, null);
/** Creates a new instance of DataHandler */
public DataHandler() {
}
/**
* fill the data from the desired source
*
* @param source where to get the data from
* @return true if data is read and false if null is read
* @throws IOException
* @throws ConverterException
*/
public boolean fillDataFrom(DataReader source) throws java.io.IOException,
ConverterException {
Map line = null;
line = source.getData();
if (line == null){
return false;
}else{
this.data.putAll(line);
return true;
}
}
/**
* fill this data with the inData
*
* @param inData the data to handle by this handler
*/
public void fillDataWith(Map inData) {
data.putAll(inData);
}
// public void transfer(DataWriter target, DataReader source) {
//
// source.setHandler(this);
//
// }
/**
* The designated output is filled with the content of this handler
*
* @param output an array of Maps [0] should hold the source language data [1] the target language data
* @throws java.io.IOException
*/
public void putDataTo(Map[] output) throws java.io.IOException {
String aKey = EMPTY;
for (int j = 0; j < output.length; j++) {
Set keys = output[j].keySet();
Iterator iter = keys.iterator();
while (iter.hasNext()) {
aKey = (String) iter.next();
output[j].put(aKey, data.get(aKey));
}
}
}
/**
* The designated output is filled with the content of this handler
*
* @param output a Map that should hold the source language data and the target language data
* @throws java.io.IOException
*/
public void putDataTo(Map output) throws java.io.IOException {
String aKey = EMPTY;
Set keys = output.keySet();
Iterator iter = keys.iterator();
while (iter.hasNext()) {
aKey = (String) iter.next();
output.put(aKey, data.get(aKey));
}
}
}
\ No newline at end of file
/*************************************************************************
*
* 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.
*
************************************************************************/
package com.sun.star.tooling.converter;
import java.io.*;
import java.util.*;
/**
* Gets Line counting from LineNumberReader all Converter Reader classes inherit
* from this.
* The abstract parent class of all converter reader classes
*
* @author Christian Schmidt
*/
abstract public class DataReader extends LineNumberReader {
/**
* Creates a new instance of DataReader
*
* @param isr
* InputStreamReader used as Source for this class
*/
public DataReader(InputStreamReader isr) {
super(isr);
}
/**
* @throws java.io.IOException
* @throws ConverterException
*
* TODO this should no longer use an array as return type better a Map
*
*/
/**
* The next block of the SDF file is reviewed and the Line including the
* source language and the Line including the target Language are given back
* in an array
*
*
* @return A Map including the source language
* and the target Language content are given back
*
* @throws java.io.IOException
* @throws ConverterException
*/
public Map getData() throws java.io.IOException, ConverterException {
return null;
}
}
\ No newline at end of file
/*************************************************************************
*
* 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.
*
************************************************************************/
/*
* DataWriter.java
*
* parent of all XXXWriter classes used by
* Converter
*/
package com.sun.star.tooling.converter;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
/**
* The abstract parent class of all converter writer classes
*
* @author Christian Schmidt
*/
abstract public class DataWriter extends OutputStreamWriter {
protected final String seperator = new String("|");
/**
* the char sequence used as line seperator
*/
protected final String lineEnd = java.lang.System.getProperty(
"line.seperator", "\n");
/** Creates a new instance of DataWriter */
/**
* @param bos the buffered output stream holding the data
* @param encoding the encoding to use for read from bos
* @throws java.io.UnsupportedEncodingException
*/
public DataWriter(BufferedOutputStream bos, String encoding)
throws java.io.UnsupportedEncodingException {
super(bos, encoding);
}
// abstract protected void writeData(Map[] data) throws java.io.IOException;
/**
* get the data that should be written from the DataHandler
*
* @param handler the DataHandler having the data
* @throws java.io.IOException
*/
abstract protected void getDataFrom(DataHandler handler)
throws java.io.IOException;
/**
* write the Data
*
* @throws java.io.IOException
*/
abstract protected void writeData() throws java.io.IOException;
/**
* @param handler
* @throws IOException
*/
abstract protected void getDatafrom(DataHandler handler) throws IOException;
}
\ No newline at end of file
/*************************************************************************
*
* 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.
*
************************************************************************/
/*
* A special HashMap,
* can be constructed of
* two Arrays
*/
package com.sun.star.tooling.converter;
import java.util.HashMap;
import java.util.Map;
/**
* @author Christian Schmidt
*
* Create a Hash Map from two Arrays
*
*/
public class ExtMap extends HashMap {
/**
*
*/
public ExtMap() {
super();
}
/**
* @see java.util.HashMap
* @param arg0
*/
public ExtMap(int arg0) {
super(arg0);
}
/**
* @param arg0
* @param arg1
*/
public ExtMap(int arg0, float arg1) {
super(arg0, arg1);
}
/**
* @param arg0
*/
public ExtMap(Map arg0) {
super(arg0);
}
// create a new Map from two string arrays
public ExtMap(String[] names, String[] content) {
super(names.length);
if (content == null)
content = new String[names.length];
for (int i = 0; i < names.length; i++) {
if (i >= content.length) {
break;
} else {
this.put(names[i], content[i]);
}
}
}
}
\ No newline at end of file
/*************************************************************************
*
* 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.
*
************************************************************************/
/*
* creates new files
* checks if they exist or
* can be overwritten
*
*/
package com.sun.star.tooling.converter;
import java.io.File;
import java.io.IOException;
/**
* Creates new files only if the file does not yet exist
* or overwriting is allowed
*
* @author Christian Schmidt 2005
*
*/
public final class FileMaker {
/**
* Create a new file if overwriting is not alowed
* ask if existing files should be overwritten
*
* @param fileName the files name to overwrite
* @param overwrite indicates wether the file can be overwritten
* @return the File created from the fileName
* @throws IOException
*/
public final static File newFile(String fileName, boolean overwrite)
throws IOException {
File file = new File(fileName);
if (file.exists()) {
if (!overwrite) {
char c = 0;
System.out.print("Warning: File " + fileName
+ " already exist.\n" + "Overwrite (y/n) ? :");
byte[] waste = new byte[10];
System.in.read(waste);
c = (char) waste[0];
if (c == 'y') {
OutputHandler.out("...overwriting " + fileName);
} else {
OutputHandler.out(
"\nPlease set '-o' switch at command line to overwrite.\n\nProgramm Aborted.");
System.exit(-1);
}
} else {
OutputHandler.out("...overwriting " + fileName);
}
} else {
OutputHandler.out("...creating new target file " + fileName);
}
return file;
}
}
\ No newline at end of file
/*************************************************************************
*
* 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.
*
************************************************************************/
/*
* Created on 2005
* by Christian Schmidt
*/
package com.sun.star.tooling.converter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import com.sun.star.tooling.languageResolver.LanguageResolver;
import com.sun.star.tooling.languageResolver.LanguageResolver.LanguageResolvingException;
/**
* @author Christian Schmidt 2005
*
*/
public class GSIReader extends DataReader {
/**
* A Map holding an empty GSIBlock
*/
private Map EmptyGSIBlock;
/**
* @see LanguageResolver
*/
LanguageResolver languageResolver;
/**
* The source language identifier
*/
protected String sourceLanguage;
/**
* The target language identifier
*/
protected String targetLanguage;
/**
* The number of the last block
*/
private String oldBlockNr;
/**
* A buffer holding one GSILine
*/
private Map GSILineBuffer;
/**
* Indicates whether to use the buffered line
*/
private boolean useBuffer = false;
private static final String EMPTY = new String("");
/**
* An empty Map to fill with language depending data
*/
private ExtMap EmptyLanguageMap;
/**
* Indicates whether the first block is read
*/
private boolean isFirst = true;
private int lineCounter;
private int blockCounter;
/**
* Indicates whether the last line is read
*/
private boolean lastLineFound = false;
/**
* Create a new Instance of GSIReader
*
* @param source
* the file to read from
* @param sourceLanguage
* the sourceLanguage (must not be empty)
* @param targetLanguage
* the targetLanguage
* @param charset
* the charset used to read source
* @throws java.io.IOException
* @throws Exception
*/
public GSIReader(File source, String sourceLanguage, String targetLanguage,
String charset) throws java.io.IOException {
super(new InputStreamReader(new FileInputStream(source), charset));
this.languageResolver = new LanguageResolver();
this.sourceLanguage = sourceLanguage;
this.targetLanguage = targetLanguage;
EmptyLanguageMap = new ExtMap(new String[0], new String[0]);
}
/**
* Read the next GSIBlock and return the data
*
* @return A Map containing the data of the read GSIBlock the keys for the language depending data are the language id (numeric) the
* single language are acessible with the keys "BlockNr", "resType", "languageNr", "status","content".
*
* @throws IOException
*/
public Map getGSIData() throws IOException {
String help;
Map helpmap;
Map GSIBlock = new HashMap();
GSIBlock.put(sourceLanguage, EmptyLanguageMap.clone());
GSIBlock.put(targetLanguage, EmptyLanguageMap.clone());
String line = EMPTY;
String[] splitLine;
Map GSILine;
String[] GSINames = { "BlockNr", "resType", "languageNr", "status",
"content" };
while (useBuffer || (line = readLine()) != null) {
if (useBuffer) {
GSILine = GSILineBuffer;
GSIBlock.put(sourceLanguage, EmptyLanguageMap.clone());
GSIBlock.put(targetLanguage, EmptyLanguageMap.clone());
GSIBlock.put("BlockNr", GSILine.get("BlockNr"));
useBuffer = false;
} else {
this.lineCounter++;
if ((splitLine = split(line)) == null) {
continue;
}
GSILine = new ExtMap(GSINames, splitLine);
if (isFirst) {
GSIBlock.put("BlockNr", GSILine.get("BlockNr"));
oldBlockNr = (String) GSILine.get("BlockNr");
isFirst = false;
}
}
if (oldBlockNr == null) {
oldBlockNr = (String) GSILine.get("BlockNr");
}
if (!oldBlockNr.equals((String) GSILine.get("BlockNr"))) {
GSILineBuffer = GSILine;
oldBlockNr = (String) GSILine.get("BlockNr");
useBuffer = true;
break;
}
String lang;
try {
// Is there the source language in this line?
if ((lang = languageResolver.getISOfromNr((String) GSILine
.get("languageNr"))).equals(this.sourceLanguage)) {
// ok..store it as Source String under the depending
// ressource type
((Map) GSIBlock.get(sourceLanguage)).put("Source"
+ ResTypeResolver.getInternKey((String) GSILine
.get("resType")), GSILine.get("content"));
// ..maybe the target language?
} else {
if (targetLanguage.equals(EMPTY)) {
// if no target language is given at command line
targetLanguage = lang;
GSIBlock.put(targetLanguage, EmptyLanguageMap.clone());
}
if (lang.equals(this.targetLanguage)) {
// ok..store it as target String under the depending
// ressource type
((Map) GSIBlock.get(targetLanguage)).put("Target"
+ ResTypeResolver.getInternKey((String) GSILine
.get("resType")), GSILine
.get("content"));
}
}
} catch (LanguageResolvingException e) {
OutputHandler.out("Can not resolve the language "+e.getMessage());
}
}
if (line == null) {
if (lastLineFound){
OutputHandler.out("\n\n");
OutputHandler.out("GSI Blocks : " + this.blockCounter);
OutputHandler.out("GSI Lines : " + this.lineCounter);
return null;
}else{
lastLineFound = true;
this.blockCounter++;
return GSIBlock;
}
} else {
this.blockCounter++;
return GSIBlock;
}
}
/**
* Split a GSILine to single fields
*
* @param line
* The line to split
* @return An array containing the contents of the columns in the given line
*/
private String[] split(String line) {
String[] splitLine = (line.substring(0, line.length() - 1))
.split("\\(\\$\\$\\)");
if (splitLine.length != 5)
return null;
else
return splitLine;
}
}
/*************************************************************************
*
* 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.
*
************************************************************************/
package com.sun.star.tooling.converter;
import java.io.*;
import java.util.Map;
import com.sun.star.tooling.languageResolver.LanguageResolver;
import com.sun.star.tooling.languageResolver.LanguageResolver.LanguageResolvingException;
/**
*
* @author cs156069
*/
public class GSIWriter extends DataWriter {
/**
* The seperator used to seperate GSI columns
*/
final String seperator=new String("($$)");
/**
* Holding the keys used by a map holding the content of an GSI Line contianing the source language
*/
final static String[] sourceLineNames= {"Project","SourceFile","Dummy","ResType","GID","LID","HID","Platform","Width","SourceLanguageID","SourceText","SourceHText","SourceQText","SourceTitle","TimeStamp"};
/**
* Holding the keys used by a map holding the content of an GSI Line contianing the target language
*/
final static String[] targetLineNames= {"Project","SourceFile","Dummy","ResType","GID","LID","HID","Platform","Width","TargetLanguageID","TargetText","TargetHText","TargetQText","TargetTitle","TimeStamp"};
/**
* Holding the keys used by a map holding the content of an GSI Line contianing the source and the target language
*/
final static String[] outLineNames= {"BlockNr","Project","SourceFile","Dummy","ResType","GID","LID","HID","Platform","Width","SourceLanguageID","SourceText","SourceHText","SourceQText","SourceTitle","TargetLanguageID","TargetText","TargetHText","TargetQText","TargetTitle","TimeStamp"};
/**
* A map holding the content of an GSI Line contianing the source language
*/
private ExtMap sourceLine=new ExtMap(sourceLineNames,null);
/**
* A map holding the content of an GSI Line contianing the target language
*/
private ExtMap targetLine=new ExtMap(targetLineNames,null);
/**
* A map holding the content of an GSI Line contianing the source and the target language
*/
private ExtMap outData=new ExtMap(outLineNames, null);
private static final String EMPTY = new String("");
/**
* The sourceLanguage to use
*/
private String sourceLanguage;
/**
* The sourceLanguage to use
*/
private String targetLanguage;
/**
* GSILines have a special Line End
*/
private final static String lineEnd="!"+'\r'+'\n';
//private boolean SourceIsFirst=false;
/**
* The blockNr of the current line
*/
private String blockNr;
/**
* Create a new Instance of GSIWriter
*
* @param bos the Buffered Output Stream to write to
* @param charset the used charset
* @throws java.io.UnsupportedEncodingException
*/
public GSIWriter(BufferedOutputStream bos,String charset) throws java.io.UnsupportedEncodingException {
super(bos,charset);
}
/* (non-Javadoc)
* @see com.sun.star.tooling.converter.DataWriter#writeData()
*/
public final void writeData() throws java.io.IOException {
StringBuffer buffer=new StringBuffer("");
if(this.sourceLanguage==null&&this.targetLanguage==null){
LanguageResolver lang =new LanguageResolver();
try {
this.sourceLanguage=lang.getNrFromISO((String)outData.get("SourceLanguageID"));
this.targetLanguage=lang.getNrFromISO((String)outData.get("TargetLanguageID"));
} catch (LanguageResolvingException e) {
OutputHandler.out(e.getMessage());
System.exit(0);
}
}
this.blockNr=(String)outData.get("BlockNr");
// get the values of the found fields
//create the gsi lines
//
//at first the source language line
buffer.append(getSourceLine("Text"));
buffer.append(getSourceLine("HText"));
buffer.append(getSourceLine("QText"));
buffer.append(getSourceLine("Title"));
//now the target language line
// put them together for output
buffer.append(getTargetLine("Text"));
buffer.append(getTargetLine("HText"));
buffer.append(getTargetLine("QText"));
buffer.append(getTargetLine("Title"));
//ok...put all to disk;
this.write(buffer.toString());
}
/**
* Create a line containing the source string from the data
* @param resType
* @return The StringBuffer containing the line
*/
private StringBuffer getSourceLine(String resType){
StringBuffer buffer =new StringBuffer(200);
String resString = "Source"+resType;
String help;
if(EMPTY.equals((String)outData.get(resString))||" ".equals(outData.get(resString))) return new StringBuffer(EMPTY);
else {
// put them together for output
buffer.append(this.blockNr);
// seperate the fields with ($$)
buffer.append(this.seperator);
buffer.append(ResTypeResolver.getExternKey(resType));
// seperate the fields with ($$)
buffer.append(this.seperator);
buffer.append(this.sourceLanguage);
// seperate the fields with ($$)
buffer.append(this.seperator);
buffer.append("int");
// seperate the fields with ($$)
buffer.append(this.seperator);
buffer.append(outData.get(resString));
// this line is full
// so close it with '! cr lf'
buffer.append(GSIWriter.lineEnd);
Converter.countLine();
return buffer;
}
}
/**
* Create a line containing the target string from the data
* @param resType
* @return The StringBuffer containing the line
*/
private StringBuffer getTargetLine(String resType){
StringBuffer buffer =new StringBuffer(200);
String resString = "Target"+resType;
if(EMPTY.equals((String)outData.get(resString))||" ".equals(outData.get(resString))) return new StringBuffer(EMPTY);
else {
// put them together for output
buffer.append(this.blockNr);
// seperate the fields with ($$)
buffer.append(this.seperator);
buffer.append(ResTypeResolver.getExternKey(resType));
// seperate the fields with ($$)
buffer.append(this.seperator);
buffer.append(this.targetLanguage);
// seperate the fields with ($$)
buffer.append(this.seperator);
buffer.append("ext");
// seperate the fields with ($$)
buffer.append(this.seperator);
buffer.append(outData.get(resString));
// this line is full
// so close it with '! cr lf'
buffer.append(GSIWriter.lineEnd);
Converter.countLine();
return buffer;
}
}
/* (non-Javadoc)
* @see com.sun.star.tooling.converter.DataWriter#writeData(java.util.Map[])
*/
protected void writeData(Map[] data) throws IOException {
// TODO redesign DataHandler in the way that this is not nessesary any more
}
/* (non-Javadoc)
* @see com.sun.star.tooling.converter.DataWriter#getDataFrom(com.sun.star.tooling.converter.DataHandler)
*/
protected void getDataFrom(DataHandler handler) throws IOException {
handler.putDataTo(this.outData);
}
/* (non-Javadoc)
* @see com.sun.star.tooling.converter.DataWriter#getDatafrom(com.sun.star.tooling.converter.DataHandler)
*/
protected void getDatafrom(DataHandler handler) throws IOException {
handler.putDataTo(this.outData);
}
}
/*************************************************************************
*
* 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.
*
************************************************************************/
/*
* Created on 2005
* by Christian Schmidt
*/
package com.sun.star.tooling.converter;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* Merge GSIFiles back to to the original (!) SDFFile
*
*
* @author Christian Schmidt 2005
*
*/
public class GSIandSDFMerger extends SDFReader {
int lineCounter=0;
GSIReader gsiReader;
private Map temp=new HashMap();
private int j;
private boolean skip=true;
Map gsiBlock=null;
Map sdfBlock=null;
private boolean dontLoadGSI=false;
private int count;
/**
* Merge the GSIFile back to the original(!) SDFFile
*
* @param source the file to read from
* @param sourceLanguage the source language in the source file
* @param targetLanguage the target language in the source file
* @param charset the charset of the files
* @throws java.io.IOException
* @throws Exception
*/
public GSIandSDFMerger(File source, File secondSource,String sourceLanguage,
String targetLanguage, String charset) throws IOException {
// merging GSI and SDF requieres two Sources
//this. is the SDF source
super(secondSource, sourceLanguage, targetLanguage, charset);
//create the GSI Source
gsiReader=new GSIReader(source,sourceLanguage,targetLanguage,charset);
}
/* (non-Javadoc)
* @see com.sun.star.tooling.converter.DataReader#getData()
*/
public Map getData()throws java.io.IOException{
do{
skip=false;
this.temp=matchGSI();
}while(skip);
if(temp==null){
OutputHandler.out("Blocks merged : "+this.lineCounter);
}
return temp;
}
/**
* Read each block of the GSIFile and check whether there is a matching
* block in the SDFFile. Match depends on the BlockNr and BlockId.
*
* @return A Map that contains the source language content
* and the target language content.
* @throws IOException
* @throws ConverterException
*/
public Map matchGSI() throws IOException{
try {
//System.out.println("Start...");
if (dontLoadGSI||(gsiBlock=gsiReader.getGSIData())!=null){
dontLoadGSI=false;
//check if we must update this block
//if so its BlockNr is in the gsi file
if((sdfBlock = super.getData())!=null){
if(((String)sdfBlock.get("BlockNr")).equals((String)gsiBlock.get("BlockNr"))){
gsiBlock.remove(EMPTY);
//if the target language string is empty this may be caused by an error in the source sdf File
//I don't want to overwrite a possibly correct translation with an empty string
// so remove the target part from the gsiBlock
Map mp=(Map)gsiBlock.get(gsiReader.targetLanguage);
if (mp.size()!=0&&!((String)mp.get("TargetText")).equals("")){
// target language part in this gsiBlock
// if(((String)mp.get("TargetText")).equals("")){
// gsiBlock.remove(targetLanguage);
// }
// count the merged blocks
lineCounter++;
Map helpMap = (Map)gsiBlock.get(super.targetLanguage);//"ja"
sdfBlock.putAll(helpMap);
skip=false;
}else{
//no target language part in this gsiBlock
skip=true;
//
// return null;
}
}else{
// skip=true;
//
// // we cant match this gsi block to the current sdf block
// try matching the next sdf block with this gsi line
dontLoadGSI=true;
}
}
return sdfBlock;
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
/*************************************************************************
*
* 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.
*
************************************************************************/
/*
* Exception for errors in
* SDFLines
*/
package com.sun.star.tooling.converter;
/**
* This Exeption is thrown if a DataReader finds an error in a read Line
* f. e. wrong column number
*
* @author Christian Schmidt 2005
*
*/
public class LineErrorException extends Exception {
public int tokenCount;
/**
*
*/
public LineErrorException() {
super();
}
/**
* @param arg0
*/
public LineErrorException(String arg0) {
super(arg0);
}
/**
* @param arg0
*/
public LineErrorException(Throwable arg0) {
super(arg0);
}
/**
* @param arg0
* @param arg1
*/
public LineErrorException(String arg0, Throwable arg1) {
super(arg0, arg1);
}
}
\ No newline at end of file
/*************************************************************************
*
* 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.
*
************************************************************************/
/*
* Created on 2005
* by Christian Schmidt
*/
package com.sun.star.tooling.converter;
import java.util.Map;
/**
* Helps resolving restype descriptors used outside the tool to
* restype descriptors used by this tool
*
* @author Christian Schmidt 2005
*
*/
public class ResTypeResolver {
final static String[] inFields={"Text","QText","HText","Title"};
final static String[] outFields={"res","res-quickhelp","res-help","res-title"};
final static Map internKeys=new ExtMap(inFields,outFields);
final static Map externKeys=new ExtMap(outFields,inFields);
/**
* Get the intern key depending to the given extern key
*
* @param externKey the externKey {"res","res-quickhelp","res-help","title"}
* @return the depending intern key
*/
public static String getInternKey(String externKey){
return (String)externKeys.get(externKey);
}
/**
* Get the extern key to the given intern key
*
* @param internKey the internal key
* @return the external key
*/
public static String getExternKey(String internKey){
return (String)internKeys.get(internKey);
}
}
/*************************************************************************
*
* 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.
*
************************************************************************/
/*
* Created on 27.01.2005
*
*/
package com.sun.star.tooling.converter;
import java.io.IOException;
import java.io.InputStream;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* Resolve external entities by provide the
* XLIFF DTD stored in the jar file
*/
public class Resolver implements EntityResolver {
/**
* Resolver constructor.
*/
public Resolver() {
}
/**
* Allow the application to resolve external entities.
*
* The Parser will call this method before opening any external entity
* except the top-level document entity (including the external DTD subset,
* external entities referenced within the DTD, and external entities
* referenced within the document element): the application may request that
* the parser resolve the entity itself, that it use an alternative URI, or
* that it use an entirely different input source.
*/
/* (non-Javadoc)
* @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
*/
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
if ((publicId != null) && (publicId.equals("-//XLIFF//DTD XLIFF//EN"))) {
systemId = "dtd:///xliff.dtd";
}
if (systemId != null) {
if (systemId.startsWith("dtd://")) {
String dtd = "com/sun/star/tooling/converter/dtd"
+ systemId.substring(6);
ClassLoader cl = this.getClass().getClassLoader();
InputStream in = cl.getResourceAsStream(dtd);
InputSource ins = new InputSource(in);
ins.setSystemId(systemId);
return ins;
} /*
* else if ( systemId.startsWith("jar:") ) { try { URL url=new
* URL(systemId); JarURLConnection jarConn =
* (JarURLConnection)url.openConnection(); InputSource ins=new
* InputSource(jarConn.getInputStream());
* ins.setSystemId(systemId); return ins; }
* catch(MalformedURLException me){ throw new SAXException(me);
* Incorrect URL format used } }
*/
}
return null;
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -36,7 +36,6 @@
#include "export.hxx"
#include "cfgmerge.hxx"
#include "tokens.h"
#include "utf8conv.hxx"
extern "C" { int yyerror( char * ); }
extern "C" { int YYWarning( char * ); }
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment