Source Code Cross Referenced for BASE.java in  » XML » activexml » org » xdev » base » core » 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 » XML » activexml » org.xdev.base.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Jun 6, 2003
003:         *
004:         * To change the template for this generated file go to
005:         * Window>Preferences>Java>Code Generation>Code and Comments
006:         */
007:        package org.xdev.base.core;
008:
009:        /**
010:         * @author AYegorov
011:         *
012:         * To change the template for this generated type comment go to
013:         * Window>Preferences>Java>Code Generation>Code and Comments
014:         */
015:        import org.xdev.base.core.object.*;
016:        import org.xdev.base.log.*;
017:
018:        import java.util.*;
019:        import java.util.regex.Matcher;
020:        import java.util.regex.Pattern;
021:        import java.io.*;
022:
023:        import java.lang.reflect.*;
024:
025:        import org.jdom.*;
026:        import org.jdom.input.*;
027:        import org.jdom.output.*;
028:
029:        import org.apache.log4j.*;
030:
031:        public class BASE {
032:            private static Logger logger = Logger.getLogger("system");
033:
034:            public static Object newObjectFromClass(String className,
035:                    Class[] parameterClasses, Object[] parameterValues)
036:                    throws Exception {
037:                Class cls = Class.forName(className);
038:                Constructor c = cls.getConstructor(parameterClasses);
039:
040:                cls = null;
041:
042:                return c.newInstance(parameterValues);
043:
044:            }
045:
046:            public static String getValueFromObject(Object obj) {
047:                String value = "";
048:
049:                if (obj instanceof  Configuration) {
050:                    value = ((Configuration) obj).getProperty("value");
051:                } else if (obj instanceof  ArrayList) {
052:                    java.lang.StringBuffer buffer = new java.lang.StringBuffer();
053:                    ArrayList list = (ArrayList) obj;
054:                    int size = list.size();
055:                    for (int i = 0; i < size; i++) {
056:                        Object o = list.get(i);
057:                        buffer.append("Value ").append(i).append(":");
058:                        if (o != null) {
059:                            buffer.append(o.toString());
060:                        } else {
061:                            buffer.append("");
062:                        }
063:                        buffer.append("\n");
064:                    }
065:                    value = buffer.toString();
066:                    buffer = null;
067:                    list = null;
068:                } else if (obj instanceof  HashMap) {
069:                    value = ((HashMap) obj).toString();
070:                } else if (obj instanceof  Exception) {
071:                    java.lang.StringBuffer buffer = new java.lang.StringBuffer();
072:                    try {
073:                        Exception ex = (Exception) obj;
074:                        ByteArrayOutputStream out = new ByteArrayOutputStream();
075:                        ex.printStackTrace(new PrintStream(out));
076:                        byte[] bytes = out.toByteArray();
077:                        for (int i = 0; i < bytes.length; i++) {
078:                            buffer.append((char) bytes[i]);
079:                        }
080:                        out.close();
081:                        bytes = null;
082:                        out = null;
083:                    } catch (Exception ex) {
084:                    }
085:                    value = buffer.toString();
086:                    buffer = null;
087:
088:                } else if (obj instanceof  File) {
089:                    try {
090:                        BufferedReader reader = new BufferedReader(
091:                                new FileReader((File) obj));
092:
093:                        String line = null;
094:
095:                        StringBuffer buffer = new StringBuffer();
096:
097:                        while ((line = reader.readLine()) != null) {
098:                            buffer.append(line).append("\n");
099:                        }
100:
101:                        value = buffer.toString();
102:                    } catch (Exception ex) {
103:                        LoggerWriter.log(ex, Level.ERROR_INT, BASE.class);
104:                    }
105:
106:                } else if (obj != null) {
107:                    value = obj.toString();
108:                }
109:                obj = null;
110:
111:                return value;
112:            }
113:
114:            public static File getFile(String path, Class cls) {
115:                java.net.URL url = cls.getResource(path);
116:                File f = null;
117:                if (url != null) {
118:                    f = new File(url.getPath());
119:                } else {
120:                    f = getFile(path);
121:                }
122:                url = null;
123:
124:                return f;
125:            }
126:
127:            public static File getFile(String path) {
128:                String classPath = System.getProperty("java.class.path");
129:
130:                String div = System.getProperty("path.separator");
131:                path = getFormattedPath(path);
132:                StringTokenizer tokens = new StringTokenizer(classPath, div);
133:                File f = null;
134:                while (tokens.hasMoreTokens()) {
135:                    String fullPath = tokens.nextToken() + path;
136:                    //System.out.println("Trying resource at path: "+fullPath);
137:                    f = new File(fullPath);
138:                    if (f.exists()) {
139:                        //System.out.println("Resource has been found: "+f.getPath());
140:                        break;
141:                    }
142:                }
143:
144:                return f;
145:            }
146:
147:            public static String getFormattedPath(String path) {
148:                String slash = System.getProperty("file.separator");
149:                if (!path.startsWith(slash)) {
150:                    String tempSlash = null;
151:                    if (slash.equals("/")) {
152:                        tempSlash = "\\";
153:                    } else if (slash.equals("\\")) {
154:                        tempSlash = "/";
155:                    }
156:                    if (path.startsWith(tempSlash)) {
157:                        path = slash + path.substring(1, path.length());
158:                    } else {
159:                        path = slash + path;
160:                    }
161:                }
162:
163:                return path;
164:            }
165:
166:            public static String getFormattedXml(String xml) {
167:                SAXBuilder builder = null;
168:                XMLOutputter out = null;
169:                Document doc = null;
170:
171:                try {
172:                    builder = new SAXBuilder();
173:
174:                    out = new XMLOutputter();
175:                    out.setTextTrim(true);
176:                    out.setTrimAllWhite(true);
177:
178:                    doc = builder.build(new StringReader(xml));
179:
180:                    xml = out.outputString(doc);
181:                } catch (Exception ex) {
182:                    logger.error(ex);
183:                } finally {
184:                    builder = null;
185:                    out = null;
186:                    doc = null;
187:                }
188:
189:                return xml;
190:            }
191:
192:            public static boolean partialMatch(String exp, String text) {
193:                boolean pass = false;
194:
195:                try {
196:                    Pattern p = Pattern.compile(exp);
197:                    Matcher m = p.matcher(text);
198:
199:                    pass = m.find();
200:                } catch (Exception ex) {
201:                    pass = false;
202:                }
203:
204:                return pass;
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.