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.journal.lar;
016    
017    import com.liferay.portal.kernel.lar.PortletDataContext;
018    import com.liferay.portlet.journal.model.JournalArticle;
019    
020    /**
021     * <p>
022     * An interface defining how newly created content should be added to the
023     * Journal when imported from a LAR file. A class implementing this interface
024     * should be specified in <i>portal.properties</i> under the
025     * <b>journal.lar.creation.strategy</b> property.
026     * </p>
027     *
028     * @author Joel Kozikowski
029     */
030    public interface JournalCreationStrategy {
031    
032            /**
033             * Constant returned by getTransformedContent() to indicate that the article
034             * text should remained unchanged.
035             */
036            public static final String ARTICLE_CONTENT_UNCHANGED = null;
037    
038            /**
039             * Constant returned by getAuthorUserId() that indicates the default portlet
040             * data import user ID strategy that should be used to determine the user
041             * ID.
042             */
043            public static final long USE_DEFAULT_USER_ID_STRATEGY = 0;
044    
045            /**
046             * Returns <code>true</code> if the default group permissions should be
047             * added when the specified journalObj is created.
048             *
049             * @param  context the portlet data context
050             * @param  journalObj the journal object
051             * @return <code>true</code> if default group permissions should be added to
052             *         the specified journalObj
053             * @throws Exception if an exception occurred
054             */
055            public boolean addGroupPermissions(
056                            PortletDataContext context, Object journalObj)
057                    throws Exception;
058    
059            /**
060             * Returns <code>true</code> if the default guest permissions should be
061             * added when the specified journalObj is created.
062             *
063             * @param  context the portlet data context
064             * @param  journalObj the journal object
065             * @return <code>true</code> if default guest permissions should be added to
066             *         the specified journalObj
067             * @throws Exception if an exception occurred
068             */
069            public boolean addGuestPermissions(
070                            PortletDataContext context, Object journalObj)
071                    throws Exception;
072    
073            /**
074             * Returns the author's user ID to assign to newly created content. If zero
075             * is returned, the default user ID import strategy will determine the
076             * author ID.
077             *
078             * @param  context the portlet data context
079             * @param  journalObj the journal object
080             * @return the author's user ID or USE_DEFAULT_USER_ID_STRATEGY to use the
081             *         default user ID strategy
082             * @throws Exception if an exception occurred
083             */
084            public long getAuthorUserId(PortletDataContext context, Object journalObj)
085                    throws Exception;
086    
087            /**
088             * Gives the content creation strategy an opportunity to transform the
089             * content before the new article is saved to the database. Possible use
090             * cases include using Velocity to merge in group specific values into the
091             * text. Returns the new content to assign to the article. If
092             * <code>null</code> is returned, the article content will be added
093             * unchanged.
094             *
095             * @param  context the portlet data context
096             * @param  newArticle the new journal article
097             * @return the transformed content to save in the database or
098             *         ARTICLE_CONTENT_UNCHANGED if the content should be added
099             *         unchanged
100             * @throws Exception if an exception occurred
101             */
102            public String getTransformedContent(
103                            PortletDataContext context, JournalArticle newArticle)
104                    throws Exception;
105    
106    }