Source Code Cross Referenced for CnConfig.java in  » Portal » Open-Portal » com » sun » portal » search » admin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.search.admin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:        import java.util.logging.LogRecord;
013:        import java.io.*;
014:
015:        import com.sun.portal.search.util.*;
016:        import com.sun.portal.log.common.PortalLogger;
017:
018:        public class CnConfig {
019:
020:            public static String CLASSIFICATION_CONF = "classification.conf";
021:
022:            // List of src's
023:            public static final String SRC_URL = "URL";
024:            public static final String SRC_HOST = "host";
025:            public static final String SRC_PROTOCOL = "protocol";
026:            public static final String SRC_URI = "uri";
027:            public static final String SRC_IP = "ip";
028:            public static final String SRC_TYPE = "type";
029:            public static final String SRC_ATTRIBUTE = "attribute";
030:
031:            // List of methods
032:            public static final String METHOD_EXACT = "by-exact";
033:            public static final String METHOD_PREFIX = "by-prefix";
034:            public static final String METHOD_SUFFIX = "by-suffix";
035:            public static final String METHOD_SUBSTR = "by-substr";
036:            public static final String METHOD_REGEX = "by-regex";
037:
038:            public static final String METHOD_LIST[] = { METHOD_EXACT,
039:                    METHOD_PREFIX, METHOD_SUFFIX, METHOD_SUBSTR, METHOD_REGEX };
040:
041:            // file header and footer initialized upon reading the file
042:            private StringBuffer filename;
043:            private StringBuffer rulesHeader = new StringBuffer();
044:            private StringBuffer rulesFooter = new StringBuffer();
045:
046:            // initialized upon reading the file and updated when
047:            // add, update, delete are done
048:            ArrayList rulesList;
049:
050:            // Create a logger for this class
051:            private static Logger debugLogger = PortalLogger
052:                    .getLogger(CnConfig.class);
053:
054:            public CnConfig(String server_root) {
055:                // Read classification.conf from server_root/config directory
056:                // parse the file and store the rules in an array
057:                filename = new StringBuffer();
058:                filename.append(server_root + File.separator);
059:                filename.append(SearchConfig.CONFDIR + File.separator);
060:                filename.append(CnConfig.CLASSIFICATION_CONF);
061:
062:                parseClassificationFile(filename.toString());
063:            }
064:
065:            public ArrayList getRulesList() {
066:                return rulesList;
067:            }
068:
069:            public boolean isExist(String src, String method, String name,
070:                    String action) {
071:                return isExist(src, method, name, action, -1);
072:            }
073:
074:            public boolean isExist(String src, String method, String name,
075:                    String action, int exceptIndex) {
076:                for (int i = 0; i < rulesList.size(); i++) {
077:                    if (i == exceptIndex) {
078:                        continue;
079:                    }
080:                    Rule r = (Rule) rulesList.get(i);
081:                    if (r.getSrc().equalsIgnoreCase(src)
082:                            && r.getMethod().equalsIgnoreCase(method)
083:                            && r.getName().equals(name)
084:                            && r.getAction().equals(action)) {
085:                        return true;
086:                    }
087:                }
088:                return false;
089:            }
090:
091:            public boolean add(String src, String method, String name,
092:                    String action, boolean isCase) {
093:                // Create a new rule object with src, method, name, action paramter
094:                // Create new rule with the params
095:                // add the rule to the rulesList
096:
097:                if (isExist(src, method, name, action)) {
098:                    return false;
099:                }
100:                Rule r = new Rule(src, method, name, action, isCase);
101:                addSortedBySrc(r);
102:                return true;
103:            }
104:
105:            void addSortedBySrc(Rule r) {
106:                for (int i = 0; i < rulesList.size(); i++) {
107:                    Rule element = (Rule) rulesList.get(i);
108:                    if (r.getSrc().compareTo(element.getSrc()) < 0) {
109:                        rulesList.add(i, r);
110:                        return;
111:                    }
112:                }
113:                rulesList.add(r);
114:            }
115:
116:            public void delete(int index) {
117:                // Delete will have an index parameter which is the rule number
118:                // Delete the rule from the rule list
119:                rulesList.remove(index);
120:            }
121:
122:            public void removeAll() {
123:                rulesList.clear();
124:            }
125:
126:            public void update(int index, String src, String method,
127:                    String name, String action) {
128:                // Is a little complicated
129:                // extract the rule from rulesList
130:                // save the new values in the rule, delete the old rule
131:
132:                Rule r = (Rule) rulesList.get(index);
133:                r.setSrc(src);
134:                r.setMethod(method);
135:                r.setName(name);
136:                r.setAction(action);
137:            }
138:
139:            public void save() {
140:                // open the file. copy the rulesHeader
141:                // Copy rulesList
142:                // copy rulesFooter
143:                // close the file
144:
145:                try {
146:                    FileOutputStream fos = new FileOutputStream(filename
147:                            .toString());
148:                    PrintWriter pw = new PrintWriter(new BufferedWriter(
149:                            new OutputStreamWriter(fos, "UTF8")), true);
150:                    pw.println(rulesHeader);
151:                    StringBuffer buf = new StringBuffer();
152:                    for (int i = 0; i < rulesList.size(); i++) {
153:                        Rule r = (Rule) rulesList.get(i);
154:                        buf.append("Classification");
155:                        buf.append(" ");
156:                        buf.append("src=");
157:                        buf.append("\"" + r.getSrc() + "\"");
158:                        buf.append(" ");
159:                        buf.append(r.getMethod());
160:                        buf.append("=");
161:                        buf.append(PBlock.quotedString(r.getName()));
162:                        buf.append(" ");
163:                        if (!r.isCaseSensitive()) {
164:                            buf.append("case="
165:                                    + (r.isCaseSensitive() ? "true" : "false"));
166:                        }
167:                        buf.append(" ");
168:                        buf.append("action=");
169:                        buf.append(PBlock.quotedString(r.getAction()));
170:                        buf.append("\n");
171:                    }
172:                    pw.println(buf.toString());
173:                    pw.print(rulesFooter);
174:                    pw.close();
175:                } catch (Exception e) {
176:                    if (debugLogger.isLoggable(Level.INFO)) {
177:                        LogRecord logRecord = new LogRecord(Level.INFO,
178:                                "PSSH_CSPSA0006");
179:                        logRecord.setParameters(new Object[] { filename });
180:                        logRecord.setThrown(e);
181:                        logRecord.setLoggerName(debugLogger.getName());
182:                        debugLogger.log(logRecord);
183:                    }
184:                }
185:            }
186:
187:            public void parseClassificationFile(String fname) {
188:                // read the file, parse it
189:                // set rulesHeader, rulesFooter
190:                // Create each rule object with appropriate values
191:                // create rulesList
192:
193:                rulesHeader = new StringBuffer("");
194:                rulesFooter = new StringBuffer("");
195:                rulesList = new ArrayList();
196:
197:                boolean inHeader = true;
198:                boolean inFooter = false;
199:
200:                try {
201:                    BufferedReader br = new BufferedReader(
202:                            new InputStreamReader(new FileInputStream(fname),
203:                                    "UTF-8"));
204:                    String line = null;
205:                    while ((line = br.readLine()) != null) {
206:                        if (line.startsWith("Classification")) {
207:                            addRule(line);
208:                        } else if (line
209:                                .startsWith("<Preprocess directive=\"Generate\">")) {
210:                            rulesHeader.append(line + "\n");
211:                            inHeader = false;
212:                        } else if (line.startsWith("</Preprocess>")) {
213:                            rulesFooter.append(line + "\n");
214:                            inFooter = true;
215:                        } else if (inHeader) {
216:                            rulesHeader.append(line + "\n");
217:                        } else if (inFooter) {
218:                            rulesFooter.append(line + "\n");
219:                        }
220:                    }
221:                    br.close();
222:                } catch (IOException e) {
223:                    debugLogger.info("PSSH_CSPSA0007");
224:                }
225:            }
226:
227:            public void addRule(String rule) {
228:                HashMap map = new HashMap();
229:                try {
230:                    PBlock.str2pblock(rule, map);
231:                    Rule r = new Rule();
232:
233:                    String value;
234:
235:                    value = (String) map.get("src");
236:                    if (value != null) {
237:                        int methodIndex;
238:                        r.setSrc(value);
239:                        for (methodIndex = 0; methodIndex < METHOD_LIST.length; methodIndex++) {
240:                            value = (String) map.get(METHOD_LIST[methodIndex]);
241:                            if (value != null)
242:                                break;
243:                        }
244:                        if (value != null) {
245:                            r.setMethod(METHOD_LIST[methodIndex]);
246:                            r.setName(value);
247:                            value = (String) map.get("action");
248:                            if (value != null) {
249:                                r.setAction(value);
250:                                value = (String) map.get("case");
251:                                if (value != null && value.equals("false")) {
252:                                    r.setCaseSensitive(false);
253:                                }
254:                                if (!isExist(r.getSrc(), r.getMethod(), r
255:                                        .getName(), r.getAction())) {
256:                                    addSortedBySrc(r);
257:                                    return;
258:                                }
259:                            }
260:                        }
261:                    }
262:
263:                } catch (Exception e) {
264:                }
265:                debugLogger.log(Level.INFO, "PSSH_CSPSA0008", rule);
266:                return;
267:            }
268:
269:            // Method to return the number of rules
270:            public int getNumberOfRules() {
271:                return rulesList.size();
272:            }
273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.