KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > portal > portlets > admin > BadURLManagerPortlet


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.jetspeed.portal.portlets.admin;
17
18 //ecs stuff
19
import org.apache.ecs.ConcreteElement;
20 import org.apache.ecs.ElementContainer;
21 import org.apache.ecs.html.A;
22 import org.apache.ecs.html.B;
23 import org.apache.ecs.html.BR;
24 import org.apache.ecs.html.LI;
25 import org.apache.ecs.html.UL;
26
27 //turbine stuff
28
import org.apache.turbine.util.DynamicURI;
29 import org.apache.turbine.util.ParameterParser;
30 import org.apache.turbine.util.RunData;
31
32
33 //jetspeed stuff
34
import org.apache.jetspeed.portal.portlets.*;
35 import org.apache.jetspeed.services.urlmanager.*;
36
37 import java.util.*;
38
39 /**
40 Shows the user what URLs are considered bad.
41
42 @author <a HREF="mailto:burton@apache.org">Kevin A. Burton</a>
43 @author <a HREF="mailto:sgala@hisitech.com">Santiago Gala</a>
44 @version $Id: BadURLManagerPortlet.java,v 1.13 2004/02/23 03:26:19 jford Exp $
45 */

46 public class BadURLManagerPortlet extends AbstractPortlet {
47
48     public static final String JavaDoc RETRY_URL = "retry";
49
50
51     public ConcreteElement getContent( RunData rundata ) {
52
53         String JavaDoc url = rundata.getParameters().getString( RETRY_URL );
54
55         if ( url != null ) {
56             URLManager.unregister(url);
57             rundata.getParameters().remove( RETRY_URL );
58         }
59
60
61         
62         ElementContainer root = new ElementContainer();
63
64         List urls = URLManager.list( URLManagerService.STATUS_BAD );
65         
66         root.addElement( "The following " +
67                          urls.size() +
68                          " URL(s) are considered bad: " );
69
70         root.addElement( new BR() );
71         
72         root.addElement( "Click on a url to take it out of the list" +
73                          " and retry it in when requested. " );
74
75         root.addElement( new BR() );
76         
77         UL ul = new UL();
78         //FIXME: the getReason() call has to be escaped from HTML markup, CR&LF
79
DynamicURI uri = new DynamicURI( rundata );
80         
81         ParameterParser params = rundata.getParameters();
82         uri.addQueryData( params );
83         
84         Iterator i = urls.iterator();
85         
86         while ( i.hasNext() ) {
87             URLInfo info = URLManager.getInfo( (String JavaDoc)i.next() );
88             /* It can happen that url is no longer in list while
89                we are processing */

90             if( info != null ) {
91                 uri.removeQueryData( RETRY_URL );
92                 uri.addQueryData(RETRY_URL, info.getURL());
93                 ul.addElement( new LI()
94                     .addElement( new A(uri.toString() )
95                         .addElement( info.getURL() ) )
96                     .addElement( new B( info.getMessage() ) ) );
97             }
98         }
99         
100         root.addElement( ul );
101
102         java.util.Hashtable JavaDoc rt = URLFetcher.getRealtimeURLs();
103
104         root.addElement( "The following " +
105                          rt.size() +
106                          " URL(s) are being loaded: " );
107
108         root.addElement( new BR() );
109         ul = new UL();
110         
111         java.util.Enumeration JavaDoc en = rt.keys();
112         while (en.hasMoreElements()) {
113             String JavaDoc key = (String JavaDoc)en.nextElement();
114             LI li = new LI().addElement( key )
115                 .addElement( " - by " );
116             if (rt.get(key) != null )
117                 li.addElement( String.valueOf(((Vector)rt.get(key)).size()) )
118                     .addElement( " threads." );
119             ul.addElement( li );
120         }
121         
122         root.addElement( ul );
123         
124
125         
126         return root;
127     }
128
129     public void init() {
130         this.setTitle( "BadURLManager" );
131         
132         this.setDescription( "Shows the admin what URLs are considered bad." );
133     }
134     
135     public boolean getAllowEdit(RunData rundata) {
136         return false;
137     }
138
139     public boolean getAllowMaximize(RunData rundata) {
140         return false;
141     }
142     
143 }
144
Popular Tags