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