Source Code Cross Referenced for NameValueParser.java in  » Database-Client » SQLMinus » util » 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 » Database Client » SQLMinus » util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package util;
002:
003:        import java.io.*;
004:        import java.util.*;
005:        import org.apache.oro.text.regex.*;
006:        import org.apache.oro.text.perl.*;
007:
008:        public class NameValueParser {
009:            Map ht = null;
010:            MultipleMatchModel mmm;
011:            String regexp;
012:
013:            public static void main(String args[]) {
014:                NameValueParser t = new NameValueParser();
015:                try {
016:                    t.mmm = createMultipleMatchModel();
017:                    /*
018:                       PerlWrapper.getMultipleMatches(
019:                       "(?:(\\w+)=(\\S+))", 
020:                       "lines=rett append=true dothis=aaa ", t.mmm);
021:                     */
022:
023:                    PerlWrapper.getMultipleMatches("(?:(\\w+)=(\\S+))",
024:                            "read a.txt lines=1,134 append=true dothis=aaa",
025:                            t.mmm);
026:
027:                } catch (MalformedPatternException exc) {
028:                    System.err.println("EXC:" + exc.toString());
029:                }
030:
031:                t.ht = (Map) t.mmm.getObject();
032:                System.out.println("lines:" + t.getValue("lines"));
033:                System.out.println("append:" + t.getValue("append"));
034:                System.out.println("dothis:" + t.getValue("dothis"));
035:                System.out.println("hta:" + t.getValue("hta"));
036:                System.out.println("htb:" + t.getValue("htb"));
037:
038:                System.out.println("keys...");
039:                Iterator e = t.ht.keySet().iterator();
040:                while (e.hasNext())
041:                    System.out.println(e.next());
042:                System.out.println("values...");
043:                e = t.ht.values().iterator();
044:                while (e.hasNext())
045:                    System.out.println(e.next());
046:
047:            }
048:
049:            /** create default name value parser, using default regexp */
050:            public NameValueParser() {
051:                mmm = createMultipleMatchModel();
052:                regexp = "(?:(\\w+)=(\\S+))";
053:            }
054:
055:            /** create name value parser with customized Model */
056:            public NameValueParser(MultipleMatchModel mmmp) {
057:                mmm = mmmp;
058:                regexp = "(?:(\\w+)=(\\S+))";
059:            }
060:
061:            /** set your own regexp, to override default one */
062:            public void setRegexp(String reg) {
063:                regexp = reg;
064:            }
065:
066:            /** get Hash table or other object based on your mmm, after parsing
067:             * given line. Returns null if your regexp was malformed */
068:            public Object getResults(String line) {
069:                // we should compile and keep this regexp.
070:                try {
071:                    PerlWrapper.getMultipleMatches(regexp, line, mmm);
072:                } catch (MalformedPatternException exc) {
073:                    System.err.println("EXC:" + exc.toString());
074:                    return null;
075:                }
076:                return mmm.getObject();
077:            }
078:
079:            public static MultipleMatchModel createMultipleMatchModel() {
080:                return new MultipleMatchModel() {
081:                    Map ht = new HashMap();
082:                    String key;
083:
084:                    public void setValueAt(String s, int row, int group) {
085:                        //System.out.println(s+":"+ row+":"+group);
086:                        if (group == 1)
087:                            key = s;
088:                        else if (group == 2)
089:                            ht.put(key, s);
090:                    }
091:
092:                    public String getValueAt(int row, int group) {
093:                        return null;
094:                    }
095:
096:                    public Object getObject() {
097:                        return ht;
098:                    }
099:
100:                };
101:
102:            }
103:
104:            public String getValue(String varname) {
105:                return (String) ht.get(varname);
106:            }
107:
108:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.