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 package transex3.model; 23 import java.util.*; 24 import java.io.*; 25 public class SdfString { 26 private SdfEntity sourceString = null; 27 //private java.util.HashMap languageStrings = new HashMap(); 28 private Vector languageList = new Vector(); 29 private String id = null; 30 private String fileid = null; 31 private String filename = null; 32 private String modulename = null; 33 private String filepath = null; 34 35 /*public HashMap getLanguageStrings() { 36 return languageStrings; 37 }*/ getLanguageStrings()38 public Vector getLanguageStrings() { 39 return languageList; 40 } 41 setLanguageStrings(Vector languageStrings)42 public void setLanguageStrings(Vector languageStrings) { 43 this.languageList = languageStrings; 44 } 45 addSourceString( SdfEntity aSdfEntity )46 public void addSourceString( SdfEntity aSdfEntity ) 47 { 48 if( id == null ) 49 id = aSdfEntity.getId(); 50 if ( fileid == null ) 51 fileid = aSdfEntity.getFileId(); 52 if( modulename == null ) 53 modulename = aSdfEntity.getProject(); 54 if( filename == null ) 55 filename = aSdfEntity.getSource_file(); 56 if( filepath == null ) 57 filepath = aSdfEntity.getResourcePath(); 58 setSourceString( aSdfEntity ); 59 } addLanguageString( SdfEntity aSdfEntity )60 public void addLanguageString( SdfEntity aSdfEntity ){ 61 if( !aSdfEntity.getLangid().equals( "en-US" ) ) 62 { 63 if( id == null ) 64 id = aSdfEntity.getId(); 65 if ( fileid == null ) 66 fileid = aSdfEntity.getFileId(); 67 if( modulename == null ) 68 modulename = aSdfEntity.getProject(); 69 if( filename == null ) 70 filename = aSdfEntity.getSource_file(); 71 if( filepath == null ) 72 filepath = aSdfEntity.getResourcePath(); 73 74 //if( aSdfEntity.getLangid().equals( "en-US" ) ) 75 //{ 76 // setSourceString( aSdfEntity ); 77 //} 78 //else 79 //{ 80 //languageStrings.put( aSdfEntity.getLangid() , aSdfEntity ); 81 languageList.add( aSdfEntity ); 82 //} 83 id = aSdfEntity.getId(); 84 } 85 } 86 getSourceString()87 public SdfEntity getSourceString() { 88 return sourceString; 89 } 90 setSourceString(SdfEntity sourceString)91 public void setSourceString(SdfEntity sourceString) { 92 this.sourceString = sourceString; 93 id = sourceString.getId(); 94 } getFilePath()95 public String getFilePath(){ 96 return filepath; 97 } getId()98 public String getId(){ 99 //return id; 100 return sourceString.getId(); 101 } getFileId()102 public String getFileId(){ 103 return fileid; 104 } 105 getFileName()106 public String getFileName() { 107 return filename; 108 } 109 setFileName(String filename)110 public void setFileName(String filename) { 111 this.filename = filename; 112 } 113 getModuleName()114 public String getModuleName() { 115 return modulename; 116 } 117 setModuleName(String modulename)118 public void setModuleName(String modulename) { 119 this.modulename = modulename; 120 } 121 getRealFileName()122 public String getRealFileName(){ 123 String filepart = sourceString.getFileId(); 124 filepart = filepart.replaceAll( "\\\\" , "_" ); 125 String filename = "/so/ws/merge/In/" + java.lang.System.getProperty( "WORK_STAMP" ) + "/" + filepart + ".sdf"; 126 return filename; 127 } removeFile()128 public void removeFile(){ 129 String filename = getRealFileName(); 130 File aFile = new File( filename ); 131 if( aFile.exists() ){ 132 if( ! aFile.delete() ) 133 { 134 System.out.println("Can't delete File "+filename+"\nWrong access rights?\n"); 135 } 136 } 137 } writeString()138 public void writeString(){ 139 String filename = getRealFileName(); 140 try { 141 if( languageList.size() > 0 ) 142 { 143 System.out.print("\nWrite to "+filename ); 144 BufferedWriter aBW = new BufferedWriter( new FileWriter( filename , true) ); 145 aBW.write( sourceString + "\n" ); 146 Iterator aIter = languageList.iterator(); 147 while( aIter.hasNext() ){ 148 SdfEntity aEntity = (SdfEntity)aIter.next(); 149 aBW.write( sourceString.getProject()+"\t" ); 150 aBW.write( sourceString.getSource_file()+"\t" ); 151 aBW.write( sourceString.getDummy1()+"\t" ); 152 aBW.write( sourceString.getResource_type()+"\t" ); 153 aBW.write( sourceString.getGid()+"\t" ); 154 aBW.write( sourceString.getLid()+"\t" ); 155 aBW.write( sourceString.getHelpid()+"\t" ); 156 aBW.write( sourceString.getPlatform()+"\t" ); 157 aBW.write( sourceString.getDummy2()+"\t" ); 158 if( aEntity.getLangid() == null ) 159 aBW.write( "\t" ); 160 else 161 aBW.write( aEntity.getLangid()+"\t" ); 162 if( aEntity.getText() == null ) 163 aBW.write( "\t" ); 164 else 165 aBW.write( aEntity.getText()+"\t" ); 166 if( aEntity.getHelptext() == null ) 167 aBW.write( "\t" ); 168 else 169 aBW.write( aEntity.getHelptext()+"\t" ); 170 if( aEntity.getQuickhelptext() == null ) 171 aBW.write( "\t" ); 172 else 173 aBW.write( aEntity.getQuickhelptext()+"\t" ); 174 if( aEntity.getTitle() == null ) 175 aBW.write( "\t" ); 176 else 177 aBW.write( aEntity.getTitle()+"\t" ); 178 aBW.write( "2002-02-02 02:02:02\n" ); 179 } 180 aBW.close(); 181 } 182 } catch (IOException e) { 183 // TODO Auto-generated catch block 184 //e.printStackTrace(); 185 System.out.println("\nERROR: Can't write to file '"+filename+"'\nPlease contact RE/Tooling!"); 186 } 187 } 188 } 189