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.blossom.dialog;
35  
36  import java.util.ArrayList;
37  import java.util.List;
38  
39  import javax.jcr.Node;
40  import javax.servlet.http.HttpServletRequest;
41  import javax.servlet.http.HttpServletResponse;
42  
43  import info.magnolia.cms.core.Content;
44  import info.magnolia.cms.gui.dialog.Dialog;
45  import info.magnolia.cms.gui.dialog.DialogTab;
46  import info.magnolia.cms.util.ContentUtil;
47  import info.magnolia.module.admininterface.SaveHandler;
48  
49  /**
50   * Holds the parameters required during dialog creation and validation.
51   *
52   * @since 0.5
53   */
54  public class DialogCreationContext {
55  
56      private HttpServletRequest request;
57      private HttpServletResponse response;
58      private Content configNode;
59      private Node contentNode;
60      private Dialog dialog;
61      private String contentPath;
62      private List<ValidationCallback> validators = new ArrayList<ValidationCallback>();
63      private SaveHandler saveHandler;
64  
65      public HttpServletRequest getRequest() {
66          return request;
67      }
68  
69      public void setRequest(HttpServletRequest request) {
70          this.request = request;
71      }
72  
73      public HttpServletResponse getResponse() {
74          return response;
75      }
76  
77      public void setResponse(HttpServletResponse response) {
78          this.response = response;
79      }
80  
81      public Content getConfigNode() {
82          return configNode;
83      }
84  
85      public void setConfigNode(Content configNode) {
86          this.configNode = configNode;
87      }
88  
89      public Node getContentNode() {
90          return contentNode;
91      }
92  
93      public void setContentNode(Node contentNode) {
94          this.contentNode = contentNode;
95      }
96  
97      /**
98       * @deprecated since 2.0.2 - use getContentNode() instead
99       */
100     @Deprecated
101     public Content getWebsiteNode() {
102         return ContentUtil.asContent(contentNode);
103     }
104 
105     /**
106      * @deprecated since 2.0.2 - use setContentNode(Node) instead
107      */
108     @Deprecated
109     public void setWebsiteNode(Content websiteNode) {
110         this.contentNode = websiteNode.getJCRNode();
111     }
112 
113     public Dialog getDialog() {
114         return dialog;
115     }
116 
117     public void setDialog(Dialog dialog) {
118         this.dialog = dialog;
119     }
120 
121     public String getContentPath() {
122         return contentPath;
123     }
124 
125     public void setContentPath(String contentPath) {
126         this.contentPath = contentPath;
127     }
128 
129     /**
130      * @deprecated since 2.0.2 - use getContentPath() instead
131      */
132     @Deprecated
133     public String getWebsitePath() {
134         return contentPath;
135     }
136 
137     /**
138      * @deprecated since 2.0.2 - use setContentPath(String) instead
139      */
140     @Deprecated
141     public void setWebsitePath(String websitePath) {
142         this.contentPath = websitePath;
143     }
144 
145     public SaveHandler getSaveHandler() {
146         return saveHandler;
147     }
148 
149     public void setSaveHandler(SaveHandler saveHandler) {
150         this.saveHandler = saveHandler;
151     }
152 
153     public void addValidator(ValidationCallback validator) {
154         validators.add(validator);
155     }
156 
157     public List<ValidationCallback> getValidators() {
158         return validators;
159     }
160 
161     public DialogTab getTab(String label) {
162         for (Object sub : dialog.getSubs()) {
163             if (sub instanceof DialogTab) {
164                 DialogTab d = (DialogTab) sub;
165                 if (d.getLabel().equals(label)) {
166                     return d;
167                 }
168             }
169         }
170         return null;
171     }
172 
173     public void executeValidators() {
174         for (ValidationCallback validator : validators) {
175             validator.validate(dialog);
176         }
177     }
178 }