Source Code Cross Referenced for StripLineComments.java in  » Build » ANT » org » apache » tools » ant » filters » 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 » Build » ANT » org.apache.tools.ant.filters 
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.tools.ant.filters;
019:
020:        import java.io.IOException;
021:        import java.io.Reader;
022:        import java.util.Vector;
023:        import org.apache.tools.ant.types.Parameter;
024:
025:        /**
026:         * This filter strips line comments.
027:         *
028:         * Example:
029:         *
030:         * <pre>&lt;striplinecomments&gt;
031:         *   &lt;comment value=&quot;#&quot;/&gt;
032:         *   &lt;comment value=&quot;--&quot;/&gt;
033:         *   &lt;comment value=&quot;REM &quot;/&gt;
034:         *   &lt;comment value=&quot;rem &quot;/&gt;
035:         *   &lt;comment value=&quot;//&quot;/&gt;
036:         * &lt;/striplinecomments&gt;</pre>
037:         *
038:         * Or:
039:         *
040:         * <pre>&lt;filterreader
041:         *      classname=&quot;org.apache.tools.ant.filters.StripLineComments&quot;&gt;
042:         *   &lt;param type=&quot;comment&quot; value="#&quot;/&gt;
043:         *   &lt;param type=&quot;comment&quot; value=&quot;--&quot;/&gt;
044:         *   &lt;param type=&quot;comment&quot; value=&quot;REM &quot;/&gt;
045:         *   &lt;param type=&quot;comment&quot; value=&quot;rem &quot;/&gt;
046:         *   &lt;param type=&quot;comment&quot; value=&quot;//&quot;/&gt;
047:         * &lt;/filterreader&gt;</pre>
048:         *
049:         */
050:        public final class StripLineComments extends BaseParamFilterReader
051:                implements  ChainableReader {
052:            /** Parameter name for the comment prefix. */
053:            private static final String COMMENTS_KEY = "comment";
054:
055:            /** Vector that holds the comment prefixes. */
056:            private Vector comments = new Vector();
057:
058:            /** The line that has been read ahead. */
059:            private String line = null;
060:
061:            /**
062:             * Constructor for "dummy" instances.
063:             *
064:             * @see BaseFilterReader#BaseFilterReader()
065:             */
066:            public StripLineComments() {
067:                super ();
068:            }
069:
070:            /**
071:             * Creates a new filtered reader.
072:             *
073:             * @param in A Reader object providing the underlying stream.
074:             *           Must not be <code>null</code>.
075:             */
076:            public StripLineComments(final Reader in) {
077:                super (in);
078:            }
079:
080:            /**
081:             * Returns the next character in the filtered stream, only including
082:             * lines from the original stream which don't start with any of the
083:             * specified comment prefixes.
084:             *
085:             * @return the next character in the resulting stream, or -1
086:             * if the end of the resulting stream has been reached
087:             *
088:             * @exception IOException if the underlying stream throws an IOException
089:             * during reading
090:             */
091:            public int read() throws IOException {
092:                if (!getInitialized()) {
093:                    initialize();
094:                    setInitialized(true);
095:                }
096:
097:                int ch = -1;
098:
099:                if (line != null) {
100:                    ch = line.charAt(0);
101:                    if (line.length() == 1) {
102:                        line = null;
103:                    } else {
104:                        line = line.substring(1);
105:                    }
106:                } else {
107:                    line = readLine();
108:                    final int commentsSize = comments.size();
109:
110:                    while (line != null) {
111:                        for (int i = 0; i < commentsSize; i++) {
112:                            String comment = (String) comments.elementAt(i);
113:                            if (line.startsWith(comment)) {
114:                                line = null;
115:                                break;
116:                            }
117:                        }
118:
119:                        if (line == null) {
120:                            // line started with comment
121:                            line = readLine();
122:                        } else {
123:                            break;
124:                        }
125:                    }
126:
127:                    if (line != null) {
128:                        return read();
129:                    }
130:                }
131:
132:                return ch;
133:            }
134:
135:            /**
136:             * Adds a <code>comment</code> element to the list of prefixes.
137:             *
138:             * @param comment The <code>comment</code> element to add to the
139:             * list of comment prefixes to strip. Must not be <code>null</code>.
140:             */
141:            public void addConfiguredComment(final Comment comment) {
142:                comments.addElement(comment.getValue());
143:            }
144:
145:            /**
146:             * Sets the list of comment prefixes to strip.
147:             *
148:             * @param comments A list of strings, each of which is a prefix
149:             * for a comment line. Must not be <code>null</code>.
150:             */
151:            private void setComments(final Vector comments) {
152:                this .comments = comments;
153:            }
154:
155:            /**
156:             * Returns the list of comment prefixes to strip.
157:             *
158:             * @return the list of comment prefixes to strip.
159:             */
160:            private Vector getComments() {
161:                return comments;
162:            }
163:
164:            /**
165:             * Creates a new StripLineComments using the passed in
166:             * Reader for instantiation.
167:             *
168:             * @param rdr A Reader object providing the underlying stream.
169:             *            Must not be <code>null</code>.
170:             *
171:             * @return a new filter based on this configuration, but filtering
172:             *         the specified reader
173:             */
174:            public Reader chain(final Reader rdr) {
175:                StripLineComments newFilter = new StripLineComments(rdr);
176:                newFilter.setComments(getComments());
177:                newFilter.setInitialized(true);
178:                return newFilter;
179:            }
180:
181:            /**
182:             * Parses the parameters to set the comment prefixes.
183:             */
184:            private void initialize() {
185:                Parameter[] params = getParameters();
186:                if (params != null) {
187:                    for (int i = 0; i < params.length; i++) {
188:                        if (COMMENTS_KEY.equals(params[i].getType())) {
189:                            comments.addElement(params[i].getValue());
190:                        }
191:                    }
192:                }
193:            }
194:
195:            /**
196:             * The class that holds a comment representation.
197:             */
198:            public static class Comment {
199:
200:                /** The prefix for a line comment. */
201:                private String value;
202:
203:                /**
204:                 * Sets the prefix for this type of line comment.
205:                 *
206:                 * @param comment The prefix for a line comment of this type.
207:                 * Must not be <code>null</code>.
208:                 */
209:                public final void setValue(String comment) {
210:                    value = comment;
211:                }
212:
213:                /**
214:                 * Returns the prefix for this type of line comment.
215:                 *
216:                 * @return the prefix for this type of line comment.
217:                 */
218:                public final String getValue() {
219:                    return value;
220:                }
221:            }
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.