Source Code Cross Referenced for recompile.java in  » Library » jakarta-regexp-1.5 » org » apache » regexp » 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 » Library » jakarta regexp 1.5 » org.apache.regexp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.regexp;
019:
020:        import org.apache.regexp.RECompiler;
021:        import org.apache.regexp.RESyntaxException;
022:
023:        /**
024:         * 'recompile' is a command line tool that pre-compiles one or more regular expressions
025:         * for use with the regular expression matcher class 'RE'.  For example, the command
026:         * <code>java org.apache.regexp.recompile re1 "a*b"</code> produces output like this:
027:         *
028:         * <pre>
029:         *
030:         *    // Pre-compiled regular expression 'a*b'
031:         *    private static final char[] re1Instructions =
032:         *    {
033:         *        0x002a, 0x0000, 0x0007, 0x0041, 0x0001, 0xfffd, 0x0061,
034:         *        0x0041, 0x0001, 0x0004, 0x0062, 0x0045, 0x0000, 0x0000,
035:         *    };
036:         *
037:         *    private static final REProgram re1 = new REProgram(re1Instructions);
038:         *
039:         * </pre>
040:         *
041:         * By pasting this output into your code, you can construct a regular expression matcher
042:         * (RE) object directly from the pre-compiled data (the character array re1), thus avoiding
043:         * the overhead of compiling the expression at runtime.  For example:
044:         *
045:         * <pre>
046:         *
047:         *    RE r = new RE(re1);
048:         *
049:         * </pre>
050:         *
051:         * @see RE
052:         * @see RECompiler
053:         *
054:         * @author <a href="mailto:jonl@muppetlabs.com">Jonathan Locke</a>
055:         * @version $Id: recompile.java 518156 2007-03-14 14:31:26Z vgritsenko $
056:         */
057:        public class recompile {
058:            /**
059:             * Main application entrypoint.
060:             *
061:             * @param arg Command line arguments
062:             */
063:            static public void main(String[] arg) {
064:                // Create a compiler object
065:                RECompiler r = new RECompiler();
066:
067:                // Print usage if arguments are incorrect
068:                if (arg.length <= 0 || arg.length % 2 != 0) {
069:                    System.out
070:                            .println("Usage: recompile <patternname> <pattern>");
071:                    System.exit(0);
072:                }
073:
074:                // Loop through arguments, compiling each
075:                for (int i = 0; i < arg.length; i += 2) {
076:                    try {
077:                        // Compile regular expression
078:                        String name = arg[i];
079:                        String pattern = arg[i + 1];
080:                        String instructions = name + "Instructions";
081:
082:                        // Output program as a nice, formatted character array
083:                        System.out
084:                                .print("\n    // Pre-compiled regular expression '"
085:                                        + pattern
086:                                        + "'\n"
087:                                        + "    private static final char[] "
088:                                        + instructions + " = \n    {");
089:
090:                        // Compile program for pattern
091:                        REProgram program = r.compile(pattern);
092:
093:                        // Number of columns in output
094:                        int numColumns = 7;
095:
096:                        // Loop through program
097:                        char[] p = program.getInstructions();
098:                        for (int j = 0; j < p.length; j++) {
099:                            // End of column?
100:                            if ((j % numColumns) == 0) {
101:                                System.out.print("\n        ");
102:                            }
103:
104:                            // Print character as padded hex number
105:                            String hex = Integer.toHexString(p[j]);
106:                            while (hex.length() < 4) {
107:                                hex = "0" + hex;
108:                            }
109:                            System.out.print("0x" + hex + ", ");
110:                        }
111:
112:                        // End of program block
113:                        System.out.println("\n    };");
114:                        System.out
115:                                .println("\n    private static final REProgram "
116:                                        + name
117:                                        + " = new REProgram("
118:                                        + instructions + ");");
119:                    } catch (RESyntaxException e) {
120:                        System.out.println("Syntax error in expression \""
121:                                + arg[i] + "\": " + e.toString());
122:                    } catch (Exception e) {
123:                        System.out.println("Unexpected exception: "
124:                                + e.toString());
125:                    } catch (Error e) {
126:                        System.out.println("Internal error: " + e.toString());
127:                    }
128:                }
129:            }
130:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.