2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
41
package org.netbeans.modules.php.docgen;
43
import java.io.BufferedWriter;
45
import java.io.FileWriter;
46
import java.io.IOException;
47
import java.util.regex.Matcher;
48
import java.util.regex.Pattern;
57
private static final String HTML_POSTFIX = ".html";
62
private static final String H = "h"; // NOI18N
64
private static final Pattern FUNCTION_NAME_PATTERN =
65
Pattern.compile("</[ \t]*a[ \t]*>([^<]*)<\\/[ \t]*h([^>]*)>" ,
66
Pattern.CASE_INSENSITIVE); // NOI18N
68
MethodParser( String methodName , String content, File folder ){
70
myContent = content.trim();
76
void parse() throws WriteException {
77
File folder = getFolder();
78
File file = new File( folder , getFileName() );
82
BufferedWriter writer = null;
84
writer = new BufferedWriter( new FileWriter( file ));
85
writer.write( getContent() );
87
catch (IOException e) {
88
throw new WriteException( "Couldn't write file "+ file , e );
91
if ( writer != null ) {
95
catch (IOException e) {
96
throw new WriteException( "Couldn't close file " +file , e);
102
private void addToIndex() throws WriteException {
103
File file = new File( getFolder() , CategoryParser.INDEX );
104
BufferedWriter writer = null;
106
writer = new BufferedWriter( new FileWriter( file , true) );
107
writer.write( getFileName() );
108
writer.write( '\n' );
110
catch (IOException e) {
111
throw new WriteException( "Couldn't write index file for " + // NOI18N
112
getFolder().getName() , e );
118
catch (IOException e) {
119
throw new WriteException( "Couldn't close index file for "+// NOI18N
120
getFolder().getName() , e );
125
private void initContent() {
126
Matcher matcher = FUNCTION_NAME_PATTERN.matcher(getContent());
127
if ( !matcher.find() || matcher.start()!= 0) {
128
throw new IllegalStateException("Unrecognized method format found, " +
129
"method " +getName());
131
int end = matcher.end();
132
StringBuilder builder = new StringBuilder();
133
String name = matcher.group( 1 ).trim();
134
String headNumber = matcher.group( 2 ).trim();
135
builder.append( CategoriesParser.OPEN_BRACKET );
137
builder.append( headNumber );
138
builder.append( CategoriesParser.CLOSE_BRACKET );
139
builder.append( name );
140
builder.append( CategoriesParser.OPEN_BRACKET );
141
builder.append( '/' );
143
builder.append( headNumber );
144
builder.append( CategoriesParser.CLOSE_BRACKET );
145
builder.append( getContent().substring( end ) );
146
myContent = builder.toString();
149
private String getFileName() {
150
return getName()+HTML_POSTFIX;
153
private String getName() {
157
private String getContent() {
161
private File getFolder() {
165
private String myName;
167
private String myContent;
169
private File myFolder;