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


001:        package org.apache.regexp;
002:
003:        /*
004:         * ====================================================================
005:         * 
006:         * The Apache Software License, Version 1.1
007:         *
008:         * Copyright (c) 1999 The Apache Software Foundation.  All rights 
009:         * reserved.
010:         *
011:         * Redistribution and use in source and binary forms, with or without
012:         * modification, are permitted provided that the following conditions
013:         * are met:
014:         *
015:         * 1. Redistributions of source code must retain the above copyright
016:         *    notice, this list of conditions and the following disclaimer. 
017:         *
018:         * 2. Redistributions in binary form must reproduce the above copyright
019:         *    notice, this list of conditions and the following disclaimer in
020:         *    the documentation and/or other materials provided with the
021:         *    distribution.
022:         *
023:         * 3. The end-user documentation included with the redistribution, if
024:         *    any, must include the following acknowlegement:  
025:         *       "This product includes software developed by the 
026:         *        Apache Software Foundation (http://www.apache.org/)."
027:         *    Alternately, this acknowlegement may appear in the software itself,
028:         *    if and wherever such third-party acknowlegements normally appear.
029:         *
030:         * 4. The names "The Jakarta Project", "Jakarta-Regexp", and "Apache Software
031:         *    Foundation" must not be used to endorse or promote products derived
032:         *    from this software without prior written permission. For written 
033:         *    permission, please contact apache@apache.org.
034:         *
035:         * 5. Products derived from this software may not be called "Apache"
036:         *    nor may "Apache" appear in their names without prior written
037:         *    permission of the Apache Group.
038:         *
039:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
040:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
041:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
042:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
043:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
044:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
045:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
046:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
047:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
048:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
049:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
050:         * SUCH DAMAGE.
051:         * ====================================================================
052:         *
053:         * This software consists of voluntary contributions made by many
054:         * individuals on behalf of the Apache Software Foundation.  For more
055:         * information on the Apache Software Foundation, please see
056:         * <http://www.apache.org/>.
057:         *
058:         */
059:
060:        import org.apache.regexp.RECompiler;
061:        import org.apache.regexp.RESyntaxException;
062:
063:        /**
064:         * 'recompile' is a command line tool that pre-compiles one or more regular expressions
065:         * for use with the regular expression matcher class 'RE'.  For example, the command
066:         * "java recompile a*b" produces output like this:
067:         *
068:         * <pre>
069:         *
070:         *    // Pre-compiled regular expression "a*b"
071:         *    char[] re1Instructions =
072:         *    {
073:         *        0x007c, 0x0000, 0x001a, 0x007c, 0x0000, 0x000d, 0x0041,
074:         *        0x0001, 0x0004, 0x0061, 0x007c, 0x0000, 0x0003, 0x0047,
075:         *        0x0000, 0xfff6, 0x007c, 0x0000, 0x0003, 0x004e, 0x0000,
076:         *        0x0003, 0x0041, 0x0001, 0x0004, 0x0062, 0x0045, 0x0000,
077:         *        0x0000,
078:         *    };
079:         *
080:         *    REProgram re1 = new REProgram(re1Instructions);
081:         *
082:         * </pre>
083:         *
084:         * By pasting this output into your code, you can construct a regular expression matcher
085:         * (RE) object directly from the pre-compiled data (the character array re1), thus avoiding
086:         * the overhead of compiling the expression at runtime.  For example:
087:         *
088:         * <pre>
089:         *
090:         *    RE r = new RE(re1);
091:         *
092:         * </pre>
093:         *
094:         * @see RE
095:         * @see RECompiler
096:         *
097:         * @author <a href="mailto:jonl@muppetlabs.com">Jonathan Locke</a>
098:         * @version $Id: recompile.java,v 1.1.1.1 2002/01/31 03:14:37 rcm Exp $
099:         */
100:        public class recompile {
101:            /**
102:             * Main application entrypoint.
103:             * @param arg Command line arguments
104:             */
105:            static public void main(String[] arg) {
106:                // Create a compiler object
107:                RECompiler r = new RECompiler();
108:
109:                // Print usage if arguments are incorrect
110:                if (arg.length <= 0 || arg.length % 2 != 0) {
111:                    System.out
112:                            .println("Usage: recompile <patternname> <pattern>");
113:                    System.exit(0);
114:                }
115:
116:                // Loop through arguments, compiling each
117:                for (int i = 0; i < arg.length; i += 2) {
118:                    try {
119:                        // Compile regular expression
120:                        String name = arg[i];
121:                        String pattern = arg[i + 1];
122:                        String instructions = name + "PatternInstructions";
123:
124:                        // Output program as a nice, formatted character array
125:                        System.out
126:                                .print("\n    // Pre-compiled regular expression '"
127:                                        + pattern
128:                                        + "'\n"
129:                                        + "    private static char[] "
130:                                        + instructions + " = \n    {");
131:
132:                        // Compile program for pattern
133:                        REProgram program = r.compile(pattern);
134:
135:                        // Number of columns in output
136:                        int numColumns = 7;
137:
138:                        // Loop through program
139:                        char[] p = program.getInstructions();
140:                        for (int j = 0; j < p.length; j++) {
141:                            // End of column?
142:                            if ((j % numColumns) == 0) {
143:                                System.out.print("\n        ");
144:                            }
145:
146:                            // Print character as padded hex number
147:                            String hex = Integer.toHexString(p[j]);
148:                            while (hex.length() < 4) {
149:                                hex = "0" + hex;
150:                            }
151:                            System.out.print("0x" + hex + ", ");
152:                        }
153:
154:                        // End of program block
155:                        System.out.println("\n    };");
156:                        System.out.println("\n    private static RE " + name
157:                                + "Pattern = new RE(new REProgram("
158:                                + instructions + "));");
159:                    } catch (RESyntaxException e) {
160:                        System.out.println("Syntax error in expression \""
161:                                + arg[i] + "\": " + e.toString());
162:                    } catch (Exception e) {
163:                        System.out.println("Unexpected exception: "
164:                                + e.toString());
165:                    } catch (Error e) {
166:                        System.out.println("Internal error: " + e.toString());
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.