Source Code Cross Referenced for PredTableParser.java in  » Science » Cougaar12_4 » org » cougaar » planning » servlet » 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 » Science » Cougaar12_4 » org.cougaar.planning.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * <copyright>
004:         *  
005:         *  Copyright 1997-2004 BBNT Solutions, LLC
006:         *  under sponsorship of the Defense Advanced Research Projects
007:         *  Agency (DARPA).
008:         * 
009:         *  You can redistribute this software and/or modify it under the
010:         *  terms of the Cougaar Open Source License as published on the
011:         *  Cougaar Open Source Website (www.cougaar.org).
012:         * 
013:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
014:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
015:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
016:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
017:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
018:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
019:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
020:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
021:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
022:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
023:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
024:         *  
025:         * </copyright>
026:         */
027:        package org.cougaar.planning.servlet;
028:
029:        import java.io.BufferedReader;
030:        import java.io.IOException;
031:        import java.io.InputStream;
032:        import java.io.InputStreamReader;
033:        import java.io.Reader;
034:        import java.io.StringReader;
035:
036:        import org.cougaar.core.servlet.ServletUtil;
037:        import org.cougaar.util.PropertyTree;
038:
039:        /**
040:         * Parser for the <code>PlanViewServlet</code>'s "Advanced Search" 
041:         * loading of the built-in predicates.
042:         *
043:         * @see #parse(BufferedReader) for input stream format
044:         */
045:        public class PredTableParser {
046:
047:            /** @see #parse(BufferedReader) */
048:            public static final PropertyTree parse(InputStream in) {
049:                return parse(new BufferedReader(new InputStreamReader(in)));
050:            }
051:
052:            /** @see #parse(BufferedReader) */
053:            public static final PropertyTree parse(Reader in) {
054:                return parse(new BufferedReader(in));
055:            }
056:
057:            /**
058:             * Parse the input to build a PropertyTree of encoded predicates
059:             * for the <code>PlanViewServlet</code>'s "Advanced Search" page.
060:             * <pre>
061:             * Expected file format is:
062:             *
063:             *   Entry separator lines start with "***"
064:             *
065:             *   Comment lines start with "**" and then can contain additional 
066:             *     characters (except having the third char be "*", since this
067:             *     would confuse things with the entry separator)
068:             *
069:             *   Entries must have at least two lines or they are ignored.  They
070:             *     must be prefixed AND followed by "***" lines.
071:             *
072:             *   The first line is the "key", and the following lines make the
073:             *     "value".  These are encoded with 
074:             *     <tt>ServletUtil.encodeForHTML</tt> and 
075:             *     <tt>ServletUtil.encodeForJava</tt> 
076:             *     to let the PlanViewServlet print them in HTML and Javascript.
077:             * </pre>
078:             * @see #main(String[]) for an example
079:             */
080:            public static final PropertyTree parse(BufferedReader in) {
081:                PropertyTree pt = new PropertyTree();
082:                try {
083:                    // read entries
084:                    readEntries: while (true) {
085:                        // read the key line
086:                        String rawKey = in.readLine();
087:                        if (rawKey == null) {
088:                            // end of input
089:                            break readEntries;
090:                        }
091:                        if (rawKey.startsWith("**")) {
092:                            // ignore comment or empty entry
093:                            continue readEntries;
094:                        }
095:                        // read the value lines
096:                        String rawValue = null;
097:                        readValue: while (true) {
098:                            String s = in.readLine();
099:                            if (s == null) {
100:                                // end of input
101:                                break readEntries;
102:                            }
103:                            if (!(s.startsWith("**"))) {
104:                                // value line, typical case
105:                                if (rawValue != null) {
106:                                    rawValue += "\n" + s;
107:                                } else {
108:                                    rawValue = s;
109:                                }
110:                            } else {
111:                                // control line
112:                                if ((s.length() <= 2) || (s.charAt(2) != '*')) {
113:                                    // comment  ("**?");
114:                                    continue readValue;
115:                                } else {
116:                                    // end entry ("***");
117:                                    if (rawValue != null) {
118:                                        break readValue;
119:                                    } else {
120:                                        // ignore 
121:                                        break readEntries;
122:                                    }
123:                                }
124:                            }
125:                        }
126:                        // encode the key and value for javascript use
127:                        String encKey = ServletUtil.encodeForHTML(rawKey);
128:                        String encValue = ServletUtil.encodeForJava(rawValue);
129:                        // add to property tree
130:                        pt.put(encKey, encValue);
131:                    }
132:                    in.close();
133:                } catch (IOException ioe) {
134:                    System.err
135:                            .println("Unable to parse PlanViewServlet's predicates: "
136:                                    + ioe);
137:                }
138:                return pt;
139:            }
140:
141:            /** testing utility, plus illustrates file format. */
142:            public static void main(String[] args) {
143:                String s = "******" + "\n** comment " + "\n**" + "\n***"
144:                        + "\n******" + "\nkey" + "\nvalue" + "\n******"
145:                        + "\ncomplex (x < \"foo\" > z) \\ endKey"
146:                        + "\n**comment" + "\n// java comment" + "\n//"
147:                        + "\n/* another java comment \"here\"*/" + "\n"
148:                        + "\nvalue" + "\n(y < \"z\")"
149:                        + "\n  ** not a comment \\ here"
150:                        + "\n  *** not the end of the entry"
151:                        + "\n  more junk > blah"
152:                        + "\nkeep double-encoded: \\\" \\n" + "\n" + "\nend..."
153:                        + "\n***";
154:                System.out.println("Test with:\n" + s);
155:                // can replace this deprecated input with something newer...
156:                StringReader srin = new StringReader(s);
157:                // parse!
158:                PropertyTree pt = parse(srin);
159:                int n = pt.size();
160:                System.out.println("Parsed[" + n + "]");
161:                for (int i = 0; i < n; i++) {
162:                    String ki = (String) pt.getKey(i);
163:                    String vi = (String) pt.getValue(i);
164:                    System.out.println(i + ")");
165:                    System.out.println("  key=|" + ki + "|");
166:                    System.out.println("  value=|" + vi + "|");
167:                }
168:            }
169:
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.