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.util.LocaleUtil;
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    
022    import java.util.Locale;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class DDMTemplateImpl extends DDMTemplateBaseImpl {
028    
029            public DDMTemplateImpl() {
030            }
031    
032            public String getDefaultLanguageId() {
033                    Document document = null;
034    
035                    try {
036                            document = SAXReaderUtil.read(getName());
037    
038                            if (document != null) {
039                                    Element rootElement = document.getRootElement();
040    
041                                    return rootElement.attributeValue("default-locale");
042                            }
043                    }
044                    catch (Exception e) {
045                    }
046    
047                    Locale locale = LocaleUtil.getDefault();
048    
049                    return locale.toString();
050            }
051    
052    }