Kawai Wiki

Compare Revisions

Ignore whitespace Rev 188 → Rev 189

/trunk/src/test/java/org/kawai/action/PageActionTest.java
New file
0,0 → 1,143
package org.kawai.action;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.kawai.dao.PageDAO;
import org.kawai.dao.UserDAO;
import org.kawai.dao.jdbc.JdbcPageDAO;
import org.kawai.dao.jdbc.JdbcUserDAO;
import org.kawai.model.Page;
import org.kawai.model.User;
import org.mentabean.BeanConfig;
import org.mentabean.BeanManager;
import org.mentabean.BeanSession;
import org.mentabean.DBTypes;
import org.mentabean.jdbc.MySQLBeanSession;
import org.mentawai.util.MockAction;
import org.mentawai.validation.Validator;
 
/**
* Test class PageActionTest.
* @author helio frota
*
*/
public class PageActionTest {
 
/**
* Attribute action of PageActionTest.
*/
private PageAction action;
/**
* Attribute mockAction of PageActionTest.
*/
private MockAction mockAction;
/**
* Attribute userDAO of PageActionTest.
*/
private UserDAO userDAO;
/**
* Attribute pageDAO of PageActionTest.
*/
private PageDAO pageDAO;
/**
* Attribute jdbcUserDAO of PageActionTest.
*/
private JdbcUserDAO jdbcUserDAO;
/**
* Attribute jdbcPageDAO of PageActionTest.
*/
private JdbcPageDAO jdbcPageDAO;
/**
* Attribute beanSession of PageActionTest.
*/
private BeanSession beanSession;
 
/**
* Default setUp method.
* @throws Exception
*/
@Before
public void setUp() throws Exception {
 
BeanManager beanManager = new BeanManager();
BeanConfig beanConfig = new BeanConfig(Page.class, "Pages");
beanConfig.pk("id", "id", DBTypes.AUTOINCREMENT);
beanConfig.field("name", DBTypes.STRING);
beanConfig.field("title", DBTypes.STRING);
beanConfig.field("body", DBTypes.STRING);
beanConfig.field("languageId", "language_id", DBTypes.STRING);
beanConfig.field("systemPage", "system_page", DBTypes.BOOLEANSTRING);
beanConfig.field("frontPage", "front_page", DBTypes.BOOLEANSTRING);
beanConfig.field("modifiedById", "modified_by", DBTypes.INTEGER);
beanConfig.field("modifiedOn", "modified_on", DBTypes.NOW_ON_UPDATE_TIMESTAMP);
beanConfig.field("createdById", "created_by", DBTypes.INTEGER);
beanConfig.field("createdOn", "created_on", DBTypes.NOW_ON_INSERT_TIMESTAMP);
beanConfig.field("deleted", DBTypes.BOOLEANSTRING);
 
beanManager.addBeanConfig(beanConfig);
 
beanConfig = new BeanConfig(User.class, "Users");
beanConfig.pk("id", DBTypes.AUTOINCREMENT);
beanConfig.field("username", DBTypes.STRING);
beanConfig.field("password", DBTypes.STRING);
beanConfig.field("groupId", "group_id", DBTypes.INTEGER);
 
beanManager.addBeanConfig(beanConfig);
 
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/Kawai?autoReconnect=true", "kawai", "1kawai23");
beanSession = new MySQLBeanSession(beanManager, conn);
 
userDAO = new JdbcUserDAO(beanSession);
pageDAO = new JdbcPageDAO(beanSession);
 
action = new PageAction(userDAO, pageDAO);
mockAction = new MockAction(action);
action.setInput(mockAction.getInput());
action.setOutput(mockAction.getOutput());
}
 
/**
* Test method executeTest.
*/
@Ignore
@Test
public void executeTest() {
action.getInput().setValue("name", "Page");
action.getInput().setValue("lang", "pt");
action.execute();
}
 
/**
* Test method getLastRevisionsTest.
*/
@Ignore
@Test
public void getLastRevisionsTest() {
action.getInput().setValue("lang", "en_US");
action.getLastRevisions();
}
 
/**
* Test method prepareValidatorTest.
*/
@Test
public void prepareValidatorTest() {
Map<String, Object> ruleMap = new HashMap< String, Object >();
List < String > valueList = new ArrayList < String >();
ruleMap.put("ruleMap", valueList);
Map<String, Object> errorMap = new HashMap< String, Object >();
errorMap.put("errorMap", new HashMap < String, Object >());
Validator validator = new Validator(ruleMap, errorMap);
action.prepareValidator(validator, "add");
}
 
}
/trunk/src/test/java/AllTests.java
2,6 → 2,7
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.kawai.action.LoginActionTest;
import org.kawai.action.PageActionTest;
import org.kawai.model.ModelTest;
 
/**
12,7 → 13,8
@RunWith(value = Suite.class)
@SuiteClasses(value = {
ModelTest.class,
LoginActionTest.class
LoginActionTest.class,
PageActionTest.class
})
public class AllTests {
 
/trunk/src/test/resources/WEB-INF/conf/dev/appManager.properties
New file
0,0 → 1,6
# MentaBean with MySQL
mentabean.dialect = org.mentabean.jdbc.MySQLBeanSession
jdbc.driver = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql://localhost/Kawai?autoReconnect=true
jdbc.user = kawai
jdbc.pass = 1kawai23
/trunk/src/main/java/org/kawai/action/PageAction.java
16,373 → 16,379
import org.mentawai.validation.ValidationInterceptor;
import org.mentawai.validation.Validator;
 
/**
* Action class LoginAction.
*
* @author Sergio Oliveira
*
*/
public class PageAction extends AbstractAction implements AuthenticationFree, Validatable, ValidationInterceptor {
public static final String LEFT_COLUMN_KEY = "leftColumn";
public static final String BODY_COLUMN_KEY = "bodyColumn";
public static final String CSS_KEY = "css";
public static final String LOGO_KEY = "logo";
public static final String JAVASCRIPT_KEY = "js";
public PageAction(UserDAO userDAO, PageDAO pageDAO) {
super(userDAO, pageDAO);
}
 
@Override
public boolean bypassAuthentication(String method) {
if (method == null) return true;
if (method.equals("getCSS")) return true;
if (method.equals("getPrintCSS")) return true;
if (method.equals("getLastRevisions")) return true;
return false;
}
@Override
public void prepareValidator(Validator val, String method) {
if (method != null && method.equals("add") && isPost()) {
val.requiredFields("Required field!", "newPage.name", "newPage.title", "newPage.body", "newPage.languageId");
val.requiredLists("Required field!", "newPage.languageId");
val.add("newPage.name", RegexRule.getInstance("[A-Za-z0-9_\\-]+"), "Invalid name for page!");
val.add("newPage.name", MethodRule.getInstance(this, "checkPageDoesNotExist"), "This page already exists!");
val.add("newPage.name", MethodRule.getInstance(this, "checkNotSystemPage"), "Cannot create a system page!");
}
}
@Override
public boolean beforeValidation(String method) {
return true; // go ahead with validation...
}
@Override
public void afterValidation(String method, boolean wasOk) {
if (method == null) return;
if (method.equals("add") && !wasOk) {
output.setValue("showForm", method);
}
}
boolean checkPageDoesNotExist() {
Page p = input.getObject(Page.class, "newPage");
if (p.getName() == null || p.getLanguage() == null) {
return true;
}
return !pageDAO.exists(p.getName(), p.getLanguage());
}
boolean checkNotSystemPage() {
Page p = input.getObject(Page.class, "newPage");
if (p.getName() == null) {
return true;
}
return !pageDAO.isSystemPage(p.getName());
}
private Page loadLeftColumn(Language lang) {
if (sessionUser != null) {
return pageDAO.loadByNameWithPreview(sessionUser.getId(), Page.LEFT_COLUMN, lang);
} else {
return pageDAO.loadByName(Page.LEFT_COLUMN, lang);
}
}
private Page loadLogo(Language lang) {
if (sessionUser != null) {
return pageDAO.loadByNameWithPreview(sessionUser.getId(), Page.LOGO, lang);
} else {
return pageDAO.loadByName(Page.LOGO, lang);
}
}
private void setLogo(Language lang) {
Page logo = loadLogo(lang);
output.setValue(LOGO_KEY, logo);
}
private void setLeftColumn(Language lang) {
Page lc = loadLeftColumn(lang);
output.setValue(LEFT_COLUMN_KEY, lc);
}
private Page loadCSS() {
if (sessionUser != null) {
return pageDAO.loadByNameWithPreview(sessionUser.getId(), Page.CSS, Language.getDefault());
} else {
return pageDAO.loadByName(Page.CSS, Language.getDefault());
}
}
private void setCSS() {
Page css = loadCSS();
output.setValue(CSS_KEY, css);
}
private Page loadJavaScript() {
if (sessionUser != null) {
return pageDAO.loadByNameWithPreview(sessionUser.getId(), Page.JAVASCRIPT, Language.getDefault());
} else {
return pageDAO.loadByName(Page.JAVASCRIPT, Language.getDefault());
}
}
private void setJavaScript() {
Page js = loadJavaScript();
output.setValue(JAVASCRIPT_KEY, js);
}
// for ajax
public String get() {
String name = input.getString("name");
String lang = input.getString("lang");
int revision = input.getInt("revision", -1);
Language language = Language.fromLocale(lang);
if (name != null && language != null) {
Page page = pageDAO.loadByName(name, language, revision);
if (page != null) {
output.setValue("page", page);
}
}
return AJAX;
}
public String getPreview() {
String name = input.getString("name");
String lang = input.getString("lang");
Language language = Language.fromLocale(lang);
Page page = null;
if (name != null && language != null) {
if (sessionUser != null) {
Preview preview = pageDAO.loadPreview(sessionUser.getId(), name, language);
if (preview != null) {
page = preview.getPage();
}
}
if (page != null) {
output.setValue("page", page);
}
}
return AJAX;
}
public String getCSS() {
setCSS();
return SUCCESS;
}
public String getPrintCSS() {
Page page = pageDAO.loadByName(Page.PRINT_CSS, Language.getDefault());
output.setValue(CSS_KEY, page);
return SUCCESS;
}
private Language getLanguage() {
return getLanguage(input.getString("lang"));
}
private Language getLanguage(String lang) {
if (lang == null) return language;
Language l = Language.fromLocale(lang);
if (l == null) return language;
return l;
}
private String getName() {
String name = input.getString("name");
return getName(name);
}
private String getName(String name) {
if (name == null) {
name = pageDAO.getFrontPage(language);
if (name == null) {
throw new IllegalStateException("There is no front page defined for language: " + language);
}
}
return name;
}
@Override
public String execute() {
String name = getName();
Language language = getLanguage();
int revision = input.getInt("revision", -1);
Page page;
if (sessionUser != null && revision == -1) {
page = pageDAO.loadByNameWithPreview(sessionUser.getId(), name, language);
} else {
page = pageDAO.loadByName(name, language, revision);
}
if (page == null || page.isDeleted() || page.isSystemPage()) {
return INDEX;
}
setCSS();
setJavaScript();
setLeftColumn(page.getLanguage());
setLogo(page.getLanguage());
output.setValue(BODY_COLUMN_KEY, page);
return SUCCESS;
}
private void setPageRedirParams(Page page) {
if (!page.isSystemPage()) {
output.setValue("name", page.getName());
output.setValue("lang", page.getLanguage().getLocale());
}
}
public String savePreview() {
String name = input.getString("name");
Language lang = Language.fromLocale(input.getString("lang"));
int userId = sessionUser.getId();
Preview preview = pageDAO.loadPreview(userId, name, lang);
if (preview != null) {
Page page = pageDAO.loadByName(name, lang);
if (page != null) {
String oldTitle = page.getTitle();
String oldBody = page.getBody();
page.setTitle(preview.getTitle());
page.setBody(preview.getBody());
page.setModifiedById(preview.getUserId());
pageDAO.update(page);
insertRevision(page, preview.getComment(), oldTitle, oldBody);
pageDAO.deletePreview(userId, name, lang);
} else {
page = preview.getPage();
pageDAO.insert(page);
pageDAO.deletePreview(userId, name, lang);
insertRevision(page,null, null, null);
}
setPageRedirParams(page);
}
return SUCCESS;
}
private void insertRevision(Page page, String comment, String oldTitle, String oldBody) {
Revision r = new Revision();
r.setName(page.getName());
r.setLanguageId(page.getLanguageId());
r.setUserId(sessionUser.getId());
r.setNewTitle(page.getTitle());
r.setNewBody(page.getBody());
r.setOldTitle(oldTitle);
r.setOldBody(oldBody);
r.setComment(comment);
pageDAO.insertRevision(r);
}
public String edit() {
if (!isPost()) return INDEX;
String name = input.getString("name");
String lang = input.getString("lang");
if (name.equals("CSS")) {
// does not make sense to have CSS in different languages... (well, maybe it does, but we do NOT want to maintain more than one CSS)
lang = "en";
}
Page page = pageDAO.loadByName(name, Language.fromLocale(lang));
if (page != null) {
String oldTitle = page.getTitle();
String oldBody = page.getBody();
input.inject(page);
page.setModifiedById(sessionUser.getId());
if (input.getBoolean("isPreview")) {
pageDAO.insertPreview(sessionUser.getId(), page, input.getString("comment"));
} else {
pageDAO.update(page);
insertRevision(page, input.getString("comment"), oldTitle, oldBody);
// and now you have to delete the preview!
pageDAO.deletePreview(sessionUser.getId(), page.getName(), page.getLanguage());
}
setPageRedirParams(page);
}
return UPDATED;
}
public String discardPreview() {
String name = input.getString("name");
Language lang = Language.fromLocale(input.getString("lang"));
int userId = sessionUser.getId();
pageDAO.deletePreview(userId, name, lang);
output.setValue("name", name);
output.setValue("lang", lang.getLocale());
return REMOVED;
}
public String add() {
if (!isPost()) return INDEX;
Page p = input.getObject(Page.class, "newPage");
p.setCreatedById(sessionUser.getId());
if (input.getBoolean("isPreview")) {
pageDAO.insertPreview(sessionUser.getId(), p, null);
} else {
pageDAO.insert(p);
// and now you have to delete the preview!
pageDAO.deletePreview(sessionUser.getId(), p.getName(), p.getLanguage());
// also add revision zero...
insertRevision(p, null, null, null);
}
setPageRedirParams(p);
return CREATED;
}
public String list() {
List<Page> pages = pageDAO.loadAll(sessionUser.getGroup() == Group.ADMIN);
output.setValue("pages", pages);
return AJAX;
}
public String setFrontPage() {
int id = input.getInt("pageId");
Page p = pageDAO.load(id);
if (p != null) {
if (pageDAO.setNewFrontPage(p)) {
output.setValue("lang", p.getLang());
}
}
return UPDATED;
}
public String delete() {
int id = input.getInt("pageId");
Page p = pageDAO.load(id);
if (p != null ) {
pageDAO.delete(p);
}
return UPDATED;
}
public String getRevisions() {
String name = input.getString("name");
Language lang = Language.fromLocale(input.getString("lang"));
List<Revision> revisions = pageDAO.loadRevisions(name, lang);
output.setValue("revisions", revisions);
boolean isSystemPage = pageDAO.isSystemPage(name);
output.setValue("isSystemPage", isSystemPage);
return AJAX;
}
public String getLastRevisions() {
Language lang = Language.fromLocale(input.getString("lang"));
List<Revision> revisions = pageDAO.loadLastRevisions(lang, sessionUser != null);
output.setValue("revisions", revisions);
return AJAX;
}
}
public static final String LEFT_COLUMN_KEY = "leftColumn";
public static final String BODY_COLUMN_KEY = "bodyColumn";
public static final String CSS_KEY = "css";
public static final String LOGO_KEY = "logo";
public static final String JAVASCRIPT_KEY = "js";
 
public PageAction(UserDAO userDAO, PageDAO pageDAO) {
super(userDAO, pageDAO);
}
 
@Override
public boolean bypassAuthentication(String method) {
 
if (method == null) return true;
if (method.equals("getCSS")) return true;
if (method.equals("getPrintCSS")) return true;
if (method.equals("getLastRevisions")) return true;
 
return false;
}
 
@Override
public void prepareValidator(Validator val, String method) {
 
if (method != null && method.equals("add") && isPost()) {
 
val.requiredFields("Required field!", "newPage.name", "newPage.title", "newPage.body", "newPage.languageId");
 
val.requiredLists("Required field!", "newPage.languageId");
 
val.add("newPage.name", RegexRule.getInstance("[A-Za-z0-9_\\-]+"), "Invalid name for page!");
 
val.add("newPage.name", MethodRule.getInstance(this, "checkPageDoesNotExist"), "This page already exists!");
 
val.add("newPage.name", MethodRule.getInstance(this, "checkNotSystemPage"), "Cannot create a system page!");
}
}
 
@Override
public boolean beforeValidation(String method) {
return true; // go ahead with validation...
}
 
@Override
public void afterValidation(String method, boolean wasOk) {
if (method == null) return;
 
if (method.equals("add") && !wasOk) {
output.setValue("showForm", method);
}
}
 
boolean checkPageDoesNotExist() {
Page p = input.getObject(Page.class, "newPage");
if (p.getName() == null || p.getLanguage() == null) {
return true;
}
return !pageDAO.exists(p.getName(), p.getLanguage());
}
 
boolean checkNotSystemPage() {
Page p = input.getObject(Page.class, "newPage");
if (p.getName() == null) {
return true;
}
return !pageDAO.isSystemPage(p.getName());
}
 
private Page loadLeftColumn(Language lang) {
if (sessionUser != null) {
return pageDAO.loadByNameWithPreview(sessionUser.getId(), Page.LEFT_COLUMN, lang);
} else {
return pageDAO.loadByName(Page.LEFT_COLUMN, lang);
}
}
 
private Page loadLogo(Language lang) {
if (sessionUser != null) {
return pageDAO.loadByNameWithPreview(sessionUser.getId(), Page.LOGO, lang);
} else {
return pageDAO.loadByName(Page.LOGO, lang);
}
}
 
private void setLogo(Language lang) {
Page logo = loadLogo(lang);
output.setValue(LOGO_KEY, logo);
}
 
private void setLeftColumn(Language lang) {
Page lc = loadLeftColumn(lang);
output.setValue(LEFT_COLUMN_KEY, lc);
}
 
private Page loadCSS() {
if (sessionUser != null) {
return pageDAO.loadByNameWithPreview(sessionUser.getId(), Page.CSS, Language.getDefault());
} else {
return pageDAO.loadByName(Page.CSS, Language.getDefault());
}
}
 
private void setCSS() {
Page css = loadCSS();
output.setValue(CSS_KEY, css);
}
 
private Page loadJavaScript() {
if (sessionUser != null) {
return pageDAO.loadByNameWithPreview(sessionUser.getId(), Page.JAVASCRIPT, Language.getDefault());
} else {
return pageDAO.loadByName(Page.JAVASCRIPT, Language.getDefault());
}
}
 
private void setJavaScript() {
Page js = loadJavaScript();
output.setValue(JAVASCRIPT_KEY, js);
}
 
// for ajax
public String get() {
String name = input.getString("name");
String lang = input.getString("lang");
int revision = input.getInt("revision", -1);
Language language = Language.fromLocale(lang);
if (name != null && language != null) {
Page page = pageDAO.loadByName(name, language, revision);
if (page != null) {
output.setValue("page", page);
}
}
return AJAX;
}
 
public String getPreview() {
String name = input.getString("name");
String lang = input.getString("lang");
Language language = Language.fromLocale(lang);
Page page = null;
if (name != null && language != null) {
if (sessionUser != null) {
Preview preview = pageDAO.loadPreview(sessionUser.getId(), name, language);
if (preview != null) {
page = preview.getPage();
}
}
if (page != null) {
output.setValue("page", page);
}
}
return AJAX;
}
 
public String getCSS() {
setCSS();
return SUCCESS;
}
 
public String getPrintCSS() {
Page page = pageDAO.loadByName(Page.PRINT_CSS, Language.getDefault());
output.setValue(CSS_KEY, page);
return SUCCESS;
}
 
private Language getLanguage() {
return getLanguage(input.getString("lang"));
}
 
private Language getLanguage(String lang) {
if (lang == null) return language;
Language l = Language.fromLocale(lang);
if (l == null) return language;
return l;
}
 
private String getName() {
String name = input.getString("name");
return getName(name);
}
 
private String getName(String name) {
if (name == null) {
name = pageDAO.getFrontPage(language);
if (name == null) {
throw new IllegalStateException("There is no front page defined for language: " + language);
}
}
return name;
}
 
@Override
public String execute() {
String name = getName();
Language language = getLanguage();
int revision = input.getInt("revision", -1);
Page page;
if (sessionUser != null && revision == -1) {
page = pageDAO.loadByNameWithPreview(sessionUser.getId(), name, language);
} else {
page = pageDAO.loadByName(name, language, revision);
}
if (page == null || page.isDeleted() || page.isSystemPage()) {
return INDEX;
}
setCSS();
setJavaScript();
setLeftColumn(page.getLanguage());
setLogo(page.getLanguage());
output.setValue(BODY_COLUMN_KEY, page);
return SUCCESS;
}
 
private void setPageRedirParams(Page page) {
if (!page.isSystemPage()) {
output.setValue("name", page.getName());
output.setValue("lang", page.getLanguage().getLocale());
}
}
 
public String savePreview() {
String name = input.getString("name");
Language lang = Language.fromLocale(input.getString("lang"));
int userId = sessionUser.getId();
Preview preview = pageDAO.loadPreview(userId, name, lang);
if (preview != null) {
Page page = pageDAO.loadByName(name, lang);
if (page != null) {
 
String oldTitle = page.getTitle();
String oldBody = page.getBody();
 
page.setTitle(preview.getTitle());
page.setBody(preview.getBody());
page.setModifiedById(preview.getUserId());
pageDAO.update(page);
 
insertRevision(page, preview.getComment(), oldTitle, oldBody);
 
pageDAO.deletePreview(userId, name, lang);
} else {
page = preview.getPage();
pageDAO.insert(page);
pageDAO.deletePreview(userId, name, lang);
insertRevision(page,null, null, null);
}
setPageRedirParams(page);
}
return SUCCESS;
}
 
private void insertRevision(Page page, String comment, String oldTitle, String oldBody) {
Revision r = new Revision();
r.setName(page.getName());
r.setLanguageId(page.getLanguageId());
r.setUserId(sessionUser.getId());
r.setNewTitle(page.getTitle());
r.setNewBody(page.getBody());
r.setOldTitle(oldTitle);
r.setOldBody(oldBody);
r.setComment(comment);
pageDAO.insertRevision(r);
}
 
public String edit() {
if (!isPost()) return INDEX;
String name = input.getString("name");
String lang = input.getString("lang");
if (name.equals("CSS")) {
// does not make sense to have CSS in different languages... (well, maybe it does, but we do NOT want to maintain more than one CSS)
lang = "en";
}
Page page = pageDAO.loadByName(name, Language.fromLocale(lang));
if (page != null) {
 
String oldTitle = page.getTitle();
String oldBody = page.getBody();
 
input.inject(page);
 
page.setModifiedById(sessionUser.getId());
 
if (input.getBoolean("isPreview")) {
pageDAO.insertPreview(sessionUser.getId(), page, input.getString("comment"));
} else {
pageDAO.update(page);
 
insertRevision(page, input.getString("comment"), oldTitle, oldBody);
 
// and now you have to delete the preview!
pageDAO.deletePreview(sessionUser.getId(), page.getName(), page.getLanguage());
}
setPageRedirParams(page);
}
return UPDATED;
}
 
public String discardPreview() {
String name = input.getString("name");
Language lang = Language.fromLocale(input.getString("lang"));
int userId = sessionUser.getId();
pageDAO.deletePreview(userId, name, lang);
output.setValue("name", name);
output.setValue("lang", lang.getLocale());
return REMOVED;
}
 
public String add() {
if (!isPost()) return INDEX;
Page p = input.getObject(Page.class, "newPage");
p.setCreatedById(sessionUser.getId());
 
if (input.getBoolean("isPreview")) {
pageDAO.insertPreview(sessionUser.getId(), p, null);
} else {
pageDAO.insert(p);
// and now you have to delete the preview!
pageDAO.deletePreview(sessionUser.getId(), p.getName(), p.getLanguage());
// also add revision zero...
insertRevision(p, null, null, null);
}
setPageRedirParams(p);
return CREATED;
}
 
public String list() {
List<Page> pages = pageDAO.loadAll(sessionUser.getGroup() == Group.ADMIN);
output.setValue("pages", pages);
return AJAX;
}
 
public String setFrontPage() {
int id = input.getInt("pageId");
Page p = pageDAO.load(id);
if (p != null) {
if (pageDAO.setNewFrontPage(p)) {
output.setValue("lang", p.getLang());
}
}
return UPDATED;
}
 
public String delete() {
int id = input.getInt("pageId");
Page p = pageDAO.load(id);
if (p != null ) {
pageDAO.delete(p);
}
return UPDATED;
}
 
public String getRevisions() {
String name = input.getString("name");
Language lang = Language.fromLocale(input.getString("lang"));
List<Revision> revisions = pageDAO.loadRevisions(name, lang);
output.setValue("revisions", revisions);
boolean isSystemPage = pageDAO.isSystemPage(name);
output.setValue("isSystemPage", isSystemPage);
return AJAX;
}
 
public String getLastRevisions() {
Language lang = Language.fromLocale(input.getString("lang"));
List<Revision> revisions = pageDAO.loadLastRevisions(lang, sessionUser != null);
output.setValue("revisions", revisions);
return AJAX;
}
}