KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > i18n > test > Utilities


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.i18n.test;
21
22 import java.io.File JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24
25 // ide imports
26
import org.openide.filesystems.FileObject;
27 import org.openide.filesystems.FileStateInvalidException;
28 import org.openide.filesystems.FileSystem;
29 import org.openide.filesystems.Repository;
30
31 //import org.netbeans.test.oo.gui.jelly.JellyException;
32
//import org.netbeans.test.oo.gui.jello.JelloBundle;
33

34 /**
35  *
36  * @author Marian.Mirilovic@czech.sun.com
37  * @version
38  */

39
40 public class Utilities extends Object JavaDoc {
41     /** form bundles */
42     public static String JavaDoc formBundle = "org.netbeans.modules.form.Bundle";
43     public static String JavaDoc formPaletteBundle = "org.netbeans.modules.form.palette.Bundle";
44     public static String JavaDoc formActionsBundle = "org.netbeans.modules.form.actions.Bundle";
45     
46     /** core bundles */
47     public static String JavaDoc windowsCoreBundle = "org.netbeans.core.windows.Bundle";
48     public static String JavaDoc statusCompile = "org.netbeans.core.compiler.Bundle";
49     
50     /** openide bundles */
51     public static String JavaDoc openideActions = "org.openide.actions.Bundle";
52     public static String JavaDoc openideText = "org.openide.text.Bundle";
53     
54     /** jdbc bundles */
55     public static String JavaDoc jdbcPaletteBundle = "org.netbeans.modules.jdbc.resources.Bundle";
56     
57     //public static String OPEN = JelloBundle.getString (openideActions, "Open"); // Open
58
//public static String EDIT = JelloBundle.getString (openideActions, "Edit"); // Edit
59

60     /** test resource package */
61     public static String JavaDoc Resources = "Resources";
62     public static String JavaDoc passCaption = " PASS - \n\t";
63     public static String JavaDoc failCaption = " FAIL - \n\t";
64     public static String JavaDoc errorCaption = "Test ERROR : ";
65     
66     /* names of Top Components class */
67     public static String JavaDoc TP_ComponentPalette = "org.netbeans.modules.form.palette.PaletteTopComponent";
68     public static String JavaDoc TP_ComponentInspector = "org.netbeans.modules.form.ComponentInspector";
69     public static String JavaDoc TP_FormDesigner = "org.netbeans.modules.form.FormDesigner";
70     
71     //public static String separ=(File.separatorChar == '/')?File.separator:"\\\\";
72
public static String JavaDoc separ="/";
73     
74     /** Creates new utilities */
75     public Utilities() {
76     }
77     
78     /** Find file object by name and extension.
79      * @param _pack package name
80      * @param _name file name
81      * @param _extension file extension
82      * @return finded file object or null
83      */

84     public static FileObject findFileObject(String JavaDoc _package, String JavaDoc _name, String JavaDoc _extension) {
85         //FileObject f = Repository.getDefault().find(_package, _name, _extension);
86
String JavaDoc name="";
87         //System.out.println("package "+_package+" name="+_name+" ext="+_extension);
88
if (_package != null && _package.length() > 0) {
89             name=_package.replaceAll("\\.",separ)+separ;
90         }
91         if (_name != null && _name.length() > 0) {
92             name+=_name;
93         }
94         if (_extension != null && _extension.length() > 0) {
95             name+="."+_extension;
96         }
97         //System.out.println("name="+name);
98
FileObject f=Repository.getDefault().findResource(name);
99         return f;
100     }
101     
102     /** Find file system name.
103      * @param _package package name
104      * @param fileName file name
105      * @param fileExtension file extension
106      * @throws FileStateInvalidException
107      * @return full FileSystem name */

108     public static String JavaDoc getFS(String JavaDoc _package, String JavaDoc fileName, String JavaDoc fileExtension) throws Exception JavaDoc {
109         FileObject f = findFileObject(_package, fileName, fileExtension);
110         
111         if(f == null)
112             throw new Exception JavaDoc("Unable find file " + fileName + "." + fileExtension + " in package " + _package);
113         
114         String JavaDoc fs;
115         try {
116             //fs = f.getFileSystem().getSystemName();
117
fs = f.getFileSystem().getDisplayName();
118         } catch(FileStateInvalidException exc){
119             throw new Exception JavaDoc("FileStateInvalidException during attempt get filesystem name for " + fileName + "." + fileExtension + " in package " + _package);
120         }
121         
122         // hack for Win NT/2K , where in FileObject is bad file separator !!!
123
//char fileSeparator = System.getProperty("file.separator").charAt(0);
124
String JavaDoc fsName = fs.replaceAll("\\\\",separ);
125         //String path = fsName+ ", " + _package + ", " + fileName;
126

127         return fsName;
128     }
129     
130     public static String JavaDoc getPath(String JavaDoc packageName, String JavaDoc fileName, String JavaDoc fileExtension, String JavaDoc delim) throws Exception JavaDoc {
131         String JavaDoc FS_Name = getFS(packageName, fileName, fileExtension);
132         return FS_Name + delim + packageName.replace('.',delim.charAt(0)) + delim + fileName;
133     }
134     
135     public static String JavaDoc getPath(String JavaDoc packageName, String JavaDoc delim) throws Exception JavaDoc {
136         String JavaDoc FS_Name = getFS(packageName, null, null);
137         return FS_Name + delim + packageName.replace('.',delim.charAt(0));
138     }
139     
140     public static String JavaDoc getSystemPath(String JavaDoc packageName, String JavaDoc fileName, String JavaDoc fileExtension) throws Exception JavaDoc {
141         return getPath(packageName, fileName, fileExtension, separ)+ "." + fileExtension;
142     }
143     
144     public static void writeExc(Exception JavaDoc exc, PrintWriter JavaDoc err) {
145         err.println(errorCaption);
146         exc.printStackTrace(err);
147     }
148     
149     public static void main(java.lang.String JavaDoc[] args) {
150         try {
151             //String s=getFS("org.netbeans.test.gui.projects","Utillities","java");
152
String JavaDoc s;//=getFS("aaa.bbb","aaa","txt");
153
s=getPath("org.netbeans.test.gui.projects", "data", null, "|");
154             System.out.println(s);
155         } catch (Exception JavaDoc ex) {
156             ex.printStackTrace();
157         }
158     }
159     
160 }
161
Popular Tags