Source Code Cross Referenced for KeTools.java in  » J2EE » WiSerFramework » de » ug2t » kernel » 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 » J2EE » WiSerFramework » de.ug2t.kernel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // @@
002:        // @@
003:        /*
004:         * Wi.Ser Framework
005:         *
006:         * Version: 1.8.1, 20-September-2007  
007:         * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
008:         *
009:         * This library is free software; you can redistribute it and/or
010:         * modify it under the terms of the GNU Lesser General Public
011:         * License as published by the Free Software Foundation; either
012:         * version 2 of the License, or (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
017:         * Lesser General Public License for more details.
018:         *
019:         * You should have received a copy of the GNU Lesser General Public
020:         * License along with this library located in LGPL.txt in the 
021:         * license directory; if not, write to the 
022:         * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023:         * Boston, MA  02111-1307, USA.
024:         * 
025:         * If this agreement does not cover your requirements, please contact us
026:         * via email to get detailed information about the commercial license 
027:         * or our service offerings!
028:         *
029:         */
030:        // @@
031:        package de.ug2t.kernel;
032:
033:        import java.beans.*;
034:        import java.io.*;
035:        import java.nio.channels.*;
036:        import java.util.*;
037:
038:        import javax.servlet.http.*;
039:
040:        import de.ug2t.channel.markup.generic.*;
041:        import de.ug2t.channel.markup.session.*;
042:        import de.ug2t.unifiedGui.interfaces.*;
043:
044:        /**
045:         * @author Dirk
046:         * 
047:         * date: 02.01.2004 project: WiSer-Framework
048:         * 
049:         * <p>
050:         * A set of tools
051:         * </p>
052:         */
053:        public class KeTools {
054:            private static String pem_startPf = "K"
055:                    + Long.toString(new Date().getTime(), Character.MAX_RADIX)
056:                    + "_";
057:            private static IKeDeRefDelegate pem_deRefDelegate = null;
058:
059:            public KeTools() {
060:            }
061:
062:            private static long pem_id = 0;
063:
064:            /**
065:             * <p>
066:             * Sets a delegate method for derefencing variables via pcmf_deRef(String
067:             * xValue)
068:             * </p>
069:             * <p>
070:             * 
071:             * @param xDelegate
072:             *          the delegate class
073:             *          </p>
074:             */
075:            public static void pcmf_setDeRefDelegate(IKeDeRefDelegate xDelegate) {
076:                KeTools.pcmf_setDeRefDelegate(xDelegate);
077:            }
078:
079:            /**
080:             * <p>
081:             * Gets a unique ID as String
082:             * </p>
083:             * <p>
084:             * 
085:             * @returns ID
086:             *          </p>
087:             */
088:            public static synchronized String pcmf_getNewId() {
089:                return (new StringBuffer(pem_startPf).append(Long.toString(
090:                        KeTools.pem_id, Character.MAX_RADIX)).toString());
091:            }
092:
093:            /**
094:             * For internal use only
095:             */
096:            public static final KeStringTemplate pcmf_stringSubst(
097:                    KeStringTemplate xString, String xOrg, String xNew) {
098:                return (xString.pcmf_stringSubst(xOrg, xNew));
099:            }
100:
101:            /**
102:             * For internal use only
103:             */
104:            public static final KeStringTemplate pcmf_stringSubstAppend(
105:                    KeStringTemplate xString, String xOrg, String xNew,
106:                    String xAppend) {
107:                return (xString.pcmf_stringdirectSubst(xOrg, xNew, xAppend));
108:            }
109:
110:            /**
111:             * For internal use only
112:             */
113:            public static final KeStringTemplate pcmf_stringSubst(
114:                    KeStringTemplate xString, String xOrg, KeStringTemplate xNew) {
115:                return (xString.pcmf_stringdirectSubst(xOrg, xNew));
116:            }
117:
118:            /**
119:             * For internal use only
120:             */
121:            public static final KeStringTemplate pcmf_stringSingleSubst(
122:                    KeStringTemplate xString, String xOrg, KeStringTemplate xNew) {
123:                return (xString.pcmf_stringdirectSingleSubst(xOrg, xNew));
124:            }
125:
126:            /**
127:             * For internal use only
128:             */
129:            public static final KeStringTemplate pcmf_stringSingleSubst(
130:                    KeStringTemplate xString, String xOrg, String xNew) {
131:                return (xString.pcmf_stringdirectSingleSubst(xOrg, xNew));
132:            }
133:
134:            /**
135:             * For internal use only
136:             */
137:            public static final String pcmf_stringSubst(String xString,
138:                    String xOrg, String xNew) {
139:                int i_oLen = xOrg.length();
140:                int i_nextSt = 0;
141:                int i_from = 0;
142:                StringBuffer l_res = new StringBuffer(xString.length() * 2);
143:
144:                i_from = i_nextSt;
145:                while (true) {
146:                    i_nextSt = xString.indexOf(xOrg, i_nextSt);
147:                    if (i_nextSt == -1)
148:                        break;
149:
150:                    l_res.append(xString.substring(i_from, i_nextSt));
151:                    l_res.append(xNew);
152:
153:                    i_nextSt = i_from = i_nextSt + i_oLen;
154:                }
155:                l_res.append(xString.substring(i_from, xString.length()));
156:
157:                return (l_res.toString());
158:            }
159:
160:            /**
161:             * <p>
162:             * Returns an ArraList with all tokens of a string
163:             * </p>
164:             * 
165:             * <p>
166:             * 
167:             * @returns ArraList of tokens
168:             * @param xString
169:             *          String to be tokenized
170:             * @param xTokenizer
171:             *          separators
172:             *          </p>
173:             */
174:            public static final ArrayList pcmf_stringTokens(String xString,
175:                    String xTokenizer) {
176:                return (KeTools.pcmf_stringTokens(xString, xTokenizer, 0));
177:            }
178:
179:            /**
180:             * <p>
181:             * Returns an ArraList with all tokens of a string while tokenizing is stopped
182:             * after xTokens have been found
183:             * </p>
184:             * 
185:             * <p>
186:             * 
187:             * @returns ArraList of tokens
188:             * @param xString
189:             *          String to be tokenized
190:             * @param xTokenizer
191:             *          separators
192:             * @param xTokens
193:             *          stop after
194:             *          </p>
195:             */
196:            public static final ArrayList pcmf_stringTokens(String xString,
197:                    String xTokenizer, int xTokens) {
198:                int i_oLen = xTokenizer.length();
199:                int i_nextSt = 0;
200:                int i_from = 0;
201:                ArrayList l_ret = new ArrayList();
202:                int i_cnt = 0;
203:
204:                if (xString.endsWith(xTokenizer) == false)
205:                    xString += xTokenizer;
206:
207:                i_from = i_nextSt;
208:                while (true) {
209:                    i_nextSt = xString.indexOf(xTokenizer, i_nextSt);
210:                    if (i_nextSt == -1)
211:                        break;
212:
213:                    l_ret.add(xString.substring(i_from, i_nextSt));
214:                    i_nextSt = i_from = (i_nextSt + i_oLen);
215:
216:                    if (++i_cnt == xTokens)
217:                        return (l_ret);
218:                }
219:
220:                return (l_ret);
221:            }
222:
223:            /**
224:             * For internal use only
225:             */
226:            public static final String pcmf_stringSingleSubst(String xString,
227:                    String xOrg, String xNew) {
228:                StringBuffer l_res = new StringBuffer(xString.length() * 2);
229:                int l_begin = xString.indexOf(xOrg);
230:                int l_end = l_begin + xOrg.length();
231:
232:                if (l_begin != -1) {
233:                    l_res.append(xString.substring(0, l_begin));
234:                    l_res.append(xNew);
235:                    l_res.append(xString.substring(l_end));
236:                } else
237:                    return (xString);
238:
239:                return (l_res.toString());
240:            };
241:
242:            /**
243:             * For internal use only
244:             */
245:            public static final String pcmf_stringSingleSubstIC(String xString,
246:                    String xOrg, String xNew) {
247:                StringBuffer l_res = new StringBuffer(xString.length() * 2);
248:                int l_begin = xString.toUpperCase().indexOf(xOrg.toUpperCase());
249:                int l_end = l_begin + xOrg.length();
250:
251:                if (l_begin != -1) {
252:                    l_res.append(xString.substring(0, l_begin));
253:                    l_res.append(xNew);
254:                    l_res.append(xString.substring(l_end));
255:                } else
256:                    return (xString);
257:
258:                return (l_res.toString());
259:            };
260:
261:            /**
262:             * For internal use only
263:             */
264:            public static final String pcmf_stringCutParam(
265:                    KeStringWrapper xString, String xParam) {
266:                String l_res = xString.pcm_string;
267:                int l_begin = xString.pcm_string.indexOf(xParam);
268:                int l_end = l_begin + xParam.length();
269:
270:                if (l_begin != -1) {
271:                    l_res = xString.pcm_string.substring(l_end,
272:                            xString.pcm_string.length());
273:                    xString.pcm_string = xString.pcm_string.substring(0,
274:                            l_begin);
275:                }
276:                ;
277:
278:                return (l_res);
279:            };
280:
281:            /**
282:             * For internal use only
283:             */
284:            public static final void pcmf_except(String xLoc, int xNr,
285:                    String xMess, String xPar1, String xPar2) throws Exception {
286:                String except = "[$LOC:$NR] Message:$MESS, [$PAR1, $PAR2]";
287:
288:                except = KeTools.pcmf_stringSubst(except, "$LOC", xLoc);
289:                except = KeTools.pcmf_stringSubst(except, "$NR", Integer
290:                        .toString(xNr));
291:                except = KeTools.pcmf_stringSubst(except, "$MESS", xMess);
292:                except = KeTools.pcmf_stringSubst(except, "$PAR1", xPar1);
293:                except = KeTools.pcmf_stringSubst(except, "$PAR2", xPar2);
294:
295:                throw (new Exception(except));
296:            };
297:
298:            /**
299:             * <p>
300:             * Dereferences a variable (mainly used for internationalisation). This method
301:             * works recursive!
302:             * 
303:             * The string representation of a registered object #[register name]
304:             * 
305:             * or a value from a parameter file which is referenced by %[parameter
306:             * file]:[cluster]:[parameter].
307:             * 
308:             * or the result of a java expression *[scope]:[name].[function].[parameters
309:             * separated by ;]
310:             * 
311:             * while scope is either application (access to a value from the application
312:             * context), registry (access to a registered object) or httpsession (only for
313:             * web applications). The parameters may be references to objects only from
314:             * the registry (~objname) or Strings ==> String(AB), Integers ==> Integer
315:             * (3254236), Floats ==> Float(12.434), Booleans ==> Boolean (false), Long ==>
316:             * Long(375437) and Doubles ==> Double(34.4687).
317:             * 
318:             * null means null. Everything else is interpreted as String. A parameter can
319:             * be any type of variable explained in this chapter.
320:             * 
321:             * ##, %%, ** are the escape sequences for the corresponding special signs.
322:             * 
323:             * </p>
324:             * 
325:             * <p>
326:             * 
327:             * @returns derefenerced value
328:             * @param xValue
329:             *          variable to dereference
330:             * @param xDef
331:             *          default if vairiable is not valid, if null the variable string is
332:             *          returned
333:             *          </p>
334:             */
335:            public static final String pcmf_deRef(String xValue, String xDef) {
336:                if (xValue == null)
337:                    return (xDef);
338:
339:                String l_ret = KeTools.pcmf_deRef(xValue);
340:                if (xValue.equals(l_ret))
341:                    return (xDef);
342:                else
343:                    return (l_ret);
344:            }
345:
346:            /**
347:             * <p>
348:             * Dereferences a variable (mainly used for internationalisation). This method
349:             * works recursive! The string representation of a registered object
350:             * #[register name]
351:             * 
352:             * or a value from a parameter file which is referenced by %[parameter
353:             * file]:[cluster]:[parameter].
354:             * 
355:             * or the result of a java expression *[scope]:[name].[function].[parameters
356:             * separated by ;]
357:             * 
358:             * while scope is either application (access to a value from the application
359:             * context), registry (access to a registered object) or httpsession (only for
360:             * web applications). The parameters may be references to objects only from
361:             * the registry (~objname) or Strings ==> String(AB), Integers ==> Integer
362:             * (3254236), Floats ==> Float(12.434), Booleans ==> Boolean (false), Long ==>
363:             * Long(375437) and Doubles ==> Double(34.4687).
364:             * 
365:             * null means null. Everything else is interpreted as String. A parameter can
366:             * be any type of variable explained in this chapter.
367:             * 
368:             * ##, %%, ** are the escape sequences for the corresponding special signs.
369:             * </p>
370:             * 
371:             * <p>
372:             * 
373:             * @returns derefenerced value
374:             * @param xValue
375:             *          variable to dereference
376:             *          </p>
377:             */
378:            public static final String pcmf_deRef(String xValue) {
379:                // Ggf. Delegate für alternativen Deref Mechanismus
380:                if (KeTools.pem_deRefDelegate != null)
381:                    return (KeTools.pem_deRefDelegate.pcmf_deRef(xValue));
382:
383:                if (xValue == null || xValue.length() <= 0)
384:                    return (xValue);
385:
386:                char l_test = xValue.charAt(0);
387:                if (!(l_test == '#' || l_test == '%' || l_test == '*'))
388:                    return (xValue);
389:
390:                String l_org = xValue;
391:
392:                try {
393:                    byte l_b[] = xValue.getBytes();
394:
395:                    if (l_b[0] == '#' && l_b[1] != '#')
396:                        return (KeRegisteredObject.pcmf_getObjByName(xValue
397:                                .substring(1)).toString());
398:                    else if (l_b[0] == '%' && l_b[1] != '%') {
399:                        xValue = xValue.substring(1);
400:
401:                        StringTokenizer l_tok = new StringTokenizer(xValue,
402:                                ":", false);
403:
404:                        String l_source = l_tok.nextToken();
405:                        l_source = KeTools.pcmf_deRef(l_source);
406:
407:                        String l_cluster = l_tok.nextToken();
408:                        l_cluster = KeTools.pcmf_deRef(l_cluster);
409:
410:                        String l_key = l_tok.nextToken();
411:                        l_key = KeTools.pcmf_deRef(l_key);
412:
413:                        return (KeEnvironment.pcmf_getParameter(l_source,
414:                                l_cluster, l_key).toString());
415:                    } else if (l_b[0] == '*' && l_b[1] != '*') {
416:                        xValue = xValue.substring(1);
417:
418:                        int l_sep = xValue.indexOf(":");
419:                        String l_scope = xValue.substring(0, l_sep);
420:                        xValue = xValue.substring(l_sep + 1);
421:
422:                        l_scope = KeTools.pcmf_deRef(l_scope);
423:
424:                        ArrayList l_tokens = KeTools.pcmf_stringTokens(xValue,
425:                                ".", 3);
426:
427:                        String l_name = l_tokens.get(0).toString();
428:                        l_name = KeTools.pcmf_deRef(l_name);
429:
430:                        String l_prop = l_tokens.get(1).toString();
431:                        l_prop = KeTools.pcmf_deRef(l_prop);
432:
433:                        ArrayList l_params = null;
434:
435:                        if (l_tokens.size() == 3) {
436:                            l_params = new ArrayList();
437:                            String l_parstr = l_tokens.get(2).toString();
438:                            ArrayList l_tassigments = KeTools
439:                                    .pcmf_stringTokens(l_parstr, ";");
440:
441:                            Iterator l_it = l_tassigments.iterator();
442:                            while (l_it.hasNext()) {
443:                                String l_par = l_it.next().toString().trim();
444:
445:                                // Hier muss noch aufgelöst werden boolean, integer, floats, strings
446:                                if (l_par.startsWith("Integer")
447:                                        && l_par.endsWith(")")) {
448:                                    l_par = KeTools.pcmf_stringSubst(l_par,
449:                                            " ", "");
450:                                    l_par = KeTools.pcmf_stringSingleSubst(
451:                                            l_par, "Integer(", "");
452:                                    l_par = KeTools.pcmf_stringSingleSubst(
453:                                            l_par, ")", "");
454:
455:                                    l_params.add(new Integer(l_par));
456:                                } else if (l_par.startsWith("Boolean")
457:                                        && l_par.endsWith(")")) {
458:                                    l_par = KeTools.pcmf_stringSubst(l_par,
459:                                            " ", "");
460:                                    l_par = KeTools.pcmf_stringSingleSubst(
461:                                            l_par, "Boolean(", "");
462:                                    l_par = KeTools.pcmf_stringSingleSubst(
463:                                            l_par, ")", "");
464:
465:                                    l_params.add(new Boolean(l_par));
466:                                } else if (l_par.startsWith("String")
467:                                        && l_par.endsWith(")")) {
468:                                    l_par = l_par.substring(
469:                                            l_par.indexOf("(") + 1, l_par
470:                                                    .lastIndexOf(")"));
471:                                    l_params.add(l_par);
472:                                } else if (l_par.startsWith("Float")
473:                                        && l_par.endsWith(")")) {
474:                                    l_par = KeTools.pcmf_stringSubst(l_par,
475:                                            " ", "");
476:                                    l_par = KeTools.pcmf_stringSingleSubst(
477:                                            l_par, "Float(", "");
478:                                    l_par = KeTools.pcmf_stringSingleSubst(
479:                                            l_par, ")", "");
480:
481:                                    l_params.add(new Float(l_par));
482:                                } else if (l_par.startsWith("Double")
483:                                        && l_par.endsWith(")")) {
484:                                    l_par = KeTools.pcmf_stringSubst(l_par,
485:                                            " ", "");
486:                                    l_par = KeTools.pcmf_stringSingleSubst(
487:                                            l_par, "Double(", "");
488:                                    l_par = KeTools.pcmf_stringSingleSubst(
489:                                            l_par, ")", "");
490:
491:                                    l_params.add(new Double(l_par));
492:                                } else if (l_par.startsWith("Long")
493:                                        && l_par.endsWith(")")) {
494:                                    l_par = KeTools.pcmf_stringSubst(l_par,
495:                                            " ", "");
496:                                    l_par = KeTools.pcmf_stringSingleSubst(
497:                                            l_par, "Long(", "");
498:                                    l_par = KeTools.pcmf_stringSingleSubst(
499:                                            l_par, ")", "");
500:
501:                                    l_params.add(new Long(l_par));
502:                                } else if (KeTools.pcmf_isObjReference(l_par))
503:                                    l_params.add(KeTools.pcmf_deRefObj(l_par));
504:                                else {
505:                                    if (l_par.equalsIgnoreCase("null"))
506:                                        l_params.add(null);
507:                                    else
508:                                        l_params.add(KeTools.pcmf_deRef(l_par));
509:                                }
510:
511:                            }
512:                        }
513:
514:                        Object[] l_pobj = null;
515:                        if (l_params != null)
516:                            l_pobj = l_params.toArray();
517:                        else
518:                            l_pobj = new Object[0];
519:
520:                        if (l_scope.equalsIgnoreCase("registry")) {
521:                            Object o = KeRegisteredObject
522:                                    .pcmf_getObjByName(l_name);
523:                            Expression expr = new Expression(o, l_prop, l_pobj);
524:                            expr.execute();
525:
526:                            return (expr.getValue().toString());
527:                        } else if (l_scope.equalsIgnoreCase("application")) {
528:                            IUnApplication l_appl = (IUnApplication) KeRegisteredObject
529:                                    .pcmf_getObjByName(IUnApplication.MY_APPL);
530:                            Object o = l_appl.pcmf_getContext().get(l_name);
531:                            Expression expr = new Expression(o, l_prop, l_pobj);
532:                            expr.execute();
533:
534:                            return (expr.getValue().toString());
535:                        } else if (l_scope.equalsIgnoreCase("httpsession")) {
536:                            HttpSession l_sess = ((MuHttpSessionWrapper) KeRegisteredObject
537:                                    .pcmf_getObjByName(MuGenericApplication.MY_SESSION))
538:                                    .pcmf_getHttpSesstion();
539:                            if (l_sess == null)
540:                                KeLog.pcmf_log("WiSerFramework",
541:                                        "http session is not available", null,
542:                                        KeLog.ERROR);
543:
544:                            Object o = l_sess.getAttribute(l_prop);
545:                            Expression expr = new Expression(o, l_prop, l_pobj);
546:                            expr.execute();
547:
548:                            return (expr.getValue().toString());
549:                        } else
550:                            KeLog.pcmf_log("ug2t",
551:                                    "reference scope is not valid: " + l_scope,
552:                                    null, KeLog.ERROR);
553:                    } else if (l_b[0] == '%' || l_b[0] == '#' || l_b[0] == '*')
554:                        xValue = xValue.substring(1);
555:                    else
556:                        return (xValue);
557:                } catch (Exception e) {
558:                    return (l_org);
559:                }
560:                return (xValue);
561:            };
562:
563:            /**
564:             * For internal use only
565:             */
566:            public static final Object pcmf_deRefObj(String xValue) {
567:                if (xValue == null || xValue.length() <= 0)
568:                    return (xValue);
569:
570:                char l_test = xValue.charAt(0);
571:                if (l_test != '~')
572:                    return (xValue);
573:
574:                byte l_b[] = xValue.getBytes();
575:
576:                if (l_b[0] == '~' && l_b[1] != '~')
577:                    return (KeRegisteredObject.pcmf_getObjByName(xValue
578:                            .substring(1)));
579:                else if (l_b[0] == '~')
580:                    return (xValue.substring(1));
581:                else
582:                    return (xValue);
583:            };
584:
585:            /**
586:             * For internal use only
587:             */
588:            public static final boolean pcmf_isObjReference(String xValue) {
589:                if (xValue == null)
590:                    return (false);
591:
592:                byte l_b[] = xValue.getBytes();
593:                if (l_b.length <= 1)
594:                    return (false);
595:
596:                if (l_b[0] == '~' && l_b[1] != '~')
597:                    return (true);
598:                else if (l_b[0] == '~')
599:                    return (false);
600:                else
601:                    return (false);
602:            };
603:
604:            /**
605:             * For internal use only
606:             */
607:            public static final String pcmf_array2String(Object xArray[]) {
608:                String l_ret = "";
609:                for (int i = 0; i < xArray.length; i++) {
610:                    l_ret += xArray[i].toString();
611:                    if (i < xArray.length - 1)
612:                        l_ret += ", ";
613:                }
614:
615:                return (l_ret);
616:            }
617:
618:            /**
619:             * For internal use only
620:             */
621:            public static final String pcmf_array2String(Object xArray[],
622:                    int cutIdx) {
623:                String l_ret = "";
624:                for (int i = 0; i < xArray.length; i++) {
625:                    l_ret += xArray[i].toString().substring(cutIdx);
626:                    if (i < xArray.length - 1)
627:                        l_ret += ", ";
628:                }
629:
630:                return (l_ret);
631:            }
632:
633:            /**
634:             * For internal use only
635:             */
636:            public static final String pcmf_array2String(Object xArray[],
637:                    int cutIdx, int xStart, int xEnd) {
638:                String l_ret = "";
639:                for (int i = xStart; i < xArray.length; i++) {
640:                    l_ret += xArray[i].toString().substring(cutIdx);
641:
642:                    if (i == xEnd) {
643:                        l_ret += ", ... ";
644:                        break;
645:                    }
646:
647:                    if (i < xArray.length - 1)
648:                        l_ret += ", ";
649:                }
650:
651:                return (l_ret);
652:            }
653:
654:            /**
655:             * <p>
656:             * Copies the content of one directory to the other. The function works
657:             * recursive
658:             * </p>
659:             * 
660:             * <p>
661:             * 
662:             * @param xSource
663:             *          Source directory
664:             * @param xTarget
665:             *          Target directory
666:             *          </p>
667:             */
668:            public static void pcmf_copyDir(String xSource, String xTarget)
669:                    throws Exception {
670:                File l_source = new File(xSource);
671:                File l_target = new File(xTarget);
672:
673:                if (l_source.isDirectory() == false)
674:                    throw (new FileNotFoundException(xSource));
675:                if (l_target.isDirectory() == false)
676:                    throw (new FileNotFoundException(xTarget));
677:
678:                File l_subs[] = l_source.listFiles();
679:                for (int i = 0; i < l_subs.length; i++) {
680:                    if (l_subs[i].isFile()) {
681:                        File l_new = new File(xTarget, l_subs[i].getName());
682:                        pcmf_copyFile(l_subs[i].getAbsolutePath(), l_new
683:                                .getAbsolutePath());
684:                    } else {
685:                        File l_new = new File(xTarget, l_subs[i].getName());
686:                        if (l_new.exists() == false)
687:                            l_new.mkdir();
688:
689:                        pcmf_copyDir(l_subs[i].getAbsolutePath(), l_new
690:                                .getAbsolutePath());
691:                    }
692:                }
693:            }
694:
695:            /**
696:             * <p>
697:             * Copies files with a defined name from one directory to the other. The
698:             * function works recursive
699:             * </p>
700:             * 
701:             * <p>
702:             * 
703:             * @param xSource
704:             *          Source directory
705:             * @param xTarget
706:             *          Target directory
707:             * @param xFiles
708:             *          File names
709:             * @param xExact
710:             *          true indicates an exact match, false means the string has to be
711:             *          part of the file name
712:             *          </p>
713:             */
714:            public static void pcmf_copyDir(String xSource, String xTarget,
715:                    String[] xFiles, boolean xExact) throws Exception {
716:                File l_source = new File(xSource);
717:                File l_target = new File(xTarget);
718:
719:                if (l_source.isDirectory() == false)
720:                    throw (new FileNotFoundException(xSource));
721:                if (l_target.isDirectory() == false)
722:                    throw (new FileNotFoundException(xTarget));
723:
724:                File l_subs[] = l_source.listFiles();
725:                for (int i = 0; i < l_subs.length; i++) {
726:                    if (l_subs[i].isFile()) {
727:                        String l_name = l_subs[i].getName();
728:                        for (int f = 0; f < xFiles.length; f++) {
729:                            if (xExact) {
730:                                if (xFiles[f].equals(l_name)) {
731:                                    File l_new = new File(xTarget, l_name);
732:                                    pcmf_copyFile(l_subs[i].getAbsolutePath(),
733:                                            l_new.getAbsolutePath());
734:                                }
735:                            } else {
736:                                if (l_name.indexOf(xFiles[f]) != -1) {
737:                                    File l_new = new File(xTarget, l_name);
738:                                    pcmf_copyFile(l_subs[i].getAbsolutePath(),
739:                                            l_new.getAbsolutePath());
740:                                }
741:                            }
742:                        }
743:                    } else {
744:                        File l_new = new File(xTarget, l_subs[i].getName());
745:                        if (l_new.exists() == false)
746:                            l_new.mkdir();
747:
748:                        pcmf_copyDir(l_subs[i].getAbsolutePath(), l_new
749:                                .getAbsolutePath());
750:                    }
751:                }
752:            }
753:
754:            /**
755:             * <p>
756:             * Copies one file to an other
757:             * </p>
758:             * 
759:             * <p>
760:             * 
761:             * @param xSource
762:             *          Source file
763:             * @param xTarget
764:             *          Target file
765:             */
766:            public static void pcmf_copyFile(String xSource, String xTarget)
767:                    throws Exception {
768:                KeLog.pcmf_log("ug2t", "copy file: " + xSource + " to "
769:                        + xTarget, null, KeLog.DEBUG);
770:
771:                FileInputStream l_source = new FileInputStream(xSource);
772:                FileOutputStream l_target = new FileOutputStream(xTarget, false);
773:
774:                FileChannel l_sCh = l_source.getChannel();
775:                FileChannel l_tCh = l_target.getChannel();
776:
777:                l_tCh.transferFrom(l_sCh, 0, l_sCh.size());
778:
779:                l_source.close();
780:                l_target.close();
781:            }
782:
783:            /**
784:             * For internal use only
785:             */
786:            public static String pcmf_getClassName(Class xClass) {
787:                return (xClass.toString().substring(6));
788:            }
789:
790:            public static String pcmf_eventType(String xEvent) {
791:                if (xEvent.indexOf(":") != -1)
792:                    return (xEvent.substring(0, xEvent.indexOf(":")));
793:                else
794:                    return (xEvent);
795:            }
796:
797:            /**
798:             * For internal use only
799:             */
800:            public static int pcmf_getX(String xEvent) {
801:                xEvent = xEvent.substring(xEvent.indexOf(":") + 1, xEvent
802:                        .indexOf("p"));
803:
804:                return (Integer.parseInt(xEvent));
805:            }
806:
807:            /**
808:             * For internal use only
809:             */
810:            public static int pcmf_getY(String xEvent) {
811:                xEvent = xEvent.substring(xEvent.indexOf(",") + 1, xEvent
812:                        .length() - 2);
813:
814:                return (Integer.parseInt(xEvent));
815:            }
816:
817:            /**
818:             * For internal use only
819:             */
820:            public static int pcmf_getWidth(String xEvent) {
821:                xEvent = xEvent.substring(xEvent.indexOf(":") + 1, xEvent
822:                        .indexOf("p"));
823:
824:                return (Integer.parseInt(xEvent));
825:            }
826:
827:            /**
828:             * For internal use only
829:             */
830:            public static int pcmf_getHeight(String xEvent) {
831:                xEvent = xEvent.substring(xEvent.indexOf(",") + 1, xEvent
832:                        .length() - 2);
833:
834:                return (Integer.parseInt(xEvent));
835:            }
836:
837:            /**
838:             * <p>
839:             * Deletes a file or directory. This method works recursive.
840:             * </p>
841:             * 
842:             * <p>
843:             * 
844:             * @param xFile
845:             *          File or directory to delete
846:             * @param xDelThis
847:             *          In case of a directory this indicates whether the directory itself
848:             *          is deleted or only it's content
849:             */
850:            public static void pcmf_deleteFiles(File xFile, boolean xDelThis) {
851:                File l_files[] = xFile.listFiles();
852:                if (l_files != null)
853:                    for (int i = 0; i < l_files.length; i++) {
854:                        if (l_files[i].isDirectory())
855:                            KeTools.pcmf_deleteFiles(l_files[i], false);
856:
857:                        l_files[i].delete();
858:                    }
859:
860:                if (xDelThis)
861:                    xFile.delete();
862:            }
863:
864:            /**
865:             * <p>
866:             * Formats a number with leading 0
867:             * </p>
868:             * <p>
869:             * @param xNumber the int to format
870:             * @param xLen the length
871:             * @return the formatted string
872:             * </p>
873:             */
874:            public static String pcmf_formatNumber(int xNumber, int xLen) {
875:                char[] l_len = Integer.toString(xNumber).toCharArray();
876:                char l_sLen[] = new char[xLen];
877:                Arrays.fill(l_sLen, ('0'));
878:                System.arraycopy(l_len, 0, l_sLen, xLen - l_len.length,
879:                        l_len.length);
880:
881:                return (new String(l_sLen));
882:            }
883:
884:            /**
885:             * <p>
886:             * Builds a regular expression from a string with wildcards *?
887:             * </p>
888:             * <p>
889:             * @param xWildcard wildcard string
890:             * @return regular expression string
891:             * </p>
892:             */
893:            public static String pcmf_wildcardToRegex(String xWildcard) {
894:                StringBuffer s = new StringBuffer(xWildcard.length());
895:                s.append('^');
896:                for (int i = 0, is = xWildcard.length(); i < is; i++) {
897:                    char c = xWildcard.charAt(i);
898:                    switch (c) {
899:                    case '*':
900:                        s.append(".*");
901:                        break;
902:                    case '?':
903:                        s.append(".");
904:                        break;
905:                    // escape special regexp-characters
906:                    case '(':
907:                    case ')':
908:                    case '[':
909:                    case ']':
910:                    case '$':
911:                    case '^':
912:                    case '.':
913:                    case '{':
914:                    case '}':
915:                    case '|':
916:                    case '\\':
917:                        s.append("\\");
918:                        s.append(c);
919:                        break;
920:                    default:
921:                        s.append(c);
922:                        break;
923:                    }
924:                }
925:                s.append('$');
926:                return (s.toString());
927:            }
928:
929:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.