1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.journal.model.impl;
24  
25  import com.liferay.portal.kernel.util.Validator;
26  import com.liferay.portal.kernel.xml.Document;
27  import com.liferay.portal.kernel.xml.Element;
28  import com.liferay.portal.kernel.xml.SAXReaderUtil;
29  import com.liferay.portlet.journal.model.JournalStructure;
30  import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
31  
32  import java.util.Iterator;
33  
34  /**
35   * <a href="JournalStructureImpl.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   */
39  public class JournalStructureImpl
40      extends JournalStructureModelImpl implements JournalStructure {
41  
42      public static final String RESERVED = "reserved";
43  
44      public static final String RESERVED_ARTICLE_AUTHOR_COMMENTS =
45          "reserved-article-author-comments";
46  
47      public static final String RESERVED_ARTICLE_AUTHOR_EMAIL_ADDRESS =
48          "reserved-article-author-email-address";
49  
50      public static final String RESERVED_ARTICLE_AUTHOR_ID =
51          "reserved-article-author-id";
52  
53      public static final String RESERVED_ARTICLE_AUTHOR_JOB_TITLE =
54          "reserved-article-author-job-title";
55  
56      public static final String RESERVED_ARTICLE_AUTHOR_LOCATION =
57          "reserved-article-author-location";
58  
59      public static final String RESERVED_ARTICLE_AUTHOR_NAME =
60          "reserved-article-author-name";
61  
62      public static final String RESERVED_ARTICLE_AUTHOR_ORGANIZATION =
63          "reserved-article-author-organization";
64  
65      public static final String RESERVED_ARTICLE_CREATE_DATE =
66          "reserved-article-create-date";
67  
68      public static final String RESERVED_ARTICLE_DESCRIPTION =
69          "reserved-article-description";
70  
71      public static final String RESERVED_ARTICLE_DISPLAY_DATE =
72          "reserved-article-display-date";
73  
74      public static final String RESERVED_ARTICLE_ID = "reserved-article-id";
75  
76      public static final String RESERVED_ARTICLE_MODIFIED_DATE =
77          "reserved-article-modified-date";
78  
79      public static final String RESERVED_ARTICLE_SMALL_IMAGE_URL =
80          "reserved-article-small-image-url";
81  
82      public static final String RESERVED_ARTICLE_TITLE =
83          "reserved-article-title";
84  
85      public static final String RESERVED_ARTICLE_TYPE =
86          "reserved-article-type";
87  
88      public static final String RESERVED_ARTICLE_URL_TITLE =
89          "reserved-article-url-title";
90  
91      public static final String RESERVED_ARTICLE_VERSION =
92          "reserved-article-version";
93  
94      public JournalStructureImpl() {
95      }
96  
97      public String getMergedXsd() {
98          String parentStructureId = getParentStructureId();
99  
100         String xsd = getXsd();
101 
102         if (Validator.isNull(parentStructureId)) {
103             return xsd;
104         }
105 
106         try {
107             JournalStructure parentStructure =
108                 JournalStructureLocalServiceUtil.getStructure(
109                     getGroupId(), parentStructureId);
110 
111             Document doc = SAXReaderUtil.read(getXsd());
112 
113             Element root = doc.getRootElement();
114 
115             Document parentDoc = SAXReaderUtil.read(
116                 parentStructure.getMergedXsd());
117 
118             Element parentRoot = parentDoc.getRootElement();
119 
120             addParentStructureId(parentRoot, parentStructureId);
121 
122             root.content().addAll(0, parentRoot.content());
123 
124             xsd = root.asXML();
125         }
126         catch (Exception e) {
127         }
128 
129         return xsd;
130     }
131 
132     protected void addParentStructureId(
133         Element parentEl, String parentStructureId) {
134 
135         Iterator<Element> itr = parentEl.elements(_DYNAMIC_ELEMENT).iterator();
136 
137         while (itr.hasNext()) {
138             Element dynamicEl = itr.next();
139 
140             dynamicEl.addAttribute(_PARENT_STRUCTURE_ID, parentStructureId);
141 
142             addParentStructureId(dynamicEl, parentStructureId);
143         }
144     }
145 
146     private static final String _DYNAMIC_ELEMENT = "dynamic-element";
147 
148     private static final String _PARENT_STRUCTURE_ID = "parent-structure-id";
149 
150 }