Source code: com/flexstor/flexdbserver/services/asset/DefaultThumbnailService.java
1 /*
2 * DefaultThumbnailService.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:28 $ FLEXSTOR.net Inc.
5 *
6 * This work is licensed for use and distribution under license terms found at
7 * http://www.flexstor.org/license.html
8 *
9 */
10
11 package com.flexstor.flexdbserver.services.asset;
12
13 import java.util.Enumeration;
14 import java.util.Vector;
15
16 import com.flexstor.common.data.ActionData;
17 import com.flexstor.common.data.ActionResult;
18 import com.flexstor.common.data.ejb.disguiserecord.AssetRoleData;
19 import com.flexstor.common.data.ejb.disguiserecord.DisguiseAssetRecordData;
20 import com.flexstor.common.data.ejb.disguiserecord.DisguiseRecordData;
21 import com.flexstor.common.errorlogger.FlexError;
22 import com.flexstor.common.importprocessor.ImportCtlData;
23 import com.flexstor.common.importprocessor.ImportData;
24 import com.flexstor.common.importprocessor.ImportResult;
25 import com.flexstor.common.io.xfile.FlexXFile;
26 import com.flexstor.common.util.Diagnostic;
27 import com.flexstor.flexdbserver.importprocessor.ConversionOptions;
28 import com.flexstor.flexdbserver.services.Service;
29 import com.flexstor.flexdbserver.services.ServiceContext;
30
31 /**
32 *
33 * <P>
34 * DefaultThumbnailService <BR>
35 * <BLOCKQUOTE>
36 * Determines if the thumbnail file actually exists. If it doesn't, retrieves
37 * the icon specified in the thumbnail creation configuration (*.cfg) file for
38 * the thumbnail file type and updates the asset with the icon file location. <BR>
39 * </BLOCKQUOTE>
40 * </P>
41 *
42 *
43 * Configurable Properties in roletype_services.config <BR>
44 *
45 *
46 * <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="3">
47 * <CAPTION ALIGN=TOP>
48 * <B> In/Out Properties for Assets </B>
49 * </CAPTION>
50 * <TR>
51 * <FONT SIZE=+1><B>
52 * <TH WIDTH="120">Attribute</TH>
53 * <TH WIDTH="30">IN</TH> <TH WIDTH="30">OUT</TH> <TH WIDTH="30">Default IN</TH> <TH WIDTH="30">Default OUT</TH>
54 * </B></FONT>
55 * </TR>
56 * <TR>
57 * <TH ALIGN=LEFT><FONT SIZE=+1><B>ROLE</B></FONT></TH>
58 * </TR>
59 * <TR><TH> Highres </TH> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
60 * <TR><TH> Lowres </TH> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
61 * <TR><TH> Thumbnail </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
62 * <TR><TH> Layout </TH> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
63 * <TR><TH> Video </TH> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
64 * <TR><TH> Audio </TH> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
65 * <TR>
66 * <TH ALIGN=LEFT><FONT SIZE=+1><B>TYPE</B></FONT></TH>
67 * <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER> ALL </TD> <TD ALIGN=CENTER>   </TD></TR>
68 * </TR>
69 * <TR>
70 * <TH ALIGN=LEFT><FONT SIZE=+1><B>FLAG</B></FONT></TH>
71 * </TR>
72 * <TR><TH> PARENT </TH> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
73 * <TR><TH> CHLDREN </TH> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
74 * <TR><TH> ALL </TH> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
75 * <TR><TH> TEMP_PARENT </TH> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
76 * <TR><TH> TEMP_CHILDREN </TH> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
77 * <TR><TH> TEMP_ALL </TH> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
78 * </TABLE>
79 *
80 * <P>
81 * Input Data Object <BR>
82 * <BLOCKQUOTE>
83 * ImportData
84 * </BLOCKQUOTE>
85 * </P>
86 *
87 * <P>
88 * Output Data Object <BR>
89 * <BLOCKQUOTE>
90 * ImportResult
91 * </BLOCKQUOTE>
92 * </P>
93 *
94 * <P>
95 * Programmable Properties (passed inside data object) <BR>
96 * <BLOCKQUOTE>
97 * Global Properties (apply to all assets) <BR>
98 * <BLOCKQUOTE>
99 * <P>
100 * C/NC,Type:Icon path,Icon filename: In the xxx.cfg file, a list of types
101 * and the associated icon file. C/NC designates convertable/nonconvertable<BR>
102 * Data type: String <BR>
103 * Legal values: Any legal types and paths <BR>
104 * </P>
105 * </BLOCKQUOTE>
106 * </BLOCKQUOTE>
107 * </P>
108 */
109 public class DefaultThumbnailService
110 implements Service
111 {
112 // To get the version number from MKS
113 public final static String IDENTIFIER="$Id: DefaultThumbnailService.java,v 1.4 2003/08/11 02:22:28 aleric Exp $";
114
115
116
117 protected String sThumbLocation = " ";
118 protected String sThumbServer = " ";
119 protected String sThumbName = " ";
120 protected String sThumbPath = " ";
121
122 protected String sThisService = "";
123 protected String sConfigFile = "";
124 protected boolean successful = true;
125
126 protected ImportCtlData refCtlData = null;
127 protected ConversionOptions refConversionOptions = null;
128 protected ImportData refImportData = null;
129
130 private String fileSeparator;
131
132 /**
133 * Calls before the service is initialized (before initData is called) to
134 * pass information about the environment in which the service is running.
135 * This environment consists of information about the properties set for the
136 * service in one of these files (services.config, roletype_services.config,
137 * or *.ctl), plus methods to access other information such as an instance
138 * of the service broker to invoke other services, the transaction id for
139 * the service, file separator character and local path for the installation
140 * directory and configuration directory.
141 *
142 * @param context Holds information about the environment in which the service
143 * is running.
144 */
145 public void setServiceContext( ServiceContext context )
146 {
147 fileSeparator = context.getFileSeparator();
148 }
149
150 /**
151 * A data initialization method called at the beginning of the service.
152 * The input argument, ActionData must be cast into its subclass, ConvertData
153 * in order to extract the ConvertService specific data from it.
154 */
155 public void initData(ActionData actionData)
156 {
157 // cast the data object to a convert data wrapper
158 refImportData = (ImportData) actionData;
159
160 // Get the reference to the .CTL data object
161 refCtlData = refImportData.getCtlDataRef();
162
163 // Get the config file name listed in the CTL data and create fully-qualified path
164 sConfigFile = refCtlData.getValuePerKey("CONTROLFILESPATH") + refCtlData.getValuePerKey("CONFIGFILE");
165
166 //5882=Alchemy Convert Service
167 sThisService = "Default Thumbnail";//Resources.get(5882) + " (" + id + ")";
168
169 } // initData
170
171 /**
172 * The start of the Convert Service.
173 */
174 public ActionResult go()
175 {
176 Diagnostic.trace(Diagnostic.APPSERVER_SERVICES, "Default Thumbnail Server Starting");
177
178 // Read the config file to obtain the default icons
179 if (!readCfgFile())
180 {
181 ImportResult response = new ImportResult(false);
182 response.setImportData(refImportData);
183 return response;
184 }
185
186 successful = true;
187
188 // Get a reference to the DisguiseRecordData so we can get the assets
189 DisguiseRecordData refDisguiseRecordData = refImportData.getDisguiseRecordRef();
190 Vector assetRecords = null;
191
192 String sRole = "THUMBNAIL";
193 String sType = "ALL";
194 String sFlag = "ALL";
195
196 if(refDisguiseRecordData != null)
197 {
198 // Get the assets
199 assetRecords = refDisguiseRecordData.getAssets(sRole, sType, sFlag);
200 if(assetRecords != null)
201 {
202 Enumeration assets = assetRecords.elements();
203
204 // Processs each asset in each element in ImportData as required
205 while(assets.hasMoreElements())
206 {
207 DisguiseAssetRecordData anAsset = (DisguiseAssetRecordData)assets.nextElement();
208 String sLocation = anAsset.getLocation();
209 if ( sLocation.startsWith(fileSeparator) == false )
210 {
211 sLocation = fileSeparator + sLocation;
212 }
213
214 String sFilename = anAsset.getFileName();
215 String sThumbPath = sLocation + sFilename;
216
217 AssetRoleData refAssetRole = anAsset.getAssetRole();
218 String sAssetType = refAssetRole.getAssetFileType();
219
220 // Does the thumbnail actually exist?
221 FlexXFile fThumb = new FlexXFile(sThumbPath);
222 if (!fThumb.exists())
223 {
224 // Output default icon the file type or the UNKNOWN icon
225 if ((checkFileType(sAssetType, "C") == true) ||
226 (checkFileType("UNKNOWN" , "C") == true))
227 {
228 anAsset.setServer(sThumbServer);
229 anAsset.setLocation(sThumbLocation);
230 anAsset.setFileName(sThumbName);
231 }
232 } // if (!fThumb.exists())
233 } // while
234 } // assetRecords null if
235
236 else
237 {
238 successful = false;
239 }
240 } // refDisguiseRecordData if
241
242 else
243 {
244 successful = false;
245 }
246
247 // pass back the ImportData
248 ImportResult response = new ImportResult(successful); // turn off default result
249 response.setImportData(refImportData);
250
251 return response;
252 } // go()
253
254 /**
255 *
256 */
257 private boolean readCfgFile()
258 {
259 // Need to read the .cfg conversion file to get all of the parameters
260 // that Alchemy needs to do the conversions
261 refConversionOptions = new ConversionOptions(sConfigFile);
262 if ( refConversionOptions.processSection(false) )
263 return true; // we read the file OK so return true
264 else
265 {
266 //5521=Unable to read configuration input file: %%1
267 refImportData.addErrorRecord( new FlexError(FlexError.CRITICAL, sThisService, IDENTIFIER, 5521, (new String[] { sConfigFile })) );
268 return false;
269 }
270 } // readCfgFile()
271
272
273 /**
274 *
275 */
276 protected boolean checkFileType(String sExtension, String sType)
277 {
278 // Return true if the extension is found
279 boolean bResult = false;
280
281 int nExtIndex = -1;
282 if (sExtension.length() > 0)
283 nExtIndex = refConversionOptions.checkExtension(sExtension, sType);
284
285 if (nExtIndex >= 0)
286 {
287 // A default icon exists
288 sThumbServer = refConversionOptions.getDefaultIconServer(nExtIndex);
289 sThumbName = refConversionOptions.getDefaultIconName(nExtIndex);
290 sThumbLocation = refConversionOptions.getDefaultIconLocation(nExtIndex);
291 bResult = true;
292 }
293 return bResult;
294 } // checkFileType
295
296 } // DefaultThumbnailService