1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 /* 24 * SDFWriter.java 25 * 26 * 27 */ 28 29 package com.sun.star.tooling.converter; 30 import java.io.*; 31 import java.util.Map; 32 33 /** 34 * Write data to a SDFFile 35 * 36 * @author Christian Schmidt 2005 37 * 38 */ 39 public class SDFWriter extends DataWriter { 40 /** 41 * the seperator the seperate columns 42 */ 43 final String seperator=new String("\t"); 44 /** 45 * an array of the SDF files column names if the source language is in 46 */ 47 final static String[] sourceLineNames= {"Project","SourceFile","Dummy","ResType","GID","LID","HID","Platform","Width","SourceLanguageID","SourceText","SourceHText","SourceQText","SourceTitle","TimeStamp"}; 48 /** 49 * an array of the SDF files column names if the target language is in 50 */ 51 final static String[] targetLineNames= {"Project","SourceFile","Dummy","ResType","GID","LID","HID","Platform","Width","TargetLanguageID","TargetText","TargetHText","TargetQText","TargetTitle","TimeStamp"}; 52 /** 53 * an array of the SDF files column names if the source and the target language is in 54 */ 55 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"}; 56 57 /** 58 * A Map holding the source language line content 59 */ 60 private ExtMap sourceLine=new ExtMap(sourceLineNames,null); 61 /** 62 * A Map holding the target language line content 63 */ 64 private ExtMap targetLine=new ExtMap(targetLineNames,null); 65 /** 66 * A Map holding the whole content for output 67 */ 68 private ExtMap outData=new ExtMap(outLineNames, null); 69 // private ExtMap SDFLine; 70 // private InputStreamReader isr; 71 /** 72 * The language to translate from 73 */ 74 private String sourceLanguage; 75 /** 76 * The language to translate to 77 */ 78 private String targetLanguage; 79 80 // private boolean SourceIsFirst=false; 81 82 83 84 85 /** 86 * Create a new Instance of SDFWriter 87 * 88 * @param bos BufferedWriter to write to 89 * @param charset the charset to use to write 90 * @throws java.io.UnsupportedEncodingException 91 */ SDFWriter(BufferedOutputStream bos,String charset)92 public SDFWriter(BufferedOutputStream bos,String charset) throws java.io.UnsupportedEncodingException { 93 super(bos,charset); 94 95 } 96 97 /* (non-Javadoc) 98 * @see com.sun.star.tooling.converter.DataWriter#writeData() 99 */ writeData()100 public final void writeData() throws java.io.IOException { 101 102 StringBuffer buffer=new StringBuffer(""); 103 104 // get the values of the found fields 105 //create the two sdf lines 106 107 //at first the source language line 108 for(int i=0;i<sourceLineNames.length;i++){ 109 // put them together for output 110 buffer.append(outData.get(sourceLineNames[i])); 111 if(i!=sourceLineNames.length-1) { 112 // seperate the fields with tab 113 buffer.append(seperator); 114 }else{ 115 // this line is full 116 // so close it with lf 117 buffer.append(lineEnd); 118 Converter.countLine(); 119 } 120 } 121 // is there a target line with anything in the strings? 122 if (!(outData.get("TargetLanguageID")==null||((outData.get("TargetTitle").equals("")&&outData.get("TargetText").equals("")&&outData.get("TargetHText").equals("")&&outData.get("TargetQText").equals(""))))){ 123 //now the target language line 124 for(int i=0;i<targetLineNames.length;i++){ 125 // put them together for output 126 buffer.append(outData.get(targetLineNames[i])); 127 if(i!=targetLineNames.length-1) { 128 // seperate the fields with tab 129 buffer.append(seperator); 130 }else{ 131 // this line is full 132 //so close it with lf 133 buffer.append(lineEnd); 134 Converter.countLine(); 135 } 136 } 137 } 138 this.write(buffer.toString()); 139 140 } 141 142 143 144 /* (non-Javadoc) 145 * @see com.sun.star.tooling.converter.DataWriter#writeData(java.util.Map[]) 146 */ writeData(Map[] data)147 protected void writeData(Map[] data) throws IOException { 148 // TODO redesign DataHandler in the way that this is not nessesary any more 149 150 } 151 152 /* (non-Javadoc) 153 * @see com.sun.star.tooling.converter.DataWriter#getDataFrom(com.sun.star.tooling.converter.DataHandler) 154 */ getDataFrom(DataHandler handler)155 protected void getDataFrom(DataHandler handler) throws IOException { 156 157 handler.putDataTo(this.outData); 158 } 159 160 /* (non-Javadoc) 161 * @see com.sun.star.tooling.converter.DataWriter#getDatafrom(com.sun.star.tooling.converter.DataHandler) 162 */ getDatafrom(DataHandler handler)163 protected void getDatafrom(DataHandler handler) throws IOException { 164 165 handler.putDataTo(this.outData); 166 167 } 168 } 169