001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.xml.Document;
021    import com.liferay.portal.kernel.xml.Element;
022    import com.liferay.portal.kernel.xml.SAXReaderUtil;
023    import com.liferay.portal.model.Image;
024    import com.liferay.portal.service.ImageLocalServiceUtil;
025    
026    import java.util.Locale;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class DDMTemplateImpl extends DDMTemplateBaseImpl {
032    
033            public DDMTemplateImpl() {
034            }
035    
036            public String getDefaultLanguageId() {
037                    Document document = null;
038    
039                    try {
040                            document = SAXReaderUtil.read(getName());
041    
042                            if (document != null) {
043                                    Element rootElement = document.getRootElement();
044    
045                                    return rootElement.attributeValue("default-locale");
046                            }
047                    }
048                    catch (Exception e) {
049                    }
050    
051                    Locale locale = LocaleUtil.getDefault();
052    
053                    return locale.toString();
054            }
055    
056            public String getSmallImageType() throws PortalException, SystemException {
057                    if ((_smallImageType == null) && isSmallImage()) {
058                            Image smallImage = ImageLocalServiceUtil.getImage(
059                                    getSmallImageId());
060    
061                            _smallImageType = smallImage.getType();
062                    }
063    
064                    return _smallImageType;
065            }
066    
067            public void setSmallImageType(String smallImageType) {
068                    _smallImageType = smallImageType;
069            }
070    
071            private String _smallImageType;
072    
073    }