package mildo.wiwo.components;

import mildo.wiwo.Session;
import mildo.wiwo.data.WiwoPage;

import com.webobjects.appserver.*;

// Generated by the WOLips Templateengine Plug-in at Apr 14, 2009 8:38:04 PM
public class NewWiwoPageComp 
	extends mildo.wiwo.components.BaseComp 
{
    
	public NewWiwoPageComp(WOContext context) {
        super(context);
    }
	
	private String pageName;
	
	public void setPageName(String aValue) {
		pageName = aValue;
	}
	
	public String pageName() {
		return pageName;
	}
	
	// -------------
	
	private String wikiMarkup;
	
	public void setWikiMarkup(String aValue) {
		wikiMarkup = aValue;
	}
	
	public String wikiMarkup() {
		return wikiMarkup;
	}
	
	// ------------
	
	public WOComponent savePageAction() {
		WOComponent ret = null;
		if (pageName != null && pageName.length() > 0 && wikiMarkup != null && wikiMarkup.length() > 0) {
			if (WiwoPage.canCreateNewWiwoPage(session().defaultEditingContext(), pageName)) {
				WiwoPage thePage = WiwoPage.createPage(session().defaultEditingContext(), ((Session)session()).getActualSessionUser(), pageName, wikiMarkup);
				session().defaultEditingContext().saveChanges();
				WiwoPageComp thePageComp = (WiwoPageComp) pageWithName(WiwoPageComp.class.getName());
				thePageComp.setWiwoPage(thePage);
				thePageComp.showWiwoPage();
				ret = thePageComp;
			} else {
				System.out.println("Page already exists");
			}
		}
		return ret;
	}
	
}