01: /*
02: JSPWiki - a JSP-based WikiWiki clone.
03:
04: Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
05:
06: This program is free software; you can redistribute it and/or modify
07: it under the terms of the GNU Lesser General Public License as published by
08: the Free Software Foundation; either version 2.1 of the License, or
09: (at your option) any later version.
10:
11: This program is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU Lesser General Public License for more details.
15:
16: You should have received a copy of the GNU Lesser General Public License
17: along with this program; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package com.ecyrd.jspwiki.dav;
21:
22: import java.io.IOException;
23: import java.util.Collection;
24: import java.util.Iterator;
25:
26: import javax.servlet.http.HttpServletResponse;
27:
28: import org.apache.ecs.XhtmlDocument;
29: import org.apache.ecs.xhtml.li;
30: import org.apache.ecs.xhtml.ul;
31:
32: import com.ecyrd.jspwiki.WikiContext;
33: import com.ecyrd.jspwiki.WikiPage;
34:
35: /**
36: * @author jalkanen
37: *
38: * @since
39: */
40: public class DavUtil {
41: public static String getCollectionInHTML(WikiContext context,
42: Collection coll) {
43: XhtmlDocument doc = new XhtmlDocument("UTF-8");
44:
45: ul content = new ul();
46:
47: for (Iterator i = coll.iterator(); i.hasNext();) {
48: Object o = i.next();
49:
50: if (o instanceof WikiPage) {
51: WikiPage p = (WikiPage) o;
52: content.addElement(new li().addElement(p.getName()));
53: } else if (o instanceof String) {
54: content.addElement(new li().addElement(o.toString()));
55: }
56: }
57:
58: doc.appendBody(content);
59:
60: return doc.toString();
61: }
62:
63: public static void sendHTMLResponse(HttpServletResponse res,
64: String txt) throws IOException {
65: res.setContentType("text/html; charset=UTF-8");
66: res.setContentLength(txt.length());
67:
68: res.getWriter().print(txt);
69: }
70:
71: public static String combineURL(String part1, String part2) {
72: if (part1.endsWith("/")) {
73: if (part2.startsWith("/")) {
74: part2 = part2.substring(1);
75: }
76: } else {
77: if (!part2.startsWith("/")) {
78: return part1 + "/" + part2;
79: }
80: }
81:
82: return part1 + part2;
83: }
84: }
|