View Javadoc

1   /**
2    * This file Copyright (c) 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.ui.vaadin.gwt.client.editor.dom;
35  
36  import com.google.gwt.dom.client.Element;
37  import com.google.gwt.json.client.JSONObject;
38  import com.google.gwt.json.client.JSONString;
39  
40  import info.magnolia.ui.vaadin.gwt.client.editor.model.Model;
41  import info.magnolia.ui.vaadin.gwt.client.editor.widget.controlbar.AbstractBar;
42  import info.magnolia.ui.vaadin.gwt.client.editor.widget.controlbar.AreaEndBar;
43  import info.magnolia.ui.vaadin.gwt.client.editor.widget.placeholder.ComponentPlaceHolder;
44  
45  import java.util.Map;
46  
47  /**
48  * MgnlElement Constructor.
49  *
50  */
51  public class MgnlElement extends CmsNode {
52  
53      private Map<String, String> attributes;
54  
55      private Element startComment;
56      private Element endComment;
57  
58      private Element firstElement;
59      private Element lastElement;
60      private Element componentElement;
61      private Element areaElement;
62  
63      private Element editElement;
64      private AbstractBar controlBar;
65  
66      // only used in areas
67      ComponentPlaceHolder componentPlaceHolder;
68      AreaEndBar areaEndBar;
69  
70  
71      /**
72   * MgnlElement. Represents a node in the tree built on cms-tags.
73   */
74      public MgnlElement(MgnlElement parent) {
75          super(parent);
76      }
77  
78  
79      public void setAttributes(Map<String, String> attributes) {
80          this.attributes = attributes;
81      }
82  
83      public Map<String, String> getAttributes() {
84          return this.attributes;
85      }
86  
87      public AbstractBar getControlBar() {
88          return controlBar;
89      }
90  
91      public void setControlBar(AbstractBar controlBar) {
92          this.controlBar = controlBar;
93      }
94      public ComponentPlaceHolder getComponentPlaceHolder() {
95          return componentPlaceHolder;
96      }
97  
98      public void setComponentPlaceHolder(ComponentPlaceHolder componentPlaceHolder) {
99          this.componentPlaceHolder = componentPlaceHolder;
100     }
101 
102     public AreaEndBar getAreaEndBar() {
103         return areaEndBar;
104     }
105 
106     public void setAreaEndBar(AreaEndBar areaEndBar) {
107         this.areaEndBar = areaEndBar;
108     }
109 
110     public Element getFirstElement() {
111         return firstElement;
112     }
113 
114     public void setFirstElement(Element firstElement) {
115         this.firstElement = firstElement;
116     }
117 
118     public Element getLastElement() {
119         return lastElement;
120     }
121 
122     public void setLastElement(Element lastElement) {
123         this.lastElement = lastElement;
124     }
125 
126     public void setComponentElement(Element componentElement) {
127         this.componentElement = componentElement;
128     }
129 
130     public void setAreaElement(Element areaElement) {
131         this.areaElement = areaElement;
132     }
133 
134     public void setEditElement(Element editElement) {
135         this.editElement = editElement;
136     }
137 
138     public Element getComponentElement() {
139         return componentElement;
140     }
141 
142     public Element getAreaElement() {
143         return areaElement;
144     }
145 
146     public Element getEditElement() {
147         return editElement;
148     }
149 
150     public String getAttribute(String key) {
151         return this.attributes.get(key);
152     }
153 
154     public boolean containsAttribute(String key) {
155         return this.attributes.containsKey(key);
156     }
157 
158     public Element getStartComment() {
159         return startComment;
160     }
161 
162     public Element getEndComment() {
163         return this.endComment;
164     }
165 
166     public void setStartComment(Element element) {
167         this.startComment = element;
168     }
169     public void setEndComment(Element element) {
170         this.endComment = element;
171     }
172 
173     public String getType() {
174 
175         if (isPage()) {
176             return Model.CMS_PAGE;
177         }
178         if (isArea()) {
179             return Model.CMS_AREA;
180         }
181         else {
182             return Model.CMS_COMPONENT;
183         }
184     }
185 
186     public String getJsonAttributes() {
187 
188         JSONObject json = new JSONObject();
189 
190         for ( String key : attributes.keySet()) {
191             String value = attributes.get(key);
192             json.put(key, new JSONString(value));
193         }
194         return json.toString();
195     }
196 }