1
19
20 package com.liferay.portal.tools;
21
22 import com.liferay.portal.kernel.util.CharPool;
23 import com.liferay.portal.kernel.util.ClassUtil;
24 import com.liferay.portal.kernel.util.ListUtil;
25 import com.liferay.portal.kernel.util.StringPool;
26 import com.liferay.portal.kernel.util.StringUtil;
27 import com.liferay.portal.util.ContentUtil;
28 import com.liferay.portal.util.FileImpl;
29
30 import java.io.BufferedReader;
31 import java.io.File;
32 import java.io.InputStream;
33 import java.io.IOException;
34 import java.io.StringReader;
35 import java.net.URL;
36 import java.util.ArrayList;
37 import java.util.HashSet;
38 import java.util.List;
39 import java.util.Properties;
40 import java.util.Set;
41 import java.util.regex.Matcher;
42 import java.util.regex.Pattern;
43
44 import org.apache.tools.ant.DirectoryScanner;
45
46
52 public class SourceFormatter {
53
54 public static void main(String[] args) {
55 try {
56 _readExclusions();
57
58 _checkPersistenceTestSuite();
59 _checkWebXML();
60 _formatJava();
61 _formatJSP();
62 }
63 catch (Exception e) {
64 e.printStackTrace();
65 }
66 }
67
68 public static String stripImports(
69 String content, String packageDir, String className)
70 throws IOException {
71
72 int x = content.indexOf("import ");
73
74 if (x == -1) {
75 return content;
76 }
77
78 int y = content.indexOf("{", x);
79
80 y = content.substring(0, y).lastIndexOf(";") + 1;
81
82 String imports = _formatImports(content.substring(x, y));
83
84 content =
85 content.substring(0, x) + imports +
86 content.substring(y + 1, content.length());
87
88 Set<String> classes = ClassUtil.getClasses(
89 new StringReader(content), className);
90
91 classes.add("_getMarkup");
92 classes.add("_performBlockingInteraction");
93
94 x = content.indexOf("import ");
95
96 y = content.indexOf("{", x);
97
98 y = content.substring(0, y).lastIndexOf(";") + 1;
99
100 imports = content.substring(x, y);
101
102 StringBuilder sb = new StringBuilder();
103
104 BufferedReader br = new BufferedReader(new StringReader(imports));
105
106 String line = null;
107
108 while ((line = br.readLine()) != null) {
109 if (line.indexOf("import ") != -1) {
110 int importX = line.indexOf(" ");
111 int importY = line.lastIndexOf(".");
112
113 String importPackage = line.substring(importX + 1, importY);
114 String importClass = line.substring(
115 importY + 1, line.length() - 1);
116
117 if (!packageDir.equals(importPackage)) {
118 if (!importClass.equals("*")) {
119 if (classes.contains(importClass)) {
120 sb.append(line);
121 sb.append("\n");
122 }
123 }
124 else {
125 sb.append(line);
126 sb.append("\n");
127 }
128 }
129 }
130 }
131
132 imports = _formatImports(sb.toString());
133
134 content =
135 content.substring(0, x) + imports +
136 content.substring(y + 1, content.length());
137
138 return content;
139 }
140
141 public static void _checkPersistenceTestSuite() throws IOException {
142 String basedir = "./portal-impl/test";
143
144 if (!_fileUtil.exists(basedir)) {
145 return;
146 }
147
148 DirectoryScanner ds = new DirectoryScanner();
149
150 ds.setBasedir(basedir);
151 ds.setIncludes(new String[] {"**\\*PersistenceTest.java"});
152
153 ds.scan();
154
155 String[] files = ds.getIncludedFiles();
156
157 Set<String> persistenceTests = new HashSet<String>();
158
159 for (String file : files) {
160 String persistenceTest = file.substring(0, file.length() - 5);
161
162 persistenceTest = persistenceTest.substring(
163 persistenceTest.lastIndexOf(File.separator) + 1,
164 persistenceTest.length());
165
166 persistenceTests.add(persistenceTest);
167 }
168
169 String persistenceTestSuite = _fileUtil.read(
170 basedir + "/com/liferay/portal/service/persistence/" +
171 "PersistenceTestSuite.java");
172
173 for (String persistenceTest : persistenceTests) {
174 if (persistenceTestSuite.indexOf(persistenceTest) == -1) {
175 System.out.println("PersistenceTestSuite: " + persistenceTest);
176 }
177 }
178 }
179
180 private static void _checkWebXML() throws IOException {
181 String basedir = "./";
182
183 if (_fileUtil.exists(basedir + "portal-impl")) {
184 return;
185 }
186
187 String webXML = ContentUtil.get(
188 "com/liferay/portal/deploy/dependencies/web.xml");
189
190 DirectoryScanner ds = new DirectoryScanner();
191
192 ds.setBasedir(basedir);
193 ds.setIncludes(new String[] {"**\\web.xml"});
194
195 ds.scan();
196
197 String[] files = ds.getIncludedFiles();
198
199 for (String file : files) {
200 String content = _fileUtil.read(basedir + file);
201
202 if (content.equals(webXML)) {
203 System.out.println(file);
204 }
205 }
206 }
207
208 private static void _checkXSS(String fileName, String jspContent) {
209 Matcher matcher = _xssPattern.matcher(jspContent);
210
211 while (matcher.find()) {
212 boolean xssVulnerable = false;
213
214 String jspVariable = matcher.group(1);
215
216 String inputVulnerability =
217 " type=\"hidden\" value=\"<%= " + jspVariable + " %>";
218
219 if (jspContent.indexOf(inputVulnerability) != -1) {
220 xssVulnerable = true;
221 }
222
223 String anchorVulnerability = " href=\"<%= " + jspVariable + " %>";
224
225 if (jspContent.indexOf(anchorVulnerability) != -1) {
226 xssVulnerable = true;
227 }
228
229 String inlineStringVulnerability1 = "'<%= " + jspVariable + " %>";
230
231 if (jspContent.indexOf(inlineStringVulnerability1) != -1) {
232 xssVulnerable = true;
233 }
234
235 String inlineStringVulnerability2 = "(\"<%= " + jspVariable + " %>";
236
237 if (jspContent.indexOf(inlineStringVulnerability2) != -1) {
238 xssVulnerable = true;
239 }
240
241 String inlineStringVulnerability3 = " \"<%= " + jspVariable + " %>";
242
243 if (jspContent.indexOf(inlineStringVulnerability3) != -1) {
244 xssVulnerable = true;
245 }
246
247 String documentIdVulnerability = ".<%= " + jspVariable + " %>";
248
249 if (jspContent.indexOf(documentIdVulnerability) != -1) {
250 xssVulnerable = true;
251 }
252
253 if (xssVulnerable) {
254 System.out.println(
255 "(xss): " + fileName + " (" + jspVariable + ")");
256 }
257 }
258 }
259
260 public static String _formatImports(String imports) throws IOException {
261 if ((imports.indexOf("/*") != -1) ||
262 (imports.indexOf("*/") != -1) ||
263 (imports.indexOf("//") != -1)) {
264
265 return imports + "\n";
266 }
267
268 List<String> importsList = new ArrayList<String>();
269
270 BufferedReader br = new BufferedReader(new StringReader(imports));
271
272 String line = null;
273
274 while ((line = br.readLine()) != null) {
275 if (line.indexOf("import ") != -1) {
276 if (!importsList.contains(line)) {
277 importsList.add(line);
278 }
279 }
280 }
281
282 importsList = ListUtil.sort(importsList);
283
284 StringBuilder sb = new StringBuilder();
285
286 String temp = null;
287
288 for (int i = 0; i < importsList.size(); i++) {
289 String s = importsList.get(i);
290
291 int pos = s.indexOf(".");
292
293 pos = s.indexOf(".", pos + 1);
294
295 if (pos == -1) {
296 pos = s.indexOf(".");
297 }
298
299 String packageLevel = s.substring(7, pos);
300
301 if ((i != 0) && (!packageLevel.equals(temp))) {
302 sb.append("\n");
303 }
304
305 temp = packageLevel;
306
307 sb.append(s);
308 sb.append("\n");
309 }
310
311 return sb.toString();
312 }
313
314 private static void _formatJava() throws IOException {
315 String basedir = "./";
316
317 String copyright = _getCopyright();
318
319 boolean portalJavaFiles = true;
320
321 String[] files = null;
322
323 if (_fileUtil.exists(basedir + "portal-impl")) {
324 files = _getPortalJavaFiles();
325 }
326 else {
327 portalJavaFiles = false;
328
329 files = _getPluginJavaFiles();
330 }
331
332 for (int i = 0; i < files.length; i++) {
333 File file = new File(basedir + files[i]);
334
335 String content = _fileUtil.read(file);
336
337 String className = file.getName();
338
339 className = className.substring(0, className.length() - 5);
340
341 String packagePath = files[i];
342
343 int packagePathX = packagePath.indexOf(
344 File.separator + "src" + File.separator);
345 int packagePathY = packagePath.lastIndexOf(File.separator);
346
347 if ((packagePathX + 5) >= packagePathY) {
348 packagePath = StringPool.BLANK;
349 }
350 else {
351 packagePath = packagePath.substring(
352 packagePathX + 5, packagePathY);
353 }
354
355 packagePath = StringUtil.replace(
356 packagePath, File.separator, StringPool.PERIOD);
357
358 if (packagePath.endsWith(".model")) {
359 if (content.indexOf(
360 "extends " + className + "Model {") != -1) {
361
362 continue;
363 }
364 }
365
366 String newContent = _formatJavaContent(files[i], content);
367
368 if (newContent.indexOf("$\n */") != -1) {
369 System.out.println("*: " + files[i]);
370
371 newContent = StringUtil.replace(
372 newContent, "$\n */", "$\n *\n */");
373 }
374
375 if (newContent.indexOf(copyright) == -1) {
376 System.out.println("(c): " + files[i]);
377 }
378
379 if (newContent.indexOf(className + ".java.html") == -1) {
380 System.out.println("Java2HTML: " + files[i]);
381 }
382
383 newContent = stripImports(newContent, packagePath, className);
384
385 newContent = StringUtil.replace(
386 newContent, "@author Raymond Aug?", "@author Raymond Augé");
387
388 if (newContent.indexOf(";\n/**") != -1) {
389 newContent = StringUtil.replace(
390 newContent,
391 ";\n/**",
392 ";\n\n/**");
393 }
394
395 if (newContent.indexOf("\t/*\n\t *") != -1) {
396 newContent = StringUtil.replace(
397 newContent,
398 "\t/*\n\t *",
399 "\t/**\n\t *");
400 }
401
402 if (newContent.indexOf("if(") != -1) {
403 newContent = StringUtil.replace(
404 newContent,
405 "if(",
406 "if (");
407 }
408
409 if (newContent.indexOf("while(") != -1) {
410 newContent = StringUtil.replace(
411 newContent,
412 "while(",
413 "while (");
414 }
415
416 if (newContent.indexOf("\n\n\n") != -1) {
417 newContent = StringUtil.replace(
418 newContent,
419 "\n\n\n",
420 "\n\n");
421 }
422
423 if (newContent.indexOf("*/\npackage ") != -1) {
424 System.out.println("package: " + files[i]);
425 }
426
427 if (newContent.indexOf(" ") != -1) {
428 if (!files[i].endsWith("StringPool.java")) {
429 System.out.println("tab: " + files[i]);
430 }
431 }
432
433 if (newContent.indexOf(" {") != -1) {
434 System.out.println("{:" + files[i]);
435 }
436
437 if (!newContent.endsWith("\n\n}") &&
438 !newContent.endsWith("{\n}")) {
439
440 System.out.println("}: " + files[i]);
441 }
442
443 if (portalJavaFiles && className.endsWith("ServiceImpl") &&
444 (newContent.indexOf("ServiceUtil.") != -1)) {
445
446 System.out.println("ServiceUtil: " + files[i]);
447 }
448
449 if ((newContent != null) && !content.equals(newContent)) {
450 _fileUtil.write(file, newContent);
451
452 System.out.println(file);
453 }
454 }
455 }
456
457 private static String _formatJavaContent(String fileName, String content)
458 throws IOException {
459
460 boolean longLogFactoryUtil = false;
461
462 StringBuilder sb = new StringBuilder();
463
464 BufferedReader br = new BufferedReader(new StringReader(content));
465
466 int lineCount = 0;
467
468 String line = null;
469
470 while ((line = br.readLine()) != null) {
471 lineCount++;
472
473 if (line.trim().length() == 0) {
474 line = StringPool.BLANK;
475 }
476
477 line = StringUtil.trimTrailing(line);
478
479 line = StringUtil.replace(
480 line,
481 new String[] {
482 "* Copyright (c) 2000-2008 Liferay, Inc.",
483 "* Copyright 2008 Sun Microsystems Inc."
484 },
485 new String[] {
486 "* Copyright (c) 2000-2009 Liferay, Inc.",
487 "* Copyright 2009 Sun Microsystems Inc."
488 });
489
490 sb.append(line);
491 sb.append("\n");
492
493 StringBuilder lineSB = new StringBuilder();
494
495 int spacesPerTab = 4;
496
497 for (char c : line.toCharArray()) {
498 if (c == CharPool.TAB) {
499 for (int i = 0; i < spacesPerTab; i++) {
500 lineSB.append(CharPool.SPACE);
501 }
502
503 spacesPerTab = 4;
504 }
505 else {
506 lineSB.append(c);
507
508 spacesPerTab--;
509
510 if (spacesPerTab <= 0) {
511 spacesPerTab = 4;
512 }
513 }
514 }
515
516 line = lineSB.toString();
517
518 String excluded = _exclusions.getProperty(
519 StringUtil.replace(fileName, "\\", "/") + StringPool.AT +
520 lineCount);
521
522 if (excluded == null) {
523 excluded = _exclusions.getProperty(
524 StringUtil.replace(fileName, "\\", "/"));
525 }
526
527 if ((excluded == null) && (line.length() > 80) &&
528 (!line.startsWith("import "))) {
529
530 if (line.contains(
531 "private static Log _log = LogFactoryUtil.getLog(")) {
532
533 longLogFactoryUtil = true;
534 }
535
536 System.out.println("> 80: " + fileName + " " + lineCount);
537 }
538 }
539
540 br.close();
541
542 String newContent = sb.toString();
543
544 if (newContent.endsWith("\n")) {
545 newContent = newContent.substring(0, newContent.length() -1);
546 }
547
548 if (longLogFactoryUtil) {
549 newContent = StringUtil.replace(
550 newContent, "private static Log _log = ",
551 "private static Log _log =\n\t\t");
552 }
553
554 return newContent;
555 }
556
557 private static void _formatJSP() throws IOException {
558 String basedir = "./";
559
560 List<File> list = new ArrayList<File>();
561
562 DirectoryScanner ds = new DirectoryScanner();
563
564 ds.setBasedir(basedir);
565 ds.setExcludes(new String[] {"**\\null.jsp", "**\\tmp\\**"});
566 ds.setIncludes(new String[] {"**\\*.jsp", "**\\*.jspf", "**\\*.vm"});
567
568 ds.scan();
569
570 list.addAll(ListUtil.fromArray(ds.getIncludedFiles()));
571
572 String copyright = _getCopyright();
573
574 String[] files = list.toArray(new String[list.size()]);
575
576 for (int i = 0; i < files.length; i++) {
577 File file = new File(basedir + files[i]);
578
579 String content = _fileUtil.read(file);
580 String newContent = _formatJSPContent(files[i], content);
581
582 newContent = StringUtil.replace(
583 newContent,
584 new String[] {
585 "<br/>", "\"/>", "\" >", "@page import", "\"%>", ")%>",
586 "javascript: "
587 },
588 new String[] {
589 "<br />", "\" />", "\">", "@ page import", "\" %>", ") %>",
590 "javascript:"
591 });
592
593 newContent = StringUtil.replace(
594 newContent,
595 new String[] {
596 "* Copyright (c) 2000-2008 Liferay, Inc.",
597 "* Copyright 2008 Sun Microsystems Inc."
598 },
599 new String[] {
600 "* Copyright (c) 2000-2009 Liferay, Inc.",
601 "* Copyright 2009 Sun Microsystems Inc."
602 });
603
604 if (files[i].endsWith(".jsp")) {
605 if (newContent.indexOf(copyright) == -1) {
606 System.out.println("(c): " + files[i]);
607 }
608 }
609
610 if (newContent.indexOf("alert('<%= LanguageUtil.") != -1) {
611 newContent = StringUtil.replace(newContent,
612 "alert('<%= LanguageUtil.",
613 "alert('<%= UnicodeLanguageUtil.");
614 }
615
616 if (newContent.indexOf("alert(\"<%= LanguageUtil.") != -1) {
617 newContent = StringUtil.replace(newContent,
618 "alert(\"<%= LanguageUtil.",
619 "alert(\"<%= UnicodeLanguageUtil.");
620 }
621
622 if (newContent.indexOf("confirm('<%= LanguageUtil.") != -1) {
623 newContent = StringUtil.replace(newContent,
624 "confirm('<%= LanguageUtil.",
625 "confirm('<%= UnicodeLanguageUtil.");
626 }
627
628 if (newContent.indexOf("confirm(\"<%= LanguageUtil.") != -1) {
629 newContent = StringUtil.replace(newContent,
630 "confirm(\"<%= LanguageUtil.",
631 "confirm(\"<%= UnicodeLanguageUtil.");
632 }
633
634 if (newContent.indexOf(" ") != -1) {
635 if (!files[i].endsWith("template.vm")) {
636 System.out.println("tab: " + files[i]);
637 }
638 }
639
640 _checkXSS(files[i], content);
641
642 if ((newContent != null) && !content.equals(newContent)) {
643 _fileUtil.write(file, newContent);
644
645 System.out.println(file);
646 }
647 }
648 }
649
650 private static String _formatJSPContent(String fileName, String content)
651 throws IOException {
652
653 StringBuilder sb = new StringBuilder();
654
655 BufferedReader br = new BufferedReader(new StringReader(content));
656
657 String line = null;
658
659 while ((line = br.readLine()) != null) {
660 if (line.trim().length() == 0) {
661 line = StringPool.BLANK;
662 }
663
664 line = StringUtil.trimTrailing(line);
665
666 sb.append(line);
667 sb.append("\n");
668 }
669
670 br.close();
671
672 content = sb.toString();
673
674 if (content.endsWith("\n")) {
675 content = content.substring(0, content.length() -1);
676 }
677
678 content = _formatTaglibQuotes(fileName, content, StringPool.QUOTE);
679 content = _formatTaglibQuotes(fileName, content, StringPool.APOSTROPHE);
680
681 return content;
682 }
683
684 private static String _formatTaglibQuotes(
685 String fileName, String content, String quoteType) {
686
687 String quoteFix = StringPool.APOSTROPHE;
688
689 if (quoteFix.equals(quoteType)) {
690 quoteFix = StringPool.QUOTE;
691 }
692
693 Pattern pattern = Pattern.compile(_getTaglibRegex(quoteType));
694
695 Matcher matcher = pattern.matcher(content);
696
697 while (matcher.find()) {
698 int x = content.indexOf(quoteType + "<%=", matcher.start());
699 int y = content.indexOf("%>" + quoteType, x);
700
701 while ((x != -1) && (y != -1)) {
702 String result = content.substring(x + 1, y + 2);
703
704 if (result.indexOf(quoteType) != -1) {
705 int lineCount = 1;
706
707 char contentCharArray[] = content.toCharArray();
708
709 for (int i = 0; i < x; i++) {
710 if (contentCharArray[i] == CharPool.NEW_LINE) {
711 lineCount++;
712 }
713 }
714
715 if (result.indexOf(quoteFix) == -1) {
716 StringBuilder sb = new StringBuilder();
717
718 sb.append(content.substring(0, x));
719 sb.append(quoteFix);
720 sb.append(result);
721 sb.append(quoteFix);
722 sb.append(content.substring(y + 3, content.length()));
723
724 content = sb.toString();
725 }
726 else {
727 System.out.println(
728 "taglib: " + fileName + " " + lineCount);
729 }
730 }
731
732 x = content.indexOf(quoteType + "<%=", y);
733
734 if (x > matcher.end()) {
735 break;
736 }
737
738 y = content.indexOf("%>" + quoteType, x);
739 }
740 }
741
742 return content;
743 }
744
745 private static String _getCopyright() throws IOException {
746 try {
747 return _fileUtil.read("copyright.txt");
748 }
749 catch (Exception e1) {
750 try {
751 return _fileUtil.read("../copyright.txt");
752 }
753 catch (Exception e2) {
754 return _fileUtil.read("../../copyright.txt");
755 }
756 }
757 }
758
759 private static String[] _getPluginJavaFiles() {
760 String basedir = "./";
761
762 List<File> list = new ArrayList<File>();
763
764 DirectoryScanner ds = new DirectoryScanner();
765
766 ds.setBasedir(basedir);
767 ds.setExcludes(
768 new String[] {
769 "**\\model\\*Clp.java", "**\\model\\*Model.java",
770 "**\\model\\*Soap.java", "**\\model\\impl\\*ModelImpl.java",
771 "**\\service\\*Service.java", "**\\service\\*ServiceClp.java",
772 "**\\service\\*ServiceFactory.java",
773 "**\\service\\*ServiceUtil.java",
774 "**\\service\\ClpSerializer.java",
775 "**\\service\\base\\*ServiceBaseImpl.java",
776 "**\\service\\http\\*JSONSerializer.java",
777 "**\\service\\http\\*ServiceHttp.java",
778 "**\\service\\http\\*ServiceJSON.java",
779 "**\\service\\http\\*ServiceSoap.java",
780 "**\\service\\messaging\\*ClpMessageListener.java",
781 "**\\service\\persistence\\*Finder.java",
782 "**\\service\\persistence\\*Persistence.java",
783 "**\\service\\persistence\\*PersistenceImpl.java",
784 "**\\service\\persistence\\*Util.java", "**\\tmp\\**"
785 });
786 ds.setIncludes(new String[] {"**\\*.java"});
787
788 ds.scan();
789
790 list.addAll(ListUtil.fromArray(ds.getIncludedFiles()));
791
792 return list.toArray(new String[list.size()]);
793 }
794
795 private static String[] _getPortalJavaFiles() {
796 String basedir = "./";
797
798 List<File> list = new ArrayList<File>();
799
800 DirectoryScanner ds = new DirectoryScanner();
801
802 ds.setBasedir(basedir);
803 ds.setExcludes(
804 new String[] {
805 "**\\classes\\*", "**\\jsp\\*", "**\\tmp\\**",
806 "**\\EARXMLBuilder.java", "**\\EJBXMLBuilder.java",
807 "**\\PropsKeys.java", "**\\InstanceWrapperBuilder.java",
808 "**\\ServiceBuilder.java", "**\\SourceFormatter.java",
809 "**\\UserAttributes.java", "**\\WebKeys.java",
810 "**\\*_IW.java", "**\\XHTMLComplianceFormatter.java",
811 "**\\portal-service\\**\\model\\*Model.java",
812 "**\\portal-service\\**\\model\\*Soap.java",
813 "**\\model\\impl\\*ModelImpl.java",
814 "**\\portal\\service\\**", "**\\portal-client\\**",
815 "**\\portal-web\\classes\\**\\*.java",
816 "**\\portal-web\\test\\**\\*Test.java",
817 "**\\portlet\\**\\service\\**", "**\\tools\\ext_tmpl\\**",
818 "**\\util-wsrp\\**", "**\\wsrp\\**"
819 });
820 ds.setIncludes(new String[] {"**\\*.java"});
821
822 ds.scan();
823
824 list.addAll(ListUtil.fromArray(ds.getIncludedFiles()));
825
826 ds = new DirectoryScanner();
827
828 ds.setBasedir(basedir);
829 ds.setExcludes(
830 new String[] {
831 "**\\tools\\ext_tmpl\\**", "**\\*_IW.java",
832 "**\\test\\**\\*PersistenceTest.java"
833 });
834 ds.setIncludes(
835 new String[] {
836 "**\\com\\liferay\\portal\\service\\ServiceContext*.java",
837 "**\\model\\BaseModel.java",
838 "**\\model\\impl\\BaseModelImpl.java",
839 "**\\service\\base\\PrincipalBean.java",
840 "**\\service\\http\\*HttpTest.java",
841 "**\\service\\http\\*SoapTest.java",
842 "**\\service\\http\\TunnelUtil.java",
843 "**\\service\\impl\\*.java", "**\\service\\jms\\*.java",
844 "**\\service\\permission\\*.java",
845 "**\\service\\persistence\\BasePersistence.java",
846 "**\\service\\persistence\\BatchSession*.java",
847 "**\\service\\persistence\\*FinderImpl.java",
848 "**\\service\\persistence\\impl\\BasePersistenceImpl.java",
849 "**\\portal-impl\\test\\**\\*.java",
850 "**\\portal-service\\**\\liferay\\counter\\**.java",
851 "**\\portal-service\\**\\liferay\\documentlibrary\\**.java",
852 "**\\portal-service\\**\\liferay\\lock\\**.java",
853 "**\\portal-service\\**\\liferay\\mail\\**.java",
854 "**\\util-bridges\\**\\*.java"
855 });
856
857 ds.scan();
858
859 list.addAll(ListUtil.fromArray(ds.getIncludedFiles()));
860
861 return list.toArray(new String[list.size()]);
862 }
863
864 private static String _getTaglibRegex(String quoteType) {
865 StringBuilder sb = new StringBuilder();
866
867 sb.append("<(");
868
869 for (int i = 0; i < _TAG_LIBRARIES.length; i++) {
870 sb.append(_TAG_LIBRARIES[i]);
871 sb.append(StringPool.PIPE);
872 }
873
874 sb.deleteCharAt(sb.length() - 1);
875 sb.append("):([^>]|%>)*");
876 sb.append(quoteType);
877 sb.append("<%=[^>]*");
878 sb.append(quoteType);
879 sb.append("[^>]*%>");
880 sb.append(quoteType);
881 sb.append("([^>]|%>)*>");
882
883 return sb.toString();
884 }
885
886 private static void _readExclusions() throws IOException {
887 _exclusions = new Properties();
888
889 ClassLoader classLoader = SourceFormatter.class.getClassLoader();
890
891 String sourceFormatterExclusions = System.getProperty(
892 "source-formatter-exclusions",
893 "com/liferay/portal/tools/dependencies/" +
894 "source_formatter_exclusions.properties");
895
896 URL url = classLoader.getResource(sourceFormatterExclusions);
897
898 if (url == null) {
899 return;
900 }
901
902 InputStream is = url.openStream();
903
904 _exclusions.load(is);
905
906 is.close();
907 }
908
909 private static final String[] _TAG_LIBRARIES = new String[] {
910 "c", "html", "jsp", "liferay-portlet", "liferay-security",
911 "liferay-theme", "liferay-ui", "liferay-util", "portlet", "struts",
912 "tiles"
913 };
914
915 private static FileImpl _fileUtil = FileImpl.getInstance();
916 private static Properties _exclusions;
917 private static Pattern _xssPattern = Pattern.compile(
918 "String\\s+([^\\s]+)\\s*=\\s*ParamUtil\\.getString\\(");
919
920 }
921