Source Code Cross Referenced for Match.java in  » XML » xerces-2_9_1 » org » apache » xerces » impl » xpath » regex » 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 » XML » xerces 2_9_1 » org.apache.xerces.impl.xpath.regex 
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.xerces.impl.xpath.regex;
019:
020:        import java.text.CharacterIterator;
021:
022:        /**
023:         * An instance of this class has ranges captured in matching.
024:         * 
025:         * @xerces.internal
026:         *
027:         * @see RegularExpression#matches(char[], int, int, Match)
028:         * @see RegularExpression#matches(char[], Match)
029:         * @see RegularExpression#matches(java.text.CharacterIterator, Match)
030:         * @see RegularExpression#matches(java.lang.String, int, int, Match)
031:         * @see RegularExpression#matches(java.lang.String, Match)
032:         * @author TAMURA Kent <kent@trl.ibm.co.jp>
033:         * @version $Id: Match.java 446721 2006-09-15 20:35:34Z mrglavas $
034:         */
035:        public class Match implements  Cloneable {
036:            int[] beginpos = null;
037:            int[] endpos = null;
038:            int nofgroups = 0;
039:
040:            CharacterIterator ciSource = null;
041:            String strSource = null;
042:            char[] charSource = null;
043:
044:            /**
045:             * Creates an instance.
046:             */
047:            public Match() {
048:            }
049:
050:            /**
051:             *
052:             */
053:            public synchronized Object clone() {
054:                Match ma = new Match();
055:                if (this .nofgroups > 0) {
056:                    ma.setNumberOfGroups(this .nofgroups);
057:                    if (this .ciSource != null)
058:                        ma.setSource(this .ciSource);
059:                    if (this .strSource != null)
060:                        ma.setSource(this .strSource);
061:                    for (int i = 0; i < this .nofgroups; i++) {
062:                        ma.setBeginning(i, this .getBeginning(i));
063:                        ma.setEnd(i, this .getEnd(i));
064:                    }
065:                }
066:                return ma;
067:            }
068:
069:            /**
070:             *
071:             */
072:            protected void setNumberOfGroups(int n) {
073:                int oldn = this .nofgroups;
074:                this .nofgroups = n;
075:                if (oldn <= 0 || oldn < n || n * 2 < oldn) {
076:                    this .beginpos = new int[n];
077:                    this .endpos = new int[n];
078:                }
079:                for (int i = 0; i < n; i++) {
080:                    this .beginpos[i] = -1;
081:                    this .endpos[i] = -1;
082:                }
083:            }
084:
085:            /**
086:             *
087:             */
088:            protected void setSource(CharacterIterator ci) {
089:                this .ciSource = ci;
090:                this .strSource = null;
091:                this .charSource = null;
092:            }
093:
094:            /**
095:             *
096:             */
097:            protected void setSource(String str) {
098:                this .ciSource = null;
099:                this .strSource = str;
100:                this .charSource = null;
101:            }
102:
103:            /**
104:             *
105:             */
106:            protected void setSource(char[] chars) {
107:                this .ciSource = null;
108:                this .strSource = null;
109:                this .charSource = chars;
110:            }
111:
112:            /**
113:             *
114:             */
115:            protected void setBeginning(int index, int v) {
116:                this .beginpos[index] = v;
117:            }
118:
119:            /**
120:             *
121:             */
122:            protected void setEnd(int index, int v) {
123:                this .endpos[index] = v;
124:            }
125:
126:            /**
127:             * Return the number of regular expression groups.
128:             * This method returns 1 when the regular expression has no capturing-parenthesis.
129:             */
130:            public int getNumberOfGroups() {
131:                if (this .nofgroups <= 0)
132:                    throw new IllegalStateException("A result is not set.");
133:                return this .nofgroups;
134:            }
135:
136:            /**
137:             * Return a start position in the target text matched to specified regular expression group.
138:             *
139:             * @param index Less than <code>getNumberOfGroups()</code>.
140:             */
141:            public int getBeginning(int index) {
142:                if (this .beginpos == null)
143:                    throw new IllegalStateException("A result is not set.");
144:                if (index < 0 || this .nofgroups <= index)
145:                    throw new IllegalArgumentException(
146:                            "The parameter must be less than " + this .nofgroups
147:                                    + ": " + index);
148:                return this .beginpos[index];
149:            }
150:
151:            /**
152:             * Return an end position in the target text matched to specified regular expression group.
153:             *
154:             * @param index Less than <code>getNumberOfGroups()</code>.
155:             */
156:            public int getEnd(int index) {
157:                if (this .endpos == null)
158:                    throw new IllegalStateException("A result is not set.");
159:                if (index < 0 || this .nofgroups <= index)
160:                    throw new IllegalArgumentException(
161:                            "The parameter must be less than " + this .nofgroups
162:                                    + ": " + index);
163:                return this .endpos[index];
164:            }
165:
166:            /**
167:             * Return an substring of the target text matched to specified regular expression group.
168:             *
169:             * @param index Less than <code>getNumberOfGroups()</code>.
170:             */
171:            public String getCapturedText(int index) {
172:                if (this .beginpos == null)
173:                    throw new IllegalStateException(
174:                            "match() has never been called.");
175:                if (index < 0 || this .nofgroups <= index)
176:                    throw new IllegalArgumentException(
177:                            "The parameter must be less than " + this .nofgroups
178:                                    + ": " + index);
179:                String ret;
180:                int begin = this .beginpos[index], end = this .endpos[index];
181:                if (begin < 0 || end < 0)
182:                    return null;
183:                if (this .ciSource != null) {
184:                    ret = REUtil.substring(this .ciSource, begin, end);
185:                } else if (this .strSource != null) {
186:                    ret = this .strSource.substring(begin, end);
187:                } else {
188:                    ret = new String(this.charSource, begin, end - begin);
189:                }
190:                return ret;
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.