Permalink
Browse files

novo helper para auxiliar a criacao de slugs adicionado. Adicionado t…

…ambem slug nas paginas
  • Loading branch information...
1 parent b4044e1 commit accc6853f37d45a8926a4e138f24e2f6617310d2 @demetriusfeijoo committed May 14, 2012
@@ -15,7 +15,8 @@
<property name="dateOfRegistration" update="false"></property>
<property name="status"></property>
<property name="title"></property>
- <property name="author"></property>
+ <property name="slug"></property>
+ <property name="author" update="false"></property>
<property name="content"></property>
</class>
@@ -20,15 +20,16 @@
<ul>
+ <li><a href="<c:url value="/" />">Ir para o site</a></li>
<li><a href="<c:url value="/adm/user/logout" />">Logout</a></li>
<li><a href="<c:url value="/adm/user/create" />">Criar Usuário</a></li>
- <li><a href="<c:url value="/adm/user" />">Listar Usuário</a></li>
+ <li><a href="<c:url value="/adm/user" />">Listar Usuários</a></li>
<li><a href="<c:url value="/adm/group/create" />">Criar Grupo</a></li>
<li><a href="<c:url value="/adm/group" />">Listar Grupos</a></li>
<li><a href="<c:url value="/adm/permission/create" />">Criar Permissão</a></li>
<li><a href="<c:url value="/adm/permission" />">Listar Permissões</a></li>
<li><a href="<c:url value="/adm/page/create" />">Criar página</a></li>
- <li><a href="<c:url value="/adm/page" />">Listar página</a></li>
+ <li><a href="<c:url value="/adm/page" />">Listar páginas</a></li>
</ul>
@@ -20,7 +20,9 @@
<table>
<tr>
<td>Status: </td>
- <td><label for="ativado">Ativado:</label><input type="radio" name="page.status" id="ativado" value="1" /> <label for="desativado">Desativado:</label><input type="radio" name="page.status" id="desativado" value="0" /> </td>
+ <td>
+ <label for="ativado">Ativado:</label><input type="radio" name="page.status" id="ativado" <c:if test="${page.status || page.status == null }">checked="checked"</c:if> value="1" />
+ <label for="desativado">Desativado:</label><input type="radio" name="page.status" id="desativado" <c:if test="${ !page.status || page.status == null }">checked="checked"</c:if> value="0" /> </td>
</tr>
<tr>
<td>Título: </td>
@@ -125,6 +125,7 @@ $(function(){
dataType: 'json',
colModel : [
{display: 'Id', name : 'id', width : 45, sortable : true, align: 'left'},
+ {display: 'Título', name : 'title', width : 210, sortable : true, align: 'left'},
{display: 'Autor', name : 'author', width : 210, sortable : true, align: 'left'},
{display: 'Data do registro', name : 'dateOfRegistration', width : 210, sortable : true, align: 'left'}
],
@@ -143,6 +144,7 @@ $(function(){
],
searchitems : [
{display: 'Id', name : 'id'},
+ {display: 'Título', name : 'title'},
{display: 'Autor', name : 'author'}
],
sortname: "id",
@@ -154,7 +156,7 @@ $(function(){
resizable: false,
showTableToggleBtn: true,
singleSelect: true,
- width: 520,
+ width: 730,
height: 200
});
@@ -11,7 +11,7 @@
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.view.Results;
import br.com.umake.dao.AdmGroupDao;
-import br.com.umake.helper.FlexiGridJson;
+import br.com.umake.helper.flexigrid.FlexiGridJson;
import br.com.umake.model.AdmGroup;
import br.com.umake.permissions.PermissionAnnotation;
import br.com.umake.permissions.PermissionType;
@@ -11,7 +11,7 @@
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.view.Results;
import br.com.umake.dao.AdmPermissionDao;
-import br.com.umake.helper.FlexiGridJson;
+import br.com.umake.helper.flexigrid.FlexiGridJson;
import br.com.umake.model.AdmPermission;
import br.com.umake.permissions.PermissionAnnotation;
import br.com.umake.permissions.PermissionType;
@@ -17,7 +17,7 @@
import br.com.umake.dao.AdmGroupDao;
import br.com.umake.dao.AdmPermissionDao;
import br.com.umake.dao.AdmUserDao;
-import br.com.umake.helper.FlexiGridJson;
+import br.com.umake.helper.flexigrid.FlexiGridJson;
import br.com.umake.interceptor.AdmUserControl;
import br.com.umake.model.AdmGroup;
import br.com.umake.model.AdmPermission;
@@ -5,6 +5,7 @@
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.view.Results;
import br.com.umake.model.Application;
+import br.com.umake.model.Page;
@Resource
public class IndexController {
@@ -19,20 +20,20 @@ public IndexController(Result result, Application application){
}
- //@Get("/")
- public void index(){
+ @Get("/")
+ public void index(String pageOrCategory, String complement ){
//this.result.forwardTo("/WEB-INF/jsp/index.jsp");
- this.result.use(Results.http()).body("inicial");
+ this.result.use(Results.http()).body(pageOrCategory+" - "+complement);
}
- //@Get({"/{namePage}", "/{namePage}/{teste}"})
- public void page(String namePage, String teste ){
-
- this.result.use(Results.http()).body(namePage+" "+teste);
+ @Get("/{page.slug}")
+ public void page(Page page){
+
+ this.result.use(Results.http()).body(page.getSlug());
}
-
+
}
@@ -13,7 +13,8 @@
import br.com.caelum.vraptor.ioc.RequestScoped;
import br.com.caelum.vraptor.view.Results;
import br.com.umake.dao.PageDao;
-import br.com.umake.helper.FlexiGridJson;
+import br.com.umake.helper.flexigrid.FlexiGridJson;
+import br.com.umake.helper.utils.TextHelper;
import br.com.umake.interceptor.AdmUserControl;
import br.com.umake.model.Page;
import br.com.umake.permissions.PermissionAnnotation;
@@ -73,21 +74,22 @@ public void create(Page page) {
page.setDateOfRegistration( new Date() );
page.setAuthor(this.admUserControl.getUserAdm().getName());
+ page.setSlug(TextHelper.createSlug(page.getTitle()));
- System.out.println(page.getAuthor()+page.getContent()+page.getTitle()+page.getDateOfRegistration()+page.getStatus());
this.result.include("retorno", this.pageDao.insert(page) );
this.result.include("tipoSubmit", "cadastrado" );
-
- this.result.include("page", page);
+ this.result.include("page", page);
this.result.redirectTo(this).formPage();
}
@Put("adm/page")
@Restrictable(permissions={ @PermissionAnnotation(context="ADM_PAGE", permissionsTypes = { PermissionType.EDIT})})
- public void editAdmGroup(final Page page){
-
+ public void edit(final Page page){
+
+ page.setSlug(TextHelper.createSlug(page.getTitle()));
+
this.result.include("retorno", this.pageDao.edit(page) );
this.result.include("tipoSubmit", "editado" );
this.result.include("page", this.pageDao.get(page));
@@ -1,4 +1,4 @@
-package br.com.umake.helper;
+package br.com.umake.helper.flexigrid;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -1,4 +1,4 @@
-package br.com.umake.helper;
+package br.com.umake.helper.flexigrid;
import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -59,7 +59,7 @@ private int getTotalFieldsAnnotedWithColumn(Field[] fields){
for (Field field : fields){
- if(field.isAnnotationPresent(br.com.umake.helper.Column.class))
+ if(field.isAnnotationPresent(br.com.umake.helper.flexigrid.Column.class))
totalFieldsWithAnnotationColumn++;
}
@@ -74,7 +74,7 @@ private String getNameColumnId(List<T> rows){
for (Field field : fields) {
- if(field.isAnnotationPresent(br.com.umake.helper.Id.class)){
+ if(field.isAnnotationPresent(br.com.umake.helper.flexigrid.Id.class)){
return field.getName();
@@ -103,9 +103,9 @@ private String getNameColumnId(List<T> rows){
for (Field field : fields){
- if(field.isAnnotationPresent(br.com.umake.helper.Column.class)){
+ if(field.isAnnotationPresent(br.com.umake.helper.flexigrid.Column.class)){
- Column column = field.getAnnotation(br.com.umake.helper.Column.class);
+ Column column = field.getAnnotation(br.com.umake.helper.flexigrid.Column.class);
if( column.position() <= minOfTheLoop && !fieldsMappeds.contains(field.getName()) ){
@@ -1,4 +1,4 @@
-package br.com.umake.helper;
+package br.com.umake.helper.flexigrid;
import java.util.List;
@@ -1,4 +1,4 @@
-package br.com.umake.helper;
+package br.com.umake.helper.flexigrid;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -0,0 +1,23 @@
+package br.com.umake.helper.utils;
+
+public final class TextHelper {
+
+ public static String createSlug( String originalForm ){
+
+ String generateSlug = originalForm.replaceAll("[ÁáÀàÃãÂâÄä]", "a");
+ generateSlug = generateSlug.replaceAll("[ÉéÈèÊêËë]", "e");
+ generateSlug = generateSlug.replaceAll("[ÍíÌìÎîÏï]", "i");
+ generateSlug = generateSlug.replaceAll("[ÓóÒòÕõÔôÖö]", "o");
+ generateSlug = generateSlug.replaceAll("[ÚúÙùÛûÜü]", "u");
+ generateSlug = generateSlug.replaceAll("[Ññ]", "n");
+ generateSlug = generateSlug.replaceAll("[Çç]", "c");
+ generateSlug = generateSlug.replaceAll("[ÿÝý]", "y");
+ generateSlug = generateSlug.replaceAll("[ª]", "a.");
+ generateSlug = generateSlug.replaceAll("[º]", "o.");
+ generateSlug = generateSlug.replaceAll("(\\s)++", "-");
+
+ return generateSlug;
+
+ }
+
+}
@@ -6,8 +6,8 @@
import java.util.Set;
import br.com.caelum.vraptor.ioc.Component;
-import br.com.umake.helper.Column;
-import br.com.umake.helper.Id;
+import br.com.umake.helper.flexigrid.Column;
+import br.com.umake.helper.flexigrid.Id;
@Component
public class AdmGroup{
@@ -6,8 +6,8 @@
import java.util.Set;
import br.com.caelum.vraptor.ioc.Component;
-import br.com.umake.helper.Column;
-import br.com.umake.helper.Id;
+import br.com.umake.helper.flexigrid.Column;
+import br.com.umake.helper.flexigrid.Id;
@Component
public class AdmPermission {
@@ -9,8 +9,8 @@
import java.util.Set;
import br.com.caelum.vraptor.ioc.Component;
-import br.com.umake.helper.Column;
-import br.com.umake.helper.Id;
+import br.com.umake.helper.flexigrid.Column;
+import br.com.umake.helper.flexigrid.Id;
@Component
public class AdmUser implements Serializable {
@@ -5,20 +5,22 @@
import java.util.Date;
import br.com.caelum.vraptor.ioc.Component;
-import br.com.umake.helper.Column;
-import br.com.umake.helper.Id;
+import br.com.umake.helper.flexigrid.Column;
+import br.com.umake.helper.flexigrid.Id;
@Component
public class Page {
@Column(position=1)
@Id
private Long id;
- @Column(position=3)
+ @Column(position=4)
private Date dateOfRegistration;
private Boolean status;
- private String title;
@Column(position=2)
+ private String title;
+ private String slug;
+ @Column(position=3)
private String author;
private String content;
@@ -68,6 +70,14 @@ public String getTitle(){
}
+ public String getSlug(){
+
+
+ return this.slug;
+
+ }
+
+
public String getAuthor(){
return this.author;
@@ -101,6 +111,12 @@ public void setStatus( Boolean status ){
public void setTitle( String title ){
this.title = title;
+
+ }
+
+ public void setSlug(String slug){
+
+ this.slug = slug;
}
@@ -15,7 +15,8 @@
<property name="dateOfRegistration" update="false"></property>
<property name="status"></property>
<property name="title"></property>
- <property name="author"></property>
+ <property name="slug"></property>
+ <property name="author" update="false"></property>
<property name="content"></property>
</class>

0 comments on commit accc685

Please sign in to comment.