Source Code Cross Referenced for MethodParser.java in  » IDE-Netbeans » php » org » netbeans » modules » php » docgen » 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 » IDE Netbeans » php » org.netbeans.modules.php.docgen 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        package org.netbeans.modules.php.docgen;
042:
043:        import java.io.BufferedWriter;
044:        import java.io.File;
045:        import java.io.FileWriter;
046:        import java.io.IOException;
047:        import java.util.regex.Matcher;
048:        import java.util.regex.Pattern;
049:
050:        /**
051:         * @author ads
052:         *
053:         */
054:        class MethodParser {
055:
056:            private static final String HTML_POSTFIX = ".html"; // NOI18N
057:
058:            private static final String METHOD_POSTFIX = ".method"; // NOI18N
059:
060:            /*
061:             * Head html tag.
062:             */
063:            private static final String H = "h"; // NOI18N
064:
065:            private static final Pattern FUNCTION_NAME_PATTERN = Pattern
066:                    .compile("</[ \t]*a[ \t]*>([^<]*)<\\/[ \t]*h([^>]*)>",
067:                            Pattern.CASE_INSENSITIVE); // NOI18N
068:
069:            private static final String TYPE_PATTERN = "[\\s>]*([^\\s>]*)\\s*<b\\s+class\\s*=\\s*"
070:                    + "\"methodname\"" + "\\s*>\\s*"; // NOI18N
071:
072:            private static final String ARGS_PATTERN = "\\s*</b\\s*>\\s*(\\([^\\)]*\\))"; // NOI18N
073:
074:            MethodParser(String methodNameId, String content, File folder) {
075:                myNameId = methodNameId;
076:                myContent = content.trim();
077:                myFolder = folder;
078:
079:                initContent();
080:            }
081:
082:            void parse() throws WriteException {
083:                File folder = getFolder();
084:                File file = new File(folder, getFileName());
085:
086:                addToIndex();
087:
088:                writeMethod();
089:
090:                BufferedWriter writer = null;
091:                try {
092:                    writer = new BufferedWriter(new FileWriter(file));
093:                    writer.write(getContent());
094:                } catch (IOException e) {
095:                    throw new WriteException("Couldn't write file " + file, e);
096:                } finally {
097:                    if (writer != null) {
098:                        try {
099:                            writer.close();
100:                        } catch (IOException e) {
101:                            throw new WriteException("Couldn't close file "
102:                                    + file, e);
103:                        }
104:                    }
105:                }
106:            }
107:
108:            private void writeMethod() throws WriteException {
109:                writeMethodField(myDocName);
110:                writeMethodField(myType);
111:                writeMethodField(myArguments);
112:            }
113:
114:            private void writeMethodField(String field) throws WriteException {
115:                File file = new File(getFolder(), getMethodName());
116:                BufferedWriter writer = null;
117:                try {
118:                    writer = new BufferedWriter(new FileWriter(file, true));
119:                    if (field != null) {
120:                        writer.write(field);
121:                    }
122:                    writer.newLine();
123:                } catch (IOException e) {
124:                    throw new WriteException(
125:                            "Couldn't write method structure file for " + // NOI18N
126:                                    myNameId + " method ", e);
127:                } finally {
128:                    try {
129:                        writer.close();
130:                    } catch (IOException e) {
131:                        throw new WriteException(
132:                                "Couldn't close method name file for " + // NOI18N
133:                                        myNameId, e);
134:                    }
135:                }
136:            }
137:
138:            private void addToIndex() throws WriteException {
139:                File file = new File(getFolder(), CategoryParser.INDEX);
140:                BufferedWriter writer = null;
141:                try {
142:                    writer = new BufferedWriter(new FileWriter(file, true));
143:                    writer.write(getFileName());
144:                    writer.write('\n');
145:                } catch (IOException e) {
146:                    throw new WriteException("Couldn't write index file for " + // NOI18N
147:                            getFolder().getName(), e);
148:                } finally {
149:                    try {
150:                        writer.close();
151:                    } catch (IOException e) {
152:                        throw new WriteException(
153:                                "Couldn't close index file for " + // NOI18N 
154:                                        getFolder().getName(), e);
155:                    }
156:                }
157:            }
158:
159:            private void initContent() {
160:                Matcher matcher = FUNCTION_NAME_PATTERN.matcher(getContent());
161:                if (!matcher.find() || matcher.start() != 0) {
162:                    throw new IllegalStateException(
163:                            "Unrecognized method format found, " + "method "
164:                                    + getNameId());
165:                }
166:                int end = matcher.end();
167:                StringBuilder builder = new StringBuilder();
168:                String name = matcher.group(1).trim();
169:                String headNumber = matcher.group(2).trim();
170:                builder.append(CategoriesParser.OPEN_BRACKET);
171:                builder.append(H);
172:                builder.append(headNumber);
173:                builder.append(CategoriesParser.CLOSE_BRACKET);
174:                builder.append(name);
175:                builder.append(CategoriesParser.OPEN_BRACKET);
176:                builder.append('/');
177:                builder.append(H);
178:                builder.append(headNumber);
179:                builder.append(CategoriesParser.CLOSE_BRACKET);
180:                builder.append(getContent().substring(end));
181:                myContent = builder.toString();
182:
183:                Pattern pattern = Pattern.compile(TYPE_PATTERN + name
184:                        + ARGS_PATTERN, Pattern.CASE_INSENSITIVE);
185:                matcher = pattern.matcher(getContent());
186:                if (matcher.find()) {
187:                    myType = matcher.group(1).trim();
188:                    myArguments = matcher.group(2).trim();
189:                }
190:
191:                myDocName = name;
192:            }
193:
194:            private String getFileName() {
195:                return getNameId() + HTML_POSTFIX;
196:            }
197:
198:            private String getMethodName() {
199:                return getNameId() + METHOD_POSTFIX;
200:            }
201:
202:            private String getNameId() {
203:                return myNameId;
204:            }
205:
206:            private String getContent() {
207:                return myContent;
208:            }
209:
210:            private File getFolder() {
211:                return myFolder;
212:            }
213:
214:            private String myNameId;
215:
216:            private String myContent;
217:
218:            private File myFolder;
219:
220:            private String myDocName;
221:
222:            private String myType;
223:
224:            private String myArguments;
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.