01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05:
06: package com.sun.portal.rewriter.services.ids;
07:
08: import com.sun.portal.rewriter.rom.Rule;
09: import com.sun.portal.rewriter.rom.common.Attribute;
10: import com.sun.portal.rewriter.rom.common.AttributeRule;
11: import com.sun.portal.rewriter.rom.common.TagText;
12: import com.sun.portal.rewriter.rom.common.TagTextRule;
13: import com.sun.portal.rewriter.rom.html.Applet;
14: import com.sun.portal.rewriter.rom.html.AppletRule;
15: import com.sun.portal.rewriter.rom.html.Form;
16: import com.sun.portal.rewriter.rom.html.FormRule;
17: import com.sun.portal.rewriter.rom.js.Function;
18: import com.sun.portal.rewriter.rom.js.FunctionRule;
19: import com.sun.portal.rewriter.util.StringHelper;
20:
21: final class IDSRuleBuilder {
22: static AppletRule buildAppletRule(final String s) {
23: final String[] values = StringHelper.tokenize(s, " ", true);
24: if (values.length < 3) {
25: return null;
26: }
27:
28: String src = values[0];
29: String code = values[1];
30: String param = values[2];
31: String pattern = (values.length == 4) ? values[3] : "";
32: return new AppletRule(new Applet(code, param, pattern, src));
33: }//buildAppletRule()
34:
35: static FormRule buildFormRule(final String s) {
36: final String[] values = StringHelper.tokenize(s, " ", true);
37: if (values.length < 3) {
38: return null;
39: }
40: String src = values[0];
41: String name = values[1];
42: String tag = values[2];
43: StringBuffer pattern = new StringBuffer("");
44: for (int i = 3; i < values.length; i++) {
45: pattern.append(values[i]).append(" ");
46: }
47: return new FormRule(
48: new Form(name, tag, pattern.toString(), src));
49: }//buildFormRule()
50:
51: static FunctionRule buildFunctionRule(final String value,
52: final String type) {
53: final String[] values = StringHelper.tokenize(value, ":", true);
54: if (values.length < 2) {
55: return null;
56: }
57: String name = values[0];
58: String pattern = values[1];
59: return new FunctionRule(new Function(name, pattern, type, null));
60: }//buildFunctionRule()
61:
62: static AttributeRule buildAttributeRule(String s) {
63:
64: String[] values = StringHelper.tokenize(s, ",", true);
65: if (values.length < 1) {
66: return null;
67: }
68:
69: String aTag = values[0];
70: String aName = new String();
71: if (values.length < 2)
72: aName = "";
73: else
74: aName = values[1];
75:
76: String pattern = (values.length == 3) ? values[2] : "";
77:
78: return new AttributeRule(new Attribute(aTag, aName, pattern,
79: Rule.URL, null));
80: }//buildAttributeRule()
81:
82: static TagTextRule buildTagTextRule(String s) {
83: String[] values = StringHelper.tokenize(s, ", ", true);
84: if (values.length < 1) {
85: return null;
86: }
87:
88: String aTag = values[0];
89:
90: String pattern = (values.length == 2) ? values[1] : "";
91:
92: return new TagTextRule(new TagText(aTag, pattern, null));
93: }//buildTagTextRule()
94:
95: }//class IDSRuleBuilder
|