diff --git a/nb-configuration.xml b/nb-configuration.xml
new file mode 100644
index 0000000..0a6f886
--- /dev/null
+++ b/nb-configuration.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+ 1.5
+ WildFly
+ true
+ apache20
+ /less:/css
+ false
+ false
+
+
+ /scss:/css
+ js/libs
+ false
+
+
diff --git a/nb_jr_remoting.cfg b/nb_jr_remoting.cfg
new file mode 100644
index 0000000..2c9de9c
--- /dev/null
+++ b/nb_jr_remoting.cfg
@@ -0,0 +1,8 @@
+
+
+
+ false
+ 200
+ true
+ {"syncEnabled":"false","serverAuthenticationPassword":"","httpBasicAuthenticationUser":"","httpBasicAuthenticationPassword":"","useServerAuthentication":"false","deleteFilesOnServer":"true","useHttpBasicAuthentication":"false","url":"http:\/\/127.0.0.1"}
+
diff --git a/nbactions.xml b/nbactions.xml
new file mode 100644
index 0000000..3c2e308
--- /dev/null
+++ b/nbactions.xml
@@ -0,0 +1,61 @@
+
+
+
+ run
+
+ war
+ ear
+ ejb
+
+
+ package
+
+
+ true
+ main.action
+
+
+
+ debug
+
+ war
+ ear
+ ejb
+
+
+ package
+
+
+ true
+ true
+ main.action
+
+
+
+ profile
+
+ ejb
+ ear
+ war
+
+
+ package
+
+
+ true
+ true
+ main.action
+
+
+
+ rebuild
+
+ *
+
+
+ clean
+ install
+
+
+
+
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..976c5cd
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,112 @@
+
+ 4.0.0
+
+ it.jee_book
+ JakiWiki
+ war
+ 1.0-SNAPSHOT
+
+ JakiWiki
+ http://maven.apache.org
+
+
+
+ java.net2
+ http://download.java.net/maven/2/
+
+
+
+
+
+ javax.servlet
+ servlet-api
+ 2.5
+ provided
+
+
+ javax.servlet.jsp
+ jsp-api
+ 2.1
+ provided
+
+
+ org.apache.commons
+ commons-lang3
+ 3.4
+
+
+ org.eclipse.persistence
+ eclipselink
+ 2.5.2
+ provided
+
+
+ org.hibernate
+ hibernate-entitymanager
+ 4.3.1.Final
+
+
+ org.hibernate.javax.persistence
+ hibernate-jpa-2.1-api
+ 1.0.0.Final
+
+
+
+ mysql
+ mysql-connector-java
+ 6.0.2
+
+
+ org.seleniumhq.selenium
+ selenium-java
+ test
+ 2.44.0
+
+
+ com.opera
+ operadriver
+ test
+ 1.5
+
+
+ org.seleniumhq.selenium
+ selenium-remote-driver
+
+
+
+
+ junit
+ junit
+ test
+ 4.11
+
+
+ javaee
+ javaee-api
+ 5
+ provided
+
+
+ it.jee_book
+ JakiWiki
+ 1.0-SNAPSHOT
+ war
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.0.2
+
+ 1.5
+ 1.5
+ true
+
+
+
+
+
diff --git a/src/main/java/it/jee_book/jakiwiki/actions/ListaPagineAction.java b/src/main/java/it/jee_book/jakiwiki/actions/ListaPagineAction.java
new file mode 100644
index 0000000..c9df887
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/actions/ListaPagineAction.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.actions;
+
+import it.jee_book.jakiwiki.business.pagine.PaginaManager;
+import it.jee_book.jakiwiki.business.pagine.PaginaManagerDelegate;
+import it.jee_book.jakiwiki.context.ContextObjectFactory;
+import it.jee_book.jakiwiki.context.RequestObject;
+import it.jee_book.jakiwiki.context.ResponseAndView;
+import it.jee_book.jakiwiki.context.ResponseObject;
+import it.jee_book.jakiwiki.controller.action.Action;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+class ListaPagineAction implements Action {
+
+ private PaginaManager paginaManager = new PaginaManagerDelegate();
+
+ @Override
+ public ResponseAndView createResponseAndView(RequestObject requestObject) {
+ ResponseObject response = ContextObjectFactory.getResponseObject();
+ String tipoRichiesta = (String) requestObject.getValue("tipo_richiesta");
+
+ if ("tutte".equals(tipoRichiesta)) {
+ response.setValue("intestazione", "Tutte le pagine");
+ response.setValue("lista", paginaManager.elencaPagine());
+ } else {
+ response.setValue("intestazione", "Ultime pagine modificate");
+ response.setValue("lista", paginaManager.elencaPagineRecenti());
+ }
+
+ return new ResponseAndView(response, "list");
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/actions/ModificaPaginaAction.java b/src/main/java/it/jee_book/jakiwiki/actions/ModificaPaginaAction.java
new file mode 100644
index 0000000..33a2c4d
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/actions/ModificaPaginaAction.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.actions;
+
+import it.jee_book.jakiwiki.business.pagine.PaginaManager;
+import it.jee_book.jakiwiki.business.pagine.PaginaManagerDelegate;
+import it.jee_book.jakiwiki.context.ContextObjectFactory;
+import it.jee_book.jakiwiki.context.RequestObject;
+import it.jee_book.jakiwiki.context.ResponseAndView;
+import it.jee_book.jakiwiki.context.ResponseObject;
+import it.jee_book.jakiwiki.controller.action.Action;
+import it.jee_book.jakiwiki.exception.JakiWikiException;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class ModificaPaginaAction implements Action {
+
+ private PaginaManager paginaManager = new PaginaManagerDelegate();
+
+ public ResponseAndView createResponseAndView(RequestObject requestObject) throws JakiWikiException {
+ ResponseObject response = ContextObjectFactory.getResponseObject();
+ String titolo = (String) requestObject.getValue("titolo");
+
+ response.setValue("titolo", titolo);
+ response.setValue("contenuto", paginaManager.leggi(titolo));
+
+ return new ResponseAndView(response, "edit");
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/actions/PulsantieraAction.java b/src/main/java/it/jee_book/jakiwiki/actions/PulsantieraAction.java
new file mode 100644
index 0000000..0473826
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/actions/PulsantieraAction.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.actions;
+
+import it.jee_book.jakiwiki.context.RequestObject;
+import it.jee_book.jakiwiki.context.ResponseAndView;
+import it.jee_book.jakiwiki.controller.action.Action;
+import it.jee_book.jakiwiki.exception.JakiWikiException;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class PulsantieraAction implements Action {
+
+ private final String PRINCIPALE = "principale";
+ private final String RECENTI = "recenti";
+ private final String TUTTE = "tutte";
+ private final String EMAIL = "email";
+ private final String CONFIGURA = "configura";
+
+ @Override
+ public ResponseAndView createResponseAndView(RequestObject requestObject) throws JakiWikiException {
+
+ if (requestObject.getValue(PRINCIPALE) != null) {
+ requestObject.setValue("titolo", null);
+ return new VediPaginaAction().createResponseAndView(requestObject);
+ }
+
+ if (requestObject.getValue(TUTTE) != null) {
+ requestObject.setValue("tipo_richiesta", "tutte");
+ return new ListaPagineAction().createResponseAndView(requestObject);
+ }
+
+ if (requestObject.getValue(RECENTI) != null) {
+ requestObject.setValue("tipo_richiesta", "recenti");
+ return new ListaPagineAction().createResponseAndView(requestObject);
+ }
+
+ if (requestObject.getValue(EMAIL) != null) {
+ return new ResponseAndView(null, "email");
+ }
+
+ throw new JakiWikiException("Action non valida");
+ }
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/actions/VediPaginaAction.java b/src/main/java/it/jee_book/jakiwiki/actions/VediPaginaAction.java
new file mode 100644
index 0000000..ff901de
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/actions/VediPaginaAction.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.actions;
+
+import it.jee_book.jakiwiki.business.pagine.PaginaManager;
+import it.jee_book.jakiwiki.business.pagine.PaginaManagerDelegate;
+import it.jee_book.jakiwiki.context.RequestObject;
+import it.jee_book.jakiwiki.context.ResponseAndView;
+import it.jee_book.jakiwiki.context.ResponseObject;
+import it.jee_book.jakiwiki.controller.action.Action;
+import it.jee_book.jakiwiki.model.Pagina;
+import it.jee_book.jakiwiki.utils.TextConverter;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class VediPaginaAction implements Action {
+
+ private PaginaManager paginaManager = new PaginaManagerDelegate();
+
+ @Override
+ public ResponseAndView createResponseAndView(RequestObject requestObject) {
+ ResponseObject response = new ResponseObject();
+ String titolo = (String) requestObject.getValue("titolo");
+
+ if (titolo == null) {
+ titolo = "PaginaPrincipale";
+ }
+
+ Pagina pagina = paginaManager.leggi(titolo);
+ response.setValue("titolo", titolo);
+ response.setValue("contenuto", TextConverter.convert(pagina.getContenuto()));
+
+ return new ResponseAndView(response, "main");
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/business/AbstractDelegate.java b/src/main/java/it/jee_book/jakiwiki/business/AbstractDelegate.java
new file mode 100644
index 0000000..940df21
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/business/AbstractDelegate.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.business;
+
+import it.jee_book.jakiwiki.exception.JakiWikiException;
+import javax.naming.InitialContext;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public abstract class AbstractDelegate {
+
+ /**
+ * In ogni delegato è necessario implementare questo metodo in modo che
+ * ritorni il nome jndi del servizio.
+ *
+ * @return il nome del servizio
+ */
+ protected abstract String getServiceName();
+
+ /**
+ * Accede al servizio
+ *
+ * @return
+ */
+ protected Object getService() throws JakiWikiException {
+ InitialContext context;
+
+ try {
+ context = new InitialContext();
+ Object lookup = context.lookup(getServiceName());
+ return lookup;
+ } catch (Exception e) {
+ throw new JakiWikiException(JakiWikiException.SERVICE_CONNECTION_ERROR, "Non esiste il servizio denominato "
+ + getServiceName(), e);
+ }
+ }
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/business/email/EmailManager.java b/src/main/java/it/jee_book/jakiwiki/business/email/EmailManager.java
new file mode 100644
index 0000000..87e2396
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/business/email/EmailManager.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.business.email;
+
+import javax.ejb.Local;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+@Local
+public interface EmailManager {
+
+ /**
+ *
+ * @param mittente
+ * @param destinatario
+ * @param commento
+ * @param titolo
+ */
+ public void sendEmail(String mittente, String destinatario, String commento, String titolo);
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/business/email/EmailManagerDelegate.java b/src/main/java/it/jee_book/jakiwiki/business/email/EmailManagerDelegate.java
new file mode 100644
index 0000000..a8fc7b9
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/business/email/EmailManagerDelegate.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.business.email;
+
+import it.jee_book.jakiwiki.business.AbstractDelegate;
+import it.jee_book.jakiwiki.exception.JakiWikiException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class EmailManagerDelegate extends AbstractDelegate implements EmailManager {
+
+ @Override
+ protected String getServiceName() {
+ return "java:global/JakiWiki/EmailManager";
+ }
+
+ public void sendEmail(String mittente, String destinatario, String commento, String titolo) {
+ try {
+ ((EmailManager) getService()).sendEmail(mittente, destinatario, commento, titolo);
+ } catch (JakiWikiException ex) {
+ Logger.getLogger(EmailManagerDelegate.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/business/email/EmailManagerImplementation.java b/src/main/java/it/jee_book/jakiwiki/business/email/EmailManagerImplementation.java
new file mode 100644
index 0000000..3dfc818
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/business/email/EmailManagerImplementation.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.business.email;
+
+import it.jee_book.jakiwiki.integration.dao.PaginaDao;
+import it.jee_book.jakiwiki.integration.mail.EmailIntegrator;
+import it.jee_book.jakiwiki.model.Pagina;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+@Stateless
+public class EmailManagerImplementation implements EmailManager {
+
+ @EJB
+ private EmailIntegrator emailIntegrator;
+
+ @EJB
+ private PaginaDao dao;
+
+ public void sendEmail(String mittente, String destinatario, String commento, String titolo) {
+ Pagina pagina = dao.leggi(titolo);
+ emailIntegrator.sendEmail(mittente, destinatario, commento, pagina);
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/business/pagine/PaginaManager.java b/src/main/java/it/jee_book/jakiwiki/business/pagine/PaginaManager.java
new file mode 100644
index 0000000..428f4d8
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/business/pagine/PaginaManager.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.business.pagine;
+
+import it.jee_book.jakiwiki.model.Pagina;
+import java.util.List;
+import javax.ejb.Local;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+@Local
+public interface PaginaManager {
+
+ /**
+ *
+ * @param pagina
+ */
+ public void save(Pagina pagina);
+
+ /**
+ *
+ * @param titolo
+ */
+ public void elimina(String titolo);
+
+ /**
+ *
+ * @param titolo
+ * @return la pagina con che si chiama titolo
+ */
+ public Pagina leggi(String titolo);
+
+ /**
+ *
+ * @return l'elenco di tutte le pagine
+ */
+ public List elencaPagine();
+
+ /**
+ *
+ * @return l'elenco di tutte le recenti pagine
+ */
+ public List elencaPagineRecenti();
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/business/pagine/PaginaManagerDelegate.java b/src/main/java/it/jee_book/jakiwiki/business/pagine/PaginaManagerDelegate.java
new file mode 100644
index 0000000..171f0ab
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/business/pagine/PaginaManagerDelegate.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.business.pagine;
+
+import it.jee_book.jakiwiki.business.AbstractDelegate;
+import it.jee_book.jakiwiki.exception.JakiWikiException;
+import it.jee_book.jakiwiki.model.Pagina;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class PaginaManagerDelegate extends AbstractDelegate implements PaginaManager {
+
+ @Override
+ protected String getServiceName() {
+ return "java:global/JakiWiki/PaginaManagerImplementation";
+ }
+
+ public void save(Pagina pagina) {
+ try {
+ ((PaginaManager) getService()).save(pagina);
+ } catch (JakiWikiException ex) {
+ Logger.getLogger(PaginaManagerDelegate.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ public void elimina(String titolo) {
+ try {
+ ((PaginaManager) getService()).elimina(titolo);
+ } catch (JakiWikiException ex) {
+ Logger.getLogger(PaginaManagerDelegate.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ public Pagina leggi(String titolo) {
+ try {
+ return ((PaginaManager) getService()).leggi(titolo);
+ } catch (JakiWikiException ex) {
+ Logger.getLogger(PaginaManagerDelegate.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+ return null;
+ }
+
+ public List elencaPagine() {
+ try {
+ ((PaginaManager) getService()).elencaPagine();
+ } catch (JakiWikiException ex) {
+ Logger.getLogger(PaginaManagerDelegate.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+ return null;
+ }
+
+ public List elencaPagineRecenti() {
+ try {
+ return ((PaginaManager) getService()).elencaPagineRecenti();
+ } catch (JakiWikiException ex) {
+ Logger.getLogger(PaginaManagerDelegate.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/business/pagine/PaginaManagerImplementation.java b/src/main/java/it/jee_book/jakiwiki/business/pagine/PaginaManagerImplementation.java
new file mode 100644
index 0000000..dce91ca
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/business/pagine/PaginaManagerImplementation.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.business.pagine;
+
+import it.jee_book.jakiwiki.integration.dao.PaginaDao;
+import it.jee_book.jakiwiki.model.Pagina;
+import java.util.Date;
+import java.util.List;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+@Stateless
+public class PaginaManagerImplementation implements PaginaManager {
+
+ @EJB
+ private PaginaDao dao;
+
+ public void save(Pagina pagina) {
+ dao.salva(pagina);
+ }
+
+ public void elimina(String titolo) {
+ Pagina pagina = leggi(titolo);
+ dao.elimina(pagina);
+ }
+
+ public Pagina leggi(String titolo) {
+ Pagina p = dao.leggi(titolo);
+
+ if (p == null) {
+ p = new Pagina();
+ p.setTitolo("");
+ p.setUltimaModifica(new Date());
+ p.setContenuto("Questa è una nuova pagina");
+ }
+
+ return p;
+ }
+
+ public List elencaPagine() {
+ return dao.elencaPagine(0);
+ }
+
+ public List elencaPagineRecenti() {
+ return dao.elencaPagine(3);
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/context/ContextObjectFactory.java b/src/main/java/it/jee_book/jakiwiki/context/ContextObjectFactory.java
new file mode 100644
index 0000000..bc5a3d9
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/context/ContextObjectFactory.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.context;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class ContextObjectFactory {
+
+ /**
+ *
+ * @param request
+ * @return
+ */
+ public static RequestObject getRequestObject(HttpServletRequest request) {
+
+ RequestObject ret = new RequestObject();
+ String path = request.getServletPath().split(".action")[0];
+
+ if (path.startsWith("/")) {
+ path.substring(1);
+ }
+
+ ret.setRequestCommand(path);
+
+ // mappa i parametri della request
+ Map pMap = request.getParameterMap();
+ for (Iterator listaParams = pMap.keySet().iterator(); listaParams.hasNext();) {
+ String key = (String) listaParams.next();
+ ret.request.put(key, pMap.get(key));
+ }
+
+ // mappa i parametri della sessione
+ for (Enumeration listaSession = request.getSession().getAttributeNames(); listaSession.hasMoreElements();) {
+ String key = (String) listaSession.nextElement();
+ ret.session.put(key, request.getSession().getAttribute(key));
+ }
+
+ return ret;
+ }
+
+ public static ResponseObject getResponseObject() {
+ return new ResponseObject();
+ }
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/context/RequestObject.java b/src/main/java/it/jee_book/jakiwiki/context/RequestObject.java
new file mode 100644
index 0000000..9afd2f3
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/context/RequestObject.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.context;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class RequestObject {
+
+ protected Map request = new HashMap();
+ protected Map session = new HashMap();
+
+ protected String requestCommand;
+
+ /**
+ * Imposta una chiave-valore nella richiesta corrente
+ */
+ public void setValue(String key, Object value) {
+ request.put(key, value);
+ }
+
+ /**
+ * Imposta chiave-valore nella sessione corrente
+ */
+ public void setValueInSession(String key, Object value) {
+ session.put(key, value);
+ }
+
+ /**
+ * Ritorna il valore associato ad una chiave, cercandolo prima nell
+ * richiesta corrente e poi nella sessione.
+ */
+ public Object getValue(String key) {
+ Object value = request.get(key);
+
+ if (value == null) {
+ return value = session.get(key);
+ }
+
+ if (value instanceof Object[]) {
+ value = ((Object[]) value)[0];
+ }
+
+ return value;
+ }
+
+ /**
+ * Ritorna tutte le chiavi a cui sono associati dei valore nella richiesta
+ * corrente.
+ */
+ public Set getRequestKeys() {
+ return request.keySet();
+ }
+
+ /**
+ * Ritorna tutte le chiavi a cui sono associati dei valori nella sessione
+ * corrente.
+ */
+ public Set getSessionKeys() {
+ return session.keySet();
+ }
+
+ public String getRequestCommand() {
+ return requestCommand;
+ }
+
+ public void setRequestCommand(String requestCommand) {
+ this.requestCommand = requestCommand;
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/context/ResponseAndView.java b/src/main/java/it/jee_book/jakiwiki/context/ResponseAndView.java
new file mode 100644
index 0000000..eb6d783
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/context/ResponseAndView.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.context;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class ResponseAndView {
+
+ protected String view;
+ protected ResponseObject responseObject;
+
+ public ResponseAndView(ResponseObject responseObject, String viewName) {
+ this.view = viewName;
+ this.responseObject = responseObject;
+ }
+
+ public String getView() {
+ return view;
+ }
+
+ public void setView(String view) {
+ this.view = view;
+ }
+
+ public ResponseObject getResponseObject() {
+ return responseObject;
+ }
+
+ public void setResponseObject(ResponseObject responseObject) {
+ this.responseObject = responseObject;
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/context/ResponseObject.java b/src/main/java/it/jee_book/jakiwiki/context/ResponseObject.java
new file mode 100644
index 0000000..b303c06
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/context/ResponseObject.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.context;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class ResponseObject {
+
+ protected Map response = new HashMap();
+ protected Map session = new HashMap();
+
+ protected String responseCommand;
+
+ /**
+ * Imposta una chiave-valore nella richiesta corrente
+ */
+ public void setValue(String key, Object value) {
+ response.put(key, value);
+ }
+
+ /**
+ * Imposta chiave-valore nella sessione corrente
+ */
+ public void setValueInSession(String key, Object value) {
+ session.put(key, value);
+ }
+
+ /**
+ * Ritorna il valore associato ad una chiave, cercandolo prima nell
+ * richiesta corrente e poi nella sessione.
+ */
+ public Object getValue(String key) {
+ Object value = response.get(key);
+
+ if (value == null) {
+ return value = session.get(key);
+ }
+
+ if (value instanceof Object[]) {
+ value = ((Object[]) value)[0];
+ }
+
+ return value;
+ }
+
+ /**
+ * Ritorna tutte le chiavi a cui sono associati dei valore nella richiesta
+ * corrente.
+ */
+ public Set getResponseKeys() {
+ return response.keySet();
+ }
+
+ /**
+ * Ritorna tutte le chiavi a cui sono associati dei valori nella sessione
+ * corrente.
+ */
+ public Set getSessionKeys() {
+ return session.keySet();
+ }
+
+ public String getResponseCommand() {
+ return responseCommand;
+ }
+
+ public void setResponseCommand(String responseCommand) {
+ this.responseCommand = responseCommand;
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/context/ViewDispatcher.java b/src/main/java/it/jee_book/jakiwiki/context/ViewDispatcher.java
new file mode 100644
index 0000000..a0ae7e6
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/context/ViewDispatcher.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.context;
+
+import java.io.IOException;
+import java.util.Iterator;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class ViewDispatcher {
+
+ protected RequestDispatcher dispatcher;
+
+ /**
+ *
+ * @param requestDispatcher
+ */
+ public ViewDispatcher(RequestDispatcher requestDispatcher) {
+ dispatcher = requestDispatcher;
+ }
+
+ /**
+ *
+ * @param request
+ * @param response
+ * @param responseAndView
+ * @throws ServletException
+ * @throws IOException
+ */
+ public void forward(HttpServletRequest request, HttpServletResponse response, ResponseAndView responseAndView)
+ throws ServletException, IOException {
+ mergeDataRequest(request, responseAndView.getResponseObject());
+ dispatcher.forward(request, response);
+ }
+
+ private void mergeDataRequest(HttpServletRequest request, ResponseObject responseObject) {
+
+ if (responseObject == null) {
+ return;
+ }
+
+ for (Iterator listaParams = responseObject.getResponseKeys().iterator(); listaParams.hasNext();) {
+ String key = (String) listaParams.next();
+ request.setAttribute(key, responseObject.getValue(key));
+ }
+
+ for (Iterator listaParams = responseObject.getSessionKeys().iterator(); listaParams.hasNext();) {
+ String key = (String) listaParams.next();
+ request.getSession().setAttribute(key, responseObject.getValue(key));
+ }
+ }
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/controller/ActionFactory.java b/src/main/java/it/jee_book/jakiwiki/controller/ActionFactory.java
new file mode 100644
index 0000000..c29c333
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/controller/ActionFactory.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.controller;
+
+import it.jee_book.jakiwiki.context.RequestObject;
+import it.jee_book.jakiwiki.controller.action.Action;
+import it.jee_book.jakiwiki.exception.JakiWikiException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class ActionFactory {
+
+ protected static Map actions = new HashMap();
+
+ /**
+ *
+ * @param requestObject
+ * @return
+ * @throws JakiWikiException
+ */
+ public static Action createAction(RequestObject requestObject) throws JakiWikiException {
+
+ String requestCommand = requestObject.getRequestCommand().substring(1);
+ Action action = (Action) actions.get(requestCommand);
+
+ if (action == null) {
+ String actionClassName = Configuration.getAction(requestCommand);
+
+ if (actionClassName == null) {
+ throw new JakiWikiException(JakiWikiException.ACTION_ERROR, "Non esiste nessuna action");
+ }
+
+ try {
+ action = (Action) Class.forName(actionClassName).newInstance();
+ actions.put(requestCommand, action);
+ } catch (Throwable t) {
+ throw new JakiWikiException(JakiWikiException.ACTION_ERROR, actionClassName, t);
+ }
+ }
+
+ return action;
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/controller/Configuration.java b/src/main/java/it/jee_book/jakiwiki/controller/Configuration.java
new file mode 100644
index 0000000..24f04d4
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/controller/Configuration.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.controller;
+
+import java.io.FileInputStream;
+import java.util.Properties;
+import javax.servlet.ServletConfig;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class Configuration {
+
+ protected static Properties views;
+ protected static Properties actions;
+
+ /**
+ *
+ * @param config
+ */
+ public static void init(ServletConfig config) {
+ String actionFile = config.getServletContext().getRealPath("WEB-INF/actions.properties");
+ String viewsFile = config.getServletContext().getRealPath("WEB-INF/views.properties");
+ views = new Properties();
+ actions = new Properties();
+ try {
+ views.load(new FileInputStream(viewsFile));
+ actions.load(new FileInputStream(actionFile));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ * @param view
+ * @return
+ */
+ public static String getViewPage(String view) {
+ return views.getProperty(view);
+ }
+
+ /**
+ *
+ * @param action
+ * @return
+ */
+ public static String getAction(String action) {
+ return actions.getProperty(action);
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/controller/action/Action.java b/src/main/java/it/jee_book/jakiwiki/controller/action/Action.java
new file mode 100644
index 0000000..3b11f9c
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/controller/action/Action.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.controller.action;
+
+import it.jee_book.jakiwiki.context.RequestObject;
+import it.jee_book.jakiwiki.context.ResponseAndView;
+import it.jee_book.jakiwiki.exception.JakiWikiException;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public interface Action {
+
+ /**
+ *
+ * @param requestObject
+ * @return
+ * @throws it.jee_book.jakiwiki.exception.JakiWikiException
+ */
+ ResponseAndView createResponseAndView(RequestObject requestObject) throws JakiWikiException;
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/exception/JakiWikiException.java b/src/main/java/it/jee_book/jakiwiki/exception/JakiWikiException.java
new file mode 100644
index 0000000..e06c0aa
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/exception/JakiWikiException.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.exception;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class JakiWikiException extends Throwable {
+
+ public static final String ACTION_ERROR = "Azione errata";
+ public static String SERVICE_CONNECTION_ERROR = "Errore di connessione al servizio";
+
+ private String error;
+ private String msg;
+ private Throwable exception;
+
+ public JakiWikiException(String error, String msg) {
+ this(error, msg, null);
+ }
+
+ public JakiWikiException(String error, String msg, Throwable exception) {
+ this.error = error;
+ this.msg = msg;
+ this.exception = exception;
+ }
+
+ public JakiWikiException(String string) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ public String getError() {
+ return error;
+ }
+
+ public void setError(String error) {
+ this.error = error;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+
+ public void setMsg(String msg) {
+ this.msg = msg;
+ }
+
+ public Throwable getException() {
+ return exception;
+ }
+
+ public void setException(Throwable exception) {
+ this.exception = exception;
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/integration/dao/PaginaDao.java b/src/main/java/it/jee_book/jakiwiki/integration/dao/PaginaDao.java
new file mode 100644
index 0000000..c819950
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/integration/dao/PaginaDao.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.integration.dao;
+
+import it.jee_book.jakiwiki.model.Pagina;
+import java.util.List;
+import javax.ejb.Local;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+@Local
+public interface PaginaDao {
+
+ /**
+ *
+ * @param pagina
+ */
+ public void salva(Pagina pagina);
+
+ /**
+ *
+ * @param pagina
+ */
+ public void elimina(Pagina pagina);
+
+ /**
+ *
+ * @param titolo
+ * @return
+ */
+ public Pagina leggi(String titolo);
+
+ /**
+ *
+ * @param maxRisultati
+ * @return
+ */
+ public List elencaPagine(int maxRisultati);
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/integration/dao/PaginaDaoImplementation.java b/src/main/java/it/jee_book/jakiwiki/integration/dao/PaginaDaoImplementation.java
new file mode 100644
index 0000000..4ffa37c
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/integration/dao/PaginaDaoImplementation.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.integration.dao;
+
+import it.jee_book.jakiwiki.model.Pagina;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+@Stateless
+public class PaginaDaoImplementation implements PaginaDao {
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ public void salva(Pagina pagina) {
+ entityManager.merge(pagina);
+ }
+
+ public void elimina(Pagina pagina) {
+ entityManager.remove(pagina);
+ }
+
+ public Pagina leggi(String titolo) {
+ return entityManager.find(Pagina.class, titolo);
+ }
+
+ public List elencaPagine(int maxRisultati) {
+ Query query = entityManager.createQuery("SELECT p FROM Pagina p");
+
+ if (maxRisultati > 0) {
+ query.setMaxResults(3);
+ }
+
+ return query.getResultList();
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/integration/mail/EmailIntegrator.java b/src/main/java/it/jee_book/jakiwiki/integration/mail/EmailIntegrator.java
new file mode 100644
index 0000000..bf3ffb8
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/integration/mail/EmailIntegrator.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.integration.mail;
+
+import it.jee_book.jakiwiki.model.Pagina;
+import javax.ejb.Local;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+@Local
+public interface EmailIntegrator {
+
+ /**
+ *
+ * @param mittente
+ * @param destinatario
+ * @param commento
+ * @param pagina
+ */
+ public void sendEmail(String mittente, String destinatario, String commento, Pagina pagina);
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/integration/mail/EmailIntegratorImplementation.java b/src/main/java/it/jee_book/jakiwiki/integration/mail/EmailIntegratorImplementation.java
new file mode 100644
index 0000000..313638b
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/integration/mail/EmailIntegratorImplementation.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.integration.mail;
+
+import it.jee_book.jakiwiki.model.Pagina;
+import java.util.Properties;
+import javax.ejb.Stateless;
+import javax.mail.Authenticator;
+import javax.mail.Message;
+import javax.mail.PasswordAuthentication;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+@Stateless
+public class EmailIntegratorImplementation implements EmailIntegrator {
+
+ public void sendEmail(String mittente, String destinatario, String commento, Pagina pagina) {
+ Properties prop = new Properties();
+
+ Authenticator auth = new PasswordAuthenticator();
+ Session session = Session.getDefaultInstance(prop, auth);
+
+ MimeMessage message = new MimeMessage(session);
+ try {
+ message.setFrom(new InternetAddress(mittente));
+ message.addRecipient(Message.RecipientType.TO, new InternetAddress(destinatario));
+ message.setSubject(pagina.getTitolo());
+ message.setText(pagina.getContenuto());
+ Transport.send(message);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private class PasswordAuthenticator extends Authenticator {
+
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication("utente", "password");
+ }
+
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/model/Pagina.java b/src/main/java/it/jee_book/jakiwiki/model/Pagina.java
new file mode 100644
index 0000000..94c27c0
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/model/Pagina.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.model;
+
+import java.io.Serializable;
+import java.util.Date;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+@Entity
+@Table(name = "PAGINE")
+public class Pagina implements Serializable {
+
+ @Id
+ @Column(name = "TITOLO", nullable = false)
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private String titolo;
+
+ @Column(name = "CONTENUTO")
+ private String contenuto;
+
+ @Column(name = "ULTIMA_MODIFICA")
+ @Temporal(TemporalType.DATE)
+ private Date ultimaModifica;
+
+ public String getTitolo() {
+ return titolo;
+ }
+
+ public void setTitolo(String titolo) {
+ this.titolo = titolo;
+ }
+
+ public String getContenuto() {
+ return contenuto;
+ }
+
+ public void setContenuto(String contenuto) {
+ this.contenuto = contenuto;
+ }
+
+ public Date getUltimaModifica() {
+ return ultimaModifica;
+ }
+
+ public void setUltimaModifica(Date ultimaModifica) {
+ this.ultimaModifica = ultimaModifica;
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/servlet/MainController.java b/src/main/java/it/jee_book/jakiwiki/servlet/MainController.java
new file mode 100644
index 0000000..f15a127
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/servlet/MainController.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.servlet;
+
+import it.jee_book.jakiwiki.context.ContextObjectFactory;
+import it.jee_book.jakiwiki.context.RequestObject;
+import it.jee_book.jakiwiki.context.ResponseAndView;
+import it.jee_book.jakiwiki.context.ViewDispatcher;
+import it.jee_book.jakiwiki.controller.ActionFactory;
+import it.jee_book.jakiwiki.controller.Configuration;
+import it.jee_book.jakiwiki.controller.action.Action;
+import it.jee_book.jakiwiki.exception.JakiWikiException;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class MainController extends HttpServlet {
+
+ /**
+ *
+ * @param config
+ * @throws ServletException
+ */
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ Configuration.init(config);
+ }
+
+ /**
+ * Processes requests for both HTTP GET and POST
+ * methods.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ protected void handleRequest(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException, JakiWikiException {
+ RequestObject requestObject = ContextObjectFactory.getRequestObject(request);
+ Action action = ActionFactory.createAction(requestObject);
+ ResponseAndView responseObject = action.createResponseAndView(requestObject);
+ dispatchView(request, response, responseObject);
+ }
+
+ /**
+ * Handles the HTTP GET method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ try {
+ handleRequest(request, response);
+ } catch (JakiWikiException ex) {
+ Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ /**
+ * Handles the HTTP POST method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ try {
+ handleRequest(request, response);
+ } catch (JakiWikiException ex) {
+ Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ /**
+ *
+ * @param request
+ * @param response
+ * @param responseAndView
+ * @throws JakiWikiException
+ * @throws ServletException
+ * @throws IOException
+ */
+ private void dispatchView(HttpServletRequest request, HttpServletResponse response, ResponseAndView responseAndView) throws JakiWikiException, ServletException, IOException {
+ String view = responseAndView.getView();
+
+ String resultPage = Configuration.getViewPage(view);
+
+ if (resultPage == null) {
+ throw new JakiWikiException(JakiWikiException.ACTION_ERROR, "Non è configurata alcuna action con il nome: " + view);
+ }
+
+ ViewDispatcher viewDispatcher = new ViewDispatcher(request.getRequestDispatcher(resultPage));
+ viewDispatcher.forward(request, response, responseAndView);
+ }
+
+}
diff --git a/src/main/java/it/jee_book/jakiwiki/tag/ListaPagine.java b/src/main/java/it/jee_book/jakiwiki/tag/ListaPagine.java
new file mode 100644
index 0000000..2fcc106
--- /dev/null
+++ b/src/main/java/it/jee_book/jakiwiki/tag/ListaPagine.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2016 Fabio Scotto di Santolo.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.jee_book.jakiwiki.tag;
+
+import it.jee_book.jakiwiki.model.Pagina;
+import java.io.IOException;
+import java.util.List;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.SimpleTagSupport;
+
+/**
+ *
+ * @author Fabio Scotto di Santolo
+ */
+public class ListaPagine extends SimpleTagSupport {
+
+ private List pagine;
+
+ public List getPagine() {
+ return pagine;
+ }
+
+ public void setPagine(List pagine) {
+ this.pagine = pagine;
+ }
+
+ @Override
+ public void doTag() throws JspException, IOException {
+ if (getPagine() == null || getPagine().size() == 0) {
+ return;
+ }
+
+ getJspContext().getOut().write("
"
+ + "
Titolo
Data ultima"
+ + " modifica
");
+
+ for (int i = 0; i < getPagine().size(); i++) {
+ Pagina pagina = (Pagina) getPagine().get(i);
+ String line = "