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   */
40  public class JournalStructureImpl
41      extends JournalStructureModelImpl implements JournalStructure {
42  
43      public static final String RESERVED = "reserved";
44  
45      public static final String RESERVED_ARTICLE_AUTHOR_COMMENTS =
46          "reserved-article-author-comments";
47  
48      public static final String RESERVED_ARTICLE_AUTHOR_EMAIL_ADDRESS =
49          "reserved-article-author-email-address";
50  
51      public static final String RESERVED_ARTICLE_AUTHOR_ID =
52          "reserved-article-author-id";
53  
54      public static final String RESERVED_ARTICLE_AUTHOR_JOB_TITLE =
55          "reserved-article-author-job-title";
56  
57      public static final String RESERVED_ARTICLE_AUTHOR_LOCATION =
58          "reserved-article-author-location";
59  
60      public static final String RESERVED_ARTICLE_AUTHOR_NAME =
61          "reserved-article-author-name";
62  
63      public static final String RESERVED_ARTICLE_AUTHOR_ORGANIZATION =
64          "reserved-article-author-organization";
65  
66      public static final String RESERVED_ARTICLE_CREATE_DATE =
67          "reserved-article-create-date";
68  
69      public static final String RESERVED_ARTICLE_DESCRIPTION =
70          "reserved-article-description";
71  
72      public static final String RESERVED_ARTICLE_DISPLAY_DATE =
73          "reserved-article-display-date";
74  
75      public static final String RESERVED_ARTICLE_ID = "reserved-article-id";
76  
77      public static final String RESERVED_ARTICLE_MODIFIED_DATE =
78          "reserved-article-modified-date";
79  
80      public static final String RESERVED_ARTICLE_SMALL_IMAGE_URL =
81          "reserved-article-small-image-url";
82  
83      public static final String RESERVED_ARTICLE_TITLE =
84          "reserved-article-title";
85  
86      public static final String RESERVED_ARTICLE_TYPE =
87          "reserved-article-type";
88  
89      public static final String RESERVED_ARTICLE_VERSION =
90          "reserved-article-version";
91  
92      public JournalStructureImpl() {
93      }
94  
95      public String getMergedXsd() {
96          String parentStructureId = getParentStructureId();
97  
98          String xsd = getXsd();
99  
100         if (Validator.isNull(parentStructureId)) {
101             return xsd;
102         }
103 
104         try {
105             JournalStructure parentStructure =
106                 JournalStructureLocalServiceUtil.getStructure(
107                     getGroupId(), parentStructureId);
108 
109             Document doc = SAXReaderUtil.read(getXsd());
110 
111             Element root = doc.getRootElement();
112 
113             Document parentDoc = SAXReaderUtil.read(
114                 parentStructure.getMergedXsd());
115 
116             Element parentRoot = parentDoc.getRootElement();
117 
118             addParentStructureId(parentRoot, parentStructureId);
119 
120             root.content().addAll(0, parentRoot.content());
121 
122             xsd = root.asXML();
123         }
124         catch (Exception e) {
125         }
126 
127         return xsd;
128     }
129 
130     protected void addParentStructureId(
131         Element parentEl, String parentStructureId) {
132 
133         Iterator<Element> itr = parentEl.elements(_DYNAMIC_ELEMENT).iterator();
134 
135         while (itr.hasNext()) {
136             Element dynamicEl = itr.next();
137 
138             dynamicEl.addAttribute(_PARENT_STRUCTURE_ID, parentStructureId);
139 
140             addParentStructureId(dynamicEl, parentStructureId);
141         }
142     }
143 
144     private static final String _DYNAMIC_ELEMENT = "dynamic-element";
145 
146     private static final String _PARENT_STRUCTURE_ID = "parent-structure-id";
147 
148 }