001
014
015 package com.liferay.portlet.dynamicdatamapping.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.util.LocaleUtil;
020 import com.liferay.portal.kernel.util.StringBundler;
021 import com.liferay.portal.kernel.util.StringPool;
022 import com.liferay.portal.kernel.xml.Document;
023 import com.liferay.portal.kernel.xml.Element;
024 import com.liferay.portal.kernel.xml.SAXReaderUtil;
025 import com.liferay.portal.model.Group;
026 import com.liferay.portal.model.Image;
027 import com.liferay.portal.service.ImageLocalServiceUtil;
028 import com.liferay.portal.theme.ThemeDisplay;
029 import com.liferay.portal.util.PortalUtil;
030 import com.liferay.portal.util.PropsValues;
031
032 import java.util.Locale;
033
034
037 public class DDMTemplateImpl extends DDMTemplateBaseImpl {
038
039 public DDMTemplateImpl() {
040 }
041
042 public String getDefaultLanguageId() {
043 Document document = null;
044
045 try {
046 document = SAXReaderUtil.read(getName());
047
048 if (document != null) {
049 Element rootElement = document.getRootElement();
050
051 return rootElement.attributeValue("default-locale");
052 }
053 }
054 catch (Exception e) {
055 }
056
057 Locale locale = LocaleUtil.getDefault();
058
059 return locale.toString();
060 }
061
062 public String getSmallImageType() throws PortalException, SystemException {
063 if ((_smallImageType == null) && isSmallImage()) {
064 Image smallImage = ImageLocalServiceUtil.getImage(
065 getSmallImageId());
066
067 _smallImageType = smallImage.getType();
068 }
069
070 return _smallImageType;
071 }
072
073
082 public String getWebDavURL(ThemeDisplay themeDisplay, String webDAVToken) {
083 StringBundler sb = new StringBundler(11);
084
085 boolean secure = false;
086
087 if (themeDisplay.isSecure() ||
088 PropsValues.WEBDAV_SERVLET_HTTPS_REQUIRED) {
089
090 secure = true;
091 }
092
093 String portalURL = PortalUtil.getPortalURL(
094 themeDisplay.getServerName(), themeDisplay.getServerPort(), secure);
095
096 sb.append(portalURL);
097
098 sb.append(themeDisplay.getPathContext());
099 sb.append(StringPool.SLASH);
100 sb.append("webdav");
101
102 Group group = themeDisplay.getScopeGroup();
103
104 sb.append(group.getFriendlyURL());
105
106 sb.append(StringPool.SLASH);
107 sb.append(webDAVToken);
108 sb.append(StringPool.SLASH);
109 sb.append("Templates");
110 sb.append(StringPool.SLASH);
111 sb.append(getTemplateId());
112
113 return sb.toString();
114 }
115
116 public void setSmallImageType(String smallImageType) {
117 _smallImageType = smallImageType;
118 }
119
120 private String _smallImageType;
121
122 }