001
014
015 package com.liferay.portlet.journal.model.impl;
016
017 import com.liferay.portal.kernel.util.Validator;
018 import com.liferay.portal.kernel.xml.Document;
019 import com.liferay.portal.kernel.xml.Element;
020 import com.liferay.portal.kernel.xml.SAXReaderUtil;
021 import com.liferay.portlet.journal.model.JournalStructure;
022 import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
023
024 import java.util.Iterator;
025
026
029 public class JournalStructureImpl
030 extends JournalStructureModelImpl implements JournalStructure {
031
032 public JournalStructureImpl() {
033 }
034
035 public String getMergedXsd() {
036 String parentStructureId = getParentStructureId();
037
038 String xsd = getXsd();
039
040 if (Validator.isNull(parentStructureId)) {
041 return xsd;
042 }
043
044 try {
045 JournalStructure parentStructure =
046 JournalStructureLocalServiceUtil.getStructure(
047 getGroupId(), parentStructureId);
048
049 Document doc = SAXReaderUtil.read(getXsd());
050
051 Element root = doc.getRootElement();
052
053 Document parentDoc = SAXReaderUtil.read(
054 parentStructure.getMergedXsd());
055
056 Element parentRoot = parentDoc.getRootElement();
057
058 addParentStructureId(parentRoot, parentStructureId);
059
060 root.content().addAll(0, parentRoot.content());
061
062 xsd = root.asXML();
063 }
064 catch (Exception e) {
065 }
066
067 return xsd;
068 }
069
070 protected void addParentStructureId(
071 Element parentEl, String parentStructureId) {
072
073 Iterator<Element> itr = parentEl.elements(_DYNAMIC_ELEMENT).iterator();
074
075 while (itr.hasNext()) {
076 Element dynamicEl = itr.next();
077
078 dynamicEl.addAttribute(_PARENT_STRUCTURE_ID, parentStructureId);
079
080 addParentStructureId(dynamicEl, parentStructureId);
081 }
082 }
083
084 private static final String _DYNAMIC_ELEMENT = "dynamic-element";
085
086 private static final String _PARENT_STRUCTURE_ID = "parent-structure-id";
087
088 }