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