Source Code Cross Referenced for Util.java in  » IDE-Netbeans » iep.editor » org » netbeans » modules » iep » model » common » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » iep.editor » org.netbeans.modules.iep.model.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Util.java
003:         *
004:         * Created on October 4, 2005, 7:48 PM
005:         *
006:         * To change this template, choose Tools | Template Manager
007:         * and open the template in the editor.
008:         */
009:
010:        package org.netbeans.modules.iep.model.common;
011:
012:        import java.io.BufferedInputStream;
013:        import java.io.BufferedOutputStream;
014:        import java.io.BufferedReader;
015:        import java.io.File;
016:        import java.io.FileInputStream;
017:        import java.io.FileOutputStream;
018:        import java.io.IOException;
019:        import java.io.InputStream;
020:        import java.io.InputStreamReader;
021:        import java.io.OutputStream;
022:        import java.io.PrintWriter;
023:        import java.net.URI;
024:        import java.util.Collection;
025:        import javax.swing.text.Document;
026:        import org.netbeans.modules.xml.schema.model.GlobalSimpleType;
027:        import org.netbeans.modules.xml.schema.model.SchemaModel;
028:        import org.netbeans.modules.xml.schema.model.SchemaModelFactory;
029:        import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
030:        import org.netbeans.modules.xml.wsdl.model.WSDLModel;
031:        import org.netbeans.modules.xml.wsdl.model.visitor.FindWSDLComponent;
032:        import org.netbeans.modules.xml.xam.dom.AbstractDocumentModel;
033:        import org.openide.filesystems.FileObject;
034:        import org.openide.filesystems.FileUtil;
035:        import org.openide.filesystems.FileLock;
036:        import org.openide.filesystems.Repository;
037:
038:        /**
039:         *
040:         * @author nn136682
041:         */
042:        public class Util {
043:            public static final String EMPTY_XSD = "resources/Empty.wsdl";
044:
045:            static {
046:                registerXMLKit();
047:            }
048:
049:            public static void registerXMLKit() {
050:                String[] path = new String[] { "Editors", "text", "x-xml" };
051:                FileObject target = Repository.getDefault()
052:                        .getDefaultFileSystem().getRoot();
053:                try {
054:                    for (int i = 0; i < path.length; i++) {
055:                        FileObject f = target.getFileObject(path[i]);
056:                        if (f == null) {
057:                            f = target.createFolder(path[i]);
058:                        }
059:                        target = f;
060:                    }
061:                    String name = "EditorKit.instance";
062:                    if (target.getFileObject(name) == null) {
063:                        FileObject f = target.createData(name);
064:                        f.setAttribute("instanceClass",
065:                                "org.netbeans.modules.xml.text.syntax.XMLKit");
066:                    }
067:                } catch (IOException ioe) {
068:                    ioe.printStackTrace();
069:                }
070:            }
071:
072:            public static Document getResourceAsDocument(String path)
073:                    throws Exception {
074:                InputStream in = Util.class.getResourceAsStream(path);
075:                return loadDocument(in);
076:            }
077:
078:            public static String getResourceAsString(String path)
079:                    throws Exception {
080:                InputStream in = Util.class.getResourceAsStream(path);
081:                BufferedReader br = new BufferedReader(new InputStreamReader(
082:                        in, "UTF-8"));
083:                StringBuffer sbuf = new StringBuffer();
084:                try {
085:                    String line = null;
086:                    while ((line = br.readLine()) != null) {
087:                        sbuf.append(line);
088:                        sbuf.append(System.getProperty("line.separator"));
089:                    }
090:                } finally {
091:                    br.close();
092:                }
093:                return sbuf.toString();
094:            }
095:
096:            public static Document loadDocument(InputStream in)
097:                    throws Exception {
098:                Document sd = new org.netbeans.editor.BaseDocument(
099:                        org.netbeans.modules.xml.text.syntax.XMLKit.class,
100:                        false);
101:                BufferedReader br = new BufferedReader(
102:                        new InputStreamReader(in));
103:                StringBuffer sbuf = new StringBuffer();
104:                try {
105:                    String line = null;
106:                    while ((line = br.readLine()) != null) {
107:                        sbuf.append(line);
108:                        sbuf.append(System.getProperty("line.separator"));
109:                    }
110:                } finally {
111:                    br.close();
112:                }
113:                sd.insertString(0, sbuf.toString(), null);
114:                return sd;
115:            }
116:
117:            public static int count = 0;
118:
119:            public static WSDLModel loadWSDLModel(String resourcePath)
120:                    throws Exception {
121:                NamespaceLocation nl = NamespaceLocation
122:                        .valueFromResourcePath(resourcePath);
123:                if (nl != null) {
124:                    return TestCatalogModel.getDefault().getWSDLModel(nl);
125:                }
126:                String location = resourcePath.substring(resourcePath
127:                        .lastIndexOf('/') + 1);
128:                URI locationURI = new URI(location);
129:                TestCatalogModel.getDefault().addURI(locationURI,
130:                        getResourceURI(resourcePath));
131:                return TestCatalogModel.getDefault().getWSDLModel(locationURI);
132:            }
133:
134:            public static WSDLModel createEmptyWSDLModel() throws Exception {
135:                return loadWSDLModel(EMPTY_XSD);
136:            }
137:
138:            /*public static WSDLModel loadWSDLModel(Document doc) throws Exception {
139:                return WSDLModelFactory.getDefault().getModel(doc);
140:            }*/
141:
142:            public static void dumpToStream(Document doc, OutputStream out)
143:                    throws Exception {
144:                PrintWriter w = new PrintWriter(out);
145:                w.print(doc.getText(0, doc.getLength()));
146:                w.close();
147:                out.close();
148:            }
149:
150:            public static void dumpToFile(Document doc, File f)
151:                    throws Exception {
152:                if (!f.exists()) {
153:                    f.createNewFile();
154:                }
155:                OutputStream out = new BufferedOutputStream(
156:                        new FileOutputStream(f));
157:                PrintWriter w = new PrintWriter(out);
158:                w.print(doc.getText(0, doc.getLength()));
159:                w.close();
160:                out.close();
161:            }
162:
163:            public static File dumpToTempFile(Document doc) throws Exception {
164:                File f = File.createTempFile("xsm", "xsd");
165:                dumpToFile(doc, f);
166:                return f;
167:            }
168:
169:            public static WSDLModel dumpAndReloadModel(Document doc)
170:                    throws Exception {
171:                File f = dumpToTempFile(doc);
172:                URI dumpURI = new URI("dummyDump" + count++);
173:                TestCatalogModel.getDefault().addURI(dumpURI, f.toURI());
174:                return TestCatalogModel.getDefault().getWSDLModel(dumpURI);
175:            }
176:
177:            public static Document loadDocument(File f) throws Exception {
178:                InputStream in = new BufferedInputStream(new FileInputStream(f));
179:                return loadDocument(in);
180:            }
181:
182:            public static URI getResourceURI(String path)
183:                    throws RuntimeException {
184:                try {
185:                    return Util.class.getResource(path).toURI();
186:                } catch (Exception ex) {
187:                    throw new RuntimeException(ex);
188:                }
189:            }
190:
191:            public static File getTempDir(String path) throws Exception {
192:                File tempdir = new File(System.getProperty("java.io.tmpdir"),
193:                        path);
194:                tempdir.mkdirs();
195:                return tempdir;
196:            }
197:
198:            public static GlobalSimpleType getPrimitiveType(String typeName) {
199:                SchemaModel primitiveModel = SchemaModelFactory.getDefault()
200:                        .getPrimitiveTypesModel();
201:                Collection<GlobalSimpleType> primitives = primitiveModel
202:                        .getSchema().getSimpleTypes();
203:                for (GlobalSimpleType ptype : primitives) {
204:                    if (ptype.getName().equals(typeName)) {
205:                        return ptype;
206:                    }
207:                }
208:                return null;
209:            }
210:
211:            public static Document setDocumentContentTo(Document doc,
212:                    InputStream in) throws Exception {
213:                BufferedReader br = new BufferedReader(
214:                        new InputStreamReader(in));
215:                StringBuffer sbuf = new StringBuffer();
216:                try {
217:                    String line = null;
218:                    while ((line = br.readLine()) != null) {
219:                        sbuf.append(line);
220:                        sbuf.append(System.getProperty("line.separator"));
221:                    }
222:                } finally {
223:                    br.close();
224:                }
225:                doc.remove(0, doc.getLength());
226:                doc.insertString(0, sbuf.toString(), null);
227:                return doc;
228:            }
229:
230:            public static Document setDocumentContentTo(Document doc,
231:                    String resourcePath) throws Exception {
232:                return setDocumentContentTo(doc, Util.class
233:                        .getResourceAsStream(resourcePath));
234:            }
235:
236:            public static void setDocumentContentTo(WSDLModel model,
237:                    String resourcePath) throws Exception {
238:                Document doc = ((AbstractDocumentModel) model)
239:                        .getBaseDocument();
240:                setDocumentContentTo(doc, Util.class
241:                        .getResourceAsStream(resourcePath));
242:            }
243:
244:            public static FileObject copyResource(String path,
245:                    FileObject destFolder) throws Exception {
246:                String filename = getFileName(path);
247:
248:                FileObject dest = destFolder.getFileObject(filename);
249:                if (dest == null) {
250:                    dest = destFolder.createData(filename);
251:                }
252:                FileLock lock = dest.lock();
253:                OutputStream out = dest.getOutputStream(lock);
254:                InputStream in = Util.class.getResourceAsStream(path);
255:                try {
256:                    FileUtil.copy(in, out);
257:                } finally {
258:                    out.close();
259:                    in.close();
260:                    if (lock != null)
261:                        lock.releaseLock();
262:                }
263:                return dest;
264:            }
265:
266:            public static String getFileName(String path) {
267:                int i = path.lastIndexOf('/');
268:                if (i > -1) {
269:                    return path.substring(i + 1);
270:                } else {
271:                    return path;
272:                }
273:            }
274:
275:            public static <T extends WSDLComponent> T find(Class<T> type,
276:                    WSDLModel model, String xpath) {
277:                return type.cast(FindWSDLComponent.findComponent(type, model
278:                        .getDefinitions(), xpath));
279:            }
280:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.