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.WikiContext;
022import org.apache.wiki.WikiEngine;
023import org.apache.wiki.WikiPage;
024import org.apache.wiki.api.exceptions.WikiException;
025import org.apache.wiki.tasks.TasksManager;
026import org.apache.wiki.workflow.Outcome;
027import org.apache.wiki.workflow.Task;
028import org.apache.wiki.workflow.WorkflowManager;
029
030
031/**
032 * Handles the actual page save and post-save actions. 
033 */
034public class SaveWikiPageTask extends Task {
035
036    private static final long serialVersionUID = 3190559953484411420L;
037
038    /**
039     * Creates the Task.
040     */
041    public SaveWikiPageTask() {
042        super( TasksManager.WIKIPAGE_SAVE_TASK_MESSAGE_KEY );
043    }
044
045    /**
046     * {@inheritDoc}
047     */
048    @Override
049    public Outcome execute() throws WikiException {
050        // Retrieve attributes
051        WikiContext context = (WikiContext) getWorkflow().getAttribute( WorkflowManager.WF_WP_SAVE_ATTR_PRESAVE_WIKI_CONTEXT );
052        String proposedText = (String) getWorkflow().getAttribute( WorkflowManager.WF_WP_SAVE_FACT_PROPOSED_TEXT );
053
054        WikiEngine engine = context.getEngine();
055        WikiPage page = context.getPage();
056
057        // Let the rest of the engine handle actual saving.
058        engine.getPageManager().putPageText(page, proposedText);
059
060        // Refresh the context for post save filtering.
061        engine.getPage(page.getName());
062        engine.textToHTML(context, proposedText);
063        engine.getFilterManager().doPostSaveFiltering(context, proposedText);
064
065        return Outcome.STEP_COMPLETE;
066    }
067
068}