1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.admininterface.pages;
35
36 import info.magnolia.cms.beans.config.ContentRepository;
37 import info.magnolia.cms.gui.control.Button;
38 import info.magnolia.cms.gui.misc.CssConstants;
39 import info.magnolia.cms.gui.misc.Sources;
40 import info.magnolia.cms.i18n.MessagesManager;
41 import info.magnolia.module.admininterface.SimplePageMVCHandler;
42
43 import java.io.IOException;
44 import java.io.PrintWriter;
45 import java.util.Date;
46
47 import javax.servlet.http.HttpServletRequest;
48 import javax.servlet.http.HttpServletResponse;
49
50 import org.apache.commons.lang.StringUtils;
51
52
53
54
55
56
57 public class LinkBrowserDialogPage extends SimplePageMVCHandler {
58
59 public LinkBrowserDialogPage(String name, HttpServletRequest request, HttpServletResponse response) {
60 super(name, request, response);
61 }
62
63
64
65
66 private static final long serialVersionUID = 222L;
67
68 protected void render(HttpServletRequest request, HttpServletResponse response) throws IOException {
69 PrintWriter out = response.getWriter();
70 String repository = request.getParameter("repository");
71 if (StringUtils.isEmpty(repository)) {
72 repository = ContentRepository.WEBSITE;
73 }
74
75 String path = request.getParameter("path");
76 String pathOpen = request.getParameter("pathOpen");
77 String pathSelected = request.getParameter("pathSelected");
78
79 StringBuffer src = getIFrameSrc(request, repository, path, pathOpen, pathSelected);
80
81 StringBuffer html = new StringBuffer();
82 html.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); //$NON-NLS-1$
83 html.append("<html><head>");
84 html.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>");
85 html.append(new Sources(request.getContextPath()).getHtmlJs());
86 html.append(new Sources(request.getContextPath()).getHtmlCss());
87 html.append("<script>");
88 html.append("MgnlDHTMLUtil.addOnResize(mgnlDialogLinkBrowserResize);");
89 html.append("MgnlDHTMLUtil.addOnLoad(function(){mgnlDialogLinkBrowserResize();document.getElementById('mgnlDialogLinkBrowserIFrame').src='"+src+"';window.focus();})");
90 html.append("</script>");
91
92 html.append("</head>");
93 html.append("<body class=\"mgnlBgDark\" >");
94
95
96 html.append("<div id=\"mgnlTreeDiv\" class=\"mgnlDialogLinkBrowserTreeDiv\">");
97 html.append("<iframe id=\"mgnlDialogLinkBrowserIFrame\" name=\"mgnlDialogLinkBrowserIFrame\" src=\""
98
99 + "\" scrolling=\"no\" frameborder=\"0\" width=\"100%\" height=\"100%\"></iframe>");
100 html.append("</div>");
101
102 Button bOk = new Button();
103 bOk.setLabel(MessagesManager.get("buttons.ok"));
104
105 bOk.setOnclick("mgnlDialogLinkBrowserWriteBack()");
106
107 Button bCancel = new Button();
108 bCancel.setLabel(MessagesManager.get("buttons.cancel"));
109 bCancel.setOnclick("window.top.close();");
110
111 html.append("<div class=\"" + CssConstants.CSSCLASS_TABSETSAVEBAR + "\">");
112 html.append(bOk.getHtml());
113 html.append(" ");
114 html.append(bCancel.getHtml());
115 html.append("</div>");
116
117 html.append("</body></html>");
118
119 out.println(html);
120 }
121
122 private StringBuffer getIFrameSrc(HttpServletRequest request, String repository, String path, String pathOpen,
123 String pathSelected) {
124 StringBuffer src = new StringBuffer();
125 src.append(request.getContextPath());
126 src.append("/.magnolia/trees/" + repository + ".html");
127 src.append("?mgnlCK=" + new Date().getTime());
128 src.append("&browseMode=true");
129 if (path != null) {
130 src.append("&path=" + path);
131 }
132 if (pathOpen != null) {
133 src.append("&pathOpen=" + pathOpen);
134 }
135 if (pathSelected != null) {
136 src.append("&pathSelected=" + pathSelected);
137 }
138 return src;
139 }
140 }