Source Code Cross Referenced for SRAPUtil.java in  » Portal » Open-Portal » migration » modules » srap » erproxy » 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 » Portal » Open Portal » migration.modules.srap.erproxy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: SRAPUtil.java,v 1.2 2002/07/22 08:47:29 mm132998 Exp $
003:         * $Source: /m/portal/ps/srap/src/migration/modules/srap/erproxy/Attic/SRAPUtil.java,v $
004:         * $Log: SRAPUtil.java,v $
005:         * Revision 1.2  2002/07/22 08:47:29  mm132998
006:         * Bug ID - 4718198 , Desc - Initial code changes
007:         *
008:         *
009:         */
010:
011:        /**
012:         * $Id: SRAPUtil.java,v 1.2 2002/07/22 08:47:29 mm132998 Exp $
013:         * Copyright 2002 Sun Microsystems, Inc. All
014:         * rights reserved. Use of this product is subject
015:         * to license terms. Federal Acquisitions:
016:         * Commercial Software -- Government Users
017:         * Subject to Standard License Terms and
018:         * Conditions.
019:         *
020:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
021:         * are trademarks or registered trademarks of Sun Microsystems,
022:         * Inc. in the United States and other countries.
023:         */package migration.modules.srap.erproxy;
024:
025:        import javax.xml.parsers.*;
026:        import org.xml.sax.*;
027:        import org.xml.sax.helpers.*;
028:        import org.w3c.dom.*;
029:        import org.apache.xml.serialize.*;
030:        import java.io.*;
031:        import java.util.ArrayList;
032:        import java.util.Date;
033:        import java.text.SimpleDateFormat;
034:
035:        public class SRAPUtil {
036:            public static RandomAccessFile raf = null;
037:            public static final String ENCODING = "ISO-8859-1";
038:
039:            /**
040:             * Creates the DOM object for the specified XML file.
041:             */
042:            public static Document create(String infile, boolean nsAware,
043:                    boolean validate) throws SRAPDOMException {
044:                boolean ignoreWhitespace = false;
045:                boolean ignoreComments = false;
046:                try {
047:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
048:                            .newInstance();
049:                    dbf.setNamespaceAware(nsAware);
050:                    dbf.setValidating(validate);
051:                    dbf.setIgnoringComments(true);
052:                    dbf.setIgnoringElementContentWhitespace(true);
053:                    DocumentBuilder db = dbf.newDocumentBuilder();
054:                    OutputStreamWriter errorWriter = new OutputStreamWriter(
055:                            System.out, "UTF-8");
056:                    db.setErrorHandler(new MyHandler(new PrintWriter(
057:                            errorWriter, true)));
058:                    return db.parse(createTmpWithComponent(infile));
059:                } catch (Exception ex) {
060:                    throw new SRAPDOMException(ex.toString());
061:                }
062:            }
063:
064:            /**
065:             * Creates an empty DOM object.
066:             */
067:            static Document create(boolean nsAware, boolean validate)
068:                    throws SRAPDOMException {
069:                boolean ignoreWhitespace = false;
070:                boolean ignoreComments = false;
071:                try {
072:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
073:                            .newInstance();
074:                    dbf.setNamespaceAware(nsAware);
075:                    dbf.setValidating(validate);
076:                    dbf.setIgnoringComments(true);
077:                    dbf.setIgnoringElementContentWhitespace(true);
078:                    DocumentBuilder db = dbf.newDocumentBuilder();
079:                    OutputStreamWriter errorWriter = new OutputStreamWriter(
080:                            System.out, "UTF-8");
081:                    db.setErrorHandler(new MyHandler(new PrintWriter(
082:                            errorWriter, true)));
083:                    return db.newDocument();
084:                } catch (Exception ex) {
085:                    throw new SRAPDOMException(ex.toString());
086:                }
087:            }
088:
089:            /**
090:             * This method serializes a DOM object to a specified OS.
091:             */
092:            public static void serializeDOMTree(Document doc, OutputStream os)
093:                    throws SRAPDOMException {
094:                try {
095:                    OutputFormat format = new OutputFormat();
096:                    format.setIndenting(true);
097:                    format.setEncoding(ENCODING);
098:                    format.setVersion("1.0");
099:                    XMLSerializer serializer = new XMLSerializer(format);
100:                    serializer.setOutputByteStream(os);
101:                    serializer.serialize(doc);
102:                } catch (Exception ex) {
103:                    throw new SRAPDOMException(ex.toString());
104:                }
105:            }
106:
107:            /*
108:             * Create a valid temporary XML file (namespace aware)
109:             **/
110:            private static FileInputStream createTmpWithComponent(String infile)
111:                    throws Exception {
112:                BufferedReader br = new BufferedReader(new InputStreamReader(
113:                        new FileInputStream(infile), ENCODING));
114:                File tmp = File.createTempFile("wt1234", "xml",
115:                        new File("/tmp"));
116:                tmp.deleteOnExit();
117:                FileOutputStream out = new FileOutputStream(tmp);
118:                /*String compstuff = "<iwt:Component xmlns:iwt=\"\" name=\""+infile+"\" >\n";
119:                System.out.println( compstuff);
120:                out.write(compstuff.getBytes());*/
121:                String read = br.readLine();
122:                while (read != null) {
123:                    if (read.trim().startsWith("<iwt:Component")) {
124:                        int indx = read.indexOf("<iwt:Component");
125:                        StringBuffer sb = new StringBuffer();
126:                        sb.append(read.substring(0, indx + 14));
127:                        sb.append(" xmlns:iwt=\"\"");
128:                        sb.append(read.substring(indx + 14, read.length()));
129:                        out.write(sb.toString().getBytes());
130:
131:                        /*int indx = read.indexOf('>');
132:                        while(indx == -1){
133:                            read = br.readLine();
134:                            if(read == null)
135:                                throw new Exception("Error in the XML structure");
136:                            indx = read.indexOf('>');
137:                        }
138:                        if(indx != read.length())
139:                            out.write( read.substring(indx+1, read.length()).getBytes() );*/
140:
141:                    } else {
142:                        out.write(read.getBytes());
143:                    }
144:                    read = br.readLine();
145:                }
146:                br.close();
147:                out.flush();
148:                out.close();
149:                return new FileInputStream(tmp);
150:            }
151:
152:            private static class MyHandler extends DefaultHandler {
153:                private PrintWriter out;
154:
155:                MyHandler(PrintWriter out) {
156:                    this .out = out;
157:                }//constructor
158:
159:                /**
160:                 * Returns a string describing parse exception details
161:                 */
162:                private String getParseExceptionInfo(SAXParseException spe) {
163:                    String systemId = spe.getSystemId();
164:                    if (systemId == null) {
165:                        systemId = "null";
166:                    }
167:                    String info = "URI = " + systemId + " Line = "
168:                            + spe.getLineNumber() + ": " + spe.getMessage();
169:                    return info;
170:                }//getParseExceptionInfo()
171:
172:                /**
173:                 * The following methods are standard SAX ErrorHandler methods.
174:                 * See SAX documentation for more info.
175:                 */
176:                public void warning(SAXParseException spe) throws SAXException {
177:                    String message = "Warning: " + getParseExceptionInfo(spe);
178:                    //Debug.message( message, spe );
179:                    out.println(message);
180:                    throw spe;
181:                }//warning()
182:
183:                public void error(SAXParseException spe) throws SAXException {
184:                    String message = "Error: " + getParseExceptionInfo(spe);
185:                    //Debug.message( message, spe );
186:                    out.println(message);
187:                    throw spe;
188:                }//error()
189:
190:                public void fatalError(SAXParseException spe)
191:                        throws SAXException {
192:                    String message = "Fatal Error: "
193:                            + getParseExceptionInfo(spe);
194:                    //Debug.message( message, spe );
195:                    out.println(message);
196:                    throw spe;
197:                }//fatalError()
198:
199:            }//class MyHandler
200:
201:            public static Attribute getAttribute(String key, String value) {
202:                Attribute attrib = new Attribute();
203:                attrib.setKey(key);
204:                attrib.setValue(value);
205:                return attrib;
206:            }
207:
208:            public static InstAttribute getSRAPInstAttribute(String key,
209:                    ArrayList value) {
210:                InstAttribute attrib = new InstAttribute();
211:                attrib.setKey(key);
212:                attrib.setValue(value);
213:                return attrib;
214:            }
215:
216:            /**
217:             * This method gets the current date and time with the customized pattern.
218:             */
219:            public static String getCurrentDateTime() {
220:                //Get the curernt date
221:                Date date = new Date();
222:                //Get the DateFormat instance
223:                SimpleDateFormat sdf = new SimpleDateFormat(
224:                        "yyyy/MM/dd kk:mm:ss");
225:                //Get the datetime in the required format.
226:                String sDate = sdf.format(date);
227:                return sDate.trim();
228:            }
229:
230:            public static void getReportLogHandle(String reportfile)
231:                    throws Exception {
232:                raf = new RandomAccessFile(reportfile, "rw");
233:                raf.seek(raf.length());
234:            }
235:
236:            public static void writelog(String message) {
237:                try {
238:                    raf.writeChars(message);
239:                } catch (Exception ex) {
240:                    System.out.println(message);
241:                }
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.