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