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