001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */
022:
023: import com.liferay.portlet.mail.util.*;
024: import com.liferay.util.*;
025: import com.liferay.util.xml.*;
026:
027: import de.hunsicker.jalopy.storage.*;
028:
029: import java.awt.image.*;
030:
031: import java.io.*;
032:
033: import java.lang.reflect.*;
034:
035: import java.net.*;
036:
037: import java.sql.*;
038:
039: import java.util.*;
040:
041: import javax.imageio.*;
042:
043: import net.jmge.gif.Gif89Encoder;
044:
045: import org.apache.oro.text.perl.Perl5Util;
046:
047: import org.apache.tools.ant.DirectoryScanner;
048:
049: import org.jdom.*;
050: import org.jdom.input.*;
051:
052: /**
053: * <a href="Test.java.html"><b><i>View Source</i></b></a>
054: *
055: * @author Brian Wing Shun Chan
056: *
057: */
058: public class Test {
059:
060: public static void main(String[] args) {
061: try {
062: Convention convention = Convention.getInstance();
063:
064: convention.putBoolean(ConventionKeys.SORT, false);
065:
066: convention.putInt(ConventionKeys.BLANK_LINES_AFTER_HEADER,
067: 1);
068: convention.putBoolean(ConventionKeys.HEADER, true);
069: convention.put(ConventionKeys.HEADER_TEXT, FileUtil
070: .read("../copyright.txt"));
071:
072: convention.putInt(ConventionKeys.BLANK_LINES_AFTER_IMPORT,
073: 1);
074:
075: convention.putInt(ConventionKeys.INDENT_SIZE_TABS, 4);
076: convention
077: .putBoolean(ConventionKeys.INDENT_WITH_TABS, true);
078:
079: convention.putBoolean(
080: ConventionKeys.INSERT_TRAILING_NEWLINE, false);
081:
082: convention.putBoolean(ConventionKeys.BRACE_NEWLINE_RIGHT,
083: true);
084: convention.putInt(
085: ConventionKeys.INDENT_SIZE_BRACE_RIGHT_AFTER, 0);
086:
087: convention.putBoolean(ConventionKeys.SPACE_AFTER_CAST,
088: false);
089:
090: /*
091: convention.putInt(ConventionKeys.BLANK_LINES_AFTER_BRACE_LEFT, 1);
092: //convention.putInt(ConventionKeys.BLANK_LINES_AFTER_CLASS, 1);
093: //convention.putInt(ConventionKeys.BLANK_LINES_AFTER_INTERFACE, 1);
094: convention.putInt(ConventionKeys.BLANK_LINES_AFTER_DECLARATION, 1);
095: convention.putInt(ConventionKeys.BLANK_LINES_KEEP_UP_TO, 1);
096:
097: //convention.putBoolean(ConventionKeys.INDENT_CONTINUATION_IF_TERNARY, true);
098: convention.putInt(ConventionKeys.INDENT_SIZE_CONTINUATION, 0);
099: //convention.putBoolean(ConventionKeys.INDENT_USE_PARAMS_METHOD_CALL, true);
100:
101: convention.putBoolean(ConventionKeys.LINE_WRAP_BEFORE_THROWS, true);
102: convention.putInt(ConventionKeys.INDENT_SIZE_THROWS, 4);
103: */
104:
105: String classMask = "/**\n"
106: + " * <a href=\"$fileName$.html\"><b><i>View Source</i></b></a>\n"
107: + " *\n" + " * @author $author$\n" + " *\n" + " */";
108:
109: convention.putInt(
110: ConventionKeys.COMMENT_JAVADOC_CLASS_MASK, 1);
111: convention.putBoolean(
112: ConventionKeys.COMMENT_JAVADOC_REMOVE, true);
113: convention.putBoolean(
114: ConventionKeys.COMMENT_REMOVE_MULTI_LINE, true);
115: convention.putBoolean(
116: ConventionKeys.COMMENT_REMOVE_SINGLE_LINE, true);
117: convention.put(
118: ConventionKeys.COMMENT_JAVADOC_TEMPLATE_CLASS,
119: classMask);
120: convention.put(
121: ConventionKeys.COMMENT_JAVADOC_TEMPLATE_INTERFACE,
122: classMask);
123:
124: convention.exportSettings(new FileOutputStream(new File(
125: "../tools/jalopy.xml")), Convention.EXTENSION_XML);
126:
127: /*
128: com.liferay.portlet.messageboards.util.Preference pref =
129: new com.liferay.portlet.messageboards.util.Preference();
130:
131: com.liferay.portlet.messageboards.util.PreferenceSerializer prefSerializer =
132: new com.liferay.portlet.messageboards.util.PreferenceSerializer();
133:
134: System.out.println(prefSerializer.toPrefString(pref));
135: */
136:
137: /*
138: String basedir = "../portal-web/";
139:
140: DirectoryScanner ds = new DirectoryScanner();
141: ds.setIncludes(new String[] {"**\\*.jsp"});
142: ds.setBasedir(basedir);
143: ds.scan();
144:
145: String[] files = ds.getIncludedFiles();
146:
147: for (int i = 0; i < files.length; i++) {
148: File file = new File(basedir + files[i]);
149:
150: String content = FileUtil.read(file);
151:
152: BufferedReader br =
153: new BufferedReader(new StringReader(content));
154:
155: StringBuffer sb = new StringBuffer();
156: String line = null;
157:
158: while ((line = br.readLine()) != null) {
159: int x = line.indexOf("<%=");
160: int y = line.indexOf("%>", x);
161:
162: if ((x != -1) && (y != -1) && ((line.indexOf("<jsp:") != -1) || (line.indexOf("<util:") != -1))) {
163: try {
164: String regexp = line.substring(
165: x, y + 2);
166:
167: if (regexp.indexOf("\\\"") != -1) {
168: regexp = regexp.substring(0, regexp.length() - 2);
169:
170: if (regexp.indexOf("\\\"") != -1) {
171: String patched = StringUtil.replace(regexp, "\\\"", "\"");
172:
173: sb.append(line.substring(0, x) + patched + line.substring(y, line.length()));
174:
175: //return;
176: }
177: else {
178: sb.append(line);
179: }
180: }
181: else {
182: sb.append(line);
183: }
184: }
185: catch (Exception exc) {
186: sb.append(line);
187: }
188: }
189: else if ((x != -1) && (y == -1)) {
190: System.out.println("ERROR " + file.toString());
191:
192: return;
193: }
194: else {
195: sb.append(line);
196: }
197:
198: sb.append("\n");
199: }
200:
201: sb.delete(sb.length() - 1, sb.length());
202:
203: br.close();
204:
205: String newContent = sb.toString();
206:
207: //System.out.println(content.length());
208: //System.out.println(newContent.length());
209:
210: if ((newContent != null) && !content.equals(newContent)) {
211: FileUtil.write(file, newContent);
212:
213: System.out.println(file.toString());
214:
215: //break;
216: }
217: }
218: */
219:
220: /*
221: String basedir = "../portal-web/";
222:
223: DirectoryScanner ds = new DirectoryScanner();
224: ds.setIncludes(new String[] {"**\\*.jsp"});
225: ds.setBasedir(basedir);
226: ds.scan();
227:
228: String[] files = ds.getIncludedFiles();
229:
230: for (int i = 0; i < files.length; i++) {
231: File file = new File(basedir + files[i]);
232:
233: String content = FileUtil.read(file);
234:
235: BufferedReader br =
236: new BufferedReader(new StringReader(content));
237:
238: StringBuffer sb = new StringBuffer();
239: String line = null;
240:
241: while ((line = br.readLine()) != null) {
242: int x = line.indexOf("<%=");
243: int y = line.indexOf("%>", x);
244:
245: if ((x != -1) && (y != -1) && ((line.indexOf("<c:") != -1) || (line.indexOf("<jsp:") != -1) || (line.indexOf("<util:") != -1))) {
246: try {
247: String regexp = line.substring(
248: x, y + 2);
249:
250: if (regexp.indexOf("\\\"") == -1) {
251: regexp = regexp.substring(0, regexp.length() - 2);
252:
253: if (regexp.indexOf("\"") != -1) {
254: String patched = StringUtil.replace(regexp, "\"", "\\\"");
255:
256: sb.append(line.substring(0, x) + patched + line.substring(y, line.length()));
257:
258: //return;
259: }
260: else {
261: sb.append(line);
262: }
263: }
264: else {
265: sb.append(line);
266: }
267: }
268: catch (Exception exc) {
269: sb.append(line);
270: }
271: }
272: else if ((x != -1) && (y == -1)) {
273: System.out.println("ERROR " + file.toString());
274:
275: return;
276: }
277: else {
278: sb.append(line);
279: }
280:
281: sb.append("\n");
282: }
283:
284: if (sb.length() > 0) {
285: sb.delete(sb.length() - 1, sb.length());
286: }
287:
288: br.close();
289:
290: String newContent = sb.toString();
291:
292: //System.out.println(content.length());
293: //System.out.println(newContent.length());
294:
295: if ((newContent != null) && !content.equals(newContent)) {
296: FileUtil.write(file, newContent);
297:
298: System.out.println(file.toString());
299:
300: //break;
301: }
302: }
303: */
304:
305: /*
306: String basedir = "../portal-web/";
307:
308: DirectoryScanner ds = new DirectoryScanner();
309: ds.setIncludes(new String[] {"**\\*.jsp"});
310: ds.setBasedir(basedir);
311: ds.scan();
312:
313: String[] files = ds.getIncludedFiles();
314:
315: for (int i = 0; i < files.length; i++) {
316: File file = new File(basedir + files[i]);
317:
318: String content = FileUtil.read(file);
319:
320: BufferedReader br =
321: new BufferedReader(new StringReader(content));
322:
323: StringBuffer sb = new StringBuffer();
324: String line = null;
325:
326: while ((line = br.readLine()) != null) {
327: int x = line.indexOf("\"<%=");
328: int y = line.indexOf("%>\"", x);
329:
330: if ((x != -1) && (y != -1) && ((line.indexOf("<c:") != -1) || (line.indexOf("<jsp:") != -1) || (line.indexOf("<liferay:") != -1))) {
331: try {
332: String regexp = line.substring(
333: x, y + 3);
334:
335: if (regexp.indexOf("\\\"") == -1) {
336: regexp = regexp.substring(1, regexp.length() - 1);
337:
338: if (regexp.indexOf("\"") != -1) {
339: //System.out.println(regexp);
340:
341: sb.append(line.substring(0, x));
342: sb.append("'");
343: sb.append(regexp);
344: sb.append("'");
345: sb.append(line.substring(y + 3, line.length()));
346: }
347: else {
348: sb.append(line);
349: }
350: }
351: else {
352: sb.append(line);
353: }
354: }
355: catch (Exception exc) {
356: sb.append(line);
357: }
358: }
359: //else if ((x != -1) && (y == -1)) {
360: // System.out.println("ERROR " + file.toString());
361: //
362: // return;
363: //}
364: else {
365: sb.append(line);
366: }
367:
368: sb.append("\n");
369: }
370:
371: if (sb.length() > 0) {
372: sb.delete(sb.length() - 1, sb.length());
373: }
374:
375: br.close();
376:
377: String newContent = sb.toString();
378:
379: //System.out.println(content.length());
380: //System.out.println(newContent.length());
381:
382: if ((newContent != null) && !content.equals(newContent)) {
383: FileUtil.write(file, newContent);
384:
385: System.out.println(file.toString());
386:
387: break;
388: }
389: }
390: */
391: } catch (Exception e) {
392: e.printStackTrace();
393: }
394: }
395:
396: }
|