View Javadoc

1   /**
2    * This file Copyright (c) 2003-2011 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
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   * @author Fabrizio Giustina
55   * @version $Id: LinkBrowserDialogPage.java 41137 2011-01-06 18:19:25Z gjoseph $
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       * Stable serialVersionUID.
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"); //$NON-NLS-1$
71          if (StringUtils.isEmpty(repository)) {
72              repository = ContentRepository.WEBSITE;
73          }
74  
75          String path = request.getParameter("path"); //$NON-NLS-1$
76          String pathOpen = request.getParameter("pathOpen"); //$NON-NLS-1$
77          String pathSelected = request.getParameter("pathSelected"); //$NON-NLS-1$
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>"); //$NON-NLS-1$
84          html.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>"); //$NON-NLS-1$
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>"); //$NON-NLS-1$
93          html.append("<body class=\"mgnlBgDark\" >"); //$NON-NLS-1$
94  
95  
96          html.append("<div id=\"mgnlTreeDiv\" class=\"mgnlDialogLinkBrowserTreeDiv\">"); //$NON-NLS-1$
97          html.append("<iframe id=\"mgnlDialogLinkBrowserIFrame\" name=\"mgnlDialogLinkBrowserIFrame\" src=\"" //$NON-NLS-1$
98              //+ src
99              + "\" scrolling=\"no\" frameborder=\"0\" width=\"100%\" height=\"100%\"></iframe>"); //$NON-NLS-1$
100         html.append("</div>"); //$NON-NLS-1$
101 
102         Button bOk = new Button();
103         bOk.setLabel(MessagesManager.get("buttons.ok")); //$NON-NLS-1$
104         // this will call the callback command
105         bOk.setOnclick("mgnlDialogLinkBrowserWriteBack()"); //$NON-NLS-1$
106 
107         Button bCancel = new Button();
108         bCancel.setLabel(MessagesManager.get("buttons.cancel")); //$NON-NLS-1$
109         bCancel.setOnclick("window.top.close();"); //$NON-NLS-1$
110 
111         html.append("<div class=\"" + CssConstants.CSSCLASS_TABSETSAVEBAR + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
112         html.append(bOk.getHtml());
113         html.append(" "); //$NON-NLS-1$
114         html.append(bCancel.getHtml());
115         html.append("</div>"); //$NON-NLS-1$
116 
117         html.append("</body></html>"); //$NON-NLS-1$
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"); //$NON-NLS-1$
127         src.append("?mgnlCK=" + new Date().getTime()); //$NON-NLS-1$
128         src.append("&browseMode=true"); //$NON-NLS-1$
129         if (path != null) {
130             src.append("&path=" + path); //$NON-NLS-1$
131         }
132         if (pathOpen != null) {
133             src.append("&pathOpen=" + pathOpen); //$NON-NLS-1$
134         }
135         if (pathSelected != null) {
136             src.append("&pathSelected=" + pathSelected); //$NON-NLS-1$
137         }
138         return src;
139     }
140 }