Kawai Wiki

Compare Revisions

Ignore whitespace Rev 205 → Rev 206

/trunk/src/main/java/org/kawai/model/Page.java
4,6 → 4,8
import java.util.Date;
import java.util.Locale;
 
import org.mentawai.util.HttpUtils;
 
/**
* Model class Page.
*
64,6 → 66,8
private int revisionNumber;
/** Attribute comment of Page. */
private String comment;
private String prettyURLFormattedTitle;
 
/**
* Default constructor.
174,7 → 178,16
*/
public void setTitle(String title) {
this.title = title;
if (title != null) {
this.prettyURLFormattedTitle = HttpUtils.getPrettyURLFormatted(title);
} else {
this.prettyURLFormattedTitle = null;
}
}
public String getPrettyURLFormattedTitle() {
return prettyURLFormattedTitle;
}
 
/**
* Gets the body of Page.
/trunk/src/main/java/org/kawai/AppManager.java
245,10 → 245,12
on(AJAX, ajax(new JsonRenderer()));
 
ActionConfig mainAction = action("/Page", PageAction.class)
.prettyURLParams("name", "title")
.on(SHOW, redir()) // for the pretty url
.on(SUCCESS, fwd("/show_page.jsp"));
 
on(INDEX, redir(mainAction));
on(UPDATED, redir(mainAction, true));
on(UPDATED, redir(mainAction));
 
Filter adminFilter = new AuthorizationFilter("admin");
Filter editorFilter = new AuthorizationFilter("admin", "editor");
265,25 → 267,25
 
action("/Login", LoginAction.class)
.on(ERROR, chain(mainAction))
.on(SUCCESS, redir(mainAction, true));
.on(SUCCESS, redir(mainAction));
 
action("/Logout", LogoutAction.class)
.on(SUCCESS, redir(mainAction));
 
action("/Page", PageAction.class, "get")
.filter(editorFilter);
.filter(editorFilter);
 
 
action("/Page", PageAction.class, "getPreview")
.filter(editorFilter);
.filter(editorFilter);
 
action("/Page", PageAction.class, "getRevisions")
.filter(editorFilter);
.filter(editorFilter);
 
action("/Page", PageAction.class, "add")
.filter(editorFilter)
.on(ERROR, chain(mainAction))
.on(CREATED, redir(mainAction, true));
.on(CREATED, redir(mainAction));
 
action("/Page", PageAction.class, "setFrontPage")
.filter(adminFilter);
299,11 → 301,11
 
action("/Page", PageAction.class, "discardPreview")
.filter(editorFilter)
.on(REMOVED, redir(mainAction, true));
.on(REMOVED, redir(mainAction));
 
action("/Page", PageAction.class, "savePreview")
.filter(editorFilter)
.on(SUCCESS, redir(mainAction, true));
.on(SUCCESS, redir(mainAction));
 
action("/Page", PageAction.class, "getCSS")
.on(SUCCESS, fwd("/generate_css.jsp"));
314,7 → 316,7
action("/File", FileAction.class, "upload")
.filter(editorFilter)
.filter(new FileUploadFilter())
.on(SUCCESS, redir(mainAction, true));
.on(SUCCESS, redir(mainAction));
 
action("/File", FileAction.class, "listFiles")
.filter(editorFilter);
/trunk/src/main/java/org/kawai/tag/kcode/AbstractKCode.java
New file
0,0 → 1,18
package org.kawai.tag.kcode;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.PageContext;
 
import org.mentawai.core.Action;
import org.mentawai.core.Forward;
 
public abstract class AbstractKCode implements KCode {
protected Action getAction(PageContext pageContext) {
return (Action) pageContext.getRequest().getAttribute(Forward.ACTION_REQUEST);
}
protected HttpServletRequest getRequest(PageContext pageContext) {
return (HttpServletRequest) pageContext.getRequest();
}
}
/trunk/src/main/java/org/kawai/tag/kcode/PageLink.java
6,8 → 6,10
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
 
import org.kawai.AppManager;
import org.kawai.action.PageAction;
import org.kawai.model.Page;
import org.mentawai.util.HttpUtils;
 
/**
* KCode class PageLink.
15,7 → 17,7
* @author Sergio Oliveira
*
*/
public class PageLink implements KCode {
public class PageLink extends AbstractKCode {
 
/**
* {@inheritDoc}
39,13 → 41,19
@Override
public String process(PageContext pageContext, Map<String, String> attrs, String html) throws JspException {
 
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
HttpServletRequest req = getRequest(pageContext);
 
String name = attrs.get("name");
if (name == null) throw new JspException("Name attribute is mandatory for tag pageLink!");
 
String text = attrs.get("text");
if (text == null) throw new JspException("Text attribute is mandatory for tag pageLink!");
String pretty = attrs.get("pretty");
boolean isPretty = false;
if (pretty != null) {
isPretty = Boolean.parseBoolean(pretty);
}
 
String linkClass = attrs.get("linkClass");
String clickedClass = attrs.get("clickedClass");
61,7 → 69,12
if (page != null && page.getName().equals(name)) {
return "<span" + (clickedClass != null ? " class=\"" + clickedClass + "\"" : "") + ">" + text + "</span>";
} else {
return "<a href=\"" + req.getContextPath() + "/Page.mtw?name=" + name + "\"" + (linkClass != null ? " class=\"" + linkClass + "\"" : "") + ">" + text + "</a>";
if (isPretty) {
String prettyURL = HttpUtils.getPrettyURL("Page", null, name);
return "<a href=\"" + req.getContextPath() + prettyURL + "\"" + (linkClass != null ? " class=\"" + linkClass + "\"" : "") + ">" + text + "</a>";
} else {
return "<a href=\"" + req.getContextPath() + "/Page." + AppManager.EXTENSION + "?name=" + name + "\"" + (linkClass != null ? " class=\"" + linkClass + "\"" : "") + ">" + text + "</a>";
}
}
}
 
/trunk/src/main/java/org/kawai/action/PageAction.java
2,6 → 2,7
 
import java.util.List;
 
import org.kawai.AppManager;
import org.kawai.dao.PageDAO;
import org.kawai.dao.UserDAO;
import org.kawai.model.Group;
10,8 → 11,10
import org.kawai.model.Preview;
import org.kawai.model.Revision;
import org.mentawai.filter.AuthenticationFree;
import org.mentawai.filter.PrettyURLParamFilter;
import org.mentawai.rule.MethodRule;
import org.mentawai.rule.RegexRule;
import org.mentawai.util.HttpUtils;
import org.mentawai.validation.Validatable;
import org.mentawai.validation.ValidationInterceptor;
import org.mentawai.validation.Validator;
307,7 → 310,7
}
return name;
}
 
/**
* {@inheritDoc}
*/
325,6 → 328,18
if (page == null || page.isDeleted() || page.isSystemPage()) {
return INDEX;
}
if (input.getBoolean("isPrettyURL", false)) {
// check if URL is complete with the correct title...
String correctTitle = page.getPrettyURLFormattedTitle();
String inputTitle = input.getString("title");
if (inputTitle == null || !inputTitle.equals(correctTitle)) {
String prettyURL = HttpUtils.getPrettyURL("Page", null, name, correctTitle);
redir(prettyURL);
return SHOW;
}
}
setCSS();
setJavaScript();
setLeftColumn(page.getLanguage());
/trunk/src/main/webapp/WEB-INF/web.xml
13,7 → 13,7
<!-- The Mentawai controller -->
<servlet>
<servlet-name>Controller</servlet-name>
<servlet-class>org.mentawai.core.Controller</servlet-class>
<servlet-class>org.mentawai.core.PrettyURLController</servlet-class>
<init-param>
<param-name>applicationManager</param-name>
<param-value>org.kawai.AppManager</param-value>
30,6 → 30,7
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>*.mtw</url-pattern>
<url-pattern>/mtw/*</url-pattern>
</servlet-mapping>
<!-- filter>
/trunk/pom.xml
80,7 → 80,7
<dependency>
<groupId>me.soliveirajr</groupId>
<artifactId>mentawai</artifactId>
<version>2.3.3-SNAPSHOT</version>
<version>2.4.2-SNAPSHOT</version>
</dependency>
 
</dependencies>