Source Code Cross Referenced for PutListFrame.java in  » Web-Server » Jigsaw » org » w3c » jigedit » filters » 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 » Web Server » Jigsaw » org.w3c.jigedit.filters 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // PutListResource.java
002:        // $Id: PutListFrame.java,v 1.11 2007/02/09 21:17:19 ylafon Exp $
003:        // (c) COPYRIGHT MIT and INRIA, 1996.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:
006:        package org.w3c.jigedit.filters;
007:
008:        import java.io.File;
009:        import java.io.PrintStream;
010:
011:        import java.util.Date;
012:        import java.util.Enumeration;
013:        import java.util.Vector;
014:
015:        import java.net.URL;
016:
017:        import org.w3c.tools.resources.FramedResource;
018:        import org.w3c.tools.resources.ProtocolException;
019:        import org.w3c.tools.resources.ReplyInterface;
020:        import org.w3c.tools.resources.RequestInterface;
021:        import org.w3c.tools.resources.ResourceException;
022:
023:        import org.w3c.tools.resources.ProtocolException;
024:
025:        import org.w3c.cvs.CVS;
026:        import org.w3c.cvs.CvsDirectory;
027:        import org.w3c.cvs.CvsException;
028:
029:        import org.w3c.jigsaw.auth.AuthFilter;
030:
031:        import org.w3c.jigsaw.http.HTTPException;
032:        import org.w3c.jigsaw.http.Reply;
033:        import org.w3c.jigsaw.http.Request;
034:
035:        import org.w3c.jigsaw.frames.HTTPFrame;
036:        import org.w3c.jigsaw.frames.PostableFrame;
037:
038:        import org.w3c.www.http.HTTP;
039:        import org.w3c.www.http.HttpMessage;
040:        import org.w3c.www.http.HttpRequestMessage;
041:
042:        import org.w3c.jigsaw.forms.URLDecoder;
043:
044:        import org.w3c.jigsaw.html.HtmlGenerator;
045:
046:        public class PutListFrame extends PostableFrame {
047:
048:            PutListResource putlist = null;
049:
050:            public void registerResource(FramedResource resource) {
051:                super .registerResource(resource);
052:                if (resource instanceof  PutListResource) {
053:                    putlist = (PutListResource) resource;
054:                }
055:            }
056:
057:            /**
058:             * perform the request.
059:             * @param req the incomming request.
060:             * @exception org.w3c.tools.resources.ProtocolException if a protocol 
061:             * error occurs
062:             * @exception org.w3c.tools.resources.ResourceException if a server 
063:             * error occurs
064:             */
065:            public ReplyInterface perform(RequestInterface req)
066:                    throws ProtocolException, ResourceException {
067:                if (putlist == null) {
068:                    Request request = (Request) req;
069:                    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
070:                    error.setContent("The PutListFrame must be associated "
071:                            + "with a PutListResource only!!");
072:                    throw new HTTPException(error);
073:                }
074:                return super .perform(req);
075:            }
076:
077:            protected HtmlGenerator getHtmlGenerator(String title) {
078:                HtmlGenerator g = new HtmlGenerator(title);
079:                addStyleSheet(g);
080:                return g;
081:            }
082:
083:            /**
084:             * Dump the list of modified files.
085:             * @param request The request to handle.
086:             * @return A Reply instance.
087:             * @exception org.w3c.tools.resources.ProtocolException if a protocol 
088:             * error occurs
089:             * @exception org.w3c.tools.resources.ResourceException if a server 
090:             * error occurs
091:             */
092:
093:            public Reply get(Request request) throws ProtocolException,
094:                    ResourceException {
095:                HtmlGenerator g = getHtmlGenerator("Modified files");
096:                g.append("<h1>List of recently published files</h1>\n");
097:                Enumeration penum = putlist.getPublishedEntries();
098:                if (!penum.hasMoreElements())
099:                    g
100:                            .append("<center><b>No recently published file</b></center>\n");
101:                g.append("<ul>\n");
102:
103:                Vector sorted = org.w3c.tools.sorter.Sorter
104:                        .sortComparableEnumeration(penum);
105:
106:                for (int i = 0; i < sorted.size(); i++) {
107:                    PutedEntry e = (PutedEntry) sorted.elementAt(i);
108:                    String url = e.getURL();
109:                    g.append("<li><a href=\"", url, "\">" + url + "</a>");
110:                    g.append("<br>Published by <em>" + e.getAuthor()
111:                            + "</em> on <strong>", new Date(e.getTime())
112:                            .toString(), "</strong>.</li>\n");
113:                }
114:
115:                g.append("</ul>\n");
116:
117:                penum = putlist.getEntries();
118:                if (penum.hasMoreElements()) {
119:                    g.append("<h1>List of modified files</h1>\n");
120:                    g.append("<form action=\"" + request.getURL()
121:                            + "\" method=\"POST\">\n");
122:                    g.append("<dl>\n");
123:                    // Dump all entries:
124:                    sorted = org.w3c.tools.sorter.Sorter
125:                            .sortComparableEnumeration(penum);
126:
127:                    for (int i = 0; i < sorted.size(); i++) {
128:                        PutedEntry e = (PutedEntry) sorted.elementAt(i);
129:                        String fname = e.getFilename();
130:                        String author = e.getAuthor();
131:                        long time = e.getTime();
132:                        String url = e.getURL();
133:
134:                        g.append("<dt><input type=\"checkbox\" name=\""
135:                                + e.getKey() + "\" value =\"mark\">",
136:                                (fname != null) ? fname : url, "</dt><dd>");
137:                        if (fname != null) {
138:                            File file = new File(fname);
139:                            File dir = new File(file.getParent());
140:                            // Compute the CVS directory URL for the file:
141:                            URL cvsurl = null;
142:                            try {
143:                                cvsurl = new URL(new URL(url), "CVS");
144:                            } catch (Exception ex) {
145:                                cvsurl = null;
146:                            }
147:                            // Display status:
148:                            int st = -1;
149:                            try {
150:                                // Local status first:
151:                                CvsDirectory cvs = CvsDirectory.getManager(dir,
152:                                        putlist.props);
153:                                st = cvs.status(file.getName());
154:                                if (cvsurl != null)
155:                                    g.append("Status: <a href=\"" + cvsurl
156:                                            + "\">", cvs.statusToString(st),
157:                                            "</a><br>");
158:                                else
159:                                    g.append("Status: ",
160:                                            cvs.statusToString(st), "<br>");
161:
162:                                if (url != null)
163:                                    g.append("URL: <a href=\"", url, "\">"
164:                                            + url + "</a><br>");
165:
166:                            } catch (CvsException ex) {
167:                                g.append(
168:                                        "Status: <strong>CVS ERROR</strong>: ",
169:                                        ex.getMessage(), "<br>");
170:                            }
171:                            // Publish status next (when possible)
172:                            if (st != CVS.FILE_Q) {
173:                                try {
174:                                    File sf = putlist.getServerFile(file);
175:                                    File sd = new File(sf.getParent());
176:                                    CvsDirectory sc = CvsDirectory.getManager(
177:                                            sd, putlist.props);
178:                                    int sst = sc.status(file.getName());
179:                                    if (sst == CVS.FILE_C) {
180:                                        g.append("Publish: (needed) <B><U>", sc
181:                                                .statusToString(sst),
182:                                                "</U></B><br>");
183:                                    } else if ((st == CVS.FILE_M)
184:                                            || (sst != CVS.FILE_OK)) {
185:                                        g.append("Publish: (needed) <em>", sc
186:                                                .statusToString(sst),
187:                                                "</em><br>");
188:                                    } else {
189:                                        g.append("Publish: <em>", sc
190:                                                .statusToString(sst),
191:                                                "</em><br>");
192:                                    }
193:                                } catch (CvsException ex) {
194:                                    g
195:                                            .append(
196:                                                    "Publish: <strong>CVS ERROR</strong>: ",
197:                                                    ex.getMessage(), "<br>");
198:                                }
199:                            }
200:                        }
201:                        // Display author:
202:                        if (author != null)
203:                            g.append("Modified by <em>" + author
204:                                    + "</em> on <strong>"
205:                                    + new Date(time).toString()
206:                                    + "</strong>.<br>\n");
207:                        else
208:                            g.append("Modified on <strong>"
209:                                    + new Date(time).toString()
210:                                    + "</strong>.<br>\n");
211:                    }
212:                    g.append("</dl>\n");
213:                    // The command button:
214:                    g
215:                            .append("<hr noshade width=\"40%\">\n<center>\n",
216:                                    "<table border=\"0\">",
217:                                    "<tr align=\"left\"><td>\n");
218:                    g.append("<b>Perform action on marked entries:</b><p>\n");
219:                    g.append("<input type=\"radio\" name=\"action\" ",
220:                            "value=\"publish\">Publish<br>\n");
221:                    g
222:                            .append("<input type=\"radio\" name=\"action\" value=\"remove\">"
223:                                    + "Remove \n");
224:                    g.append("</p><center>\n");
225:                    g.append("<input type=\"submit\" name=\"submit\" "
226:                            + "value=\"Perform Action\">\n");
227:                    g.append("</center>");
228:                    g.append("</form>\n");
229:                    g.append("</td></tr></table></center>\n");
230:                }
231:
232:                penum = putlist.getDelEntries();
233:                if (penum.hasMoreElements()) {
234:                    g.append("<h1>List of deleted files</h1>\n");
235:                    g.append("<form action=\"" + request.getURL()
236:                            + "\" method=\"POST\">\n");
237:                    g.append("<dl>\n");
238:                    //Dump only confirmed entries
239:                    sorted = org.w3c.tools.sorter.Sorter
240:                            .sortComparableEnumeration(penum);
241:                    for (int i = 0; i < sorted.size(); i++) {
242:                        DeletedEntry e = (DeletedEntry) sorted.elementAt(i);
243:                        if (e.isConfirmed()) {
244:                            String fname = e.getFilename();
245:                            String author = e.getAuthor();
246:                            long time = e.getTime();
247:                            String url = e.getURL();
248:                            g.append("<dt><input type=\"checkbox\" name=\""
249:                                    + e.getKey() + "\" value =\"mark\">",
250:                                    (fname != null) ? fname : url, "</dt><dd>");
251:                            if (url != null)
252:                                g.append("URL: <b>" + url + "</b><br>");
253:                            // Display author:
254:                            if (author != null)
255:                                g.append("Deleted by <em>" + author
256:                                        + "</em> on <strong>"
257:                                        + new Date(time).toString()
258:                                        + "</strong>.<br>\n");
259:                            else
260:                                g.append("Deleted on <strong>"
261:                                        + new Date(time).toString()
262:                                        + "</strong>.<br>\n");
263:                        }
264:                    }
265:                    g.append("</dl>\n");
266:                    // The command button:
267:                    g
268:                            .append("<hr noshade width=\"40%\">\n<center>\n",
269:                                    "<table border=\"0\">",
270:                                    "<tr align=\"left\"><td>\n");
271:                    g.append("<b>Perform action on marked entries:</b><p>\n");
272:                    g.append("<input type=\"radio\" name=\"action\" ",
273:                            "value=\"delete\">Delete<br>\n");
274:                    g.append("<input type=\"radio\" name=\"action\" "
275:                            + "value=\"removedel\">Remove \n");
276:                    g.append("</p><center>\n");
277:                    g.append("<input type=\"submit\" name=\"submit\" "
278:                            + "value=\"Perform Action\">\n");
279:                    g.append("</center>");
280:                    g.append("</form>\n");
281:                    g.append("</td></tr></table></center>\n");
282:                }
283:
284:                g.append("<h1>Putlist Configuration</h1>");
285:                g.append("<center>");
286:                g.append("<table border=\"0\"><tr align=\"left\"><td>");
287:                g.append("<form action=\"" + request.getURL()
288:                        + "\" method=\"POST\">\n");
289:                g
290:                        .append("<input type=\"hidden\" name=\"action\" value=\"config\">");
291:                g
292:                        .append("<input type=\"checkbox\"", (putlist
293:                                .getAutoPublishFlag() ? " CHECKED " : " "),
294:                                "name=\"autopublish\" value=\"mark\"> Auto Publish<br>");
295:                g.append("<input type=\"checkbox\"", (putlist
296:                        .getAutoDeleteFlag() ? " CHECKED " : " "),
297:                        "name=\"autodelete\" value=\"mark\"> Auto Delete<br>");
298:                g.append("Max published entries <input type=\"text\" "
299:                        + "size=\"3\" maxlength=\"2\" name=\"mpe\" value=\""
300:                        + putlist.getMaxPublishedEntryStored() + "\">");
301:                g.append("</p><center>");
302:                g.append("<input type=\"submit\" name=\"submit\" "
303:                        + "value=\"Save Configuration\">");
304:                g.append("</center></form>\n");
305:                g.append("</td></tr></table>\n");
306:                g.append("</center>");
307:                g.append("<hr noshade width=\"80%\">");
308:                g.close();
309:                Reply reply = createDefaultReply(request, HTTP.OK);
310:                reply.addPragma("no-cache");
311:                reply.setNoCache();
312:                reply.setStream(g);
313:                return reply;
314:            }
315:
316:            protected void performAction(Request request, String action,
317:                    String key) throws HTTPException {
318:
319:                if (action.equals("publish")) {
320:                    PutedEntry pe = (PutedEntry) putlist.getEntry(key);
321:                    if (pe == null) {
322:                        // We're in troubles !
323:                        if (putlist.debug)
324:                            System.out.println("PutList: " + key
325:                                    + " not found !");
326:                        return;
327:                    }
328:                    if (putlist.publish(pe) == PutListResource.FILE_CF) {
329:                        //send error.
330:                        Reply error = request.makeReply(HTTP.CONFLICT);
331:                        HtmlGenerator gerr = getHtmlGenerator("Warning");
332:                        gerr
333:                                .append("<H1>Warning</H1> The file on publish space has "
334:                                        + "been modified directly and attempting to merge"
335:                                        + " has failed.<p>"
336:                                        + "Ask your system administrator.");
337:                        error.setStream(gerr);
338:                        throw new HTTPException(error);
339:                    }
340:                } else if (action.equals("delete")) {
341:                    DeletedEntry de = (DeletedEntry) putlist.getDelEntry(key);
342:                    if (de == null) {
343:                        // We're in troubles !
344:                        if (putlist.debug)
345:                            System.out.println("PutList: " + key
346:                                    + " not found !");
347:                        return;
348:                    }
349:                    putlist.delete(de);
350:                } else if (action.equals("remove")) {
351:                    putlist.removeEntry(key);
352:                } else if (action.equals("removedel")) {
353:                    putlist.removeDelEntry(key);
354:                } else if (putlist.debug) {
355:                    System.out.println("PutList: " + action + " unknown.");
356:                }
357:            }
358:
359:            /**
360:             * handle the request.
361:             * @param request the incomming request.
362:             * @param data the URLDecoder.
363:             * @exception org.w3c.tools.resources.ProtocolException if a protocol 
364:             * error occurs
365:             */
366:
367:            public Reply handle(Request request,
368:                    org.w3c.jigsaw.forms.URLDecoder data)
369:                    throws ProtocolException {
370:                // Get the action to perform:
371:                String action = data.getValue("action");
372:                if (action == null) {
373:                    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
374:                    error
375:                            .setContent("You must select the action to be performed.");
376:                    return error;
377:                }
378:                if (action.equals("config")) {
379:                    if (data.getValue("autopublish") != null)
380:                        putlist.setAutoPublish(true);
381:                    else
382:                        putlist.setAutoPublish(false);
383:
384:                    if (data.getValue("autodelete") != null)
385:                        putlist.setAutoDelete(true);
386:                    else
387:                        putlist.setAutoDelete(false);
388:
389:                    String max = null;
390:                    if ((max = data.getValue("mpe")) != null) {
391:                        try {
392:                            putlist.setMaxPublishedEntryStored(Integer
393:                                    .parseInt(max));
394:                        } catch (NumberFormatException ex) {
395:                            Reply error = request.makeReply(HTTP.BAD_REQUEST);
396:                            error.setContent("Invalid number : " + max);
397:                            return error;
398:                        }
399:                    }
400:                } else {
401:                    Enumeration genum = null;
402:                    if (action.equals("publish") || action.equals("remove"))
403:                        genum = putlist.getEntriesKeys();
404:                    else
405:                        genum = putlist.getDelEntriesKeys();
406:                    // Check all entries and perform action:
407:                    while (genum.hasMoreElements()) {
408:                        String key = (String) genum.nextElement();
409:                        if (data.getValue(key) != null) {
410:                            // Perform action on that entry:
411:                            if (putlist.debug)
412:                                System.out.println("PutList: " + action
413:                                        + " on " + key);
414:                            performAction(request, action, key);
415:                        } else {
416:                            if (putlist.debug)
417:                                System.out.println("PutList: " + key
418:                                        + " not marked !");
419:                        }
420:                    }
421:                }
422:                try {
423:                    return get(request);
424:                } catch (ResourceException ex) {
425:                    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
426:                    error.setContent(ex.getMessage());
427:                    return error;
428:                }
429:            }
430:        } // PutListFrame
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.