Source Code Cross Referenced for Robot.java in  » Portal » Open-Portal » com » sun » portal » search » admin » mbeans » 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.mbeans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * Copyright 2004 Sun Microsystems, Inc. All
0003:         * rights reserved. Use of this product is subject
0004:         * to license terms. Federal Acquisitions:
0005:         * Commercial Software -- Government Users
0006:         * Subject to Standard License Terms and
0007:         * Conditions.
0008:         *
0009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0010:         * are trademarks or registered trademarks of Sun Microsystems,
0011:         * Inc. in the United States and other countries.
0012:         */package com.sun.portal.search.admin.mbeans;
0013:
0014:        import java.io.*;
0015:        import java.util.*;
0016:        import java.util.logging.*;
0017:        import java.net.*;
0018:        import java.lang.*;
0019:        import java.text.*;
0020:        import java.net.InetAddress;
0021:        import java.util.regex.Pattern;
0022:
0023:        import javax.management.MBeanServer;
0024:        import javax.management.MBeanServerConnection;
0025:        import javax.management.ObjectName;
0026:        import javax.management.remote.JMXConnector;
0027:
0028:        import com.sun.portal.log.common.*;
0029:
0030:        import com.sun.portal.admin.server.PASModule;
0031:        import com.sun.portal.admin.server.mbeans.PSResource;
0032:        import com.sun.portal.admin.common.context.PSConfigContext;
0033:        import com.sun.portal.admin.common.context.PortalDomainContext;
0034:        import com.sun.portal.admin.common.util.AdminUtil;
0035:        import com.sun.portal.admin.common.PSMBeanException;
0036:        import com.sun.portal.admin.server.AdminServerUtil;
0037:
0038:        import com.sun.portal.log.common.PortalLogger;
0039:
0040:        import com.sun.portal.search.robot.*;
0041:        import com.sun.portal.search.admin.mbeans.tasks.FilterSimulator;
0042:        import com.sun.portal.search.admin.mbeans.tasks.FilterConfigurator;
0043:
0044:        import sun.misc.BASE64Encoder;
0045:        import sun.misc.BASE64Decoder;
0046:
0047:        public class Robot extends PSResource implements  RobotMBean {
0048:
0049:            public String serverRoot = null;
0050:            public String binDir = null;
0051:            public String libDir = null;
0052:            public String libPath = null;
0053:            public String configDir = null;
0054:            public String logDir = null;
0055:            public String statusDir = "robot";
0056:
0057:            private ObjectName objectName = null;
0058:            private String host = null;
0059:            private static Logger logger = PortalLogger.getLogger(Robot.class);
0060:            private RobotConfig robotConfig = null;
0061:            private FilterConfigurator filterConfig = null;
0062:            private String[] r_env = null;
0063:            private FilterLog flog = null;
0064:            private String statestring = "";
0065:            private String[] states = { "0", "0", "0", "0", "0", "0", "0", "0",
0066:                    "0", "0", "0", "0", "0" };
0067:            private boolean isRunning = false;
0068:
0069:            public void init(PSConfigContext cc, PortalDomainContext pdc,
0070:                    List path) {
0071:                super .init(cc, pdc, path);
0072:
0073:                try {
0074:                    objectName = AdminUtil.getResourceMBeanObjectName(
0075:                            AdminUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
0076:                    host = pdc.getAttributeValue(
0077:                            AdminUtil.SEARCH_ROBOT_MBEAN_TYPE, path, "Host");
0078:                } catch (Exception e) {
0079:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0080:                }
0081:
0082:                try {
0083:                    if (AdminUtil.isLocal(host)) {
0084:                        initConfig(path);
0085:                    }
0086:                } catch (Exception e) {
0087:                    //logger.logp(Level.SEVERE, "Robot", "init()", "initialization failed", e);
0088:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0089:                }
0090:            }
0091:
0092:            private void initConfig(List path) throws PSMBeanException {
0093:
0094:                try {
0095:
0096:                    //get the SearchServer associated with the Robot
0097:                    MBeanServer ms = PASModule.getMBeanServer();
0098:                    LinkedList serverpath = new LinkedList();
0099:                    serverpath.addFirst(path.get(2));
0100:                    serverpath.addFirst(path.get(1));
0101:                    ObjectName searchServer = AdminUtil
0102:                            .getResourceMBeanObjectName(
0103:                                    AdminUtil.SEARCHSERVER_MBEAN_TYPE,
0104:                                    serverpath);
0105:
0106:                    serverRoot = (String) ms.getAttribute(searchServer,
0107:                            "SearchServerRoot");
0108:
0109:                    binDir = (String) ms.getAttribute(searchServer, "BinDir");
0110:
0111:                    libDir = (String) ms.getAttribute(searchServer, "LibDir");
0112:
0113:                    libPath = (String) ms.getAttribute(searchServer, "LibPath");
0114:
0115:                    configDir = (String) ms.getAttribute(searchServer,
0116:                            "ConfigDir");
0117:
0118:                    logDir = (String) ms.getAttribute(searchServer, "LogDir");
0119:
0120:                    if ((serverRoot == null) || (configDir == null)) {
0121:                        String message = "Robot.init(): fail to initialize robot configuration; either server root is null or config directory is null";
0122:                        Object tokens[] = { message };
0123:                        logger.log(Level.INFO, "PSSH_CSPSAMB0002", tokens);
0124:                        throw new PSMBeanException(
0125:                                "Robot.initConfig(): initialization failed");
0126:                    }
0127:
0128:                    robotConfig = new RobotConfig(configDir);
0129:
0130:                    statusDir = robotConfig.processConf.get("robot-state-dir");
0131:                    if (statusDir == null) {
0132:                        statusDir = serverRoot + File.separator + "robot";
0133:                    }
0134:
0135:                    filterConfig = new FilterConfigurator(serverRoot);
0136:                    filterConfig.readFilterToArray();
0137:
0138:                } catch (Exception e) {
0139:                    //logger.logp(Level.SEVERE, "Robot", "initConfig()", e.getMessage(), e);
0140:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0141:                    throw new PSMBeanException("Robot.initConfig()", e
0142:                            .toString(), e);
0143:                }
0144:
0145:                if (System.getProperty("os.name").startsWith("Windows")) {
0146:                    String winDir = "C:\\WINNT";
0147:                    if (System.getProperty("os.name").equals("Windows XP"))
0148:                        winDir = "C:\\WINDOWS";
0149:                    r_env = new String[6];
0150:                    r_env[0] = "LD_LIBRARY_PATH=" + libPath;
0151:                    r_env[1] = "CS_CONFIG_PATH=" + configDir;
0152:                    r_env[2] = "CS_LOGDIR=" + logDir;
0153:                    r_env[3] = "PATH=" + libPath + ";" + binDir;
0154:                    //Setting Windows specific env vars
0155:                    //SYSTEMROOT var is used by robot nspr socket libraries
0156:                    String SYSTEMROOT = "SYSTEMROOT";
0157:                    String sysRootVal = null;
0158:                    try {
0159:                        sysRootVal = getEnvVar(SYSTEMROOT);
0160:                    } catch (Exception ex) {
0161:                    }
0162:                    //logger.logp(Level.SEVERE, "Robot", "initConfig()", "Getting env prop:"+SYSTEMROOT + "=" + sysRootVal);
0163:                    if (sysRootVal == null)
0164:                        sysRootVal = winDir;
0165:
0166:                    //ComSpec var is used by rdregister to run rdmgr.bat
0167:                    String COMSPEC = "COMSPEC";
0168:                    String comSpecVal = null;
0169:                    try {
0170:                        comSpecVal = getEnvVar(COMSPEC);
0171:                    } catch (Exception ex) {
0172:                    }
0173:                    //logger.logp(Level.SEVERE, "Robot", "initConfig()", "Getting env prop:"+COMSPEC+"="+comSpecVal);
0174:                    if (comSpecVal == null)
0175:                        comSpecVal = winDir + "\\system32\\cmd.exe";
0176:                    r_env[4] = SYSTEMROOT + "=" + sysRootVal;
0177:                    r_env[5] = COMSPEC + "=" + comSpecVal;
0178:                } else {
0179:                    r_env = new String[5];
0180:                    String jss_nss_nspr_cert7_lib = "/usr/lib/mps";
0181:                    if (System.getProperty("os.name").startsWith("Linux")) {
0182:                        jss_nss_nspr_cert7_lib = "/opt/sun/private/lib";
0183:                    }
0184:
0185:                    if (System.getProperty("os.name").startsWith("HP-UX")) {
0186:                        jss_nss_nspr_cert7_lib = "/opt/sun/private/lib";
0187:                    }
0188:
0189:                    r_env[0] = "LD_LIBRARY_PATH=/usr/lib:"
0190:                            + jss_nss_nspr_cert7_lib + ":" + libPath;
0191:                    r_env[1] = "CS_CONFIG_PATH=" + configDir;
0192:                    r_env[2] = "CS_LOGDIR=" + logDir;
0193:                    r_env[3] = "PATH=" + libPath + ":" + binDir;
0194:                    r_env[4] = "SHLIB_PATH=/usr/lib:" + jss_nss_nspr_cert7_lib
0195:                            + ":" + libPath;
0196:                }
0197:
0198:                if (this .isRunning()) {
0199:                    isRunning = true;
0200:                } else {
0201:                    isRunning = false;
0202:                }
0203:
0204:            }
0205:
0206:            public Boolean start() throws UnknownHostException {
0207:
0208:                if (!AdminUtil.isLocal(host)) {
0209:                    try {
0210:                        JMXConnector jmxc = AdminServerUtil
0211:                                .getJMXConnector(host);
0212:                        MBeanServerConnection msc = jmxc
0213:                                .getMBeanServerConnection();
0214:                        Object[] params = {};
0215:                        String[] signatures = {};
0216:                        Boolean result = (Boolean) msc.invoke(objectName,
0217:                                "start", params, signatures);
0218:                        jmxc.close();
0219:                        return result;
0220:                    } catch (Exception e) {
0221:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0222:                        return Boolean.FALSE;
0223:                    }
0224:                } else {
0225:
0226:                    if (this .isRunning()) {
0227:                        isRunning = true;
0228:                        return Boolean.TRUE;
0229:                    }
0230:
0231:                    if (robotConfig.numRuleset() <= 0) {
0232:                        String message = "Robot.start(): there is no robot site set up";
0233:                        Object tokens[] = { message };
0234:                        logger.log(Level.INFO, "PSSH_CSPSAMB0002", tokens);
0235:                        return Boolean.FALSE;
0236:                    }
0237:
0238:                    if (!generate_filter_conf_run(configDir + File.separator
0239:                            + "filter.conf", configDir + File.separator
0240:                            + "filter.conf.run")) {
0241:                        String message = "Robot.start(): failed to create filter.conf.run";
0242:                        Object tokens[] = { message };
0243:                        logger.log(Level.INFO, "PSSH_CSPSAMB0002", tokens);
0244:                        return Boolean.FALSE;
0245:                    }
0246:
0247:                    if (!start_rdregister()) {
0248:                        String message = "Robot.start(): failed to start rdregister";
0249:                        Object tokens[] = { message };
0250:                        logger.log(Level.INFO, "PSSH_CSPSAMB0002", tokens);
0251:                        return Boolean.FALSE;
0252:                    }
0253:
0254:                    Runtime rt = Runtime.getRuntime();
0255:                    try {
0256:                        String cmds[] = { libDir + File.separator + ROBOT_CMD };
0257:                        rt.exec(cmds, r_env, new File(serverRoot));
0258:
0259:                        for (int i = 0; i < 10; i++) {
0260:                            try {
0261:                                this .wait(1000);
0262:                            } catch (Exception e) {
0263:                            }
0264:                        }
0265:
0266:                        isRunning = true;
0267:                        return Boolean.TRUE;
0268:
0269:                    } catch (IOException e) {
0270:                        String message = "Robot.start(): rt.exec exception: "
0271:                                + e.getMessage();
0272:                        Object tokens[] = { message };
0273:                        logger.log(Level.INFO, "PSSH_CSPSAMB0002", tokens);
0274:                        return Boolean.FALSE;
0275:                    }
0276:                }
0277:
0278:            }
0279:
0280:            public Boolean stop() throws UnknownHostException {
0281:
0282:                if (!AdminUtil.isLocal(host)) {
0283:                    try {
0284:                        JMXConnector jmxc = AdminServerUtil
0285:                                .getJMXConnector(host);
0286:                        MBeanServerConnection msc = jmxc
0287:                                .getMBeanServerConnection();
0288:                        Object[] params = {};
0289:                        String[] signatures = {};
0290:                        Boolean result = (Boolean) msc.invoke(objectName,
0291:                                "stop", params, signatures);
0292:                        jmxc.close();
0293:                        return result;
0294:                    } catch (Exception e) {
0295:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0296:                        return Boolean.FALSE;
0297:                    }
0298:                } else {
0299:
0300:                    byte[] result = this .robotURLGet(rCmd, "stop");
0301:
0302:                    for (int i = 0; i < 10; i++) {
0303:                        try {
0304:                            this .wait(1000);
0305:                        } catch (Exception e) {
0306:                        }
0307:                    }
0308:
0309:                    isRunning = false;
0310:                    return Boolean.TRUE;
0311:                }
0312:
0313:            }
0314:
0315:            public Boolean refresh() throws UnknownHostException {
0316:
0317:                if (!AdminUtil.isLocal(host)) {
0318:                    try {
0319:                        JMXConnector jmxc = AdminServerUtil
0320:                                .getJMXConnector(host);
0321:                        MBeanServerConnection msc = jmxc
0322:                                .getMBeanServerConnection();
0323:                        Object[] params = {};
0324:                        String[] signatures = {};
0325:                        Boolean result = (Boolean) msc.invoke(objectName,
0326:                                "refresh", params, signatures);
0327:                        jmxc.close();
0328:                        return result;
0329:                    } catch (Exception e) {
0330:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0331:                        return Boolean.FALSE;
0332:                    }
0333:                } else {
0334:                    states[2] = "0";
0335:                    states[3] = "0";
0336:                    states[4] = "0";
0337:                    states[5] = "0";
0338:                    states[6] = "0";
0339:                    states[7] = "0";
0340:                    states[8] = "0";
0341:                    states[9] = "0";
0342:                    states[10] = "0";
0343:                    states[11] = "0";
0344:                    states[12] = "0";
0345:                    return Boolean.valueOf(remove_status_files());
0346:                }
0347:            }
0348:
0349:            public Boolean pause() throws UnknownHostException {
0350:
0351:                if (!AdminUtil.isLocal(host)) {
0352:                    try {
0353:                        JMXConnector jmxc = AdminServerUtil
0354:                                .getJMXConnector(host);
0355:                        MBeanServerConnection msc = jmxc
0356:                                .getMBeanServerConnection();
0357:                        Object[] params = {};
0358:                        String[] signatures = {};
0359:                        Boolean result = (Boolean) msc.invoke(objectName,
0360:                                "pause", params, signatures);
0361:                        jmxc.close();
0362:                        return result;
0363:                    } catch (Exception e) {
0364:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0365:                        return Boolean.FALSE;
0366:                    }
0367:
0368:                } else {
0369:
0370:                    byte[] result = this .robotURLGet(rCmd, "pause");
0371:                    return Boolean.TRUE;
0372:                }
0373:            }
0374:
0375:            public Boolean resume() throws UnknownHostException {
0376:
0377:                if (!AdminUtil.isLocal(host)) {
0378:                    try {
0379:                        JMXConnector jmxc = AdminServerUtil
0380:                                .getJMXConnector(host);
0381:                        MBeanServerConnection msc = jmxc
0382:                                .getMBeanServerConnection();
0383:                        Object[] params = {};
0384:                        String[] signatures = {};
0385:                        Boolean result = (Boolean) msc.invoke(objectName,
0386:                                "resume", params, signatures);
0387:                        jmxc.close();
0388:                        return result;
0389:                    } catch (Exception e) {
0390:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0391:                        return Boolean.FALSE;
0392:                    }
0393:                } else {
0394:
0395:                    byte[] result = this .robotURLGet(rCmd, "resume");
0396:                    return Boolean.TRUE;
0397:                }
0398:            }
0399:
0400:            public Boolean isRobotRunning() throws UnknownHostException {
0401:
0402:                if (!AdminUtil.isLocal(host)) {
0403:                    try {
0404:                        JMXConnector jmxc = AdminServerUtil
0405:                                .getJMXConnector(host);
0406:                        MBeanServerConnection msc = jmxc
0407:                                .getMBeanServerConnection();
0408:                        Object[] params = {};
0409:                        String[] signatures = {};
0410:                        Boolean result = (Boolean) msc.invoke(objectName,
0411:                                "isRobotRunning", params, signatures);
0412:                        jmxc.close();
0413:                        return result;
0414:                    } catch (Exception e) {
0415:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0416:                        return Boolean.FALSE;
0417:                    }
0418:                } else {
0419:
0420:                    if (this .isRunning()) {
0421:                        isRunning = true;
0422:                        return Boolean.TRUE;
0423:                    } else {
0424:                        isRunning = false;
0425:                        return Boolean.FALSE;
0426:                    }
0427:                }
0428:            }
0429:
0430:            public String[] retrieveRobotStatus() throws PSMBeanException,
0431:                    UnknownHostException {
0432:                /*
0433:                 Robot states[]: 
0434:                 RobotStatus, StartingPoints, URLPool, Extracting, Filtering,
0435:                 Indexing, ExcludedByFilter, ExcludedByError, RD_NUM, RD_SIZE,
0436:                 URLRetrieved, RD_AVE_SIZE, RunningTime 
0437:                 */
0438:
0439:                if (!AdminUtil.isLocal(host)) {
0440:                    try {
0441:                        JMXConnector jmxc = AdminServerUtil
0442:                                .getJMXConnector(host);
0443:                        MBeanServerConnection msc = jmxc
0444:                                .getMBeanServerConnection();
0445:                        Object[] params = {};
0446:                        String[] signatures = {};
0447:                        String[] result = (String[]) msc.invoke(objectName,
0448:                                "retrieveRobotStatus", params, signatures);
0449:                        jmxc.close();
0450:                        return result;
0451:                    } catch (Exception e) {
0452:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0453:                        throw new PSMBeanException(
0454:                                "Robot.retrieveRobotStatus()", e.toString(), e);
0455:                    }
0456:                } else {
0457:
0458:                    if (!isRunning && !isRunning()) {
0459:                        states[0] = "Off";
0460:                        states[1] = Integer.toString(robotConfig
0461:                                .numOfStartingPoint(true));
0462:                    } else {
0463:                        if (!isRunning) {
0464:                            states[0] = "Off";
0465:                        } else {
0466:                            states[0] = "Running";
0467:                        }
0468:                        states[1] = Integer.toString(robotConfig
0469:                                .numOfStartingPoint(true));
0470:                        int url_waiting = 0;
0471:                        int processed = 0;
0472:                        int retrieved = 0;
0473:                        int rej_filter = 0;
0474:                        int rej_error = 0;
0475:                        int generated = 0;
0476:                        long generated_bytes = 0;
0477:                        long run_time = 0;
0478:                        byte[] result = this 
0479:                                .robotURLGet(rQuery, "robot-states");
0480:                        if (result != null) {
0481:                            String rs = new String(result);
0482:                            StringTokenizer st = new StringTokenizer(rs, "\n");
0483:                            while (st.hasMoreTokens()) {
0484:                                String t = st.nextToken();
0485:                                if (t.startsWith("Robot Status:")) {
0486:                                    states[0] = t.substring(13).trim();
0487:                                } else if (t.startsWith("url-waiting=")) {
0488:                                    url_waiting = Integer.parseInt(t
0489:                                            .substring(12));
0490:                                } else if (t.startsWith("processed=")) {
0491:                                    processed = Integer.parseInt(t
0492:                                            .substring(10));
0493:                                } else if (t.startsWith("retrieved=")) {
0494:                                    retrieved = Integer.parseInt(t
0495:                                            .substring(10));
0496:                                } else if (t.startsWith("reject-by-filter=")) {
0497:                                    rej_filter = Integer.parseInt(t
0498:                                            .substring(17));
0499:                                } else if (t.startsWith("reject-by-error=")) {
0500:                                    rej_error = Integer.parseInt(t
0501:                                            .substring(16));
0502:                                } else if (t.startsWith("generated=")) {
0503:                                    generated = Integer.parseInt(t
0504:                                            .substring(10));
0505:                                } else if (t.startsWith("generated-bytes=")) {
0506:                                    generated_bytes = Long.parseLong(t
0507:                                            .substring(16));
0508:                                } else if (t.startsWith("run-time=")) {
0509:                                    run_time = Long.parseLong(t.substring(9));
0510:                                }
0511:                            }
0512:
0513:                            NumberFormat nf = NumberFormat.getInstance();
0514:                            nf.setMaximumFractionDigits(2);
0515:                            states[2] = nf.format(url_waiting);
0516:                            if (run_time > 0) {
0517:                                states[3] = nf.format((float) retrieved
0518:                                        / (float) run_time);
0519:                                states[5] = nf.format((float) generated
0520:                                        / (float) run_time);
0521:                            }
0522:                            states[4] = nf.format(rej_filter + rej_error);
0523:                            states[6] = nf.format(rej_filter);
0524:                            states[7] = nf.format(rej_error);
0525:                            states[8] = nf.format(generated);
0526:                            states[9] = Long.toString(generated_bytes); //need for parsing later
0527:                            states[10] = nf.format(retrieved);
0528:                            if (generated > 0) {
0529:                                states[11] = nf.format((float) generated_bytes
0530:                                        / (float) generated);
0531:                            }
0532:                            states[12] = Long.toString(run_time); //need for parsing later
0533:                        }
0534:                    }
0535:                }
0536:
0537:                return states;
0538:            }
0539:
0540:            public String retrieveRobotStatusString() throws PSMBeanException,
0541:                    UnknownHostException {
0542:
0543:                if (!AdminUtil.isLocal(host)) {
0544:                    try {
0545:                        JMXConnector jmxc = AdminServerUtil
0546:                                .getJMXConnector(host);
0547:                        MBeanServerConnection msc = jmxc
0548:                                .getMBeanServerConnection();
0549:                        Object[] params = {};
0550:                        String[] signatures = {};
0551:                        String result = (String) msc
0552:                                .invoke(objectName,
0553:                                        "retrieveRobotStatusString", params,
0554:                                        signatures);
0555:                        jmxc.close();
0556:                        return result;
0557:                    } catch (Exception e) {
0558:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0559:                        throw new PSMBeanException(
0560:                                "Robot.retrieveRobotStatusString()", e
0561:                                        .toString(), e);
0562:                    }
0563:                } else {
0564:
0565:                    byte[] result = this .robotURLGet(rQuery, "robot-states");
0566:                    if (result != null) {
0567:                        statestring = new String(result);
0568:                    }
0569:                }
0570:
0571:                return statestring;
0572:            }
0573:
0574:            public HashMap getSiteRule(FilterRuleset frs) {
0575:
0576:                String id = frs.id;
0577:                HashMap robotSite = new HashMap();
0578:
0579:                robotSite.put("SiteName", frs.nickname);
0580:                robotSite.put("State", Boolean.valueOf(frs.isEnabled()));
0581:                robotSite.put("Comments", frs.getComments());
0582:                robotSite.put("DNSTrans", frs.getDNSTranslation());
0583:                robotSite.put("Database", frs.getDatabase());
0584:
0585:                LinkedList dgroup = new LinkedList();
0586:                int d = frs.numOfDomains();
0587:                for (int i = 0; i < d; i++) {
0588:                    String domainstring = frs.getDomainByIndex(i);
0589:                    if (domainstring != null) {
0590:                        dgroup.addLast(domainstring);
0591:                    }
0592:                }
0593:                robotSite.put("DomainGroup", dgroup);
0594:                robotSite.put("DomainPort", frs.ports);
0595:                robotSite.put("DomainProtocol", frs.getProtocol());
0596:
0597:                LinkedList sgroup = new LinkedList();
0598:                int n = frs.numOfServers();
0599:                for (int i = 0; i < n; i++) {
0600:                    String serverstring = frs.getServerByIndex(i);
0601:                    if (serverstring != null) {
0602:                        HashMap server = new HashMap();
0603:                        String host = "";
0604:                        try {
0605:                            URL url = new URL(serverstring);
0606:                            host = url.getHost();
0607:                            server.put("Server", url.getHost());
0608:                            server.put("Protocol", url.getProtocol());
0609:                            if (!url.getProtocol().equalsIgnoreCase("file")
0610:                                    && url.getPort() > 0) {
0611:                                server.put("Port", Integer.toString(url
0612:                                        .getPort()));
0613:                            } else {
0614:                                server.put("Port", "");
0615:                            }
0616:                        } catch (java.net.MalformedURLException e) {
0617:                            logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0618:                        }
0619:                        if (host.trim().length() > 0) {
0620:                            FilterSimulator frsim = new FilterSimulator();
0621:                            try {
0622:                                String cname = frsim.getHostByName(serverRoot,
0623:                                        host);
0624:                                server.put("Status", "verified");
0625:                                server.put("RealName", cname);
0626:                            } catch (Exception e) {
0627:                                server.put("Status", e.getMessage());
0628:                                server.put("RealName", "");
0629:                            }
0630:                        }
0631:                        sgroup.addLast(server);
0632:                    }
0633:                } //end of for of servers
0634:                robotSite.put("ServerGroup", sgroup);
0635:
0636:                LinkedList startpoints = new LinkedList();
0637:                int m = frs.numOfStartingPoints();
0638:                for (int i = 0; i < m; i++) {
0639:                    String sp = frs.getStartingPointByIndex(i);
0640:                    if (sp != null) {
0641:                        HashMap start = new HashMap();
0642:                        start.put("URLString", sp);
0643:                        //start.put("Depth", sp);
0644:                        startpoints.addLast(start);
0645:                        /*String urlStr = "";
0646:                        String depthStr = "";
0647:                        StringTokenizer st = new StringTokenizer(sp);
0648:                        if (st.hasMoreTokens()) {
0649:                          urlStr = st.nextToken();
0650:                        }
0651:                        if (st.hasMoreTokens()) {
0652:                          String ds = st.nextToken();
0653:                          int ndx = ds.indexOf("=");
0654:                          if (ndx != -1) {
0655:                            depthStr = ds.substring(ndx+1);
0656:                          }
0657:                        }
0658:                        if (!urlStr.equalsIgnoreCase("") && depthStr.equalsIgnoreCase("")) {
0659:                          start.put("URLString", urlStr);
0660:                          start.put("Depth", depthStr);
0661:                          startpoints.addLast(start);
0662:                        }*/
0663:                    }
0664:                } //end of for of starting points
0665:                robotSite.put("StartingPoints", startpoints);
0666:
0667:                LinkedList fgroup = new LinkedList();
0668:                int l = frs.numOfFilters();
0669:                for (int i = 0; i < l; i++) {
0670:                    HashMap filter = new HashMap();
0671:                    String fid = frs.getFiltersIDByIndex(i);
0672:                    String match = frs.getFiltersonMatchByIndex(i);
0673:                    filter.put("FilterID", fid);
0674:                    filter.put("FilterNickname", robotConfig
0675:                            .getRuleNickname(fid));
0676:                    filter.put("FilterMatch", match);
0677:                    fgroup.addLast(filter);
0678:                }
0679:                robotSite.put("FilterGroup", fgroup);
0680:                robotSite.put("FilterAllFiles", robotConfig
0681:                        .ADtoString(frs.onExit));
0682:
0683:                return robotSite;
0684:            }
0685:
0686:            public HashMap listSites(String id) throws PSMBeanException,
0687:                    UnknownHostException {
0688:
0689:                if (!AdminUtil.isLocal(host)) {
0690:                    try {
0691:                        JMXConnector jmxc = AdminServerUtil
0692:                                .getJMXConnector(host);
0693:                        MBeanServerConnection msc = jmxc
0694:                                .getMBeanServerConnection();
0695:                        Object[] params = { id };
0696:                        String[] signatures = { "java.lang.String" };
0697:                        HashMap result = (HashMap) msc.invoke(objectName,
0698:                                "listSites", params, signatures);
0699:                        jmxc.close();
0700:                        return result;
0701:                    } catch (Exception e) {
0702:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0703:                        throw new PSMBeanException("Robot.listSites()", e
0704:                                .toString(), e);
0705:                    }
0706:                } else {
0707:
0708:                    HashMap robotSites = new HashMap();
0709:                    FilterRuleset frs = null;
0710:
0711:                    int n = robotConfig.numRuleset();
0712:                    if (n <= 0) {
0713:                        String message = "Robot.listSites(): no robot site has been set up";
0714:                        Object tokens[] = { message };
0715:                        logger.log(Level.INFO, "PSSH_CSPSAMB0001", tokens);
0716:                        return null;
0717:                    }
0718:
0719:                    if (!id.equals("") && !id.equals("0")) { //single site display
0720:                        frs = robotConfig.GetRuleSet(id);
0721:                        if (frs != null) {
0722:                            robotSites.put(id, getSiteRule(frs));
0723:                        }
0724:
0725:                    } else { // all sites display
0726:                        for (int i = 0; i < n; i++) {
0727:                            frs = robotConfig.GetRuleSet(i);
0728:                            if (frs != null) {
0729:                                robotSites.put(frs.id, getSiteRule(frs));
0730:                            }
0731:                        }
0732:                    }
0733:
0734:                    return robotSites;
0735:                }
0736:            }
0737:
0738:            public String createSite(Boolean domain, String sitename,
0739:                    String depthString, String database)
0740:                    throws PSMBeanException, java.net.UnknownHostException {
0741:
0742:                if (!AdminUtil.isLocal(host)) {
0743:                    try {
0744:                        JMXConnector jmxc = AdminServerUtil
0745:                                .getJMXConnector(host);
0746:                        MBeanServerConnection msc = jmxc
0747:                                .getMBeanServerConnection();
0748:                        Object[] params = { domain, sitename, depthString,
0749:                                database };
0750:                        String[] signatures = { "java.lang.Boolean",
0751:                                "java.lang.String", "java.lang.String",
0752:                                "java.lang.String" };
0753:                        String result = (String) msc.invoke(objectName,
0754:                                "createSite", params, signatures);
0755:                        jmxc.close();
0756:                        return result;
0757:                    } catch (Exception e) {
0758:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0759:                        throw new PSMBeanException("Robot.createSite()", e
0760:                                .toString(), e);
0761:                    }
0762:                } else {
0763:
0764:                    if (depthString == null || depthString.equals(""))
0765:                        depthString = "10";
0766:
0767:                    boolean isDomain = domain.booleanValue();
0768:                    int depth = Integer.parseInt(depthString);
0769:                    String newRuleID = null;
0770:                    String newCreatedID = null;
0771:
0772:                    try {
0773:                        URL url = null;
0774:
0775:                        if (isDomain) { // the site is a domain
0776:
0777:                            String domainname = getValidatedDomain(sitename);
0778:                            FilterRuleset frs = robotConfig
0779:                                    .findFiletrRulesetHasDomain(domainname);
0780:                            if (frs != null) {
0781:                                String message = "Robot.createSite(): domain site "
0782:                                        + sitename + " already exists";
0783:                                Object tokens[] = { message };
0784:                                logger.log(Level.INFO, "PSSH_CSPSAMB0002",
0785:                                        tokens);
0786:                                return null;
0787:                            }
0788:
0789:                            if (!sitename.startsWith("http")
0790:                                    && !sitename.startsWith("https")
0791:                                    && !sitename.startsWith("ftp")
0792:                                    && !sitename.startsWith("file")
0793:                                    && !sitename.startsWith("gopher")) {
0794:                                url = new URL("http", "www." + domainname, 80,
0795:                                        "/");
0796:                            } else {
0797:                                url = getValidatedURL(sitename);
0798:                            }
0799:
0800:                        } else { // the site is a url
0801:
0802:                            url = getValidatedURL(sitename);
0803:                            FilterRuleset frs = robotConfig
0804:                                    .findFiletrRulesetHasStartingPoint(url
0805:                                            .toString());
0806:                            if (frs != null) {
0807:                                String message = "Robot.createSite(): the site "
0808:                                        + sitename + " already exists";
0809:                                Object tokens[] = { message };
0810:                                logger.log(Level.INFO, "PSSH_CSPSAMB0002",
0811:                                        tokens);
0812:                                return null;
0813:                            }
0814:
0815:                        }
0816:
0817:                        String path = url.getPath();
0818:                        int n = path.lastIndexOf('/');
0819:                        if (n >= 0 && path.length() > 1) {
0820:                            String path_filter = path.substring(0, n + 1);
0821:                            String file_name = path.substring(n + 1);
0822:                            if (file_name.indexOf('.') < 0) {
0823:                                path_filter = path;
0824:                            }
0825:
0826:                            newRuleID = robotConfig
0827:                                    .newPathFilterRule(path_filter);
0828:                        }
0829:
0830:                        FilterRuleset frs = robotConfig.newRuleset(url, depth,
0831:                                isDomain, newRuleID);
0832:
0833:                        if (frs != null) {
0834:                            if (database != null && !database.equals("")) {
0835:                                frs.setDatabase(database);
0836:                            }
0837:                            newCreatedID = frs.id;
0838:                        }
0839:
0840:                        robotConfig.updateFile();
0841:
0842:                    } catch (java.net.MalformedURLException e) {
0843:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0844:                    }
0845:
0846:                    return newCreatedID;
0847:                }
0848:
0849:            }
0850:
0851:            public Boolean deleteSite(String id) throws UnknownHostException {
0852:
0853:                if (!AdminUtil.isLocal(host)) {
0854:                    try {
0855:                        JMXConnector jmxc = AdminServerUtil
0856:                                .getJMXConnector(host);
0857:                        MBeanServerConnection msc = jmxc
0858:                                .getMBeanServerConnection();
0859:                        Object[] params = { id };
0860:                        String[] signatures = { "java.lang.String" };
0861:                        Boolean result = (Boolean) msc.invoke(objectName,
0862:                                "deleteSite", params, signatures);
0863:                        jmxc.close();
0864:                        return result;
0865:                    } catch (Exception e) {
0866:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0867:                        return Boolean.FALSE;
0868:                    }
0869:                } else {
0870:
0871:                    boolean b = robotConfig.delRuleset(id);
0872:                    if (b) {
0873:                        robotConfig.updateFile();
0874:                        return Boolean.TRUE;
0875:                    } else {
0876:                        return Boolean.FALSE;
0877:                    }
0878:                }
0879:            }
0880:
0881:            public Boolean deleteSites(ArrayList ids)
0882:                    throws UnknownHostException {
0883:
0884:                if (!AdminUtil.isLocal(host)) {
0885:                    try {
0886:                        JMXConnector jmxc = AdminServerUtil
0887:                                .getJMXConnector(host);
0888:                        MBeanServerConnection msc = jmxc
0889:                                .getMBeanServerConnection();
0890:                        Object[] params = { ids };
0891:                        String[] signatures = { "java.util.ArrayList" };
0892:                        Boolean result = (Boolean) msc.invoke(objectName,
0893:                                "deleteSites", params, signatures);
0894:                        jmxc.close();
0895:                        return result;
0896:                    } catch (Exception e) {
0897:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0898:                        return Boolean.FALSE;
0899:                    }
0900:                } else {
0901:
0902:                    if (ids != null) {
0903:                        for (int i = 0; i < ids.size(); i++) {
0904:                            String id = (String) ids.get(i);
0905:                            robotConfig.delRuleset(id);
0906:                        }
0907:                        robotConfig.updateFile();
0908:                        return Boolean.TRUE;
0909:                    } else {
0910:                        return Boolean.FALSE;
0911:                    }
0912:                }
0913:            }
0914:
0915:            public Boolean enableSites(ArrayList ids)
0916:                    throws UnknownHostException {
0917:
0918:                if (!AdminUtil.isLocal(host)) {
0919:                    try {
0920:                        JMXConnector jmxc = AdminServerUtil
0921:                                .getJMXConnector(host);
0922:                        MBeanServerConnection msc = jmxc
0923:                                .getMBeanServerConnection();
0924:                        Object[] params = { ids };
0925:                        String[] signatures = { "java.util.ArrayList" };
0926:                        Boolean result = (Boolean) msc.invoke(objectName,
0927:                                "enableSites", params, signatures);
0928:                        jmxc.close();
0929:                        return result;
0930:                    } catch (Exception e) {
0931:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0932:                        return Boolean.FALSE;
0933:                    }
0934:                } else {
0935:
0936:                    if (ids != null) {
0937:                        for (int i = 0; i < ids.size(); i++) {
0938:                            String id = (String) ids.get(i);
0939:                            FilterRuleset frs = robotConfig.GetRuleSet(id);
0940:                            frs.setEnabled(true);
0941:                        }
0942:                        robotConfig.updateFile();
0943:                        return Boolean.TRUE;
0944:                    } else {
0945:                        return Boolean.FALSE;
0946:                    }
0947:                }
0948:            }
0949:
0950:            public Boolean disableSites(ArrayList ids)
0951:                    throws UnknownHostException {
0952:
0953:                if (!AdminUtil.isLocal(host)) {
0954:                    try {
0955:                        JMXConnector jmxc = AdminServerUtil
0956:                                .getJMXConnector(host);
0957:                        MBeanServerConnection msc = jmxc
0958:                                .getMBeanServerConnection();
0959:                        Object[] params = { ids };
0960:                        String[] signatures = { "java.util.ArrayList" };
0961:                        Boolean result = (Boolean) msc.invoke(objectName,
0962:                                "disableSites", params, signatures);
0963:                        jmxc.close();
0964:                        return result;
0965:                    } catch (Exception e) {
0966:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0967:                        return Boolean.FALSE;
0968:                    }
0969:                } else {
0970:
0971:                    if (ids != null) {
0972:                        for (int i = 0; i < ids.size(); i++) {
0973:                            String id = (String) ids.get(i);
0974:                            FilterRuleset frs = robotConfig.GetRuleSet(id);
0975:                            frs.setEnabled(false);
0976:                        }
0977:                        robotConfig.updateFile();
0978:                        return Boolean.TRUE;
0979:                    } else {
0980:                        return Boolean.FALSE;
0981:                    }
0982:                }
0983:            }
0984:
0985:            public Boolean editSite(String id, String name, String desc,
0986:                    String dns, String database, ArrayList domainGroup,
0987:                    String port, ArrayList protocols, ArrayList serverGroup,
0988:                    ArrayList startPoints, ArrayList defRules, String allfile)
0989:                    throws UnknownHostException {
0990:
0991:                if (!AdminUtil.isLocal(host)) {
0992:                    try {
0993:                        JMXConnector jmxc = AdminServerUtil
0994:                                .getJMXConnector(host);
0995:                        MBeanServerConnection msc = jmxc
0996:                                .getMBeanServerConnection();
0997:                        Object[] params = { id, name, desc, dns, database,
0998:                                domainGroup, port, protocols, serverGroup,
0999:                                startPoints, defRules, allfile };
1000:                        String[] signatures = { "java.lang.String",
1001:                                "java.lang.String", "java.lang.String",
1002:                                "java.lang.String", "java.lang.String",
1003:                                "java.util.ArrayList", "java.lang.String",
1004:                                "java.util.ArrayList", "java.util.ArrayList",
1005:                                "java.util.ArrayList", "java.util.ArrayList",
1006:                                "java.lang.String" };
1007:                        Boolean result = (Boolean) msc.invoke(objectName,
1008:                                "editSite", params, signatures);
1009:                        jmxc.close();
1010:                        return result;
1011:                    } catch (Exception e) {
1012:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1013:                        return Boolean.FALSE;
1014:                    }
1015:                } else {
1016:
1017:                    FilterRuleset frs = robotConfig.GetRuleSet(id);
1018:
1019:                    if (frs != null) {
1020:
1021:                        if (name != null && !name.equals("")) {
1022:                            frs.nickname = name;
1023:                        }
1024:                        if (desc != null && !desc.equals("")) {
1025:                            frs.removeComment();
1026:                            frs.addComments(desc);
1027:                        }
1028:                        if (dns != null && !dns.equals("")) {
1029:                            frs.removeDNSTranslation();
1030:                            frs.addDNSTranslation(dns);
1031:                        }
1032:                        if (database != null && !database.equals("")) {
1033:                            frs.setDatabase(database);
1034:                        }
1035:
1036:                        if (domainGroup != null && domainGroup.size() > 0) {
1037:                            frs.removeDomains();
1038:                            for (int i = 0; i < domainGroup.size(); i++) {
1039:                                String domain = (String) domainGroup.get(i);
1040:                                frs.addDomain(domain.trim());
1041:                            }
1042:
1043:                            if (port != null && !port.equals("")) {
1044:                                frs.ports = port;
1045:                            }
1046:
1047:                            if (protocols != null && protocols.size() > 0) {
1048:                                frs.removeProtocol();
1049:                                for (int i = 0; i < protocols.size(); i++) {
1050:                                    frs.addProtocol((String) protocols.get(i));
1051:                                }
1052:                            }
1053:                        }
1054:
1055:                        if (serverGroup != null && serverGroup.size() > 0) {
1056:                            frs.removeServers();
1057:                            for (int i = 0; i < serverGroup.size(); i++) {
1058:                                HashMap server = (HashMap) serverGroup.get(i);
1059:                                String host = (String) server.get("Host");
1060:                                String protocol = (String) server
1061:                                        .get("Protocol");
1062:                                String p = (String) server.get("Port");
1063:                                if (host != null && protocol != null
1064:                                        && host.trim().length() > 0) {
1065:                                    try {
1066:                                        int portno = -1;
1067:                                        if (p != null && !p.equals("")) {
1068:                                            portno = Integer.parseInt(p);
1069:                                        }
1070:                                        URL url = new URL(protocol, host,
1071:                                                portno, "/");
1072:                                        frs.addServer(url.toString());
1073:                                    } catch (java.net.MalformedURLException e) {
1074:                                        logger.log(Level.SEVERE,
1075:                                                "PSSH_CSPSAMB0003", e);
1076:                                    }
1077:                                }
1078:                            } //end of for
1079:                        }
1080:
1081:                        if (startPoints.size() > 0) {
1082:                            frs.removeStartingPoints();
1083:                            for (int i = 0; i < startPoints.size(); i++) {
1084:                                HashMap sp = (HashMap) startPoints.get(i);
1085:                                String startURL = (String) sp.get("URL");
1086:                                String depth = (String) sp.get("Depth");
1087:                                URL url = getValidatedURL(startURL);
1088:                                frs.addStartingPoint(url, Integer
1089:                                        .parseInt(depth));
1090:                            } //end of for
1091:                        }
1092:
1093:                        if (defRules.size() > 0) {
1094:                            frs.removeFilters();
1095:                            for (int i = 0; i < defRules.size(); i++) {
1096:                                HashMap def = (HashMap) defRules.get(i);
1097:                                String ruleID = (String) def.get("Rule");
1098:                                String match = (String) def.get("Match");
1099:                                boolean on_match = false;
1100:                                if (match.equalsIgnoreCase("allow"))
1101:                                    on_match = true;
1102:                                else
1103:                                    on_match = false;
1104:                                if (ruleID != null
1105:                                        && ruleID.trim().length() > 0) {
1106:                                    frs.AddFilter(ruleID, on_match);
1107:                                }
1108:                            }
1109:                        }
1110:
1111:                        if (allfile != null && !allfile.equals("")) {
1112:                            frs.onExit = robotConfig.ADStringtoBoolean(allfile);
1113:                        }
1114:
1115:                        robotConfig.updateFile();
1116:                        return Boolean.TRUE;
1117:
1118:                    } //frs != null
1119:                    else {
1120:                        return Boolean.FALSE;
1121:                    }
1122:                }
1123:
1124:            }
1125:
1126:            public HashMap getFilterRule(FilterRule fr) {
1127:
1128:                String id = fr.id;
1129:                HashMap robotFilter = new HashMap();
1130:
1131:                robotFilter.put("FilterId", fr.id);
1132:                robotFilter.put("FilterName", fr.nickname);
1133:                robotFilter.put("FilterDesc", fr.getComments());
1134:                robotFilter.put("State", Boolean.valueOf(fr.enable));
1135:                ArrayList defs = new ArrayList();
1136:                int m = fr.numberOfStringFilters();
1137:                for (int i = 0; i < m; i++) {
1138:                    StringFilter sf = (StringFilter) fr.filters.get(i);
1139:                    if (sf != null) {
1140:                        HashMap def = new HashMap();
1141:                        String source = sf.directive;
1142:                        int match = 0;
1143:                        for (int j = 0; j < filtersource_rule.length; j++) {
1144:                            if (source.equalsIgnoreCase(filtersource_rule[j])) {
1145:                                match = j;
1146:                            }
1147:                        }
1148:                        def.put("FilterSource", filtersource[match]);
1149:
1150:                        String method = FilterRule.getMethodText(sf.method);
1151:                        for (int j = 0; j < filtermethod_rule.length; j++) {
1152:                            if (method.equalsIgnoreCase(filtermethod_rule[j])) {
1153:                                match = j;
1154:                            }
1155:                        }
1156:                        def.put("FilterMethod", filtermethod[match]);
1157:
1158:                        def.put("FilterString", sf.filter);
1159:                        defs.add(def);
1160:                    }
1161:                }
1162:                robotFilter.put("FilterDef", defs);
1163:
1164:                robotFilter.put("NewSite", Boolean.valueOf(fr.quickcf));
1165:                robotFilter.put("Include", Boolean.valueOf(fr.default_ad));
1166:
1167:                String[] ids = robotConfig.getFiletrRulesetIDsForFilterRule(id);
1168:                int j = 0;
1169:                if (ids != null) {
1170:                    StringBuffer buf = new StringBuffer();
1171:                    for (j = 0; j < ids.length; j++) {
1172:                        FilterRuleset frs = robotConfig.GetRuleSet(ids[j]);
1173:                        //buf.append(frs.id + ":" + frs.nickname);
1174:                        buf.append(frs.nickname);
1175:                        if (j < ids.length - 1) {
1176:                            buf.append(",");
1177:                        }
1178:                    }
1179:                    robotFilter.put("DeploymentNum", Integer.toString(j));
1180:                    robotFilter.put("Deployment", buf.toString());
1181:                } else {
1182:                    robotFilter.put("Deployment", "");
1183:                }
1184:
1185:                return robotFilter;
1186:            }
1187:
1188:            public ArrayList listFilters(String id) throws PSMBeanException,
1189:                    UnknownHostException {
1190:
1191:                if (!AdminUtil.isLocal(host)) {
1192:                    try {
1193:                        JMXConnector jmxc = AdminServerUtil
1194:                                .getJMXConnector(host);
1195:                        MBeanServerConnection msc = jmxc
1196:                                .getMBeanServerConnection();
1197:                        Object[] params = { id };
1198:                        String[] signatures = { "java.lang.String" };
1199:                        ArrayList result = (ArrayList) msc.invoke(objectName,
1200:                                "listFilters", params, signatures);
1201:                        jmxc.close();
1202:                        return result;
1203:                    } catch (Exception e) {
1204:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1205:                        throw new PSMBeanException("Robot.listFilters", e
1206:                                .toString(), e);
1207:                    }
1208:                } else {
1209:
1210:                    FilterRule fr = null;
1211:                    ArrayList robotFilters = new ArrayList();
1212:
1213:                    int n = robotConfig.numOfRules();
1214:                    if (n <= 0) {
1215:                        String message = "Robot.listFilters(): no robot filter has been set up";
1216:                        Object tokens[] = { message };
1217:                        logger.log(Level.INFO, "PSSH_CSPSAMB0001", tokens);
1218:                        return null;
1219:                    }
1220:
1221:                    if (!id.equals("") && !id.equals("0")) { //single filter display
1222:
1223:                        fr = robotConfig.GetRule(id);
1224:                        if (fr != null) {
1225:                            robotFilters.add(getFilterRule(fr));
1226:                        }
1227:
1228:                    } else { //all filters display
1229:
1230:                        for (int i = 0; i < n; i++) {
1231:                            fr = robotConfig.GetRuleByIndex(i);
1232:                            if (fr != null) {
1233:                                robotFilters.add(getFilterRule(fr));
1234:                            }
1235:                        } //end of for
1236:                    }
1237:
1238:                    return robotFilters;
1239:                }
1240:            }
1241:
1242:            public String createFilter(String name, String desc,
1243:                    Boolean isDefault, Boolean includeMatch, ArrayList defrules)
1244:                    throws PSMBeanException, UnknownHostException {
1245:
1246:                if (!AdminUtil.isLocal(host)) {
1247:                    try {
1248:                        JMXConnector jmxc = AdminServerUtil
1249:                                .getJMXConnector(host);
1250:                        MBeanServerConnection msc = jmxc
1251:                                .getMBeanServerConnection();
1252:                        Object[] params = { name, desc, isDefault,
1253:                                includeMatch, defrules };
1254:                        String[] signatures = { "java.lang.String",
1255:                                "java.lang.String", "java.lang.Boolean",
1256:                                "java.lang.Boolean", "java.util.ArrayList" };
1257:                        String result = (String) msc.invoke(objectName,
1258:                                "createFilter", params, signatures);
1259:                        jmxc.close();
1260:                        return result;
1261:                    } catch (Exception e) {
1262:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1263:                        throw new PSMBeanException("Robot.createFilter", e
1264:                                .toString(), e);
1265:                    }
1266:                } else {
1267:
1268:                    String existID = robotConfig.getIDByNick(name);
1269:                    if (existID != null) {
1270:                        String message = "Robot.createFilter(): filter name "
1271:                                + name + " already exists";
1272:                        Object tokens[] = { message };
1273:                        logger.log(Level.INFO, "PSSH_CSPSAMB0002", tokens);
1274:                        return null;
1275:                    }
1276:
1277:                    boolean isdefault;
1278:                    if (isDefault != null) {
1279:                        isdefault = isDefault.booleanValue();
1280:                    } else {
1281:                        isdefault = true; //default
1282:                    }
1283:
1284:                    boolean include;
1285:                    if (includeMatch != null) {
1286:                        include = includeMatch.booleanValue();
1287:                    } else {
1288:                        include = false; //default
1289:                    }
1290:
1291:                    String filterID = Integer
1292:                            .toString(robotConfig.lastRuleID + 1);
1293:                    FilterRule fr = new FilterRule(filterID, true, name,
1294:                            include, isdefault);
1295:                    fr.setComments(desc);
1296:
1297:                    for (int j = 0; j < defrules.size(); j++) {
1298:                        HashMap def = (HashMap) defrules.get(j);
1299:                        String source = (String) def.get("FilterSource");
1300:                        String method = (String) def.get("FilterMethod");
1301:                        String pattern = (String) def.get("FilterString");
1302:
1303:                        boolean validsource = false;
1304:                        int match = 0;
1305:                        for (int i = 0; i < filtersource.length; i++) {
1306:                            if (source.equalsIgnoreCase(filtersource[i])) {
1307:                                validsource = true;
1308:                                match = i;
1309:                            }
1310:                        }
1311:                        if (!validsource) {
1312:                            throw new PSMBeanException(
1313:                                    "Robot.createFilter(): Invalid filter source type.");
1314:                        }
1315:                        source = filtersource_rule[match];
1316:
1317:                        boolean validmethod = false;
1318:                        for (int i = 0; i < filtermethod.length; i++) {
1319:                            if (method.equalsIgnoreCase(filtermethod[i])) {
1320:                                validmethod = true;
1321:                                match = i;
1322:                            }
1323:                        }
1324:                        if (!validmethod) {
1325:                            throw new PSMBeanException(
1326:                                    "Robot.createFilter(): Invalid filter method type.");
1327:                        }
1328:                        method = filtermethod_rule[match];
1329:
1330:                        if (pattern != null && pattern.trim().length() > 0) {
1331:                            fr.addFilter(source, method, pattern.trim());
1332:                        }
1333:                    } // end of for
1334:
1335:                    robotConfig.AddRule(filterID, fr);
1336:                    robotConfig.updateFile();
1337:                    robotConfig.freshRulesArray();
1338:                    return filterID;
1339:                }
1340:            }
1341:
1342:            public Boolean deleteFilter(String id) throws UnknownHostException {
1343:
1344:                if (!AdminUtil.isLocal(host)) {
1345:                    try {
1346:                        JMXConnector jmxc = AdminServerUtil
1347:                                .getJMXConnector(host);
1348:                        MBeanServerConnection msc = jmxc
1349:                                .getMBeanServerConnection();
1350:                        Object[] params = { id };
1351:                        String[] signatures = { "java.lang.String" };
1352:                        Boolean result = (Boolean) msc.invoke(objectName,
1353:                                "deleteFilter", params, signatures);
1354:                        jmxc.close();
1355:                        return result;
1356:                    } catch (Exception e) {
1357:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1358:                        return Boolean.FALSE;
1359:                    }
1360:                } else {
1361:
1362:                    boolean b = robotConfig.delRule(id);
1363:                    if (b) {
1364:                        robotConfig.updateFile();
1365:                        return Boolean.TRUE;
1366:                    } else {
1367:                        return Boolean.FALSE;
1368:                    }
1369:                }
1370:            }
1371:
1372:            public Boolean deleteFilters(ArrayList ids)
1373:                    throws UnknownHostException {
1374:
1375:                if (!AdminUtil.isLocal(host)) {
1376:                    try {
1377:                        JMXConnector jmxc = AdminServerUtil
1378:                                .getJMXConnector(host);
1379:                        MBeanServerConnection msc = jmxc
1380:                                .getMBeanServerConnection();
1381:                        Object[] params = { ids };
1382:                        String[] signatures = { "java.util.ArrayList" };
1383:                        Boolean result = (Boolean) msc.invoke(objectName,
1384:                                "deleteFilters", params, signatures);
1385:                        jmxc.close();
1386:                        return result;
1387:                    } catch (Exception e) {
1388:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1389:                        return Boolean.FALSE;
1390:                    }
1391:                } else {
1392:
1393:                    if (ids != null) {
1394:                        for (int i = 0; i < ids.size(); i++) {
1395:                            String id = (String) ids.get(i);
1396:                            robotConfig.delRule(id);
1397:                        }
1398:                        robotConfig.updateFile();
1399:                        return Boolean.TRUE;
1400:                    } else {
1401:                        return Boolean.FALSE;
1402:                    }
1403:                }
1404:            }
1405:
1406:            public Boolean enableFilters(ArrayList ids)
1407:                    throws UnknownHostException {
1408:
1409:                if (!AdminUtil.isLocal(host)) {
1410:                    try {
1411:                        JMXConnector jmxc = AdminServerUtil
1412:                                .getJMXConnector(host);
1413:                        MBeanServerConnection msc = jmxc
1414:                                .getMBeanServerConnection();
1415:                        Object[] params = { ids };
1416:                        String[] signatures = { "java.util.ArrayList" };
1417:                        Boolean result = (Boolean) msc.invoke(objectName,
1418:                                "enableFilters", params, signatures);
1419:                        jmxc.close();
1420:                        return result;
1421:                    } catch (Exception e) {
1422:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1423:                        return Boolean.FALSE;
1424:                    }
1425:                } else {
1426:
1427:                    if (ids != null) {
1428:                        for (int i = 0; i < ids.size(); i++) {
1429:                            String id = (String) ids.get(i);
1430:                            FilterRule fr = robotConfig.GetRule(id);
1431:                            fr.enable = true;
1432:                        }
1433:                        robotConfig.updateFile();
1434:                        robotConfig.freshRulesArray();
1435:                        return Boolean.TRUE;
1436:                    } else {
1437:                        return Boolean.FALSE;
1438:                    }
1439:                }
1440:            }
1441:
1442:            public Boolean disableFilters(ArrayList ids)
1443:                    throws UnknownHostException {
1444:
1445:                if (!AdminUtil.isLocal(host)) {
1446:                    try {
1447:                        JMXConnector jmxc = AdminServerUtil
1448:                                .getJMXConnector(host);
1449:                        MBeanServerConnection msc = jmxc
1450:                                .getMBeanServerConnection();
1451:                        Object[] params = { ids };
1452:                        String[] signatures = { "java.util.ArrayList" };
1453:                        Boolean result = (Boolean) msc.invoke(objectName,
1454:                                "deleteFilters", params, signatures);
1455:                        jmxc.close();
1456:                        return result;
1457:                    } catch (Exception e) {
1458:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1459:                        return Boolean.FALSE;
1460:                    }
1461:                } else {
1462:
1463:                    if (ids != null) {
1464:                        for (int i = 0; i < ids.size(); i++) {
1465:                            String id = (String) ids.get(i);
1466:                            FilterRule fr = robotConfig.GetRule(id);
1467:                            fr.enable = false;
1468:                        }
1469:                        robotConfig.updateFile();
1470:                        robotConfig.freshRulesArray();
1471:                        return Boolean.TRUE;
1472:                    } else {
1473:                        return Boolean.FALSE;
1474:                    }
1475:                }
1476:            }
1477:
1478:            public Boolean editFilter(String id, String name, String desc,
1479:                    Boolean isDefault, Boolean includeMatch, ArrayList defrules)
1480:                    throws PSMBeanException, UnknownHostException {
1481:
1482:                if (!AdminUtil.isLocal(host)) {
1483:                    try {
1484:                        JMXConnector jmxc = AdminServerUtil
1485:                                .getJMXConnector(host);
1486:                        MBeanServerConnection msc = jmxc
1487:                                .getMBeanServerConnection();
1488:                        Object[] params = { id, name, desc, isDefault,
1489:                                includeMatch, defrules };
1490:                        String[] signatures = { "java.lang.String",
1491:                                "java.lang.String", "java.lang.String",
1492:                                "java.lang.Boolean", "java.lang.Boolean",
1493:                                "java.util.ArrayList" };
1494:
1495:                        Boolean result = (Boolean) msc.invoke(objectName,
1496:                                "editFilter", params, signatures);
1497:                        jmxc.close();
1498:                        return result;
1499:                    } catch (Exception e) {
1500:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1501:                        return Boolean.FALSE;
1502:                    }
1503:                } else {
1504:
1505:                    FilterRule fr = null;
1506:
1507:                    fr = robotConfig.GetRule(id);
1508:                    if (!name.equals(""))
1509:                        fr.nickname = name;
1510:                    if (!desc.equals(""))
1511:                        fr.setComments(desc);
1512:
1513:                    //boolean isdefault;
1514:                    if (isDefault != null) {
1515:                        fr.quickcf = isDefault.booleanValue();
1516:                    } else {
1517:                        fr.quickcf = true; //default
1518:                    }
1519:
1520:                    //boolean include;
1521:                    if (includeMatch != null) {
1522:                        fr.default_ad = includeMatch.booleanValue();
1523:                    } else {
1524:                        fr.default_ad = false; //default
1525:                    }
1526:
1527:                    if (defrules.size() > 0) {
1528:
1529:                        fr.removeAllFilter();
1530:
1531:                        for (int j = 0; j < defrules.size(); j++) {
1532:                            HashMap def = (HashMap) defrules.get(j);
1533:                            String source = (String) def.get("FilterSource");
1534:                            String method = (String) def.get("FilterMethod");
1535:                            String pattern = (String) def.get("FilterString");
1536:
1537:                            boolean validsource = false;
1538:                            int match = 0;
1539:                            for (int i = 0; i < filtersource.length; i++) {
1540:                                if (source.equalsIgnoreCase(filtersource[i])) {
1541:                                    validsource = true;
1542:                                    match = i;
1543:                                }
1544:                            }
1545:                            if (!validsource) {
1546:                                throw new PSMBeanException(
1547:                                        "Robot.editFilter(): Invalid filter source type.");
1548:                            }
1549:                            source = filtersource_rule[match];
1550:
1551:                            boolean validmethod = false;
1552:                            for (int i = 0; i < filtermethod.length; i++) {
1553:                                if (method.equalsIgnoreCase(filtermethod[i])) {
1554:                                    validmethod = true;
1555:                                    match = i;
1556:                                }
1557:                            }
1558:                            if (!validmethod) {
1559:                                throw new PSMBeanException(
1560:                                        "Robot.editFilter(): Invalid filter method type.");
1561:                            }
1562:                            method = filtermethod_rule[match];
1563:
1564:                            if (pattern != null && pattern.trim().length() > 0) {
1565:                                fr.addFilter(source, method, pattern.trim());
1566:                            }
1567:                        } // end of for
1568:                    }
1569:
1570:                    robotConfig.updateFile();
1571:                    robotConfig.freshRulesArray();
1572:                    return Boolean.TRUE;
1573:                }
1574:            }
1575:
1576:            public String getCrawlingConfig(String attrname)
1577:                    throws UnknownHostException {
1578:                if (!AdminUtil.isLocal(host)) {
1579:                    try {
1580:                        JMXConnector jmxc = AdminServerUtil
1581:                                .getJMXConnector(host);
1582:                        MBeanServerConnection msc = jmxc
1583:                                .getMBeanServerConnection();
1584:                        Object[] params = { attrname };
1585:                        String[] signatures = { "java.lang.String" };
1586:                        String result = (String) msc.invoke(objectName,
1587:                                "getCrawlingConfig", params, signatures);
1588:                        jmxc.close();
1589:                        return result;
1590:                    } catch (Exception e) {
1591:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1592:                        return null;
1593:                    }
1594:                } else {
1595:
1596:                    ProcessConfig processConf = robotConfig.processConf;
1597:                    return (String) processConf.get(attrname);
1598:                }
1599:            }
1600:
1601:            public Boolean setCrawlingConfig(String attrname, String attrvalue)
1602:                    throws UnknownHostException {
1603:
1604:                if (!AdminUtil.isLocal(host)) {
1605:                    try {
1606:                        JMXConnector jmxc = AdminServerUtil
1607:                                .getJMXConnector(host);
1608:                        MBeanServerConnection msc = jmxc
1609:                                .getMBeanServerConnection();
1610:                        Object[] params = { attrname, attrvalue };
1611:                        String[] signatures = { "java.lang.String",
1612:                                "java.lang.String" };
1613:                        Boolean result = (Boolean) msc.invoke(objectName,
1614:                                "setCrawlingConfig", params, signatures);
1615:                        jmxc.close();
1616:                        return result;
1617:                    } catch (Exception e) {
1618:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1619:                        return Boolean.FALSE;
1620:                    }
1621:                } else {
1622:
1623:                    ProcessConfig processConf = robotConfig.processConf;
1624:                    processConf.put(attrname, attrvalue);
1625:                    processConf.updateFile();
1626:                    return Boolean.TRUE;
1627:                }
1628:            }
1629:
1630:            public HashMap retrieveCrawlingConfigMap() throws PSMBeanException,
1631:                    UnknownHostException {
1632:
1633:                if (!AdminUtil.isLocal(host)) {
1634:                    try {
1635:                        JMXConnector jmxc = AdminServerUtil
1636:                                .getJMXConnector(host);
1637:                        MBeanServerConnection msc = jmxc
1638:                                .getMBeanServerConnection();
1639:                        Object[] params = {};
1640:                        String[] signatures = {};
1641:                        HashMap result = (HashMap) msc
1642:                                .invoke(objectName,
1643:                                        "retrieveCrawlingConfigMap", params,
1644:                                        signatures);
1645:                        jmxc.close();
1646:                        return result;
1647:                    } catch (Exception e) {
1648:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1649:                        throw new PSMBeanException(
1650:                                "Robot.retrieveCrawlingConfigMap()", e
1651:                                        .toString(), e);
1652:                    }
1653:                } else {
1654:
1655:                    ProcessConfig processConf = robotConfig.processConf;
1656:                    BASE64Decoder dec = new BASE64Decoder();
1657:
1658:                    HashMap configmap = new HashMap();
1659:
1660:                    //server delay
1661:                    configmap.put("server-delay", (String) processConf
1662:                            .get("server-delay"));
1663:                    // Max concurrent retrieval
1664:                    configmap.put("max-connections", (String) processConf
1665:                            .get("max-connections"));
1666:                    // Max connections per site
1667:                    configmap.put("site-max-connections", (String) processConf
1668:                            .get("site-max-connections"));
1669:                    // Send RDs to Index
1670:                    configmap.put("index-after-ngenerated",
1671:                            (String) processConf.get("index-after-ngenerated"));
1672:                    // Script to Launch
1673:                    configmap.put("cmd-Hook", (String) processConf
1674:                            .get("cmd-Hook"));
1675:                    // After Processing URLs
1676:                    configmap.put("onCompletion", (String) processConf
1677:                            .get("onCompletion"));
1678:                    // Contact Email
1679:                    configmap.put("email", (String) processConf.get("email"));
1680:                    // Log Level
1681:                    String loglevel = (String) processConf.get("loglevel");
1682:                    if (loglevel == null)
1683:                        loglevel = "1";
1684:                    configmap.put("loglevel", loglevel);
1685:                    // User-Agent
1686:                    configmap.put("user-agent", (String) processConf
1687:                            .get("user-agent"));
1688:                    // Ignorance of Robots.txt
1689:                    configmap.put("enable-robots-txt", (String) processConf
1690:                            .get("enable-robots-txt"));
1691:                    // Perform authentication
1692:                    configmap.put("perform-authentication",
1693:                            (String) processConf.get("perform-authentication"));
1694:                    // Robot Username
1695:                    configmap.put("username", (String) processConf
1696:                            .get("username"));
1697:                    // Robot Password
1698:                    String RobotPassDecoded = null;
1699:                    String robotPassword = (String) processConf.get("password");
1700:                    if (robotPassword != null) {
1701:                        try {
1702:                            RobotPassDecoded = new String(dec
1703:                                    .decodeBuffer(robotPassword));
1704:                        } catch (Exception e) {
1705:                            logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1706:                        }
1707:                    }
1708:                    configmap.put("password", RobotPassDecoded);
1709:                    // Proxy Username
1710:                    configmap.put("proxy-username", (String) processConf
1711:                            .get("proxy-username"));
1712:                    // Proxy Password
1713:                    String userPassDecoded = null;
1714:                    String proxyUserPassword = (String) processConf
1715:                            .get("proxy-password");
1716:                    if (proxyUserPassword != null) {
1717:                        try {
1718:                            userPassDecoded = new String(dec
1719:                                    .decodeBuffer(proxyUserPassword));
1720:                        } catch (Exception e) {
1721:                            logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1722:                        }
1723:                    }
1724:                    configmap.put("proxy-password", userPassDecoded);
1725:                    // Type of Proxy (direct, auto, manual)
1726:                    configmap.put("proxy-type", (String) processConf
1727:                            .get("proxy-type"));
1728:                    // Auto type
1729:                    configmap.put("proxy-loc", (String) processConf
1730:                            .get("proxy-loc"));
1731:                    // Auto Location
1732:                    configmap.put("auto_serv", (String) processConf
1733:                            .get("auto_serv"));
1734:                    // HTTP Proxy
1735:                    configmap.put("http_proxy", (String) processConf
1736:                            .get("http_proxy"));
1737:                    // HTTPS Proxy
1738:                    configmap.put("https_proxy", (String) processConf
1739:                            .get("https_proxy"));
1740:                    // FTP PROXY
1741:                    configmap.put("ftp_proxy", (String) processConf
1742:                            .get("ftp_proxy"));
1743:                    // Use Cookies
1744:                    configmap.put("enable-cookie", (String) processConf
1745:                            .get("enable-cookie"));
1746:                    // Use IP as Source
1747:                    configmap.put("enable-ip", (String) processConf
1748:                            .get("enable-ip"));
1749:                    // Smart Host Heuristics
1750:                    configmap.put("smart-host-heuristics", (String) processConf
1751:                            .get("smart-host-heuristics"));
1752:                    // CNAME Resolution
1753:                    configmap.put("use-dns-cname", (String) processConf
1754:                            .get("use-dns-cname"));
1755:                    // Default Starting Point
1756:                    configmap.put("depth", (String) processConf.get("depth"));
1757:                    // Work Directory
1758:                    configmap.put("tmpdir", (String) processConf.get("tmpdir"));
1759:                    // State Directory
1760:                    configmap.put("robot-state-dir", (String) processConf
1761:                            .get("robot-state-dir"));
1762:                    // Command Priviledges
1763:                    configmap.put("remote-access", (String) processConf
1764:                            .get("remote-access"));
1765:
1766:                    // Extracting
1767:                    configmap.put("htmlLink", filterConfig.getFilterConfVars(
1768:                            "Enumerate", "enumerate-urls", "enable", "true"));
1769:                    configmap.put("plainLink", filterConfig.getFilterConfVars(
1770:                            "Enumerate", "enumerate-urls-from-text", "enable",
1771:                            "false"));
1772:                    configmap.put("maxHtmlLink", filterConfig
1773:                            .getFilterConfVars("Enumerate", "enumerate-urls",
1774:                                    "max", "1024"));
1775:                    configmap.put("maxPlainLink", filterConfig
1776:                            .getFilterConfVars("Enumerate",
1777:                                    "enumerate-urls-from-text", "max", "1024"));
1778:
1779:                    return configmap;
1780:                }
1781:            }
1782:
1783:            public Boolean setCrawlingConfigMap(HashMap configmap)
1784:                    throws UnknownHostException {
1785:
1786:                if (!AdminUtil.isLocal(host)) {
1787:                    try {
1788:                        JMXConnector jmxc = AdminServerUtil
1789:                                .getJMXConnector(host);
1790:                        MBeanServerConnection msc = jmxc
1791:                                .getMBeanServerConnection();
1792:                        Object[] params = { configmap };
1793:                        String[] signatures = { "java.util.HashMap" };
1794:                        Boolean result = (Boolean) msc.invoke(objectName,
1795:                                "setCrawlingConfigMap", params, signatures);
1796:                        jmxc.close();
1797:                        return result;
1798:                    } catch (Exception e) {
1799:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1800:                        return Boolean.FALSE;
1801:                    }
1802:                } else {
1803:
1804:                    String tp = null;
1805:                    String ac = null;
1806:                    String as = null;
1807:                    String http_proxy = null;
1808:                    String https_proxy = null;
1809:                    String ftp_proxy = null;
1810:                    String userPassEncoded = "";
1811:
1812:                    ProcessConfig processConf = robotConfig.processConf;
1813:
1814:                    Iterator it = configmap.keySet().iterator();
1815:                    while (it.hasNext()) {
1816:                        String attrname = (String) it.next();
1817:                        String attrvalue = (String) configmap.get(attrname);
1818:
1819:                        if (attrname.equalsIgnoreCase("htmlLink")) {
1820:                            filterConfig.setFilterConfVars("Enumerate",
1821:                                    "enumerate-urls", "enable", attrvalue);
1822:                        } else if (attrname.equalsIgnoreCase("plainLink")) {
1823:                            filterConfig.setFilterConfVars("Enumerate",
1824:                                    "enumerate-urls-from-text", "enable",
1825:                                    attrvalue);
1826:                        } else if (attrname.equalsIgnoreCase("maxHtmlLink")) {
1827:                            filterConfig.setFilterConfVars("Enumerate",
1828:                                    "enumerate-urls", "max", attrvalue);
1829:                        } else if (attrname.equalsIgnoreCase("maxPlainLink")) {
1830:                            filterConfig.setFilterConfVars("Enumerate",
1831:                                    "enumerate-urls-from-text", "max",
1832:                                    attrvalue);
1833:                        } else {
1834:                            if (attrname.equalsIgnoreCase("password")
1835:                                    || attrname
1836:                                            .equalsIgnoreCase("proxy-password")) {
1837:                                if (attrvalue != null && !attrvalue.equals("")) {
1838:                                    userPassEncoded = new BASE64Encoder()
1839:                                            .encode(attrvalue.trim().getBytes());
1840:                                    attrvalue = userPassEncoded;
1841:                                }
1842:                            }
1843:                            processConf.put(attrname, attrvalue);
1844:                        }
1845:
1846:                        if (attrname.equals("proxy-type")) {
1847:                            tp = attrvalue;
1848:                        }
1849:                        if (attrname.equals("proxy-loc")) {
1850:                            ac = attrvalue;
1851:                        }
1852:                        if (attrname.equals("auto_serv")) {
1853:                            as = attrvalue;
1854:                        }
1855:                        if (attrname.equals("http_proxy")) {
1856:                            http_proxy = attrvalue;
1857:                        }
1858:                        if (attrname.equals("https_proxy")) {
1859:                            https_proxy = attrvalue;
1860:                        }
1861:                        if (attrname.equals("ftp_proxy")) {
1862:                            ftp_proxy = attrvalue;
1863:                        }
1864:                    } //end of while
1865:
1866:                    // callup to write the robots.pac operator.
1867:                    String ap = null;
1868:                    try {
1869:                        ap = setRobotPacFile(tp, ac, as, http_proxy,
1870:                                https_proxy, ftp_proxy);
1871:                    } catch (Exception e) {
1872:                        String message = "Robot.setCrawlingConfigMap(): failed to setRobotPacFile";
1873:                        Object tokens[] = { message };
1874:                        logger.log(Level.INFO, "PSSH_CSPSAMB0002", tokens);
1875:                    }
1876:                    // Auto proxy
1877:                    processConf.put("auto-proxy", ap);
1878:
1879:                    processConf.updateFile();
1880:                    filterConfig.updateFilterConf();
1881:
1882:                    return Boolean.TRUE;
1883:                }
1884:            }
1885:
1886:            public ArrayList retrieveScriptLaunchOptions()
1887:                    throws UnknownHostException {
1888:
1889:                if (!AdminUtil.isLocal(host)) {
1890:                    try {
1891:                        JMXConnector jmxc = AdminServerUtil
1892:                                .getJMXConnector(host);
1893:                        MBeanServerConnection msc = jmxc
1894:                                .getMBeanServerConnection();
1895:                        Object[] params = {};
1896:                        String[] signatures = {};
1897:                        ArrayList result = (ArrayList) msc.invoke(objectName,
1898:                                "retrieveScriptLaunchOptions", params,
1899:                                signatures);
1900:                        jmxc.close();
1901:                        return result;
1902:                    } catch (Exception e) {
1903:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1904:                        return null;
1905:                    }
1906:                } else {
1907:
1908:                    ArrayList ScriptLaunchOptions = new ArrayList();
1909:                    try {
1910:                        File pathName = new File(binDir);
1911:                        String[] scriptsAvail = pathName.list();
1912:                        for (int i = 0; i < scriptsAvail.length; i++) {
1913:                            if (scriptsAvail[i].length() >= 7) {
1914:                                if (scriptsAvail[i].substring(0, 7).equals(
1915:                                        "cmdHook")) {
1916:                                    try {
1917:                                        BufferedReader br = new BufferedReader(
1918:                                                new FileReader(binDir
1919:                                                        + File.separator
1920:                                                        + scriptsAvail[i]));
1921:                                        String line = null;
1922:                                        String descLine = null;
1923:                                        while ((line = br.readLine()) != null) {
1924:                                            if (line.startsWith("#")) {
1925:                                                line = line.substring(1);
1926:                                                line = line.trim();
1927:                                                if (line
1928:                                                        .startsWith("description")) {
1929:                                                    descLine = line
1930:                                                            .substring(12);
1931:                                                }
1932:                                            }
1933:                                        }
1934:                                        br.close();
1935:                                        HashMap option = new HashMap();
1936:                                        option.put("OptionLabel", descLine);
1937:                                        option.put("OptionValue", binDir
1938:                                                + File.separator
1939:                                                + scriptsAvail[i]);
1940:                                        ScriptLaunchOptions.add(option);
1941:                                    } catch (Exception e) {
1942:                                        HashMap option = new HashMap();
1943:                                        option.put("OptionLabel", "["
1944:                                                + scriptsAvail[i] + "]");
1945:                                        option.put("OptionValue", binDir
1946:                                                + File.separator
1947:                                                + scriptsAvail[i]);
1948:                                        ScriptLaunchOptions.add(option);
1949:                                        String message = "Robot.getScriptLaunchOptions(): cannot open the file "
1950:                                                + binDir
1951:                                                + File.separator
1952:                                                + scriptsAvail[i];
1953:                                        Object tokens[] = { message };
1954:                                        logger.log(Level.INFO,
1955:                                                "PSSH_CSPSAMB0002", tokens);
1956:                                    }
1957:                                }
1958:                            }
1959:                        } // end of for
1960:                    } catch (Exception e) {
1961:                        logger.log(Level.INFO, "PSSH_CSPSAMB0003", e);
1962:                    }
1963:                    return ScriptLaunchOptions;
1964:                }
1965:            }
1966:
1967:            public HashMap retrieveIndexingConfigMap() throws PSMBeanException,
1968:                    UnknownHostException {
1969:
1970:                if (!AdminUtil.isLocal(host)) {
1971:                    try {
1972:                        JMXConnector jmxc = AdminServerUtil
1973:                                .getJMXConnector(host);
1974:                        MBeanServerConnection msc = jmxc
1975:                                .getMBeanServerConnection();
1976:                        Object[] params = {};
1977:                        String[] signatures = {};
1978:                        HashMap result = (HashMap) msc
1979:                                .invoke(objectName,
1980:                                        "retrieveIndexingConfigMap", params,
1981:                                        signatures);
1982:                        jmxc.close();
1983:                        return result;
1984:                    } catch (Exception e) {
1985:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1986:                        throw new PSMBeanException(
1987:                                "Robot.retrieveIndexingConfigMap()", e
1988:                                        .toString(), e);
1989:                    }
1990:                } else {
1991:
1992:                    HashMap indexConfig = new HashMap();
1993:
1994:                    String bytesIndex = filterConfig.getFilterConfVars(
1995:                            "Generate", "extract-html-text", "truncate", "0");
1996:                    indexConfig.put("IndexBytes", bytesIndex);
1997:
1998:                    if (bytesIndex.equals("0"))
1999:                        indexConfig.put("Index", "full");
2000:                    else
2001:                        indexConfig.put("Index", "partial");
2002:
2003:                    String toc = filterConfig.getFilterConfVars("Generate",
2004:                            "extract-html-toc", "enable", "true");
2005:                    if (toc.equalsIgnoreCase("true")) {
2006:                        indexConfig.put("ExtractTOC", "true");
2007:                    } else {
2008:                        indexConfig.put("ExtractTOC", "false");
2009:                    }
2010:
2011:                    String meta = filterConfig.getFilterConfVars("Generate",
2012:                            "extract-html-meta", "enable", "true");
2013:                    if (meta.equalsIgnoreCase("true")) {
2014:                        indexConfig.put("ExtractMETA", "true");
2015:                    } else {
2016:                        indexConfig.put("ExtractMETA", "false");
2017:                    }
2018:
2019:                    ProcessConfig processConf = robotConfig.processConf;
2020:                    String allowNoClass = (String) processConf
2021:                            .get("allow-nonexist-classification");
2022:
2023:                    if (allowNoClass != null) {
2024:                        if (!allowNoClass.equalsIgnoreCase("true")
2025:                                && !allowNoClass.equalsIgnoreCase("yes")) {
2026:                            indexConfig.put("AllowNoClass", "false");
2027:                        } else {
2028:                            indexConfig.put("AllowNoClass", "true");
2029:                        }
2030:                    } else {
2031:                        indexConfig.put("AllowNoClass", "true");
2032:                    }
2033:
2034:                    indexConfig.put("ConvertTimeout", (String) processConf
2035:                            .get("convert-timeout"));
2036:
2037:                    return indexConfig;
2038:                }
2039:            }
2040:
2041:            public Boolean setIndexingConfigMap(HashMap configmap)
2042:                    throws UnknownHostException {
2043:
2044:                if (!AdminUtil.isLocal(host)) {
2045:                    try {
2046:                        JMXConnector jmxc = AdminServerUtil
2047:                                .getJMXConnector(host);
2048:                        MBeanServerConnection msc = jmxc
2049:                                .getMBeanServerConnection();
2050:                        Object[] params = { configmap };
2051:                        String[] signatures = { "java.util.HashMap" };
2052:                        Boolean result = (Boolean) msc.invoke(objectName,
2053:                                "setIndexingConfigMap", params, signatures);
2054:                        jmxc.close();
2055:                        return result;
2056:                    } catch (Exception e) {
2057:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2058:                        return Boolean.FALSE;
2059:                    }
2060:                } else {
2061:
2062:                    String indextext = (String) configmap.get("Index");
2063:                    if (indextext.equals("full")) {
2064:
2065:                        filterConfig.setFilterConfVars("Generate",
2066:                                "extract-full-text", "truncate", "0");
2067:                        filterConfig.setFilterConfVars("Generate",
2068:                                "extract-html-text", "truncate", "0");
2069:                    } else {
2070:                        filterConfig.setFilterConfVars("Generate",
2071:                                "extract-full-text", "truncate",
2072:                                (String) configmap.get("IndexBytes"));
2073:                        filterConfig.setFilterConfVars("Generate",
2074:                                "extract-html-text", "truncate",
2075:                                (String) configmap.get("IndexBytes"));
2076:                    }
2077:
2078:                    filterConfig.setFilterConfVars("Generate",
2079:                            "extract-html-toc", "enable", (String) configmap
2080:                                    .get("ExtractTOC"));
2081:                    filterConfig.setFilterConfVars("Generate",
2082:                            "extract-html-meta", "enable", (String) configmap
2083:                                    .get("ExtractMETA"));
2084:
2085:                    filterConfig.updateFilterConf();
2086:
2087:                    ProcessConfig processConf = robotConfig.processConf;
2088:                    processConf.put("allow-nonexist-classification",
2089:                            (String) configmap.get("AllowNoClass"));
2090:
2091:                    processConf.put("convert-timeout", (String) configmap
2092:                            .get("ConvertTimeout"));
2093:
2094:                    processConf.updateFile();
2095:
2096:                    return Boolean.TRUE;
2097:                }
2098:            }
2099:
2100:            public ArrayList listConverters() throws PSMBeanException,
2101:                    UnknownHostException {
2102:
2103:                if (!AdminUtil.isLocal(host)) {
2104:                    try {
2105:                        JMXConnector jmxc = AdminServerUtil
2106:                                .getJMXConnector(host);
2107:                        MBeanServerConnection msc = jmxc
2108:                                .getMBeanServerConnection();
2109:                        Object[] params = {};
2110:                        String[] signatures = {};
2111:                        ArrayList result = (ArrayList) msc.invoke(objectName,
2112:                                "listConverters", params, signatures);
2113:                        jmxc.close();
2114:                        return result;
2115:                    } catch (Exception e) {
2116:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2117:                        throw new PSMBeanException("Robot.listConverters()", e
2118:                                .toString(), e);
2119:                    }
2120:                } else {
2121:
2122:                    ConverterConfig cc = robotConfig.convertConf;
2123:
2124:                    ArrayList converters = new ArrayList();
2125:
2126:                    for (int i = 0; i < cc.numOfDocs(); i++) {
2127:                        LinkedList converter = new LinkedList();
2128:                        converter.add(cc.getDocLabel(i));
2129:                        if (cc.getDocEnable(i)) {
2130:                            converter.add(Boolean.TRUE);
2131:                        } else {
2132:                            converter.add(Boolean.FALSE);
2133:                        }
2134:                        converters.add(converter);
2135:                    }
2136:
2137:                    return converters;
2138:                }
2139:            }
2140:
2141:            public Boolean setConverters(ArrayList converters)
2142:                    throws UnknownHostException {
2143:
2144:                if (!AdminUtil.isLocal(host)) {
2145:                    try {
2146:                        JMXConnector jmxc = AdminServerUtil
2147:                                .getJMXConnector(host);
2148:                        MBeanServerConnection msc = jmxc
2149:                                .getMBeanServerConnection();
2150:                        Object[] params = { converters };
2151:                        String[] signatures = { "java.util.ArrayList" };
2152:                        Boolean result = (Boolean) msc.invoke(objectName,
2153:                                "setConverters", params, signatures);
2154:                        jmxc.close();
2155:                        return result;
2156:                    } catch (Exception e) {
2157:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2158:                        return Boolean.FALSE;
2159:                    }
2160:                } else {
2161:
2162:                    ConverterConfig cc = robotConfig.convertConf;
2163:
2164:                    for (int i = 0; i < converters.size(); i++) {
2165:                        LinkedList converter = (LinkedList) converters.get(i);
2166:                        Boolean enable = (Boolean) converter.get(1);
2167:                        if (enable.booleanValue()) {
2168:                            cc.setDocEnable(i, true); //set to enabled
2169:                        } else {
2170:                            cc.setDocEnable(i, false); //set to disabled
2171:                        }
2172:                    }
2173:
2174:                    cc.updateFile();
2175:                    return Boolean.TRUE;
2176:                }
2177:            }
2178:
2179:            public Boolean setConverter(String converter, String enable)
2180:                    throws UnknownHostException {
2181:
2182:                if (!AdminUtil.isLocal(host)) {
2183:                    try {
2184:                        JMXConnector jmxc = AdminServerUtil
2185:                                .getJMXConnector(host);
2186:                        MBeanServerConnection msc = jmxc
2187:                                .getMBeanServerConnection();
2188:                        Object[] params = { converter, enable };
2189:                        String[] signatures = { "java.lang.String",
2190:                                "java.lang.String" };
2191:                        Boolean result = (Boolean) msc.invoke(objectName,
2192:                                "setConverter", params, signatures);
2193:                        jmxc.close();
2194:                        return result;
2195:                    } catch (Exception e) {
2196:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2197:                        return Boolean.FALSE;
2198:                    }
2199:                } else {
2200:
2201:                    int id = Integer.parseInt(converter);
2202:
2203:                    ConverterConfig cc = robotConfig.convertConf;
2204:
2205:                    if (enable.equalsIgnoreCase("no")
2206:                            || enable.equalsIgnoreCase("false")) {
2207:                        cc.setDocEnable(id, false); //set to disabled
2208:                    }
2209:
2210:                    if (enable.equalsIgnoreCase("yes")
2211:                            || enable.equalsIgnoreCase("true")) {
2212:                        cc.setDocEnable(id, true); //set to enabled
2213:                    }
2214:
2215:                    cc.updateFile();
2216:                    return Boolean.TRUE;
2217:                }
2218:            }
2219:
2220:            public String retrieveConverterTimeout()
2221:                    throws UnknownHostException {
2222:
2223:                if (!AdminUtil.isLocal(host)) {
2224:                    try {
2225:                        JMXConnector jmxc = AdminServerUtil
2226:                                .getJMXConnector(host);
2227:                        MBeanServerConnection msc = jmxc
2228:                                .getMBeanServerConnection();
2229:                        Object[] params = {};
2230:                        String[] signature = {};
2231:                        String result = (String) msc.invoke(objectName,
2232:                                "retrieveConverterTimeout", params, signature);
2233:                        jmxc.close();
2234:                        return result;
2235:                    } catch (Exception e) {
2236:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2237:                        return "";
2238:                    }
2239:                } else {
2240:
2241:                    ProcessConfig processConf = robotConfig.processConf;
2242:
2243:                    return (String) processConf.get("convert-timeout");
2244:                }
2245:            }
2246:
2247:            public Boolean setConverterTimeout(String timeout)
2248:                    throws UnknownHostException {
2249:                if (!AdminUtil.isLocal(host)) {
2250:                    try {
2251:                        JMXConnector jmxc = AdminServerUtil
2252:                                .getJMXConnector(host);
2253:                        MBeanServerConnection msc = jmxc
2254:                                .getMBeanServerConnection();
2255:                        Object[] params = { timeout };
2256:                        String[] signatures = { "java.lang.String" };
2257:                        Boolean result = (Boolean) msc.invoke(objectName,
2258:                                "setConverterTimeout", params, signatures);
2259:                        jmxc.close();
2260:                        return result;
2261:                    } catch (Exception e) {
2262:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2263:                        return Boolean.FALSE;
2264:                    }
2265:                } else {
2266:
2267:                    ProcessConfig processConf = robotConfig.processConf;
2268:
2269:                    processConf.put("convert-timeout", timeout);
2270:
2271:                    processConf.updateFile();
2272:
2273:                    return Boolean.TRUE;
2274:                }
2275:            }
2276:
2277:            public HashMap runSimulator(String siteURL, Boolean checkDNS,
2278:                    Boolean checkRedirect) throws PSMBeanException,
2279:                    UnknownHostException {
2280:
2281:                if (!AdminUtil.isLocal(host)) {
2282:                    try {
2283:                        JMXConnector jmxc = AdminServerUtil
2284:                                .getJMXConnector(host);
2285:                        MBeanServerConnection msc = jmxc
2286:                                .getMBeanServerConnection();
2287:                        Object[] params = { siteURL, checkDNS, checkRedirect };
2288:                        String[] signatures = { "java.lang.String",
2289:                                "java.lang.Boolean", "java.lang.Boolean" };
2290:                        HashMap result = (HashMap) msc.invoke(objectName,
2291:                                "runSimulator", params, signatures);
2292:                        jmxc.close();
2293:                        return result;
2294:                    } catch (Exception e) {
2295:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2296:                        throw new PSMBeanException("Robot.runSimulator()", e
2297:                                .toString(), e);
2298:                    }
2299:                } else {
2300:
2301:                    ArrayList alist = new ArrayList();
2302:
2303:                    if (siteURL.equals("")) {
2304:                        int size = robotConfig.numRuleset();
2305:
2306:                        for (int i = 0; i < size; i++) {
2307:                            FilterRuleset frs = robotConfig.GetRuleSet(i);
2308:                            if (!frs.isEnabled())
2309:                                continue;
2310:                            int numOfServers = frs.numOfServers();
2311:                            for (int j = 0; j < numOfServers; j++) {
2312:                                String s = frs.getServerByIndex(j);
2313:                                alist.add(s);
2314:                            }
2315:                        }
2316:                    } else {
2317:                        alist.add(getValidatedURL(siteURL).toString());
2318:                    }
2319:
2320:                    return runSimulator(alist, checkDNS, checkRedirect);
2321:                }
2322:            }
2323:
2324:            public HashMap runSimulator(ArrayList alist, Boolean checkDNS,
2325:                    Boolean checkRedirect) throws PSMBeanException,
2326:                    UnknownHostException {
2327:
2328:                if (!AdminUtil.isLocal(host)) {
2329:                    try {
2330:                        JMXConnector jmxc = AdminServerUtil
2331:                                .getJMXConnector(host);
2332:                        MBeanServerConnection msc = jmxc
2333:                                .getMBeanServerConnection();
2334:                        Object[] params = { alist, checkDNS, checkRedirect };
2335:                        String[] signatures = { "java.util.ArrayList",
2336:                                "java.lang.Boolean", "java.lang.Boolean" };
2337:                        HashMap result = (HashMap) msc.invoke(objectName,
2338:                                "runSimulator", params, signatures);
2339:                        jmxc.close();
2340:                        return result;
2341:                    } catch (Exception e) {
2342:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2343:                        throw new PSMBeanException("Robot.runSimulator()", e
2344:                                .toString(), e);
2345:                    }
2346:                } else {
2347:
2348:                    if (alist != null) {
2349:                        for (int i = 0; i < alist.size(); i++) {
2350:                            String urlstring = (String) alist.get(i);
2351:                            alist.set(i, getValidatedURL(urlstring).toString());
2352:                        }
2353:                    }
2354:
2355:                    String[] urls = (String[]) alist.toArray(new String[0]);
2356:
2357:                    HashMap result_map = new HashMap();
2358:
2359:                    boolean check_dns = checkDNS.booleanValue();
2360:                    boolean check_redirect = checkRedirect.booleanValue();
2361:
2362:                    FilterSimulator frsim = new FilterSimulator();
2363:
2364:                    ProcessConfig pconf = robotConfig.processConf;
2365:                    String shh = (String) pconf.get("smart-host-heuristics");
2366:                    boolean is_shh;
2367:                    if (shh.equalsIgnoreCase("true"))
2368:                        is_shh = true;
2369:                    else
2370:                        is_shh = false;
2371:
2372:                    try {
2373:                        for (int i = 0; i < urls.length; i++) {
2374:
2375:                            HashMap url_map = frsim.runSimu(is_shh, serverRoot,
2376:                                    urls[i], check_dns, check_redirect);
2377:
2378:                            result_map.put(urls[i], url_map);
2379:                        }
2380:
2381:                    } catch (Exception e) {
2382:                        String message = "Robot.runSimulator(): fail to run simulator";
2383:                        Object tokens[] = { message };
2384:                        logger.log(Level.INFO, "PSSH_CSPSAMB0002", tokens);
2385:                        throw new PSMBeanException("Robot.runSimulator()", e
2386:                                .toString(), e);
2387:                    }
2388:
2389:                    result_map.put("smart-host-heuristics", shh);
2390:
2391:                    return result_map;
2392:                }
2393:            }
2394:
2395:            //utilities
2396:            public String[] retrieveFilterRuleNames() throws PSMBeanException,
2397:                    UnknownHostException {
2398:
2399:                if (!AdminUtil.isLocal(host)) {
2400:                    try {
2401:                        JMXConnector jmxc = AdminServerUtil
2402:                                .getJMXConnector(host);
2403:                        MBeanServerConnection msc = jmxc
2404:                                .getMBeanServerConnection();
2405:                        Object[] params = {};
2406:                        String[] signatures = {};
2407:                        String[] result = (String[]) msc.invoke(objectName,
2408:                                "retrieveFilterRuleNames", params, signatures);
2409:                        jmxc.close();
2410:                        return result;
2411:                    } catch (Exception e) {
2412:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2413:                        throw new PSMBeanException(
2414:                                "Robot.retrieveFilterRuleNames()",
2415:                                e.toString(), e);
2416:                    }
2417:                } else {
2418:
2419:                    return robotConfig.getRuleNicknames();
2420:                }
2421:            }
2422:
2423:            public String[] retrieveFilterRuleIds() throws PSMBeanException,
2424:                    UnknownHostException {
2425:                if (!AdminUtil.isLocal(host)) {
2426:                    try {
2427:                        JMXConnector jmxc = AdminServerUtil
2428:                                .getJMXConnector(host);
2429:                        MBeanServerConnection msc = jmxc
2430:                                .getMBeanServerConnection();
2431:                        Object[] params = {};
2432:                        String[] signatures = {};
2433:                        String[] result = (String[]) msc.invoke(objectName,
2434:                                "retrieveFilterRuleIds", params, signatures);
2435:                        jmxc.close();
2436:                        return result;
2437:                    } catch (Exception e) {
2438:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2439:                        throw new PSMBeanException(
2440:                                "Robot.retrieveFilterRuleIds()", e.toString(),
2441:                                e);
2442:                    }
2443:                } else {
2444:
2445:                    return robotConfig.getRuleIDs();
2446:                }
2447:            }
2448:
2449:            public String validateSiteURL(String url)
2450:                    throws UnknownHostException {
2451:
2452:                if (!AdminUtil.isLocal(host)) {
2453:                    try {
2454:                        JMXConnector jmxc = AdminServerUtil
2455:                                .getJMXConnector(host);
2456:                        MBeanServerConnection msc = jmxc
2457:                                .getMBeanServerConnection();
2458:                        Object[] params = { url };
2459:                        String[] signatures = { "java.lang.String" };
2460:                        String result = (String) msc.invoke(objectName,
2461:                                "validateSiteURL", params, signatures);
2462:                        jmxc.close();
2463:                        return result;
2464:                    } catch (Exception e) {
2465:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2466:                        return "";
2467:                    }
2468:                } else {
2469:
2470:                    String sitename = url.replace('\\', '/');
2471:
2472:                    if (!sitename.startsWith("file")
2473:                            && !sitename.startsWith("/")) {
2474:                        if (sitename.indexOf(" ") != -1) {
2475:                            return "search.error.space";
2476:                        }
2477:                    }
2478:
2479:                    if (sitename.indexOf("://") >= 0) {
2480:                        String[] str = sitename.split("://");
2481:                        String protocol = str[0];
2482:                        String host = str[1];
2483:
2484:                        if (!protocol.equalsIgnoreCase("http")
2485:                                && !protocol.equalsIgnoreCase("https")
2486:                                && !protocol.equalsIgnoreCase("ftp")
2487:                                && !protocol.equalsIgnoreCase("file")
2488:                                && !protocol.equalsIgnoreCase("gopher")
2489:                                && !protocol.equalsIgnoreCase("news")
2490:                                && !protocol.equalsIgnoreCase("snews")) {
2491:                            return "search.error.protocolnotsupport";
2492:                        }
2493:
2494:                        if (!protocol.equalsIgnoreCase("file")
2495:                                && !host.equalsIgnoreCase("localhost")
2496:                                && host.indexOf('.') == -1) {
2497:
2498:                            return "search.error.invalidhostname";
2499:                        }
2500:
2501:                    } else {
2502:                        if (!sitename.startsWith("/")) {
2503:                            if (sitename.indexOf('.') == -1) {
2504:                                return "search.error.invalidhostname";
2505:                            }
2506:                        }
2507:                        if (sitename.startsWith(".")) {
2508:                            return "search.error.invalidhostname";
2509:                        }
2510:                    }
2511:
2512:                    return "";
2513:                }
2514:            }
2515:
2516:            public HashMap verifyServerName(String servername)
2517:                    throws PSMBeanException, UnknownHostException {
2518:
2519:                if (!AdminUtil.isLocal(host)) {
2520:                    try {
2521:                        JMXConnector jmxc = AdminServerUtil
2522:                                .getJMXConnector(host);
2523:                        MBeanServerConnection msc = jmxc
2524:                                .getMBeanServerConnection();
2525:                        Object[] params = { servername };
2526:                        String[] signatures = { "java.lang.String" };
2527:                        HashMap result = (HashMap) msc.invoke(objectName,
2528:                                "verifyServerName", params, signatures);
2529:                        jmxc.close();
2530:                        return result;
2531:                    } catch (Exception e) {
2532:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2533:                        throw new PSMBeanException("Robot.verifyServerName()",
2534:                                e.toString(), e);
2535:                    }
2536:                } else {
2537:
2538:                    HashMap server = new HashMap();
2539:                    if (servername.trim().length() > 0) {
2540:                        FilterSimulator frsim = new FilterSimulator();
2541:                        try {
2542:                            String cname = frsim.getHostByName(serverRoot,
2543:                                    servername);
2544:                            server.put("Status", "verified");
2545:                            server.put("RealName", cname);
2546:                        } catch (Exception e) {
2547:                            server.put("Status", e.getMessage());
2548:                            server.put("RealName", "");
2549:                        }
2550:                    }
2551:                    return server;
2552:                }
2553:            }
2554:
2555:            public String getAdvanceReport(String reportType)
2556:                    throws PSMBeanException, UnknownHostException {
2557:
2558:                if (!AdminUtil.isLocal(host)) {
2559:                    try {
2560:                        JMXConnector jmxc = AdminServerUtil
2561:                                .getJMXConnector(host);
2562:                        MBeanServerConnection msc = jmxc
2563:                                .getMBeanServerConnection();
2564:                        Object[] params = { reportType };
2565:                        String[] signatures = { "java.lang.String" };
2566:                        String result = (String) msc.invoke(objectName,
2567:                                "getAdvanceReport", params, signatures);
2568:                        jmxc.close();
2569:                        return result;
2570:                    } catch (Exception e) {
2571:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2572:                        throw new PSMBeanException("Robot.getAdvanceReport()",
2573:                                e.toString(), e);
2574:                    }
2575:                } else {
2576:
2577:                    String str = "";
2578:                    try {
2579:
2580:                        if (reportType.compareTo("all") != 0) {
2581:                            int match = 0;
2582:                            for (int i = 0; i < reportQuerys.length - 1; i++) {
2583:                                if (reportType
2584:                                        .equalsIgnoreCase(reportLabels[i])) {
2585:                                    match = i;
2586:                                }
2587:                            }
2588:                            byte[] r = this .robotURLGet(reportQuerys[match]
2589:                                    + "&format=i18n");
2590:                            str = new String(r, "UTF-8");
2591:                        } else {
2592:                            StringBuffer buffer = new StringBuffer();
2593:                            for (int i = 0; i < reportQuerys.length - 1; i++) {
2594:                                byte[] r = this .robotURLGet(reportQuerys[i]
2595:                                        + "&format=i18n");
2596:                                String s = new String(r, "UTF-8");
2597:                                buffer.append(s);
2598:                            }
2599:                            str = buffer.toString();
2600:                        }
2601:
2602:                    } catch (Exception e) {
2603:                        String message = "Robot.getAdvancedReport(): failed";
2604:                        Object tokens[] = { message };
2605:                        logger.log(Level.INFO, "PSSH_CSPSAMB0002", tokens);
2606:                    }
2607:
2608:                    return str;
2609:                }
2610:            }
2611:
2612:            public ArrayList retrieveExcludedURLsReportDates()
2613:                    throws PSMBeanException, UnknownHostException {
2614:
2615:                if (!AdminUtil.isLocal(host)) {
2616:                    try {
2617:                        JMXConnector jmxc = AdminServerUtil
2618:                                .getJMXConnector(host);
2619:                        MBeanServerConnection msc = jmxc
2620:                                .getMBeanServerConnection();
2621:                        Object[] params = {};
2622:                        String[] signatures = {};
2623:                        ArrayList result = (ArrayList) msc.invoke(objectName,
2624:                                "retrieveExcludedURLsReportDates", params,
2625:                                signatures);
2626:                        jmxc.close();
2627:                        return result;
2628:                    } catch (Exception e) {
2629:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2630:                        throw new PSMBeanException(
2631:                                "Robot.retrieveExcludedURLsReportDates()", e
2632:                                        .toString(), e);
2633:                    }
2634:                } else {
2635:                    flog = new FilterLog(logDir + File.separator + "filter.log");
2636:                    ArrayList dates = flog.getRunArrayList();
2637:                    return dates;
2638:                }
2639:            }
2640:
2641:            public HashMap getExcludedURLsReport(String date)
2642:                    throws PSMBeanException, UnknownHostException {
2643:
2644:                if (!AdminUtil.isLocal(host)) {
2645:                    try {
2646:                        JMXConnector jmxc = AdminServerUtil
2647:                                .getJMXConnector(host);
2648:                        MBeanServerConnection msc = jmxc
2649:                                .getMBeanServerConnection();
2650:                        Object[] params = { date };
2651:                        String[] signatures = { "java.lang.String" };
2652:                        HashMap result = (HashMap) msc.invoke(objectName,
2653:                                "getExcludedURLsReport", params, signatures);
2654:                        jmxc.close();
2655:                        return result;
2656:                    } catch (Exception e) {
2657:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2658:                        throw new PSMBeanException(
2659:                                "Robot.getExcludedURLsReport()", e.toString(),
2660:                                e);
2661:                    }
2662:                } else {
2663:
2664:                    HashMap resultmap = new HashMap();
2665:                    flog = new FilterLog(
2666:                            logDir + File.separator + "filter.log", date);
2667:                    String[] reasons = flog.getReasons();
2668:                    for (int i = 0; i < reasons.length; i++) {
2669:                        flog = new FilterLog(logDir + File.separator
2670:                                + "filter.log", date, i);
2671:                        resultmap.put(reasons[i], flog.getFilteredURL());
2672:                    }
2673:                    return resultmap;
2674:                }
2675:            }
2676:
2677:            /*
2678:             * other public methods
2679:             */
2680:            public boolean isRunning() {
2681:                String robotProcName = "robot.exe";
2682:                if (System.getProperty("os.name").startsWith("Windows"))
2683:                    robotProcName = "robot.exe";
2684:                return this .isRunning("robot.pid", robotProcName);
2685:            }
2686:
2687:            public boolean isRunning(String pidFilePath, String cmd) {
2688:                String pid = Read1stLine(pidFilePath);
2689:                String catping = null;
2690:                if (pid == null) {
2691:                    String message = "Robot.isRunning(): " + pidFilePath
2692:                            + " is null";
2693:                    Object tokens[] = { message };
2694:                    logger.log(Level.INFO, "PSSH_CSPSAMB0001", tokens);
2695:                    return false;
2696:                }
2697:
2698:                Runtime rt = Runtime.getRuntime();
2699:                try {
2700:                    catping = libDir + File.separator + CATPING_CMD + " " + pid
2701:                            + " " + cmd;
2702:                    String cmds[] = { libDir + File.separator + CATPING_CMD,
2703:                            pid, cmd };
2704:                    Process p = rt.exec(cmds, r_env);
2705:                    try {
2706:                        p.waitFor();
2707:                    } catch (java.lang.InterruptedException e) {
2708:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2709:                    }
2710:                    int exitValue = p.exitValue();
2711:                    if (exitValue == 1) {
2712:                        return false;
2713:                    }
2714:                } catch (IOException e) {
2715:                    //logger.logp(Level.SEVERE, "Robot", "isRunning", "rt.exec( " + catping + ") Exception:" + e.getClass().getName() + " msg: " + e.getMessage());
2716:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2717:                    return false;
2718:                }
2719:                return true;
2720:            }
2721:
2722:            public boolean generate_filter_conf_run(String fc, String fcr) {
2723:                try {
2724:                    File file = new File(fc);
2725:                    if (!file.exists()) {
2726:                        return false;
2727:                    }
2728:                    Runtime rt = Runtime.getRuntime();
2729:                    String cmd = this .libDir + File.separator + "rcpp " + fc
2730:                            + " " + fcr;
2731:                    String cmds[] = { this .libDir + File.separator + "rcpp",
2732:                            fc, fcr };
2733:                    try {
2734:                        Process ps = rt.exec(cmds, r_env, new File(serverRoot));
2735:                        ps.waitFor();
2736:                        if (ps.exitValue() != 0) {
2737:                            return false;
2738:                        }
2739:                    } catch (IOException e) {
2740:                        //logger.logp(Level.SEVERE, "Robot", "generate_filter_conf_run", "rt.exec Exception: " + e.getMessage());
2741:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2742:                        return false;
2743:                    }
2744:                } catch (Exception e) {
2745:                    //logger.logp(Level.SEVERE, "Robot", "generate_filter_conf_run", "rt.exec Exception: " + e.getMessage());
2746:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2747:                    return false;
2748:                }
2749:                return true;
2750:            }
2751:
2752:            public boolean start_rdregister() {
2753:                String rdProcName = "rdregister";
2754:                if (System.getProperty("os.name").startsWith("Windows"))
2755:                    rdProcName = "rdregister.exe";
2756:                if (this .isRunning("rdregister.pid", rdProcName)) {
2757:                    return true;
2758:                }
2759:                try {
2760:                    String robot_path = (String) robotConfig.processConf
2761:                            .get("robot-state-dir");
2762:                    if (robot_path == null) {
2763:                        robot_path = serverRoot + File.separator + "robot";
2764:                    }
2765:
2766:                    File file = new File(robot_path);
2767:                    if (!file.exists()) {
2768:                        //logger.logp(Level.SEVERE, "Robot", "start_rdregister", "robot-state-dir:" + robot_path + " not exist");
2769:                        String message = "Robot.start_rdregister(): path robot-state-dir does not exist";
2770:                        Object tokens[] = { message };
2771:                        logger.log(Level.INFO, "PSSH_CSPSAMB0001", tokens);
2772:                        return false;
2773:                    }
2774:                    Runtime rt = Runtime.getRuntime();
2775:                    String cmd = libDir + File.separator + RDREGISTER_CMD
2776:                            + " -f " + configDir + File.separator + SEARCH_CONF
2777:                            + " -p " + robot_path;
2778:                    String cmds[] = { libDir + File.separator + RDREGISTER_CMD,
2779:                            "-f", configDir + File.separator + SEARCH_CONF,
2780:                            "-p", robot_path };
2781:                    try {
2782:                        //logger.logp(Level.SEVERE, "Robot", "start_rdregister", "start_rdregister: " + cmd);
2783:                        Process ps = rt.exec(cmds, r_env, new File(serverRoot));
2784:                    } catch (IOException e) {
2785:                        //logger.logp(Level.SEVERE, "Robot", "start_rdregister", "rt.exec Exception:" + e.getMessage());
2786:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2787:                        return false;
2788:                    }
2789:                } catch (Exception e) {
2790:                    //logger.logp(Level.SEVERE, "Robot", "start_rdregister", "rt.exec Exception:" + e.getMessage());
2791:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2792:                    return false;
2793:                }
2794:                return true;
2795:            }
2796:
2797:            public byte[] robotURLGet(String cmd, String fn) {
2798:                return robotURLGet(cmd + "?fn=" + fn);
2799:            }
2800:
2801:            public byte[] robotURLGet(String cmd) {
2802:                InputStream in;
2803:                int n;
2804:                try {
2805:                    //logger.logp(Level.SEVERE, "Robot", "robotURLGet", "robotURLGet:robot/" + cmd );
2806:                    String base = Read1stLine("robotbase.cmd");
2807:                    if (base == null) {
2808:                        return null;
2809:                    }
2810:                    URL command_url = new URL("http://" + base + "/robot/"
2811:                            + cmd);
2812:                    URLConnection url_conn = command_url.openConnection();
2813:                    int len = 1024;
2814:                    int offset = 0;
2815:                    byte buff[] = new byte[len];
2816:                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
2817:                    try {
2818:                        in = new BufferedInputStream(url_conn.getInputStream());
2819:                    } catch (Exception e) {
2820:                        //logger.logp(Level.SEVERE, "Robot", "robotURLGet", "(getInputStream)Exception:" + e.getMessage());
2821:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2822:                        return null;
2823:                    }
2824:                    try {
2825:                        while ((n = in.read(buff, 0, len)) >= 0)
2826:                            bos.write(buff, 0, n);
2827:                    } catch (Exception e) {
2828:                        //logger.logp(Level.SEVERE, "Robot", "robotURLGet", "(1st in.read)Exception:" + e.getMessage());
2829:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2830:                        return null;
2831:                    }
2832:                    try {
2833:                        in.close();
2834:                    } catch (Exception e) {
2835:                        //logger.logp(Level.SEVERE, "Robot", "robotURLGet", "(in.close)Exception:" + e.getMessage());
2836:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2837:                        return null;
2838:                    }
2839:                    return bos.toByteArray();
2840:                } catch (Exception e) {
2841:                    //logger.logp(Level.SEVERE, "Robot", "robotURLGet", "Exception:" + e.getMessage());
2842:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
2843:                    return null;
2844:                }
2845:            }
2846:
2847:            public boolean remove_status_files() {
2848:                boolean status = true;
2849:                if (this .isRunning())
2850:                    return false;
2851:                File f = new File(statusDir);
2852:                if (f.isDirectory()) {
2853:                    RobotStatusFileFilter ff = new RobotStatusFileFilter();
2854:                    File[] files = f.listFiles(ff);
2855:                    for (int i = 0; i < files.length; i++) {
2856:                        if (!files[i].delete()) {
2857:                            status = false;
2858:                        }
2859:                    }
2860:                }
2861:                return status;
2862:            }
2863:
2864:            /*
2865:             * private methods
2866:             */
2867:            class RobotStatusFileFilter implements  FileFilter {
2868:                public boolean accept(File path) {
2869:                    if (path.getName().startsWith("__db.")
2870:                            || path.getName().endsWith(".db")) {
2871:                        return true;
2872:                    }
2873:                    return false;
2874:                }
2875:            }
2876:
2877:            private String Read1stLine(String filename) {
2878:                try {
2879:                    FileReader in = new FileReader(serverRoot + File.separator
2880:                            + "logs" + File.separator + filename);
2881:                    BufferedReader lr = new BufferedReader(in);
2882:                    String firstLine = lr.readLine();
2883:                    return firstLine;
2884:                } catch (Exception e) {
2885:                    String message = "Robot.Read1stLine(): cannot find the file: "
2886:                            + e.getMessage();
2887:                    Object tokens[] = { message };
2888:                    logger.log(Level.INFO, "PSSH_CSPSAMB0001", tokens);
2889:                    return null;
2890:                }
2891:            }
2892:
2893:            public String setRobotPacFile(String tp, String ac, String as,
2894:                    String http_proxy, String https_proxy, String ftp_proxy)
2895:                    throws IOException {
2896:                String ap = null;
2897:                File robotPac = new File(serverRoot + File.separator + "config"
2898:                        + File.separator + "robot.pac");
2899:
2900:                // First test to for auto --> local and ignore the file, set proxy to file:auto_proxy
2901:                if (tp.equals("auto") && ac.equals("local")) {
2902:                    ap = "file:" + as;
2903:                }
2904:
2905:                // check for Proxy direct and remove the file, set proxy to null
2906:                if (tp.equals("direct")) {
2907:                    robotPac.delete();
2908:                    ap = "";
2909:                }
2910:
2911:                // check for Proxy proxy auto --> remote and remove the file, set proxy to auto_proxy
2912:                if (tp.equals("auto") && ac.equals("server")) {
2913:                    robotPac.delete();
2914:                    ap = as;
2915:                }
2916:
2917:                // check for Manual Proxy and show your love for the file. Set proxy to file:robot.pac
2918:                if (tp.equals("manual")) {
2919:                    PrintWriter out = null;
2920:                    try {
2921:                        FileOutputStream rpac = new FileOutputStream(robotPac);
2922:                        out = new PrintWriter(rpac, true);
2923:                    } catch (Exception e) {
2924:                        logger
2925:                                .log(Level.INFO, "PSSH_CSPSA0013", e
2926:                                        .getMessage());
2927:                        return ap;
2928:                    }
2929:                    out
2930:                            .print("function FindProxyForURL(url, host, method)  {\n");
2931:                    out
2932:                            .print("var protocol = url.split(\":\")[0].toLowerCase();\n\n");
2933:
2934:                    // First the HTTP proxy
2935:                    out.print("if(\"http\" == protocol) ");
2936:                    if (http_proxy != null) {
2937:                        out.print("return \"PROXY " + http_proxy + "\";\n");
2938:                    } else {
2939:                        out.print("return \"DIRECT\";\n");
2940:                    }
2941:                    // Then the HTTPS proxy
2942:                    out.print("if(\"https\" == protocol) ");
2943:                    if (https_proxy != null) {
2944:                        out.print("return \"PROXY " + https_proxy + "\";\n");
2945:                    } else {
2946:                        out.print("return \"DIRECT\";\n");
2947:                    }
2948:                    // First the HTTP proxy
2949:                    out.print("if(\"ftp\" == protocol) ");
2950:                    if (ftp_proxy != null) {
2951:                        out.print("return \"PROXY " + ftp_proxy + "\";\n");
2952:                    } else {
2953:                        out.print("return \"DIRECT\";\n");
2954:                    }
2955:                    out.print("else return \"DIRECT\";\n}\n");
2956:                    out.close();
2957:                    ap = "file:" + robotPac;
2958:                }
2959:                return ap;
2960:            }
2961:
2962:            public String getValidatedDomain(String sitename) {
2963:
2964:                String domainname = sitename;
2965:
2966:                if (sitename.startsWith("http") || sitename.startsWith("https")
2967:                        || sitename.startsWith("ftp")
2968:                        || sitename.startsWith("file")
2969:                        || sitename.startsWith("gopher")) {
2970:                    // Strip off the protocol for domain specifications
2971:                    String[] tmp = sitename.split(":");
2972:                    if (tmp.length > 1) {
2973:                        domainname = sitename.substring(tmp[0].length() + 3);
2974:                    }
2975:
2976:                    // Strip off the port for domain specifications if there's any
2977:                    String[] temp = domainname.split(":");
2978:                    if (temp.length > 1) {
2979:                        domainname = temp[0];
2980:                    }
2981:
2982:                    // Strip off the abc. for abc.blah.blah
2983:                    String[] t = domainname.split(".");
2984:                    if (t.length > 1) {
2985:                        String s1 = domainname.substring(t[0].length() + 1);
2986:                        domainname = s1;
2987:                    }
2988:
2989:                } else if (sitename.charAt(0) == '*') {
2990:                    // Strip off the *. for *.blah.blah
2991:                    domainname = sitename.substring(2);
2992:
2993:                } else {
2994:                    domainname = sitename;
2995:                }
2996:
2997:                return domainname;
2998:            }
2999:
3000:            public URL getValidatedURL(String sitename) {
3001:                URL url = null;
3002:
3003:                sitename = sitename.replace('\\', '/');
3004:
3005:                if (sitename.startsWith("file") || sitename.startsWith("/")) {
3006:                    sitename = sitename.replaceAll("\\s", "%20");
3007:                }
3008:
3009:                String urlstring = sitename;
3010:
3011:                int i = sitename.indexOf("://");
3012:                if (i < 0) {
3013:                    if (sitename.startsWith("file:")) {
3014:                        int j = sitename.indexOf(":/");
3015:                        urlstring = "file://localhost"
3016:                                + sitename.substring(j + 1);
3017:                    } else if (sitename.startsWith("//")) {
3018:                        urlstring = "file:" + sitename;
3019:                    } else if (sitename.startsWith("/")) {
3020:                        urlstring = "file://localhost" + sitename;
3021:                    } else {
3022:                        urlstring = "http://" + sitename;
3023:                    }
3024:                }
3025:
3026:                if (sitename.startsWith("file://")) {
3027:                    if (sitename.startsWith("file:///")) {
3028:                        int k = sitename.indexOf(":///");
3029:                        urlstring = "file://localhost"
3030:                                + sitename.substring(k + 3);
3031:                    } else {
3032:                        if (!(sitename.substring(7, 15))
3033:                                .equalsIgnoreCase("localhost")) {
3034:                            urlstring = "file://localhost"
3035:                                    + sitename.substring(16);
3036:                        }
3037:                    }
3038:                }
3039:
3040:                try {
3041:                    url = new URL(urlstring);
3042:                    int port = url.getPort();
3043:                    String host = url.getHost();
3044:                    String path = url.getPath();
3045:                    if (port < 0 && !url.getProtocol().equalsIgnoreCase("file")) {
3046:                        port = url.getDefaultPort();
3047:                    }
3048:                    if (path == null || path.length() == 0) {
3049:                        path = "/";
3050:                    }
3051:                    if (host == null || host.length() == 0) {
3052:                        host = "localhost";
3053:                    }
3054:
3055:                    if (!(url.getProtocol()).equals("file")) {
3056:                        url = new URL(url.getProtocol(), host, port, path);
3057:                    }
3058:                } catch (java.net.MalformedURLException e) {
3059:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
3060:                }
3061:
3062:                return url;
3063:            }
3064:
3065:            private String getEnvVar(String Str) throws Exception {
3066:                Process p = null;
3067:                Runtime r = Runtime.getRuntime();
3068:                p = r.exec("cmd.exe /c set");
3069:                BufferedReader br = new BufferedReader(new InputStreamReader(p
3070:                        .getInputStream()));
3071:                String line;
3072:                while ((line = br.readLine()) != null) {
3073:                    int idx = line.indexOf('=');
3074:                    String key = line.substring(0, idx);
3075:                    String value = line.substring(idx + 1);
3076:                    if (key.equalsIgnoreCase(Str))
3077:                        return value;
3078:                }
3079:                return null;
3080:            }
3081:
3082:            /*
3083:             * internal data
3084:             */
3085:            static final String SEARCH_CONF = "search.conf";
3086:            static final String ROBOT_CMD = "robot";
3087:            static final String CATPING_CMD = "catping";
3088:            static final String RDREGISTER_CMD = "rdregister";
3089:            static final String rCmd = "cmd";
3090:            static final String rQuery = "query";
3091:
3092:            static String filtersource[] = { "url", "protocol", "host", "path",
3093:                    "MIME" };
3094:            static String filtersource_rule[] = { "url", "protocol", "host",
3095:                    "uri", "type" };
3096:            static String filtermethod[] = { "is", "contains", "begins with",
3097:                    "ends with", "regular" };
3098:            static String filtermethod_rule[] = { "by-exact", "by-substr",
3099:                    "by-prefix", "by-suffix", "by-regex" };
3100:
3101:            private static final String crawling_conf[] = { //attr in ProcesssConfig
3102:            "server-delay", "max-connections", "site-max-connections",
3103:                    "index-after-ngenerated", "cmd-Hook", "onCompletion",
3104:                    "email", "loglevel", "user-agent", "enable-robots-txt",
3105:                    "perform-authentication", "username", "password",
3106:                    "proxy-username", "proxy-password", "proxy-type",
3107:                    "proxy-loc", "auto_serv", "http_proxy", "https_proxy",
3108:                    "ftp_proxy", "enable-cookie", "enable-ip",
3109:                    "smart-host-heuristics", "use-dns-cname", "depth",
3110:                    "tmpdir", "robot-state-dir", "remote-access" };
3111:
3112:            public static String reportLabels[] = { "version", "dnscachedump",
3113:                    "performance", "allserversfound", "rdmserverfound",
3114:                    "configuration", "databasestatus", "libnetstatus",
3115:                    "modulesstatus", "overview", "urlreadyforextraction",
3116:                    "urlreadyforindexing", "urlwaitingforfiltering",
3117:                    "urlwaitingforindexing", "all" };
3118:
3119:            public static String reportQuerys[] = { "query?fn=version",
3120:                    "query?fn=dns-mapping", "query?fn=performance",
3121:                    "query?fn=sites-status", "query?fn=rdm-server",
3122:                    "query?fn=run-status", "query?fn=database",
3123:                    "query?fn=libnet", "query?fn=status",
3124:                    "query?fn=robot-states", "query?fn=enum-ready",
3125:                    "query?fn=rdgen-ready", "query?fn=enum-pool",
3126:                    "query?fn=rdgen-pool", "all" };
3127:
3128:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.