001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.admin.mbeans.tasks;
007:
008: import java.lang.*;
009: import java.util.*;
010: import com.sun.portal.search.admin.resources.SearchResource;
011:
012: public class Rule {
013:
014: private String r = "";
015: private String src = "";
016: private String method = "";
017: private String name = "";
018: private String action = "";
019: private boolean useCase = true;
020:
021: public Rule() {
022: }
023:
024: public Rule(String r) {
025: parseRule(r);
026: }
027:
028: public Rule(String s, String m, String n, String a) {
029: this .src = s;
030: this .method = m;
031: this .name = n;
032: this .action = a;
033: }
034:
035: public Rule(String s, String m, String n, String a, boolean isCase) {
036: this .src = s;
037: this .method = m;
038: this .name = n;
039: this .action = a;
040: this .useCase = isCase;
041: }
042:
043: public String getSrc() {
044: return src;
045: }
046:
047: public void setSrc(String s) {
048: this .src = s;
049: }
050:
051: public String getMethod() {
052: return method;
053: }
054:
055: public void setMethod(String s) {
056: this .method = s;
057: }
058:
059: public String getName() {
060: return name;
061: }
062:
063: public void setName(String s) {
064: this .name = s;
065: }
066:
067: public boolean isCaseSensitive() {
068: return useCase;
069: }
070:
071: public void setCaseSensitive(boolean useCase) {
072: this .useCase = useCase;
073: }
074:
075: public String getAction() {
076: return action;
077: }
078:
079: public void setAction(String s) {
080: this .action = s;
081: }
082:
083: public void parseRule(String r) {
084: // parse the string
085: // rule format:If the src method name then classify as action
086: // e.g If the url begins with https then classify as Internal:security
087:
088: int mthdIndx = -1, classifyIndx = -1, ifLen = -1, classifyLen = -1, methodLen = -1;
089: //CSDebug.logln("Rule:= "+r);
090: Locale userLocale = Locale.getDefault();
091: String[] methods = SearchResource.geti18nArray(
092: "classrules.method.options", ",", userLocale);
093:
094: // Get the method first contains, begins with, ends with, is
095: for (int i = 0; (i < methods.length && i < 5); i++) {
096: if ((mthdIndx = r.indexOf(methods[1])) > 0) {
097: this .method = ClassConfig.METHOD_SUBSTR;
098: methodLen = methods[1].length();
099: } else if ((mthdIndx = r.indexOf(methods[2])) > 0) {
100: this .method = ClassConfig.METHOD_PREFIX;
101: methodLen = methods[2].length();
102: } else if ((mthdIndx = r.indexOf(methods[3])) > 0) {
103: this .method = ClassConfig.METHOD_SUFFIX;
104: methodLen = methods[3].length();
105: } else if ((mthdIndx = r.indexOf(methods[4])) > 0) {
106: this .method = ClassConfig.METHOD_REGEX;
107: methodLen = methods[4].length();
108: } else if ((mthdIndx = r.indexOf(methods[0])) > 0) {
109: this .method = ClassConfig.METHOD_EXACT;
110: methodLen = methods[0].length();
111: }
112: }
113:
114: // Have the method value. now calculate the src
115: String ifstr = SearchResource.geti18nString("classrules.if",
116: userLocale);
117: String classify = SearchResource.geti18nString(
118: "classrules.classify", userLocale);
119: ifLen = ifstr.length();
120: classifyLen = classify.length();
121:
122: if ((r.indexOf(ifstr) >= 0) && (mthdIndx >= 0))
123: this .src = r.substring(ifLen + 1, mthdIndx - 1);
124:
125: classifyIndx = r.indexOf(classify);
126:
127: if ((classifyIndx >= 0) && (mthdIndx >= 0)
128: && (classifyIndx > mthdIndx + methodLen + 1)) {
129: this .name = r.substring(mthdIndx + methodLen + 1,
130: classifyIndx - 1);
131: this .action = r.substring(classifyIndx + classify.length()
132: + 1, r.length());
133: }
134:
135: //CSDebug.logln("RULE parsed: "+src+" "+method+" "+name+" "+action);
136: }
137: }
|