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


001:        /**
002:         * Copyright 2005 Sun Microsystems, Inc. All
003:         * rights reserved. Use of this product is subject
004:         * to license terms. Federal Acquisitions:
005:         * Commercial Software -- Government Users
006:         * Subject to Standard License Terms and
007:         * Conditions.
008:         *
009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010:         * are trademarks or registered trademarks of Sun Microsystems,
011:         * Inc. in the United States and other countries.
012:         */package com.sun.portal.admin.console.search;
013:
014:        import java.util.*;
015:        import java.util.logging.Level;
016:        import java.io.IOException;
017:        import java.text.*;
018:        import java.net.URL;
019:
020:        import javax.management.ObjectName;
021:        import javax.management.MBeanServerConnection;
022:        import javax.faces.model.ArrayDataModel;
023:
024:        import com.sun.data.provider.DataProvider;
025:        import com.sun.data.provider.impl.ObjectListDataProvider;
026:        import com.sun.web.ui.component.RadioButton;
027:        import com.sun.web.ui.model.Option;
028:        import com.sun.web.ui.model.OptionsList;
029:
030:        import com.sun.portal.admin.common.util.AdminClientUtil;
031:        import com.sun.portal.admin.console.common.PSBaseBean;
032:
033:        public class RobotUtilityBean extends PSBaseBean {
034:
035:            private String siteName = "";
036:            private String[] urlList = {};
037:            private String report = "";
038:            private boolean showDNS = false;
039:            private boolean showDNS2 = false;
040:            private boolean showRedirect = true;
041:            private boolean showReport = false;
042:
043:            private String siteURL = "";
044:            private Boolean checkDNS;
045:            private Boolean checkRedirect;
046:            private ArrayList startpoints;
047:
048:            private HashMap resultmap;
049:
050:            public RobotUtilityBean() {
051:
052:                siteName = "";
053:                showDNS = false;
054:                showDNS2 = false;
055:                showRedirect = true;
056:                showReport = false;
057:
058:                HashMap sites = null;
059:                try {
060:                    LinkedList path = new LinkedList();
061:                    path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
062:                    path
063:                            .addFirst((String) getSessionAttribute("search.server.selected"));
064:                    path.addFirst("robot");
065:                    ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
066:                            AdminClientUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
067:
068:                    Object[] params = { "" };
069:                    String[] signature = { "java.lang.String" };
070:
071:                    sites = (HashMap) getMBeanServerConnection().invoke(on,
072:                            "listSites", params, signature);
073:
074:                    if (sites != null) {
075:                        urlList = generateStartPoints(sites);
076:                    }
077:                } catch (Exception e) {
078:                    log(
079:                            Level.SEVERE,
080:                            "RobotUtilityBean.init() failed to get the list of robot sites or starting points",
081:                            e);
082:                }
083:
084:            }
085:
086:            /* 
087:             * Action methods
088:             */
089:            public String clearPage() {
090:
091:                siteName = "";
092:                showDNS = false;
093:                showDNS2 = false;
094:                showRedirect = true;
095:                showReport = false;
096:
097:                return "gotoRobotUtilitiesHome";
098:            }
099:
100:            public String runSiteProbe() {
101:                if (!siteName.equals("")) {
102:
103:                    try {
104:                        LinkedList path = new LinkedList();
105:                        path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
106:                        path
107:                                .addFirst((String) getSessionAttribute("search.server.selected"));
108:                        path.addFirst("siteprobe");
109:                        ObjectName on = AdminClientUtil
110:                                .getResourceMBeanObjectName(
111:                                        AdminClientUtil.SEARCH_SITEPROBE_MBEAN_TYPE,
112:                                        path);
113:
114:                        if (showDNS)
115:                            checkDNS = Boolean.TRUE;
116:                        else
117:                            checkDNS = Boolean.FALSE;
118:
119:                        Object[] params = { siteName, checkDNS };
120:                        String[] signature = { "java.lang.String",
121:                                "java.lang.Boolean" };
122:                        resultmap = (HashMap) getMBeanServerConnection()
123:                                .invoke(on, "runSiteProbe", params, signature);
124:
125:                    } catch (Exception e) {
126:                        log(Level.SEVERE,
127:                                "RobotUtilityBean.runSiteProbe() failed to run SiteProbe on url: "
128:                                        + siteName, e);
129:                    }
130:
131:                    report = generateSiteProbeResult(resultmap);
132:                    showReport = true;
133:                }
134:
135:                return "gotoRobotUtilitiesHome";
136:            }
137:
138:            public String runSimulator() {
139:
140:                try {
141:                    LinkedList path = new LinkedList();
142:                    path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
143:                    path
144:                            .addFirst((String) getSessionAttribute("search.server.selected"));
145:                    path.addFirst("robot");
146:                    ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
147:                            AdminClientUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
148:
149:                    if (showDNS2)
150:                        checkDNS = Boolean.TRUE;
151:                    else
152:                        checkDNS = Boolean.FALSE;
153:
154:                    if (showRedirect)
155:                        checkRedirect = Boolean.TRUE;
156:                    else
157:                        checkRedirect = Boolean.FALSE;
158:
159:                    Object[] params = { startpoints, checkDNS, checkRedirect };
160:                    String[] signature = { "java.util.ArrayList",
161:                            "java.lang.Boolean", "java.lang.Boolean" };
162:                    resultmap = (HashMap) getMBeanServerConnection().invoke(on,
163:                            "runSimulator", params, signature);
164:
165:                } catch (Exception e) {
166:                    log(
167:                            Level.SEVERE,
168:                            "RobotUtilityBean.runSimulator() failed to run Robot Simualtor",
169:                            e);
170:                }
171:
172:                report = generateSimulatorResult(resultmap);
173:                showReport = true;
174:
175:                return "gotoRobotUtilitiesHome";
176:            }
177:
178:            /*
179:             * Methods to Get and Set Crawling Properties
180:             */
181:            public String getSiteName() {
182:                return siteName;
183:            }
184:
185:            public void setSiteName(String s) {
186:                siteName = s;
187:            }
188:
189:            public String[] getUrlList() {
190:                return urlList;
191:            }
192:
193:            public void setUrlList(String[] s) {
194:                this .urlList = s;
195:                startpoints = new ArrayList();
196:                for (int i = 0; i < urlList.length; i++) {
197:                    startpoints.add(urlList[i]);
198:                }
199:            }
200:
201:            public boolean getShowDNS() {
202:                return showDNS;
203:            }
204:
205:            public void setShowDNS(boolean s) {
206:                showDNS = s;
207:            }
208:
209:            public boolean getShowDNS2() {
210:                return showDNS2;
211:            }
212:
213:            public void setShowDNS2(boolean s) {
214:                showDNS2 = s;
215:            }
216:
217:            public boolean getShowRedirect() {
218:                return showRedirect;
219:            }
220:
221:            public void setShowRedirect(boolean s) {
222:                showRedirect = s;
223:            }
224:
225:            public boolean getShowReport() {
226:                return showReport;
227:            }
228:
229:            public String getReport() {
230:                return report;
231:            }
232:
233:            /*
234:             * Private Methods
235:             */
236:            private String getLocalizedString(String key) {
237:                return super .getLocalizedString("search", key);
238:            }
239:
240:            public String getLocalizedString(String key, Object[] arguments) {
241:                String pattern = getLocalizedString(key);
242:                MessageFormat msgFormat = new MessageFormat("");
243:                msgFormat.applyPattern(pattern);
244:                return msgFormat.format(arguments);
245:            }
246:
247:            private String getHostName(String siteURL) throws Exception {
248:                String host = siteURL;
249:                try {
250:                    URL url = new URL(siteURL);
251:                    host = url.getHost();
252:                } catch (Exception e) {
253:                    log(Level.SEVERE, "RobotUtilityBean.getHostName() failed",
254:                            e);
255:                }
256:                return host;
257:            }
258:
259:            private boolean sameHost(String url1, String host) {
260:                if (url1.charAt(0) == '/') {// no protocal, uri only
261:                    return true;
262:                }
263:                if (url1.indexOf("://" + host) > 0) { // same host
264:                    return true;
265:                }
266:                return false;
267:            }
268:
269:            private String[] generateStartPoints(HashMap sites) {
270:
271:                HashMap frs = null;
272:                String siteID;
273:                startpoints = new ArrayList();
274:
275:                Iterator it = sites.keySet().iterator();
276:                while (it.hasNext()) {
277:                    siteID = (String) it.next();
278:                    frs = (HashMap) sites.get(siteID);
279:                    if (frs != null) {
280:                        LinkedList starts = (LinkedList) frs
281:                                .get("StartingPoints");
282:                        if (starts.size() > 0) {
283:                            for (int j = 0; j < starts.size(); j++) {
284:                                HashMap start = (HashMap) starts.get(j);
285:                                String sp = (String) start.get("URLString");
286:                                int index = sp.indexOf("depth=");
287:                                startpoints.add(sp.substring(0, index - 1));
288:                                //startpoints.add((String)start.get("URLString"));
289:                            }
290:                        }
291:                    }
292:                }
293:
294:                return (String[]) startpoints.toArray(new String[0]);
295:            }
296:
297:            private String generateSiteProbeResult(HashMap map) {
298:
299:                StringBuffer sb = new StringBuffer();
300:
301:                if (map == null) {
302:                    sb.append(getLocalizedString("robot.siteprobe.failed")
303:                            + "<br>");
304:                    return sb.toString();
305:                }
306:
307:                if (map.containsKey("URLMalformed")) {
308:                    sb.append(getLocalizedString("robot.siteprobe.malformed")
309:                            + "<br>");
310:                    return sb.toString();
311:                }
312:
313:                boolean isSmartHostHeuristics = true;
314:
315:                if (map.containsKey("smart-host-heuristics")) {
316:                    String shh = (String) map.get("smart-host-heuristics");
317:                    if (shh.equalsIgnoreCase("false"))
318:                        isSmartHostHeuristics = false;
319:                    //map.remove("smart-host-heuristics");
320:                }
321:
322:                sb.append(getLocalizedString("robot.siteprobe.checkingurl")
323:                        + "<br><br>");
324:                if (map.containsKey("HostResult")) {
325:
326:                    LinkedList hr = (LinkedList) map.get("HostResult");
327:                    if (hr != null) {
328:                        String h_cname = (String) hr.get(0);
329:                        int h_type = ((Integer) hr.get(1)).intValue();
330:                        int h_errno = ((Integer) hr.get(2)).intValue();
331:                        int h_length = ((Integer) hr.get(3)).intValue();
332:                        String[] h_ips = (String[]) hr.get(4);
333:                        String[] h_aliases = (String[]) hr.get(5);
334:                        String org_url = (String) hr.get(6);
335:
336:                        if (h_errno != 0) {
337:                            //sb.append(getLocalizedString("robot.siteprobe.successdns") + "<br>");
338:                            if (h_errno == 1) {
339:                                sb
340:                                        .append(getLocalizedString("robot.siteprobe.namenotfound")
341:                                                + "<br>");
342:                            } else if (h_errno == 2) {
343:                                sb
344:                                        .append(getLocalizedString("robot.siteprobe.dnsserverfail")
345:                                                + "<br>");
346:                            } else if (h_errno == 3) {
347:                                sb
348:                                        .append(getLocalizedString("robot.siteprobe.norecovery")
349:                                                + "<br>");
350:                            } else if (h_errno == 4) {
351:                                sb
352:                                        .append(getLocalizedString("robot.siteprobe.domainname")
353:                                                + "<br>");
354:                            } else {
355:                                sb
356:                                        .append(getLocalizedString("robot.siteprobe.unknownerror")
357:                                                + "<br>");
358:                            }
359:                        }
360:
361:                        sb.append("<br>");
362:
363:                        if (checkDNS.booleanValue()) {
364:                            sb
365:                                    .append(getLocalizedString("robot.siteprobe.resultfor")
366:                                            + " '" + siteName + "'<br>");
367:                            sb
368:                                    .append(getLocalizedString("robot.siteprobe.name")
369:                                            + " ");
370:                            sb.append(h_cname != null ? h_cname + "<br>" : ""
371:                                    + "<br>");
372:
373:                            if (h_aliases != null) {
374:                                for (int i = 0; i < h_aliases.length
375:                                        && h_aliases[i] != null; i++) {
376:                                    sb
377:                                            .append(getLocalizedString("robot.siteprobe.alias")
378:                                                    + " ");
379:                                    sb.append(h_aliases[i] + "<br>");
380:                                }
381:                            }
382:
383:                            sb
384:                                    .append(getLocalizedString("robot.siteprobe.addresstype")
385:                                            + " ");
386:                            sb.append(h_type + "<br>");
387:
388:                            sb
389:                                    .append(getLocalizedString("robot.siteprobe.length")
390:                                            + " ");
391:                            sb.append(h_length + "<br>");
392:
393:                            if (h_ips != null) {
394:                                for (int i = 0; i < h_ips.length
395:                                        && h_ips[i] != null; i++) {
396:                                    sb
397:                                            .append(getLocalizedString("robot.siteprobe.ip")
398:                                                    + " ");
399:                                    sb.append(h_ips[i] + "<br>");
400:                                }
401:                            }
402:
403:                        } // end of checkDNS
404:
405:                        sb.append("<br>");
406:
407:                        sb.append(getLocalizedString("robot.siteprobe.result")
408:                                + " ");
409:
410:                        sb.append(getLocalizedString(
411:                                "robot.siteprobe.validname",
412:                                new Object[] { siteName })
413:                                + "<br>");
414:
415:                        boolean is_alias = false;
416:                        if (h_aliases != null) {
417:                            for (int j = 0; j < h_aliases.length; j++) {
418:                                if (h_aliases[j].indexOf(siteName) > -1) {
419:                                    is_alias = true;
420:                                    break;
421:                                }
422:                            }
423:                        }
424:                        if (is_alias) {
425:                            sb
426:                                    .append(getLocalizedString("robot.siteprobe.note")
427:                                            + " ");
428:                            sb.append(getLocalizedString(
429:                                    "robot.siteprobe.aliasnamefor",
430:                                    new Object[] { siteName, h_cname })
431:                                    + "<br>");
432:                        } else {
433:                            sb
434:                                    .append(getLocalizedString("robot.siteprobe.note")
435:                                            + " ");
436:                            sb.append(getLocalizedString(
437:                                    "robot.siteprobe.cnamefor",
438:                                    new Object[] { siteName })
439:                                    + "<br>");
440:                            sb
441:                                    .append(getLocalizedString("robot.siteprobe.note")
442:                                            + " ");
443:                            sb
444:                                    .append(getLocalizedString("robot.siteprobe.nodnstrans")
445:                                            + "<br>");
446:
447:                            if (!siteName.equalsIgnoreCase(h_cname)) {
448:                                sb.append(getLocalizedString(
449:                                        "robot.siteprobe.refername",
450:                                        new Object[] { h_cname })
451:                                        + "<br>");
452:                            }
453:                        }
454:
455:                        boolean is_cname_shh = false;
456:                        if (is_alias && siteName.startsWith("www.")
457:                                && h_cname.startsWith("www")) {
458:                            int k;
459:                            for (k = 3; k < h_cname.length()
460:                                    && Character.isDigit(h_cname.charAt(k)); k++)
461:                                ;
462:                            if (k < h_cname.length()
463:                                    && h_cname.charAt(k) == '.')
464:                                is_cname_shh = true;
465:                        }
466:
467:                        boolean is_host_shh = false;
468:                        String host_main = "";
469:                        if (is_alias && siteName.startsWith("www")) {
470:                            int k;
471:                            for (k = 3; k < siteName.length()
472:                                    && Character.isDigit(siteName.charAt(k)); k++)
473:                                ;
474:                            if (k < siteName.length()
475:                                    && siteName.charAt(k) == '.') {
476:                                is_host_shh = true;
477:                                host_main = "www" + siteName.substring(k);
478:                            }
479:                        }
480:
481:                        if (is_cname_shh) {
482:                            if (isSmartHostHeuristics) {
483:                                sb
484:                                        .append(getLocalizedString("robot.siteprobe.note")
485:                                                + " ");
486:                                sb.append(getLocalizedString(
487:                                        "robot.siteprobe.smarthoston",
488:                                        new Object[] { siteName })
489:                                        + "<br>");
490:                            } else {
491:                                sb
492:                                        .append(getLocalizedString("robot.siteprobe.note")
493:                                                + " ");
494:                                sb.append(getLocalizedString(
495:                                        "robot.siteprobe.issmarthoston",
496:                                        new Object[] { h_cname, siteName })
497:                                        + "<br>");
498:                            }
499:                            sb
500:                                    .append(getLocalizedString("robot.siteprobe.note")
501:                                            + " ");
502:                            sb.append(getLocalizedString(
503:                                    "robot.siteprobe.hasunique",
504:                                    new Object[] { h_cname })
505:                                    + "<br>");
506:                        } else if (is_host_shh) {
507:                            if (isSmartHostHeuristics) {
508:                                sb.append(getLocalizedString(
509:                                        "robot.siteprobe.actionsmarthostison",
510:                                        new Object[] { host_main })
511:                                        + "<br>");
512:                            } else {
513:                                sb
514:                                        .append(getLocalizedString("robot.siteprobe.note")
515:                                                + " ");
516:                                sb.append(getLocalizedString(
517:                                        "robot.siteprobe.dnsmirror",
518:                                        new Object[] { siteName })
519:                                        + "<br>");
520:                                sb.append(getLocalizedString(
521:                                        "robot.siteprobe.heavilyload",
522:                                        new Object[] { host_main })
523:                                        + "<br>");
524:                                sb.append(getLocalizedString(
525:                                        "robot.siteprobe.enablesmarthost",
526:                                        new Object[] { siteName })
527:                                        + "<br>");
528:                            }
529:                            sb
530:                                    .append(getLocalizedString("robot.siteprobe.note")
531:                                            + " ");
532:                            sb.append(getLocalizedString(
533:                                    "robot.siteprobe.hasunique",
534:                                    new Object[] { h_cname })
535:                                    + "<br>");
536:                        }
537:
538:                    } // if (hr != null)
539:
540:                } // end of HostResult
541:
542:                sb.append("<br>");
543:
544:                if (map.containsKey("RedirectResult")) {
545:
546:                    LinkedList rr = (LinkedList) map.get("RedirectResult");
547:                    if (rr != null) {
548:                        String redirect_url = (String) rr.get(0);
549:                        String server_type = (String) rr.get(1);
550:                        int content_length = ((Integer) rr.get(2)).intValue();
551:                        int return_code = ((Integer) rr.get(3)).intValue();
552:
553:                        if (return_code < 0) {
554:                            sb.append(getLocalizedString(
555:                                    "robot.siteprobe.failconnect",
556:                                    new Object[] { siteURL })
557:                                    + "<br>");
558:                        } else if (return_code == 0) {
559:                            sb.append(getLocalizedString(
560:                                    "robot.siteprobe.noredirectat",
561:                                    new Object[] { siteURL })
562:                                    + "<br>");
563:                        } else {
564:                            if (redirect_url.indexOf("://") > 0)
565:                                sb.append(getLocalizedString(
566:                                        "robot.siteprobe.isredirect",
567:                                        new Object[] { siteURL, redirect_url })
568:                                        + "<br>");
569:                            else
570:                                sb
571:                                        .append(getLocalizedString(
572:                                                "robot.siteprobe.isredirect",
573:                                                new Object[] {
574:                                                        siteURL,
575:                                                        siteURL
576:                                                                + (redirect_url
577:                                                                        .charAt(0) == '/' ? "/"
578:                                                                        : "")
579:                                                                + redirect_url })
580:                                                + "<br>");
581:                            if (sameHost(redirect_url, siteName)) {
582:                                sb
583:                                        .append(getLocalizedString("robot.siteprobe.redirect2same")
584:                                                + "<br>");
585:                            } else {
586:                                sb.append(getLocalizedString(
587:                                        "robot.siteprobe.needsite4redirect",
588:                                        new Object[] { redirect_url })
589:                                        + "<br>");
590:                            }
591:                        }
592:
593:                        sb.append("<br>");
594:
595:                        sb
596:                                .append(getLocalizedString("robot.siteprobe.servertype")
597:                                        + " ");
598:                        sb
599:                                .append(server_type == null ? getLocalizedString("robot.siteprobe.unknowntype")
600:                                        + "<br>"
601:                                        : server_type + "<br>");
602:
603:                        sb.append("<br>");
604:
605:                        if (return_code >= 0) {
606:                            sb
607:                                    .append(getLocalizedString("robot.siteprobe.checkvirtual")
608:                                            + "<br>");
609:                        }
610:
611:                    } // end of rr!=null
612:                } // end of RedirectResult
613:
614:                String url2 = (String) map.get("RedirectResult2URL");
615:                int r1_length = 0;
616:
617:                if (map.containsKey("RedirectResult1")) {
618:
619:                    LinkedList rr1 = (LinkedList) map.get("RedirectResult1");
620:                    if (rr1 != null) {
621:
622:                        String r1_redirect_url = (String) rr1.get(0);
623:                        String r1_server_type = (String) rr1.get(1);
624:                        int r1_content_length = ((Integer) rr1.get(2))
625:                                .intValue();
626:                        int r1_return_code = ((Integer) rr1.get(3)).intValue();
627:
628:                        r1_length = r1_content_length;
629:
630:                        if (r1_return_code < 0) {
631:                            sb.append(getLocalizedString(
632:                                    "robot.siteprobe.failconnect",
633:                                    new Object[] { siteURL })
634:                                    + "<br>");
635:                        }
636:
637:                        if (r1_content_length < 0) {
638:                            sb.append(getLocalizedString(
639:                                    "robot.siteprobe.failconnect",
640:                                    new Object[] { url2 })
641:                                    + "<br>");
642:                        }
643:
644:                        if (r1_return_code < 0) {
645:                            return sb.toString();
646:                        }
647:
648:                        if (r1_content_length == 0) {
649:                            sb.append(getLocalizedString(
650:                                    "robot.siteprobe.failcontentlength",
651:                                    new Object[] { siteURL })
652:                                    + "<br>");
653:                            return sb.toString();
654:                        }
655:
656:                    } // end of rr1 != null
657:                } // end of RedirectResult1
658:
659:                if (map.containsKey("RedirectResult2")) {
660:
661:                    LinkedList rr2 = (LinkedList) map.get("RedirectResult2");
662:                    if (rr2 != null) {
663:
664:                        String r2_redirect_url = (String) rr2.get(0);
665:                        String r2_server_type = (String) rr2.get(1);
666:                        int r2_content_length = ((Integer) rr2.get(2))
667:                                .intValue();
668:                        int r2_return_code = ((Integer) rr2.get(3)).intValue();
669:
670:                        if (r2_return_code < 0) {
671:                            sb.append(getLocalizedString(
672:                                    "robot.siteprobe.failconnect",
673:                                    new Object[] { url2 })
674:                                    + "<br>");
675:                            return sb.toString();
676:                        }
677:
678:                        if (r2_content_length == 0) {
679:                            sb.append(getLocalizedString(
680:                                    "robot.siteprobe.failcontentlength",
681:                                    new Object[] { url2 })
682:                                    + "<br>");
683:                            return sb.toString();
684:                        }
685:
686:                        if (r1_length == r2_content_length) {
687:                            sb.append(getLocalizedString(
688:                                    "robot.siteprobe.novirtual",
689:                                    new Object[] { siteURL })
690:                                    + "<br>");
691:                        } else {
692:                            sb.append(getLocalizedString(
693:                                    "robot.siteprobe.isvirtual", new Object[] {
694:                                            url2, url2 })
695:                                    + "<br>");
696:                        }
697:
698:                    } // rr2 != null
699:                } // end of RedirectResult2
700:
701:                return sb.toString();
702:            }
703:
704:            private String generateSimulatorResult(HashMap map) {
705:
706:                StringBuffer sb = new StringBuffer();
707:
708:                boolean isSmartHostHeuristics = true;
709:
710:                if (map.containsKey("smart-host-heuristics")) {
711:                    String shh = (String) map.get("smart-host-heuristics");
712:                    if (shh.equalsIgnoreCase("false"))
713:                        isSmartHostHeuristics = false;
714:                    map.remove("smart-host-heuristics");
715:                }
716:
717:                sb.append(getLocalizedString("robot.simulator.result")
718:                        + "<br><br>");
719:
720:                Iterator it = map.keySet().iterator();
721:                while (it.hasNext()) {
722:                    siteURL = (String) it.next();
723:                    siteName = siteURL;
724:                    try {
725:                        siteName = getHostName(siteURL);
726:                    } catch (Exception e) {
727:                        log(
728:                                Level.SEVERE,
729:                                "RobotUtilityBean.generateSimulatorResult() failed",
730:                                e);
731:                    }
732:
733:                    HashMap url_map = (HashMap) map.get(siteURL);
734:
735:                    if (url_map.containsKey("frsimResult")) {
736:                        String s = ((String) url_map.get("frsimResult"))
737:                                .replaceAll(
738:                                        "ACCEPTED:",
739:                                        getLocalizedString("robot.simulator.accept"));
740:                        sb.append(s + "<br>");
741:                    }
742:
743:                    if (url_map.containsKey("URLMalformed")) {
744:                        sb
745:                                .append(getLocalizedString("robot.simulator.malformed")
746:                                        + "<br>");
747:                        return sb.toString();
748:                    }
749:
750:                    if (url_map.containsKey("HostResult")
751:                            && checkDNS.booleanValue()) {
752:
753:                        LinkedList hr = (LinkedList) url_map.get("HostResult");
754:                        if (hr != null) {
755:                            String h_cname = (String) hr.get(0);
756:                            int h_type = ((Integer) hr.get(1)).intValue();
757:                            int h_errno = ((Integer) hr.get(2)).intValue();
758:                            int h_length = ((Integer) hr.get(3)).intValue();
759:                            String[] h_ips = (String[]) hr.get(4);
760:                            String[] h_aliases = (String[]) hr.get(5);
761:                            String org_url = (String) hr.get(6);
762:
763:                            if (h_errno != 0) {
764:                                if (h_errno == 1) {
765:                                    sb.append(getLocalizedString(
766:                                            "robot.simulator.invalidhost",
767:                                            new Object[] { siteName })
768:                                            + "<br>");
769:                                } else if (h_errno == 2 || h_errno == 3) {
770:                                    sb
771:                                            .append(getLocalizedString("robot.simulator.dnsreterror")
772:                                                    + "<br>");
773:                                } else if (h_errno == 4) {
774:                                    sb.append(getLocalizedString(
775:                                            "robot.simulator.domainnothost",
776:                                            new Object[] { siteName })
777:                                            + "<br>");
778:                                } else {
779:                                    sb
780:                                            .append(getLocalizedString("robot.simulator.unknownerror")
781:                                                    + "<br>");
782:                                }
783:                            }
784:
785:                            if (h_aliases != null) {
786:                                boolean found = false;
787:                                boolean ok = false;
788:                                for (int j = 0; j < h_aliases.length; j++) {
789:                                    if (h_aliases[j].indexOf(siteName) > -1) {
790:                                        found = true;
791:                                        break;
792:                                    }
793:                                }
794:                                if (found && isSmartHostHeuristics
795:                                        && h_cname.length() > 4) {
796:
797:                                    char c = h_cname.charAt(4);
798:
799:                                    if (h_cname.startsWith("www")
800:                                            && (c == '.' || Character
801:                                                    .isDigit(c)))
802:                                        ok = true;
803:                                }
804:                                if (ok) {
805:                                    sb.append(getLocalizedString(
806:                                            "robot.simulator.aliasallow",
807:                                            new Object[] { h_cname })
808:                                            + "<br>");
809:                                } else {
810:                                    sb.append(getLocalizedString(
811:                                            "robot.simulator.aliasreject",
812:                                            new Object[] { h_cname })
813:                                            + "<br>");
814:                                }
815:                            }
816:                        } // if (hr != null)
817:
818:                        sb.append(getLocalizedString(
819:                                "robot.simulator.validhostname",
820:                                new Object[] { siteName })
821:                                + "<br>");
822:                        sb.append("<br>");
823:
824:                    } // end of HostResult
825:
826:                    if (url_map.containsKey("RedirectResult")
827:                            && checkRedirect.booleanValue()) {
828:
829:                        LinkedList rr = (LinkedList) url_map
830:                                .get("RedirectResult");
831:                        if (rr != null) {
832:                            String redirect_url = (String) rr.get(0);
833:                            String server_type = (String) rr.get(1);
834:                            int content_length = ((Integer) rr.get(2))
835:                                    .intValue();
836:                            int return_code = ((Integer) rr.get(3)).intValue();
837:
838:                            if (return_code < 0) {
839:                                sb.append(getLocalizedString(
840:                                        "robot.simulator.failconnect",
841:                                        new Object[] { siteURL })
842:                                        + "<br>");
843:                            }
844:
845:                            if (return_code == 0) {
846:                                sb
847:                                        .append(getLocalizedString("robot.simulator.noredirect")
848:                                                + "<br>");
849:                            } else if (sameHost(redirect_url, siteName)) {
850:                                sb.append(getLocalizedString(
851:                                        "robot.simulator.rejectbyrule",
852:                                        new Object[] { siteName })
853:                                        + "<br>");
854:                            } else {
855:                                sb.append(getLocalizedString(
856:                                        "robot.simulator.redirect2",
857:                                        new Object[] { redirect_url })
858:                                        + "<br>");
859:                            }
860:                            sb.append("<br>");
861:                        }
862:
863:                    } //end of RedirectResult
864:                } // end of while
865:
866:                return sb.toString();
867:            }
868:
869:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.