001    /**
002     * Copyright (c) 2000-2013 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.dynamicdatalists.util;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryUtil;
018    import com.liferay.portal.kernel.language.LanguageUtil;
019    import com.liferay.portal.kernel.util.LocaleUtil;
020    import com.liferay.portal.kernel.util.OrderByComparator;
021    import com.liferay.portal.kernel.workflow.WorkflowConstants;
022    
023    import java.util.Locale;
024    
025    /**
026     * @author Marcellus Tavares
027     * @author Manuel de la Pe??a
028     */
029    public abstract class BaseDDLExporter implements DDLExporter {
030    
031            @Override
032            public byte[] export(long recordSetId) throws Exception {
033                    return doExport(
034                            recordSetId, WorkflowConstants.STATUS_ANY, QueryUtil.ALL_POS,
035                            QueryUtil.ALL_POS, null);
036            }
037    
038            @Override
039            public byte[] export(long recordSetId, int status) throws Exception {
040                    return doExport(
041                            recordSetId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
042            }
043    
044            @Override
045            public byte[] export(long recordSetId, int status, int start, int end)
046                    throws Exception {
047    
048                    return doExport(recordSetId, status, start, end, null);
049            }
050    
051            @Override
052            public byte[] export(
053                            long recordSetId, int status, int start, int end,
054                            OrderByComparator orderByComparator)
055                    throws Exception {
056    
057                    return doExport(recordSetId, status, start, end, orderByComparator);
058            }
059    
060            @Override
061            public Locale getLocale() {
062                    if (_locale == null) {
063                            _locale = LocaleUtil.getSiteDefault();
064                    }
065    
066                    return _locale;
067            }
068    
069            @Override
070            public void setLocale(Locale locale) {
071                    _locale = locale;
072            }
073    
074            protected abstract byte[] doExport(
075                            long recordSetId, int status, int start, int end,
076                            OrderByComparator orderByComparator)
077                    throws Exception;
078    
079            protected String getStatusMessage(int status) {
080                    String statusLabel = WorkflowConstants.getStatusLabel(status);
081    
082                    return LanguageUtil.get(_locale, statusLabel);
083            }
084    
085            private Locale _locale;
086    
087    }