1*d127360fSAndrew Rist /**************************************************************
2*d127360fSAndrew Rist  *
3*d127360fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d127360fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d127360fSAndrew Rist  * distributed with this work for additional information
6*d127360fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d127360fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d127360fSAndrew Rist  * "License"); you may not use this file except in compliance
9*d127360fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d127360fSAndrew Rist  *
11*d127360fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d127360fSAndrew Rist  *
13*d127360fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d127360fSAndrew Rist  * software distributed under the License is distributed on an
15*d127360fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d127360fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d127360fSAndrew Rist  * specific language governing permissions and limitations
18*d127360fSAndrew Rist  * under the License.
19*d127360fSAndrew Rist  *
20*d127360fSAndrew Rist  *************************************************************/
21*d127360fSAndrew Rist 
22cdf0e10cSrcweir package transex3.model;
23cdf0e10cSrcweir import java.util.*;
24cdf0e10cSrcweir import java.io.*;
25cdf0e10cSrcweir public class SdfString {
26cdf0e10cSrcweir 	private SdfEntity sourceString					= null;
27cdf0e10cSrcweir 	//private java.util.HashMap languageStrings		= new HashMap();
28cdf0e10cSrcweir 	private Vector languageList						= new Vector();
29cdf0e10cSrcweir 	private String id								= null;
30cdf0e10cSrcweir 	private String fileid							= null;
31cdf0e10cSrcweir 	private String filename							= null;
32cdf0e10cSrcweir 	private String modulename						= null;
33cdf0e10cSrcweir 	private String filepath							= null;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 	/*public HashMap getLanguageStrings() {
36cdf0e10cSrcweir 		return languageStrings;
37cdf0e10cSrcweir 	}*/
getLanguageStrings()38cdf0e10cSrcweir 	public Vector getLanguageStrings() {
39cdf0e10cSrcweir 		return languageList;
40cdf0e10cSrcweir 	}
41cdf0e10cSrcweir 
setLanguageStrings(Vector languageStrings)42cdf0e10cSrcweir 	public void setLanguageStrings(Vector languageStrings) {
43cdf0e10cSrcweir 		this.languageList = languageStrings;
44cdf0e10cSrcweir 	}
45cdf0e10cSrcweir 
addSourceString( SdfEntity aSdfEntity )46cdf0e10cSrcweir 	public void addSourceString( SdfEntity aSdfEntity )
47cdf0e10cSrcweir     {
48cdf0e10cSrcweir         if( id == null )
49cdf0e10cSrcweir 		    id = aSdfEntity.getId();
50cdf0e10cSrcweir 		if ( fileid == null )
51cdf0e10cSrcweir 		    fileid = aSdfEntity.getFileId();
52cdf0e10cSrcweir 		if( modulename == null )
53cdf0e10cSrcweir 		    modulename = aSdfEntity.getProject();
54cdf0e10cSrcweir 		if( filename == null )
55cdf0e10cSrcweir 		    filename = aSdfEntity.getSource_file();
56cdf0e10cSrcweir 		if( filepath == null )
57cdf0e10cSrcweir 		    filepath = aSdfEntity.getResourcePath();
58cdf0e10cSrcweir         setSourceString( aSdfEntity );
59cdf0e10cSrcweir     }
addLanguageString( SdfEntity aSdfEntity )60cdf0e10cSrcweir     public void addLanguageString( SdfEntity aSdfEntity ){
61cdf0e10cSrcweir 		if( !aSdfEntity.getLangid().equals( "en-US" ) )
62cdf0e10cSrcweir         {
63cdf0e10cSrcweir             if( id == null )
64cdf0e10cSrcweir 			    id = aSdfEntity.getId();
65cdf0e10cSrcweir 		    if ( fileid == null )
66cdf0e10cSrcweir 			    fileid = aSdfEntity.getFileId();
67cdf0e10cSrcweir 		    if( modulename == null )
68cdf0e10cSrcweir 			    modulename = aSdfEntity.getProject();
69cdf0e10cSrcweir 		    if( filename == null )
70cdf0e10cSrcweir 			    filename = aSdfEntity.getSource_file();
71cdf0e10cSrcweir 		    if( filepath == null )
72cdf0e10cSrcweir 			    filepath = aSdfEntity.getResourcePath();
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 		    //if( aSdfEntity.getLangid().equals( "en-US" ) )
75cdf0e10cSrcweir 		    //{
76cdf0e10cSrcweir 			//    setSourceString( aSdfEntity );
77cdf0e10cSrcweir 		    //}
78cdf0e10cSrcweir 		    //else
79cdf0e10cSrcweir 		    //{
80cdf0e10cSrcweir 			//languageStrings.put( aSdfEntity.getLangid() , aSdfEntity );
81cdf0e10cSrcweir 			languageList.add( aSdfEntity );
82cdf0e10cSrcweir 		    //}
83cdf0e10cSrcweir 		id = aSdfEntity.getId();
84cdf0e10cSrcweir         }
85cdf0e10cSrcweir 	}
86cdf0e10cSrcweir 
getSourceString()87cdf0e10cSrcweir 	public SdfEntity getSourceString() {
88cdf0e10cSrcweir 		return sourceString;
89cdf0e10cSrcweir 	}
90cdf0e10cSrcweir 
setSourceString(SdfEntity sourceString)91cdf0e10cSrcweir 	public void setSourceString(SdfEntity sourceString) {
92cdf0e10cSrcweir 		this.sourceString = sourceString;
93cdf0e10cSrcweir 		id = sourceString.getId();
94cdf0e10cSrcweir 	}
getFilePath()95cdf0e10cSrcweir 	public String getFilePath(){
96cdf0e10cSrcweir 		return filepath;
97cdf0e10cSrcweir 	}
getId()98cdf0e10cSrcweir 	public String getId(){
99cdf0e10cSrcweir 		//return id;
100cdf0e10cSrcweir 		return sourceString.getId();
101cdf0e10cSrcweir 	}
getFileId()102cdf0e10cSrcweir 	public String getFileId(){
103cdf0e10cSrcweir 		return fileid;
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir 
getFileName()106cdf0e10cSrcweir 	public String getFileName() {
107cdf0e10cSrcweir 		return filename;
108cdf0e10cSrcweir 	}
109cdf0e10cSrcweir 
setFileName(String filename)110cdf0e10cSrcweir 	public void setFileName(String filename) {
111cdf0e10cSrcweir 		this.filename = filename;
112cdf0e10cSrcweir 	}
113cdf0e10cSrcweir 
getModuleName()114cdf0e10cSrcweir 	public String getModuleName() {
115cdf0e10cSrcweir 		return modulename;
116cdf0e10cSrcweir 	}
117cdf0e10cSrcweir 
setModuleName(String modulename)118cdf0e10cSrcweir 	public void setModuleName(String modulename) {
119cdf0e10cSrcweir 		this.modulename = modulename;
120cdf0e10cSrcweir 	}
121cdf0e10cSrcweir 
getRealFileName()122cdf0e10cSrcweir     public String getRealFileName(){
123cdf0e10cSrcweir         String filepart = sourceString.getFileId();
124cdf0e10cSrcweir 	    filepart = filepart.replaceAll( "\\\\" , "_" );
125cdf0e10cSrcweir         String filename = "/so/ws/merge/In/" +  java.lang.System.getProperty( "WORK_STAMP" ) + "/" + filepart + ".sdf";
126cdf0e10cSrcweir         return filename;
127cdf0e10cSrcweir     }
removeFile()128cdf0e10cSrcweir 	public void removeFile(){
129cdf0e10cSrcweir 		String filename = getRealFileName();
130cdf0e10cSrcweir 		File aFile = new File( filename );
131cdf0e10cSrcweir 		if( aFile.exists() ){
132cdf0e10cSrcweir 			if( ! aFile.delete() )
133cdf0e10cSrcweir 			{
134cdf0e10cSrcweir 				System.out.println("Can't delete File "+filename+"\nWrong access rights?\n");
135cdf0e10cSrcweir 			}
136cdf0e10cSrcweir 		}
137cdf0e10cSrcweir 	}
writeString()138cdf0e10cSrcweir 	public void writeString(){
139cdf0e10cSrcweir 		String filename = getRealFileName();
140cdf0e10cSrcweir 		try {
141cdf0e10cSrcweir 			if( languageList.size() > 0 )
142cdf0e10cSrcweir 			{
143cdf0e10cSrcweir 				System.out.print("\nWrite to "+filename );
144cdf0e10cSrcweir 				BufferedWriter aBW = new BufferedWriter( new FileWriter( filename , true) );
145cdf0e10cSrcweir 				aBW.write( sourceString + "\n" );
146cdf0e10cSrcweir                 Iterator aIter = languageList.iterator();
147cdf0e10cSrcweir 				while( aIter.hasNext() ){
148cdf0e10cSrcweir 					SdfEntity aEntity = (SdfEntity)aIter.next();
149cdf0e10cSrcweir 					aBW.write( sourceString.getProject()+"\t" 	);
150cdf0e10cSrcweir 					aBW.write( sourceString.getSource_file()+"\t"	);
151cdf0e10cSrcweir 					aBW.write( sourceString.getDummy1()+"\t"  	);
152cdf0e10cSrcweir 					aBW.write( sourceString.getResource_type()+"\t" );
153cdf0e10cSrcweir 					aBW.write( sourceString.getGid()+"\t"  		);
154cdf0e10cSrcweir 					aBW.write( sourceString.getLid()+"\t"  		);
155cdf0e10cSrcweir 					aBW.write( sourceString.getHelpid()+"\t"  	);
156cdf0e10cSrcweir 					aBW.write( sourceString.getPlatform()+"\t"  );
157cdf0e10cSrcweir 					aBW.write( sourceString.getDummy2()+"\t"  	);
158cdf0e10cSrcweir 					if( aEntity.getLangid() == null )
159cdf0e10cSrcweir 						aBW.write( "\t"  );
160cdf0e10cSrcweir 					else
161cdf0e10cSrcweir 						aBW.write( aEntity.getLangid()+"\t"    );
162cdf0e10cSrcweir 					if( aEntity.getText() == null )
163cdf0e10cSrcweir 						aBW.write( "\t"  );
164cdf0e10cSrcweir 					else
165cdf0e10cSrcweir 						aBW.write( aEntity.getText()+"\t"   		);
166cdf0e10cSrcweir 					if( aEntity.getHelptext() == null )
167cdf0e10cSrcweir 						aBW.write( "\t"  );
168cdf0e10cSrcweir 					else
169cdf0e10cSrcweir 						aBW.write( aEntity.getHelptext()+"\t"  		);
170cdf0e10cSrcweir 					if( aEntity.getQuickhelptext() == null )
171cdf0e10cSrcweir 						aBW.write( "\t"  );
172cdf0e10cSrcweir 					else
173cdf0e10cSrcweir 						aBW.write( aEntity.getQuickhelptext()+"\t" 	);
174cdf0e10cSrcweir 					if( aEntity.getTitle() == null )
175cdf0e10cSrcweir 						aBW.write( "\t"  );
176cdf0e10cSrcweir 					else
177cdf0e10cSrcweir 						aBW.write( aEntity.getTitle()+"\t"   		);
178cdf0e10cSrcweir 					aBW.write( "2002-02-02 02:02:02\n"   		);
179cdf0e10cSrcweir 				}
180cdf0e10cSrcweir 				aBW.close();
181cdf0e10cSrcweir 			}
182cdf0e10cSrcweir 		} catch (IOException e) {
183cdf0e10cSrcweir 				// TODO Auto-generated catch block
184cdf0e10cSrcweir 				//e.printStackTrace();
185cdf0e10cSrcweir                 System.out.println("\nERROR: Can't write to file '"+filename+"'\nPlease contact RE/Tooling!");
186cdf0e10cSrcweir 		}
187cdf0e10cSrcweir 	}
188cdf0e10cSrcweir }
189