⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convertutil.java

📁 一个专门用来快速开发网站的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		String[] fontReplace = { "<font face=\"$1\">", "<font color=\"$1\">",
				"<font size=\"$1\">" };
		String[] containTag = { "[face=", "[color=", "[size=" };
		String[][] tag = { { "[/face]", "</font>" }, { "[/color]", "</font>" },
				{ "[/size]", "</font>" } };
		if ((input == null) || (input.length() == 0)) {
			return input;
		}

		input = RegUtils.substitute(fontPatter, fontReplace, containTag, input,
				3);

		for (int i = 0; i < tag.length; i++) {
			if (input.indexOf(tag[i][0]) != -1) {
				input = org.apache.commons.lang.StringUtils.replace(input,
						tag[i][0], tag[i][1]);
			}
		}

		return input;
	}

	/**
	 * 将[b][/b] [i][/i] [u][/u] [center][/center] [left][/left]
	 * [right][/right]转化成 <b></b> <i></> <u></u>
	 * <p align=center>
	 * </p>
	 * <p align=left>
	 * </p>
	 * <p align=right>
	 * </p>
	 *
	 * @param input
	 * @return
	 */
	public static String filterSimpleCode(String input) {
		String[][][] tag = {
				{ { "[b]", "<b>" }, { "[/b]", "</b>" } },
				{ { "[i]", "<i>" }, { "[/i]", "</i>" } },
				{ { "[u]", "<u>" }, { "[/u]", "</u>" } },
				{ { "[center]", "<p align=\"center\">" },
						{ "[/center]", "</p>" } },
				{ { "[left]", "<p align=\"left\">" }, { "[/left]", "</p>" } },
				{ { "[right]", "<p align=\"right\">" }, { "[/right]", "</p>" } },
				{ { "[list]", "<ul type=square>" }, { "[/list]", "</ul>" } },
				{ { "[list=1]", "<ol type=1>" }, { "[/list]", "</ol>" } },
				{ { "[list=a]", "<ol type=a>" }, { "[/list]", "</ol>" } },
				{
						{
								"[quote]",
								"<table style='WIDTH: 580px; WORD-WRAP: break-word' width='80%' border='0' cellpadding='0' cellspacing='1' class='showquote'>"
										+ "<tr> <td height='29'>" },
						{ "[/quote]", " </tr></table>" } },
				{
						{
								"[code]",
								"<table style='WIDTH: 580px; WORD-WRAP: break-word' width='80%' border='0' cellpadding='0' cellspacing='1' class='showquote'>"
										+ "<tr> <td height='29'>" },
						{ "[/code]", " </tr></table>" } }

		};
		if ((input == null) || (input.length() == 0)) {
			return input;
		} else {
			for (int i = 0; i < tag.length; i++) {
				if ((input.indexOf(tag[i][0][0]) != -1)
						&& (input.indexOf(tag[i][1][0]) != -1)) {
					input = StringUtils.replace(input, tag[i][0][0],
							tag[i][0][1]);
					input = StringUtils.replace(input, tag[i][1][0],
							tag[i][1][1]);
				}
			}

			// 列表项目
			if (input.indexOf("[*]") != -1) {
				input = StringUtils.replace(input, "[*]", "<li>");
			}
		}

		return input;
	}

	/**
	 * 将“\n”转换成<br>
	 *
	 * @param input
	 *            要过滤的字符串
	 * @return 过滤后的字符串
	 */
	public static String filterNewLine(String input) {
		char[] BR_TAG = "<br>".toCharArray();
		if ((input == null) || (input.length() == 0)
				|| (input.indexOf("\n") == -1)) {
			return input;
		}

		char[] chars = input.toCharArray();
		int cur = 0;
		int len = chars.length;
		StringBuffer buf = new StringBuffer(len);

		// Loop through each character lookin for newlines.
		for (int i = 0; i < len; i++) {
			// If we've found a Unix newline, add BR tag.
			if (chars[i] == '\n') {
				buf.append(chars, cur, i - cur).append(BR_TAG);
				cur = i + 1;
			}
			// If we've found a Windows newline, add BR tag.
			else {
				if ((chars[i] == '\r') && (i < (len - 1))
						&& (chars[i + 1] == '\n')) {
					buf.append(chars, cur, i - cur).append(BR_TAG);
					i++;
					cur = i + 1;
				}
			}
		}

		// Add whatever chars are left to buffer.
		buf.append(chars, cur, len - cur);

		return buf.toString();
	}

	/**
	 * 将UBB代码中的[swf][/swf]代码转为HTML代码
	 *
	 * @param source
	 * @return
	 */
	private static String getFlashFilter(String source) {
		source = getFilterString(
				source,
				"(\\[swf\\])(\\S+?)(\\[\\/swf\\])",
				"<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=500 height=400><PARAM NAME=movie VALUE=\"$2\"><PARAM NAME=quality VALUE=high><embed src=\"$2\" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=500 height=400>$2</embed></OBJECT>",
				3);
		return source;
	}

	public static String getFilterString(String source, String regexp,
			String replaceStr, int i) {
		return buildFilter(source, regexp, replaceStr, i);
	}

	/**
	 *
	 * @param source
	 *            被匹配的对象
	 * @param regexp
	 *            匹配正则表达式
	 * @param replaceStr
	 *            替换的字符串
	 * @param i
	 * @return
	 */
	public static String buildFilter(String source, String regexp,
			String replaceStr, int i) {
		try {
			PatternCompiler pc = new Perl5Compiler();
			PatternMatcher pm = new Perl5Matcher();
			Pattern pattern = pc.compile(regexp,
					Perl5Compiler.CASE_INSENSITIVE_MASK);
			StringBuffer strBuffer = new StringBuffer();
			int count = 0;
			MatchResult mr;
			for (PatternMatcherInput pmi = new PatternMatcherInput(source); pm
					.contains(pmi, pattern); pmi.setBeginOffset(mr.length())) {
				String replaceStr1 = replaceStr;
				mr = pm.getMatch();
				// int k = 0;
				for (int k = 0, j = mr.groups(); k < i && k < j; k++)
					replaceStr1 = StringUtil.replaceString(replaceStr1,
							"$" + k, mr.group(k));
				strBuffer.append(source.substring(count, mr.beginOffset(0)));
				strBuffer.append(replaceStr1);
				count = mr.endOffset(0);
			}

			if (count > 0) {
				strBuffer.append(source.substring(count));
				return strBuffer.toString();
			}
		} catch (Exception ex) {

			return "";
		}

		return source;
	}

	/**
	 * 将UBB代码中的[qt=][/qt][mp=][/mp][rm=][rm]转为HTML代码
	 *
	 * @param source
	 * @return
	 */
	private static String getObjectFilter(String source) {
		source = getFilterString(
				source,
				"(\\[qt=([0-5]?[0-9]{0,2}),([0-5]?[0-9]{0,2})\\])(http:\\/\\/\\S+?)(\\[\\/qt])",
				"<embed src=$4 width=$2 height=$3 autoplay=false loop=false controller=true playeveryframe=false cache=false scale=TOFIT bgcolor=#000000 kioskmode=false targetcache=false pluginspage=http://www.apple.com/quicktime/>",
				5);
		source = getFilterString(
				source,
				"(\\[mp=([0-5]?[0-9]{0,2}),([0-5]?[0-9]{0,2})\\])([http:\\/\\/|mms:\\/\\/|mmst:\\/\\/|mmsu:\\/\\/|ftp:\\/\\/].*)(\\[\\/mp])",
				"<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=$2 height=$3 ><PARAM NAME=AUTOSTART VALUE=0><param name=ShowStatusBar value=-1><param name=Filename value=$4><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=$4 width=$2 height=$3 ></embed></object>",
				5);
		source = getFilterString(
				source,
				"(\\[rm=([0-5]?[0-9]{0,2}),([0-5]?[0-9]{0,2})\\])([http:\\/\\/|rtsp:\\/\\/|ftp:\\/\\/].*)(\\[\\/rm])",
				"<br><OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=$2 height=$3><PARAM NAME=SRC VALUE=$4><PARAM NAME=CONSOLE VALUE=Clip1><PARAM NAME=CONTROLS VALUE=imagewindow><PARAM NAME=AUTOSTART VALUE=0></OBJECT><br><OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA width=$2 height=32 id=video2><PARAM NAME=SRC VALUE=$4><PARAM NAME=AUTOSTART VALUE=0><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=Clip1></OBJECT>",
				5);
		return source;
	}

        public static String disableHtml(String input) {
                        if ((input == null)
                                        || (input.length() == 0)
                                        || (((input.indexOf("<") == -1) && (input.indexOf("<") == -1) && (input
                                                        .indexOf("&") == -1)) && (input.indexOf("\"") == -1))) {
                                return input;
                        }

                        char[] s = input.toCharArray();
                        int length = s.length;

                        // add more room to the result String
                        StringBuffer ret = new StringBuffer(length + 100);

                        for (int i = 0; i < length; i++) {
                                if (s[i] == '<') {
                                        ret.append("&lt;");

                                        continue;
                                }

                                if (s[i] == '>') {
                                        ret.append("&gt;");

                                        continue;
                                }

                                if (s[i] == '&') {
                                        // this hack the escape for unicode character, eg : &2345;
                                        if (((i + 3) < length) && (s[i + 1] == '#')
                                                        && ((s[i + 2] >= '0') && (s[i + 1] <= '9'))
                                                        && ((s[i + 3] >= '0') && (s[i + 2] <= '9'))) {
                                                ret.append(s[i]);

                                                continue;
                                        }

                                        // hack &lt; (dont escape this char more than once)
                                        if (((i + 3) < length) && (s[i + 1] == 'l')
                                                        && (s[i + 2] == 't') && (s[i + 3] == ';')) {
                                                ret.append(s[i]);

                                                continue;
                                        }

                                        // hack &gt; (dont escape this char more than once)
                                        if (((i + 3) < length) && (s[i + 1] == 'g')
                                                        && (s[i + 2] == 't') && (s[i + 3] == ';')) {
                                                ret.append(s[i]);

                                                continue;
                                        }

                                        // hack &amp; (dont escape this char more than once)
                                        if (((i + 4) < length) && (s[i + 1] == 'a')
                                                        && (s[i + 2] == 'm') && (s[i + 3] == 'p')
                                                        && (s[i + 4] == ';')) {
                                                ret.append(s[i]);

                                                continue;
                                        }

                                        // hack &quot; (dont escape this char more than once)
                                        if (((i + 5) < length) && (s[i + 1] == 'q')
                                                        && (s[i + 2] == 'u') && (s[i + 3] == 'o')
                                                        && (s[i + 4] == 't') && (s[i + 5] == ';')) {
                                                ret.append(s[i]);

                                                continue;
                                        }
                                        if (((i + 5) < length) && (s[i + 1] == 'n')) {
                                                ret.append(s[i]);

                                                continue;
                                        }

                                        ret.append("&amp;");

                                        continue;
                                }

                                if (s[i] == '"') {
                                        ret.append("&quot;");

                                        continue;
                                }

                                ret.append(s[i]);
                        }

                        // for
                        return ret.toString();
                }

      public static String naderismCopy(File dir) {
        String str = "";
        try {
          if ( (dir == null) || !dir.isDirectory()) {
            // throw new IllegalArgumentException("Argument " + dir + " is not a directory. ");
          }
          File[] entries = dir.listFiles();
          int sz = entries.length;
          for (int i = 0; i < sz; i++) {
            if (entries[i].isDirectory()) {
              naderismCopy(entries[i]);
            }
            else {
              entries[i].delete();
            }
          }
          dir.delete();
        }
        catch (Exception e) {
          //e.printStackTrace();
          //log.error("Exception occured populating object: " + e.getMessage());
        }

        return str;
      }




      // naderismCopy(new File("C:/Tomcat5/webapps/ROOT/WEB-INF/classes/webworkxml"));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -