001/* 
002    Licensed to the Apache Software Foundation (ASF) under one
003    or more contributor license agreements.  See the NOTICE file
004    distributed with this work for additional information
005    regarding copyright ownership.  The ASF licenses this file
006    to you under the Apache License, Version 2.0 (the
007    "License"); you may not use this file except in compliance
008    with the License.  You may obtain a copy of the License at
009
010       http://www.apache.org/licenses/LICENSE-2.0
011
012    Unless required by applicable law or agreed to in writing,
013    software distributed under the License is distributed on an
014    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015    KIND, either express or implied.  See the License for the
016    specific language governing permissions and limitations
017    under the License.  
018 */
019package org.apache.wiki.tasks.pages;
020
021import org.apache.wiki.api.core.Context;
022import org.apache.wiki.api.core.Page;
023import org.apache.wiki.api.exceptions.WikiException;
024import org.apache.wiki.api.providers.PageProvider;
025import org.apache.wiki.filters.FilterManager;
026import org.apache.wiki.pages.PageManager;
027import org.apache.wiki.render.RenderingManager;
028import org.apache.wiki.search.SearchManager;
029import org.apache.wiki.tasks.TasksManager;
030import org.apache.wiki.workflow.Outcome;
031import org.apache.wiki.workflow.Task;
032import org.apache.wiki.workflow.WorkflowManager;
033
034
035/**
036 * Handles the actual page save and post-save actions. 
037 */
038public class SaveWikiPageTask extends Task {
039
040    private static final long serialVersionUID = 3190559953484411420L;
041
042    /**
043     * Creates the Task.
044     */
045    public SaveWikiPageTask() {
046        super( TasksManager.WIKIPAGE_SAVE_TASK_MESSAGE_KEY );
047    }
048
049    /**
050     * {@inheritDoc}
051     */
052    @Override
053    public Outcome execute( final Context context ) throws WikiException {
054        // Retrieve attributes
055        final String proposedText = ( String )getWorkflowContext().get( WorkflowManager.WF_WP_SAVE_FACT_PROPOSED_TEXT );
056
057        final Page page = context.getPage();
058
059        // Let the rest of the engine handle actual saving.
060        context.getEngine().getManager( PageManager.class ).putPageText( page, proposedText );
061
062        // Refresh the context for post save filtering.
063        context.getEngine().getManager( PageManager.class ).getPage( page.getName() );
064        context.getEngine().getManager( RenderingManager.class ).textToHTML( context, proposedText );
065        context.getEngine().getManager( FilterManager.class ).doPostSaveFiltering( context, proposedText );
066
067        // Reindex saved page
068        page.setVersion( PageProvider.LATEST_VERSION );
069        context.getEngine().getManager( SearchManager.class ).reindexPage( page );
070
071        return Outcome.STEP_COMPLETE;
072    }
073
074}