Last change
on this file since 3341 was 3341, checked in by kjdon, 22 years ago |
some modifications
|
-
Property svn:keywords
set to
Author Date Id Revision
|
File size:
1.4 KB
|
Line | |
---|
1 | package org.greenstone.gsdl3.util;
|
---|
2 |
|
---|
3 | public class GSHTML {
|
---|
4 |
|
---|
5 | public static String htmlSafe(String input) {
|
---|
6 |
|
---|
7 | StringBuffer filtered = new StringBuffer(input.length());
|
---|
8 | char c;
|
---|
9 | for (int i=0; i<input.length(); i++) {
|
---|
10 | c = input.charAt(i);
|
---|
11 | if (c == '<') {
|
---|
12 | filtered.append("<");
|
---|
13 | } else if (c == '>') {
|
---|
14 | filtered.append(">");
|
---|
15 | } else if (c == '"') {
|
---|
16 | filtered.append(""");
|
---|
17 | } else if (c == '&') {
|
---|
18 | filtered.append("&");
|
---|
19 | } else {
|
---|
20 | filtered.append(c);
|
---|
21 | }
|
---|
22 | }
|
---|
23 | return(filtered.toString());
|
---|
24 | }
|
---|
25 |
|
---|
26 | public static String htmlUnsafe(String input) {
|
---|
27 | StringBuffer filtered = new StringBuffer(input.length());
|
---|
28 | char c;
|
---|
29 | for (int i=0; i<input.length(); i++) {
|
---|
30 | c = input.charAt(i);
|
---|
31 | if (c =='&') {
|
---|
32 | int j=input.indexOf(';', i);
|
---|
33 | String entity = input.substring(i, j);
|
---|
34 | i=j;
|
---|
35 | System.out.println("entity="+entity);
|
---|
36 | if (entity.equals("amp")) {
|
---|
37 | filtered.append('&');
|
---|
38 | } else if (entity.equals("lt")){
|
---|
39 | filtered.append('<');
|
---|
40 | } else if (entity.equals("gt")){
|
---|
41 | filtered.append('>');
|
---|
42 | } else if (entity.equals("quot")) {
|
---|
43 | filtered.append('"');
|
---|
44 | } // else just ignore it.
|
---|
45 | } else {
|
---|
46 | filtered.append(c);
|
---|
47 | }
|
---|
48 | }
|
---|
49 | return(filtered.toString());
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | public static String errorPage(String error) {
|
---|
54 | String page = "<html><head><Title>GSDL3 Error!</Title><head>\n"+
|
---|
55 | "<body><h1>Greenstone Error!</h1>"+
|
---|
56 | "<p>"+error+"</body></html>";
|
---|
57 | return page;
|
---|
58 | }
|
---|
59 |
|
---|
60 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.