PageRenderTime 62ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/org/vietspider/js/JsUtils.java

https://code.google.com/p/rrdws/
Java | 126 lines | 81 code | 18 blank | 27 comment | 48 complexity | 4e33d882243b402f2fd0d928a3620935 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. /***************************************************************************
  2. * Copyright 2001-2008 The VietSpider All rights reserved. *
  3. **************************************************************************/
  4. package org.vietspider.js;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. /**
  8. * Author : Nhu Dinh Thuan
  9. * nhudinhthuan@yahoo.com
  10. * Jul 7, 2008
  11. */
  12. public class JsUtils {
  13. public static String [] getParams(String jsFunction) {
  14. List<String> list = new ArrayList<String>();
  15. int i = 0;
  16. while(i < jsFunction.length()) {
  17. char c = jsFunction.charAt(i);
  18. i++;
  19. if(c == '(' || c == '=') break;
  20. }
  21. while(i < jsFunction.length()) {
  22. char c = jsFunction.charAt(i);
  23. while(Character.isWhitespace(c) || Character.isSpaceChar(c)) {
  24. i++;
  25. if(i >= jsFunction.length()) break;
  26. c = jsFunction.charAt(i);
  27. }
  28. if(c == ',') {
  29. i++;
  30. continue;
  31. } else if (c == ')' && jsFunction.charAt(i-1) != '\\' ) {
  32. break;
  33. }
  34. while(Character.isWhitespace(c) || Character.isSpaceChar(c)) {
  35. i++;
  36. if(i >= jsFunction.length()) break;
  37. c = jsFunction.charAt(i);
  38. }
  39. if(c == '\'') {
  40. i++;
  41. int start = i;
  42. while(i < jsFunction.length()) {
  43. c = jsFunction.charAt(i);
  44. if( (c == '\'' && jsFunction.charAt(i-1) != '\\')
  45. || (c == ')' && jsFunction.charAt(i-1) != '\\')) break;
  46. i++;
  47. }
  48. if(i <= start) {
  49. list.add("");
  50. } else {
  51. list.add(jsFunction.substring(start, i).trim());
  52. }
  53. i++;
  54. continue;
  55. }
  56. if(c == '"') {
  57. i++;
  58. int start = i;
  59. while(i < jsFunction.length()) {
  60. c = jsFunction.charAt(i);
  61. if( (c == '"' && jsFunction.charAt(i-1) != '\\')
  62. || (c == ')' && jsFunction.charAt(i-1) != '\\')) break;
  63. i++;
  64. }
  65. if(i <= start) {
  66. list.add("");
  67. } else {
  68. list.add(jsFunction.substring(start, i).trim());
  69. }
  70. i++;
  71. continue;
  72. }
  73. int start = i;
  74. i++;
  75. while(i < jsFunction.length()) {
  76. c = jsFunction.charAt(i);
  77. if((c == ',' && jsFunction.charAt(i-1) != '\\')
  78. || (c == ')' && jsFunction.charAt(i-1) != '\\') ) break;
  79. i++;
  80. }
  81. if(i <= start) {
  82. list.add("");
  83. } else if( start < Math.min(i, jsFunction.length())){
  84. list.add(jsFunction.substring(start, Math.min(i, jsFunction.length())).trim());
  85. }
  86. }
  87. return list.toArray(new String[list.size()]);
  88. }
  89. // public static void main(String[] args) throws Exception {
  90. // String aaa = "200905181719249.1.108896_14113.rar";
  91. // String value = "javascript:popupPageMail('/gdtLive/Khoi-chuc-nang/Mail-popup?contentId=115584&amp;location=tct&amp;sendSiteNodeId=100074')";
  92. // String [] params = JsUtils.getParams(value);
  93. // for(String param : params ){
  94. // System.out.println(param);
  95. // }
  96. // }
  97. //StringBuilder builder = new StringBuilder(" <div class=\"bText\">");
  98. //builder.append("\n\t\t<script language=\"javascript\"> show_postcontent('a aaaa bbdd\n");
  99. //builder.append("<font face=\"Ariral\"> sdfdshfjdsfds </font> xcvxcvcxdf 333223 ');</script>\n\t");
  100. //builder.append("<a id=\"feedbacks\"></a><a id=\"comments\"></a><a id=\"trackbacks\">");
  101. //builder.append("</a><a id=\"pingbacks\"></a> \n\t");
  102. //List<String> jsScripts = new ArrayList<String>();
  103. //jsScripts.add("show_postcontent");
  104. //HTMLDocument document = HTMLParser.createDocument(builder.toString());
  105. //JsScriptHandler.updateDocument(document, jsScripts);
  106. //System.out.println(document.getTextValue());
  107. //}
  108. }