KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdic > packager > impl > JnlpPackageInfo


1 /*
2  * Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is
3  * subject to license terms.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the Lesser GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  */

20
21 package org.jdesktop.jdic.packager.impl;
22
23 import java.util.List JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.FileInputStream JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.net.URL JavaDoc;
30
31 import com.sun.deploy.xml.XMLEncoding;
32 import com.sun.deploy.xml.XMLNode;
33 import com.sun.deploy.xml.XMLParser;
34 import com.sun.javaws.exceptions.BadFieldException;
35 import com.sun.javaws.exceptions.MissingFieldException;
36 import com.sun.javaws.jnl.ExtensionDesc;
37 import com.sun.javaws.jnl.IconDesc;
38 import com.sun.javaws.jnl.InformationDesc;
39 import com.sun.javaws.jnl.JARDesc;
40 import com.sun.javaws.jnl.JREDesc;
41 import com.sun.javaws.jnl.LaunchDesc;
42 import com.sun.javaws.jnl.LaunchDescFactory;
43 import com.sun.javaws.jnl.PackageDesc;
44 import com.sun.javaws.jnl.PropertyDesc;
45 import com.sun.javaws.jnl.ResourceVisitor;
46 import com.sun.javaws.jnl.ResourcesDesc;
47 import com.sun.javaws.jnl.XMLUtils;
48 import com.sun.javaws.util.GeneralUtil;
49
50 /**
51  * This parameter class encapsulates all the description information for the
52  * generated packages.
53  */

54 public final class JnlpPackageInfo {
55
56     private static String JavaDoc osName = System.getProperty("os.name").toLowerCase();
57  
58     /**
59      * JnlpPackageInfo contructor.
60      *
61      */

62     public JnlpPackageInfo() {
63         titles = new String JavaDoc[JnlpConstants.LOCALES.length];
64         vendors = new String JavaDoc[JnlpConstants.LOCALES.length];
65         licenses = new String JavaDoc[JnlpConstants.LOCALES.length];
66         descriptions = new String JavaDoc[JnlpConstants.LOCALES.length];
67         uniqueTmpDirPath = null;
68         enableLocalization = false;
69         bannerJpgFilePath = null;
70         panelJpgFilePath = null;
71         jnlpRefFilePaths = new ArrayList JavaDoc();
72     }
73
74     /**
75      * Jnlp file title fields of different locales.
76      */

77     private String JavaDoc[] titles;
78     /**
79      * Jnlp file vendor fields of different locales.
80      */

81     private String JavaDoc[] vendors;
82     /**
83      * Jnlp file license fields of different locales.
84      */

85     private String JavaDoc[] licenses;
86     /**
87      * Jnlp file description fields of different locales.
88      */

89     private String JavaDoc[] descriptions;
90
91     /**
92      * License Dir path.
93      */

94     private String JavaDoc licenseDirPath;
95
96     /**
97      * Unique temporary dir path in system tmp dir.
98      */

99     private String JavaDoc uniqueTmpDirPath;
100
101     /**
102      * Package name. Such as: notepad.
103      */

104     private String JavaDoc packageName;
105
106     /**
107      * The destination path where the package file would be placed.
108      */

109     private String JavaDoc outputDirPath;
110
111     /**
112      * Jnlp href, which is codebase + href.
113      * Such as: http://java.sun.com/products/javawebstart/apps/notepad.jnlp
114      */

115     private String JavaDoc jnlpFileHref;
116
117     /**
118      * Path of the jnlp file. Such as: C:/temp/notepad.jnlp
119      */

120     private String JavaDoc jnlpFilePath;
121
122     /**
123      * Parent path of resource files referenced by the jnlp file,
124      * Which should be given by users' input, it will be the parent
125      * path of Jnlp file by default.
126      * Such as: C:/temp
127      */

128     private String JavaDoc resourceDirPath;
129
130     /**
131      * Version Number of the application to be packaged.
132      */

133     private String JavaDoc version;
134
135     /**
136      * Release Number of the application to be packaged.
137      */

138     private String JavaDoc release;
139
140     /**
141      * Relative path list of resource files referenced by the jnlp file.
142      * Such as: notepad/notepad.jar, notepad/images/notepad.jpg
143      */

144     private List JavaDoc jnlpRefFilePaths;
145
146     /**
147      * Absolutepath to Banner jpg file.
148      */

149     private String JavaDoc bannerJpgFilePath;
150
151     /**
152      * Absolutepath to Panel jpg file.
153      */

154     private String JavaDoc panelJpgFilePath;
155     /**
156      * Absolutepath to the MS SDK update.
157      */

158     private String JavaDoc msSDKDirPath;
159     /**
160      * Absolutepath to the raw msi file.
161      */

162     private String JavaDoc rawMsiFilePath;
163
164     /**
165      * If localization needed.
166      */

167     private boolean enableLocalization;
168
169     /**
170      * If show license or not.
171      */

172     private boolean enableLicense;
173
174     /**
175      * If the shortcut should be created
176      */

177     private boolean shortcutEnabled;
178
179     /**
180      * If the association should be created
181      */

182     private boolean enableAssociation;
183
184     /**
185      * If use system or user(default) cache.
186      */

187     private boolean enableSystemCache;
188
189     /**
190      * Retrieves the banner jpeg file path.
191      * @return The banner jpeg file path.
192      */

193     public String JavaDoc getBannerJpgFilePath() {
194         return bannerJpgFilePath;
195     }
196
197     /**
198      * Sets the banner jpeg file path.
199      * @param theBannerJpgFilePath The given banner jpeg file path.
200      */

201     public void setBannerJpgFilePath(String JavaDoc theBannerJpgFilePath) {
202         bannerJpgFilePath = theBannerJpgFilePath;
203     }
204
205     /**
206      * Gets the panel jpeg file path.
207      * @return The panel jpeg file path.
208      */

209     public String JavaDoc getPanelJpgFilePath() {
210         return panelJpgFilePath;
211     }
212
213     /**
214      * Sets the panel jpeg file path.
215      * @param thePanelJpegFilePath The given panel jpeg file path.
216      */

217     public void setPanelJpgFilePath(String JavaDoc thePanelJpegFilePath) {
218         panelJpgFilePath = thePanelJpegFilePath;
219     }
220     /**
221      * Gets the MS SDK Path.
222      * @return The MS SDK Path.
223      */

224     public String JavaDoc getMSSDKDirPath() {
225         return msSDKDirPath;
226     }
227     /**
228      * Sets the MS SDK Path.
229      * @param theMSSDKDirPath The given ms SDK path.
230      */

231     public void setMSSDKDirPath(String JavaDoc theMSSDKDirPath) {
232         msSDKDirPath = theMSSDKDirPath;
233     }
234     /**
235      * Gets the raw msi file path.
236      * @return The raw msi file path.
237      */

238     public String JavaDoc getRawMsiFilePath() {
239         return rawMsiFilePath;
240     }
241
242     /**
243      * Sets the raw msi file path.
244      * @param theRawMsiFilePath The given raw msi file path.
245      */

246     public void setRawMsiFilePath(String JavaDoc theRawMsiFilePath) {
247         rawMsiFilePath = theRawMsiFilePath;
248     }
249
250     /**
251      * Gets whether to install the application into system cache or not.
252      * @return True if the application goes into the system cache.
253      */

254     public boolean getSystemCacheEnabled() {
255         return enableSystemCache;
256     }
257
258     /**
259      * Sets whether to install into the system cache.
260      * @param systemcache True if the application will goes into the sys cache.
261      */

262     public void setSystemCacheEnabled(boolean systemcache) {
263         enableSystemCache = systemcache;
264     }
265
266     /**
267      * Gets the package name.
268      * @return The name of the package.
269      */

270     public String JavaDoc getPackageName() {
271         return packageName;
272     }
273
274     /**
275      * Sets the package name.
276      * @param theName The given name of the package.
277      */

278     public void setPackageName(String JavaDoc theName) {
279         packageName = theName;
280     }
281
282     /**
283      * Gets the output directory path.
284      * @return The path of the output directory.
285      */

286     public String JavaDoc getOutputDirPath() {
287         return outputDirPath;
288     }
289
290     /**
291      * Sets the output directory.
292      * @param theOutputDirPath The path of the output directory.
293      */

294     public void setOutputDirPath(String JavaDoc theOutputDirPath) {
295         outputDirPath = theOutputDirPath;
296     }
297
298     /**
299      * Gets the jnlp file href.
300      * @return The href of the jnlp file.
301      */

302     public String JavaDoc getJnlpFileHref() {
303         return jnlpFileHref;
304     }
305
306     /**
307      * Sets the jnlp file href.
308      * @param theJnlpFileHref The given jnlp file href.
309      */

310     public void setJnlpFileHref(String JavaDoc theJnlpFileHref) {
311         jnlpFileHref = theJnlpFileHref;
312     }
313
314     /**
315      * Gest the jnlp file path.
316      * @return The path of the jnlp file.
317      */

318     public String JavaDoc getJnlpFilePath() {
319         return jnlpFilePath;
320     }
321
322     /**
323      * Sets the jnlp file path.
324      * @param theJnlpFilePath The given jnlp file path.
325      */

326     public void setJnlpFilePath(String JavaDoc theJnlpFilePath) {
327         jnlpFilePath = theJnlpFilePath;
328     }
329
330     /**
331      * Returns jnlp file name with extension of the jnlp file according to the
332      * jnlpFilePath field.
333      * <p>
334      * For examples: if jnlpFilePath is C:/temp/notepad.jnlp, this field is
335      * notepad.jnlp.
336      * <p>
337      * Since this field is generated from the jnlpFilePath field,
338      * there is no associated variable member, and there is only getter method
339      * for this field, no setter method.
340      * @return The single jnlp file name without any parent dir info.
341      */

342     public String JavaDoc getJnlpFileName() {
343         return new File JavaDoc(jnlpFilePath).getName();
344     }
345
346     /**
347      * Gets the resource directory information.
348      * @return The resource directory path.
349      */

350     public String JavaDoc getResourceDirPath() {
351         return resourceDirPath;
352     }
353
354     /**
355      * Sets the resource directory information.
356      * @param theResourcePath The given resource directory path.
357      */

358     public void setResourcePath(String JavaDoc theResourcePath) {
359         resourceDirPath = theResourcePath;
360     }
361
362     /**
363      * Gets version info.
364      * @return The version number string.
365      */

366     public String JavaDoc getVersion() {
367         return version;
368     }
369
370     /**
371      * Sets the version number info.
372      * @param theVersion The given version number.
373      */

374     public void setVersion(String JavaDoc theVersion) {
375         if (osName.startsWith(JnlpConstants.OS_WINDOWS)) {
376             try {
377                 Float.parseFloat(theVersion);
378             } catch (NumberFormatException JavaDoc e) {
379                 throw new IllegalArgumentException JavaDoc("Error: " +
380                     "Illegal Version Number (Valid input: digits & '.')");
381             }
382         }
383         version = theVersion;
384     }
385
386     /**
387      * Gets the release number info.
388      * @return The release number info.
389      */

390     public String JavaDoc getRelease() {
391         return release;
392     }
393
394     /**
395      * Sets the release number.
396      * @param theRelease The given release number.
397      */

398     public void setRelease(String JavaDoc theRelease) {
399         if (osName.startsWith(JnlpConstants.OS_WINDOWS)) {
400             try {
401                 Float.parseFloat(theRelease);
402             } catch (NumberFormatException JavaDoc e) {
403                 throw new IllegalArgumentException JavaDoc("Error: " +
404                     "Illegal Release Number (Valid input: digits & '.')");
405             }
406         }
407         release = theRelease;
408     }
409
410     /**
411      * Gets the jnlp file refereced paths info.
412      * @return The list iterator of jnlp file refereced paths.
413      */

414     public Iterator JavaDoc getJnlpRefFilePaths() {
415         return jnlpRefFilePaths.iterator();
416     }
417
418     /**
419      * Gets whether to create a shortcut after the installation.
420      * @return True if the installation will create a shortcut.
421      */

422     public boolean getShortcutEnabled() {
423         return shortcutEnabled;
424     }
425
426     /**
427      * Sets whether to create a shortcut during the installation process.
428      * @param shortcut True if the installation will create a shortcut.
429      */

430     public void setShortcutEnabled(boolean shortcut) {
431         shortcutEnabled = shortcut;
432     }
433
434     /**
435      * Gets whether to create an association during the installation process.
436      * @return True if the installation will create an association.
437      */

438     public boolean getAssociationEnabled() {
439         return enableAssociation;
440     }
441
442     /**
443      * Sets whether to create an association during the installation process.
444      * @param association True if the installation will create an association.
445      */

446     public void setAssociationEnabled(boolean association) {
447         enableAssociation = association;
448     }
449
450     /**
451      * Gets whether we need to localize the installation package.
452      * @return True if localization supported.
453      */

454     public boolean getLocalizationEnabled() {
455         return enableLocalization;
456     }
457
458     /**
459      * Sets whether we need to provide localization support.
460      * @param globalization True if localization supported.
461      */

462     public void setGlocalizationEnabled(boolean globalization) {
463         enableLocalization = globalization;
464     }
465
466     /**
467      * Gets the license directory.
468      * @return The directory containing all the license files.
469      */

470     public String JavaDoc getLicenseDirPath() {
471         return licenseDirPath;
472     }
473
474     /**
475      * Sets the license directory.
476      * @param theLicenseDirPath The directory containing all the license files.
477      */

478     public void setLicenseDirPath(String JavaDoc theLicenseDirPath) {
479         licenseDirPath = theLicenseDirPath;
480     }
481
482     /**
483      * Sets whether to show license info during installation process.
484      * @param bShow True if license info gets displayed durinig installation.
485      */

486     public void setShowLicense(boolean bShow) {
487         enableLicense = bShow;
488     }
489
490     /**
491      * Gets whether to show license info during installation process.
492      * @return True if license info gets displayed during installation process.
493      */

494     public boolean getShowLicense() {
495         return enableLicense;
496     }
497
498     /**
499      * Gets a unique temp directory.
500      * @return The path of the uniqe temp directory.
501      * @throws IOException If failed to get such a directory.
502      */

503     public String JavaDoc getUniqueTmpDirPath() throws IOException JavaDoc {
504         if (uniqueTmpDirPath == null) {
505             uniqueTmpDirPath = FileOperUtility.createUniqueTmpDir();
506         }
507         return uniqueTmpDirPath;
508     }
509
510     /**
511      * Gets localized jnlp file field.
512      * @param locale The given locale name.
513      * @param info The name of the jnlp file field.
514      * @return The lolized jnlp field content string.
515      */

516     public String JavaDoc getLocalizedJnlpInfo(String JavaDoc locale, String JavaDoc info) {
517         int localeIndex = getLocaleIndex(locale);
518         String JavaDoc ret = null;
519         if (info.compareToIgnoreCase(JnlpConstants.JNLP_FIELD_TITLE) == 0) {
520             ret = titles[localeIndex];
521         } else if (
522             info.compareToIgnoreCase(JnlpConstants.JNLP_FIELD_VENDOR) == 0) {
523             ret = vendors[localeIndex];
524         } else if (
525             info.compareToIgnoreCase(JnlpConstants.JNLP_FIELD_LICENSE) == 0) {
526             ret = licenses[localeIndex];
527         } else if (
528             info.compareToIgnoreCase(JnlpConstants.JNLP_FIELD_DESCRIPTION)
529                 == 0) {
530             ret = descriptions[localeIndex];
531         }
532         return ret;
533     }
534
535     /**
536      * Gets the corresponding locale index.
537      * @param locale The given locale string.
538      * @return The index of the locale string.
539      */

540     protected int getLocaleIndex(String JavaDoc locale) {
541         int index = -1;
542         for (int i = 0; i < JnlpConstants.LOCALES.length; i++) {
543             if (locale.compareToIgnoreCase(JnlpConstants.LOCALES[i]) == 0) {
544                 index = i;
545                 break;
546             }
547         }
548         return index;
549     }
550     
551     /**
552      * get remote resources to local directory, and set the related fields of
553      * the JnlpPackageInfo
554      *
555      * @param jnlp points to the remote jnlp file
556      * @throws IOException
557      */

558     public void parseRemoteJnlpInfo(URL JavaDoc jnlp)
559             throws IOException JavaDoc {
560         if (jnlp == null)
561             throw new IOException JavaDoc("url is null when trying to parse JnlpInfo");
562         String JavaDoc localBase = FileOperUtility.createUniqueTmpDir();
563         URL JavaDoc localJnlp = FileOperUtility.getRemoteResource(jnlp, localBase);
564         setResourcePath(localBase);
565         parseLocalJnlpInfo(localJnlp);
566     }
567     
568     /**
569      * add file path to JnlpRefFilePath
570      *
571      * @param url points to the file
572      * @param codebase
573      * @throws IOException
574      */

575     public void addJnlpRefFilePath(URL JavaDoc url, URL JavaDoc codebase) throws IOException JavaDoc {
576         String JavaDoc relPath = FileOperUtility.getRelativePath(
577                 url.toString(), codebase.toString());
578
579         jnlpRefFilePaths.add(relPath);
580     }
581     
582     /**
583      * set related fields of the JnlpPackageInfo according to the local jnlp
584      * file
585      *
586      * @param jnlp points to the local jnlp file
587      * @throws IOException
588      */

589     public void parseLocalJnlpInfo(URL JavaDoc jnlp) throws IOException JavaDoc {
590         URL JavaDoc codebase = null;
591         
592         if (jnlp == null)
593             throw new IOException JavaDoc("url is null when trying to parse JnlpInfo");
594         
595         if (resourceDirPath == null || resourceDirPath.length() <= 0)
596             throw new IOException JavaDoc("resourcePath have not been set");
597         
598         try {
599             File JavaDoc jnlpFile = new File JavaDoc(jnlp.toURI());
600             setJnlpFilePath(jnlpFile.getPath());
601             LaunchDesc laDesc = LaunchDescFactory.buildDescriptor(jnlp);
602             codebase = laDesc.getCodebase();
603             setJnlpFileHref(laDesc.getCanonicalHome().toString());
604             InformationDesc infoDesc = laDesc.getInformation();
605             setTitle(JnlpConstants.LOCALE_EN, infoDesc.getTitle());
606             setVendor(JnlpConstants.LOCALE_EN, infoDesc.getVendor());
607             setDescription(JnlpConstants.LOCALE_EN,
608                     infoDesc.getDescription(InformationDesc.DESC_DEFAULT));
609
610             addJnlpRefFilePaths(jnlp);
611         } catch (Exception JavaDoc e) {
612             e.printStackTrace();
613         }
614     }
615
616     public void addJnlpRefFilePaths(URL JavaDoc jnlp) throws IOException JavaDoc{
617         
618         if (jnlp == null)
619             throw new IOException JavaDoc("url is null when trying to parse JnlpInfo");
620         
621         if (resourceDirPath == null || resourceDirPath.length() <= 0)
622             throw new IOException JavaDoc("resourcePath have not been set");
623         
624         try {
625             File JavaDoc jnlpFile = new File JavaDoc(jnlp.toURI());
626             jnlpRefFilePaths.add(jnlpFile.getAbsolutePath());
627             LaunchDesc laDesc = LaunchDescFactory.buildDescriptor(jnlp);
628             URL JavaDoc codebase = laDesc.getCodebase();
629             InformationDesc infoDesc = laDesc.getInformation();
630             IconDesc[] iconArray = infoDesc.getIcons();
631             for (int i = 0; i < iconArray.length; i++) {
632                 URL JavaDoc iconURL = iconArray[i].getLocation();
633                 this.addJnlpRefFilePath(iconURL, codebase);
634             }
635             ResourcesDesc reDesc = laDesc.getResources();
636             reDesc.visit(
637                     new JDICPackagerFileRefVisitor(codebase,
638                             resourceDirPath, this));
639         } catch (Exception JavaDoc e) {
640             e.printStackTrace();
641         }
642     }
643     /**
644      * set title in the given locale
645      *
646      * @param index
647      * @param title
648      */

649     public void setTitle(int index, String JavaDoc title) {
650         titles[index] = title;
651     }
652     
653     /**
654      * set vector in the given locale
655      *
656      * @param index
657      * @param vendor
658      */

659     public void setVendor(int index, String JavaDoc vendor) {
660         vendors[index] = vendor;
661     }
662     
663     /**
664      * set description in the give locale
665      *
666      * @param index
667      * @param description
668      */

669     public void setDescription(int index, String JavaDoc description) {
670         descriptions[index] = description;
671     }
672     
673     /**
674      * set license in the give locale
675      *
676      * @param index
677      * @param license
678      */

679     public void setLicense(int index, String JavaDoc license) {
680         licenses[index] = license;
681     }
682     
683     /**
684      * set localized information to the jnlpPackagerInfo
685      *
686      * @throws IOException
687      */

688     public void setLocalizedInformation()
689             throws IOException JavaDoc {
690         File JavaDoc jnlpFile = null;
691         jnlpFile = new File JavaDoc(getJnlpFilePath());
692         
693         if (jnlpFile == null) {
694             throw new IOException JavaDoc("Cannot find local jnlp file: " +
695                     jnlpFile.getPath());
696         }
697         byte[] bits;
698         try {
699             bits = LaunchDescFactory.readBytes(new FileInputStream JavaDoc(jnlpFile),
700                 jnlpFile.length());
701         } catch (Exception JavaDoc e) {
702             throw new IOException JavaDoc("Exception when build localized InfoDesc " +
703                     e.getMessage());
704         }
705
706         setLocalizedInformation(bits);
707         
708         for (int i = 0; i < JnlpConstants.LOCALES.length; i++) {
709             if (titles[i] == null || titles[i].length() == 0) {
710                 titles[i] = titles[JnlpConstants.LOCALE_EN];
711             }
712             
713             if (vendors[i] == null || vendors[i].length() == 0) {
714                 vendors[i] = vendors[JnlpConstants.LOCALE_EN];
715             }
716             
717             if (descriptions[i] == null || descriptions[i].length() == 0) {
718                 descriptions[i] = descriptions[JnlpConstants.LOCALE_EN];
719             }
720         }
721     }
722     
723     private void setLocalizedInformation(byte[] bits)
724             throws IOException JavaDoc {
725         String JavaDoc source;
726         String JavaDoc encoding;
727         XMLNode root;
728
729         try {
730             source = XMLEncoding.decodeXML(bits);
731         } catch (Exception JavaDoc e) {
732             throw new IOException JavaDoc("exception determining encoding of jnlp " +
733                     "file: " + e.getMessage());
734         }
735
736         try {
737             root = (new XMLParser(source)).parse();
738         } catch (Exception JavaDoc e) {
739             throw new IOException JavaDoc("exception parsing jnlp file " +
740                     e.getMessage());
741         }
742         
743         try {
744             XMLUtils.visitElements(root, "<information>",
745                     new JDICPackagerInfoElementVisitor(this));
746         } catch (Exception JavaDoc e) {
747             throw new IOException JavaDoc("exception creating InformationDesc " +
748                     e.getMessage());
749         }
750     }
751 }
752
753 /**
754  * ResourceVisitor to add all the local resource file paths to
755  * JnlpPackageInfo.jnlpRefFilePaths
756  */

757 class JDICPackagerFileRefVisitor implements ResourceVisitor {
758     private URL JavaDoc codebase = null;
759     private String JavaDoc localBase = null;
760     private JnlpPackageInfo pkgInfo = null;
761
762     public JDICPackagerFileRefVisitor(URL JavaDoc incodebase, String JavaDoc inlocalbase,
763             JnlpPackageInfo inpkgInfo) {
764         codebase = incodebase;
765         localBase = inlocalbase;
766         pkgInfo = inpkgInfo;
767     }
768     public void visitJARDesc(JARDesc jad) {
769         try {
770             pkgInfo.addJnlpRefFilePath(jad.getLocation(), codebase);
771         } catch (IOException JavaDoc ioE) {
772             ioE.printStackTrace();
773         }
774     }
775     
776     public void visitExtensionDesc(ExtensionDesc ed) {
777         String JavaDoc relPath = FileOperUtility.getRelativePath(
778                 ed.getLocation().toString(), codebase.toString());
779         File JavaDoc tmpFile = new File JavaDoc(pkgInfo.getResourceDirPath() + File.separator +
780                 relPath);
781         try {
782             pkgInfo.addJnlpRefFilePaths(tmpFile.toURL());
783         } catch (IOException JavaDoc ioE) {
784             ioE.printStackTrace();
785         }
786     }
787     
788     public void visitPropertyDesc(PropertyDesc prd) {}
789     public void visitJREDesc(JREDesc jrd) {}
790     public void visitPackageDesc(PackageDesc pad) {}
791 }
792
793 /**
794  * Element Visitor to set informations in different locales.
795  */

796 class JDICPackagerInfoElementVisitor extends XMLUtils.ElementVisitor {
797     private JnlpPackageInfo pkgInfo;
798     
799     public JDICPackagerInfoElementVisitor(JnlpPackageInfo inpkgInfo) {
800         pkgInfo = inpkgInfo;
801     }
802     
803     public void visitElement(XMLNode e) throws BadFieldException,
804         MissingFieldException {
805         String JavaDoc[] locales = GeneralUtil.getStringList(
806                 XMLUtils.getAttribute(e, "", "locale", null));
807         for (int i = 0; i < JnlpConstants.LOCALES.length; i++) {
808              if (matchLocale(JnlpConstants.LOCALES[i], locales)) {
809                  String JavaDoc title = XMLUtils.getElementContents(e, "<title>");
810                  pkgInfo.setTitle(i, title);
811                  String JavaDoc vendor = XMLUtils.getElementContents(e, "<vendor>");
812                  pkgInfo.setVendor(i, vendor);
813                  String JavaDoc description = XMLUtils.getElementContentsWithAttribute(
814                         e, "<description>", "kind", "", null);
815                  pkgInfo.setDescription(i, description);
816              }
817         }
818     }
819     
820     private boolean matchLocale(String JavaDoc locale, String JavaDoc[] locales) {
821         boolean match = false;
822         if (locales == null)
823             return match;
824         
825         for (int i = 0; i < locales.length; i++) {
826             if (locales[i] != null && locales[i].equals(locale)) {
827                 match = true;
828                 break;
829             }
830         }
831         
832         return match;
833     }
834 }
835
Popular Tags