Author: szimano Date: 2006-05-12 12:43:04 -0400 (Fri, 12 May 2006) New Revision: 4209 Added: labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/CharResponseWrapper.java labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/TitleChangeFilter.java labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/management/NotificationMsg.java labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/src/java/org/jboss/wiki/MailNotificationBean.java Modified: labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/portal-server.war/WEB-INF/web.xml labs/jbosslabs/trunk/portal-extensions/forge-root-redirect/src/web/WEB-INF/web.xml labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiCommon.java labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiEngine.java labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/project.xml Log: msb sources JBWIKI-87 Modified: labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/portal-server.war/WEB-INF/web.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/portal-server.war/WEB-INF/web.xml 2006-05-12 12:55:53 UTC (rev 4208) +++ labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/portal-server.war/WEB-INF/web.xml 2006-05-12 16:43:04 UTC (rev 4209) @@ -11,8 +11,17 @@ --> - <!-- LABS FILTERS --> - + <!-- LABS FILTERS --> + <filter> + <filter-name>titleAndTimestampFilter</filter-name> + <filter-class>org.jboss.forge.portal.TitleChangeFilter</filter-class> + </filter> + + <filter-mapping> + <filter-name>titleAndTimestampFilter</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + <!-- SSL Processor --> <filter> <filter-name>SSLProcessor</filter-name> Added: labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/CharResponseWrapper.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/CharResponseWrapper.java 2006-05-12 12:55:53 UTC (rev 4208) +++ labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/CharResponseWrapper.java 2006-05-12 16:43:04 UTC (rev 4209) @@ -0,0 +1,45 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.forge.portal; + +import java.io.CharArrayWriter; +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponseWrapper; + +public class CharResponseWrapper extends HttpServletResponseWrapper { + private CharArrayWriter output; + + public String toString() { + return output.toString(); + } + + public CharResponseWrapper(HttpServletResponse response) { + super(response); + output = new CharArrayWriter(); + } + + public PrintWriter getWriter() { + return new PrintWriter(output); + } +} Added: labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/TitleChangeFilter.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/TitleChangeFilter.java 2006-05-12 12:55:53 UTC (rev 4208) +++ labs/jbosslabs/trunk/portal-extensions/forge-portal-attr/src/java/org/jboss/forge/portal/TitleChangeFilter.java 2006-05-12 16:43:04 UTC (rev 4209) @@ -0,0 +1,137 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.forge.portal; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.jboss.shotoku.ContentManager; +import org.jboss.shotoku.Node; +import org.jboss.shotoku.exceptions.RepositoryException; +import org.jboss.shotoku.exceptions.ResourceDoesNotExist; + +public class TitleChangeFilter implements Filter { + + private static final String TITLE_START_TAG = "<title>"; + + private static final String TITLE_END_TAG = "</title>"; + + private static final String PORTAL_CONTEXT = "/portal/"; + + private static final String SHOT_PREF = "/default/members/"; + + private static final String FREEZONE = "/freezone"; + + public void init(FilterConfig conf) throws ServletException { + + } + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + HttpServletResponse hResp = (HttpServletResponse) response; + HttpServletRequest hReq = (HttpServletRequest)request; + + String uri = hReq.getRequestURI(); + + setTimestamp(uri, hResp); + + CharResponseWrapper wrapper = new CharResponseWrapper( + (HttpServletResponse) response); + chain.doFilter(request, wrapper); + + if (wrapper.getContentType().startsWith("text/html")) { + + PrintWriter out = response.getWriter(); + + out.write(changePageTitle(wrapper.toString())); + + out.close(); + } + } + + private void setTimestamp(String uri, HttpServletResponse resp) { + if (uri.startsWith(PORTAL_CONTEXT)) { + uri = uri.substring(PORTAL_CONTEXT.length()); + + if (uri.indexOf('/') != -1) { + StringBuffer uriBuffer = new StringBuffer(uri); + uriBuffer.insert(uri.indexOf('/'), FREEZONE); + + uriBuffer.insert(0, SHOT_PREF); + + uri = uriBuffer.toString(); + + try { + Node node = ContentManager.getContentManager().getNode(uri); + + resp.setDateHeader("Last-Modified", node.getLastModification()); + } catch (RepositoryException e) { + e.printStackTrace(); + } catch (ResourceDoesNotExist e) { + //it's not a shotoku element. ignore. + } + } + } + } + + public void destroy() { + + } + + private String changePageTitle(String content) { + String pageContent = content.toLowerCase(); + + int titleIndx = pageContent.indexOf(TITLE_START_TAG); + int titleEnd = pageContent.indexOf(TITLE_END_TAG, titleIndx); + + if (titleIndx != -1) { + int titleToUse; + int endOfTitleTag; + + if ((titleToUse = pageContent.indexOf(TITLE_START_TAG, + titleIndx + 1)) != -1 + && (endOfTitleTag = pageContent.indexOf(TITLE_END_TAG, + titleToUse + 1)) != -1 && titleEnd != endOfTitleTag) { + return content.substring(0, titleIndx + + TITLE_START_TAG.length()) + + content.substring(titleToUse + + TITLE_START_TAG.length(), endOfTitleTag) + + content.substring(titleEnd, + content.length() - 1); + } else { + return content; + } + } else { + return content; + } + } +} Modified: labs/jbosslabs/trunk/portal-extensions/forge-root-redirect/src/web/WEB-INF/web.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-root-redirect/src/web/WEB-INF/web.xml 2006-05-12 12:55:53 UTC (rev 4208) +++ labs/jbosslabs/trunk/portal-extensions/forge-root-redirect/src/web/WEB-INF/web.xml 2006-05-12 16:43:04 UTC (rev 4209) @@ -13,4 +13,5 @@ <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> </filter-mapping> + </web-app> \ No newline at end of file Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiCommon.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiCommon.java 2006-05-12 12:55:53 UTC (rev 4208) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiCommon.java 2006-05-12 16:43:04 UTC (rev 4209) @@ -21,9 +21,23 @@ */ package org.jboss.wiki; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; + +import javax.jms.ObjectMessage; +import javax.jms.Queue; +import javax.jms.QueueConnectionFactory; +import javax.jms.QueueSession; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import org.jboss.logging.Logger; import org.jboss.mx.util.MBeanProxyExt; import org.jboss.mx.util.MBeanServerLocator; import org.jboss.wiki.exceptions.WikiManagementNotFoundException; +import org.jboss.wiki.management.NotificationMsg; import org.jboss.wiki.management.WikiServiceMenagement; public class WikiCommon { @@ -32,9 +46,11 @@ public static final String WIKI_SERVICE_NAME = "wiki:service=wikiService"; - private WikiServiceMenagement wikiServiceMenagement; + private static Logger log = Logger.getLogger(WikiCommon.class); + + private static WikiServiceMenagement wikiServiceMenagement; - public WikiServiceMenagement getWikiManagement() throws WikiManagementNotFoundException{ + public static WikiServiceMenagement getWikiManagement() throws WikiManagementNotFoundException{ try { if (wikiServiceMenagement == null) wikiServiceMenagement = (WikiServiceMenagement) MBeanProxyExt.create( @@ -47,4 +63,66 @@ throw new WikiManagementNotFoundException(e); } } + + public static void sendNotificationMail(WikiPage page) { + try { + InitialContext context = new InitialContext(); + + QueueSession sess = null; + Queue queue = null; + try { + queue = (Queue) context.lookup("queue/mdb"); + QueueConnectionFactory factory = (QueueConnectionFactory) context + .lookup("ConnectionFactory"); + sess = factory.createQueueConnection().createQueueSession( + false, QueueSession.AUTO_ACKNOWLEDGE); + + if (sess != null) { + + String notifs = page.getMetaDataProperty("notifications"); + + if (notifs != null) { + Set<String> emails = new TreeSet<String>(); + String[] splitedMails = notifs.split(";"); + + for (int i = 0; i < splitedMails.length; i++) { + emails.add(splitedMails[i]); + } + + page = (WikiPage) page.clone(); + WikiEngine engine = getWikiManagement().getWikiEngine(); + page = engine.getWikiType("htmlClear").process(page, new WikiSession(){ + + private Map<String, Object> attributes = new TreeMap<String, Object>(); + public Object getAttribute(String attributeName) { + return attributes.get(attributeName); + } + + public void setAttribute(String attributeName, Object attribute) { + attributes.put(attributeName, attribute); + } + + public void removeAttribute(String attributeName) { + attributes.remove(attributeName); + } + + public String getId() { + return this.toString(); + }}); + + NotificationMsg notifMsg = new NotificationMsg(emails, page.getContent(), page.getName()); + ObjectMessage msg = sess.createObjectMessage(notifMsg); + sess.createSender(queue).send(msg); + } + } + else { + log.error("Couldn't create queue session."); + } + } catch (Exception e) { + log.error(e); + } + } catch (NamingException e1) { + log.error(e1); + } + } } Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiEngine.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiEngine.java 2006-05-12 12:55:53 UTC (rev 4208) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiEngine.java 2006-05-12 16:43:04 UTC (rev 4209) @@ -893,6 +893,11 @@ } postSave(langCode); + + // send notifications + page.setMetaDataProperty("notifications", "sz...@as..."); + log.info("sending notif"); + WikiCommon.sendNotificationMail(page); } Added: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/management/NotificationMsg.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/management/NotificationMsg.java 2006-05-12 12:55:53 UTC (rev 4208) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/management/NotificationMsg.java 2006-05-12 16:43:04 UTC (rev 4209) @@ -0,0 +1,70 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.wiki.management; + +import java.io.Serializable; +import java.util.Set; + +public class NotificationMsg implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + + private Set<String> emails; + + private String pageContent; + + private String pageName; + + public NotificationMsg(Set<String> emails, String pageContent, String pageName) { + this.emails = emails; + this.pageContent = pageContent; + this.pageName = pageName; + } + + public Set<String> getEmails() { + return emails; + } + + public void setEmails(Set<String> emails) { + this.emails = emails; + } + + public String getPageContent() { + return pageContent; + } + + public void setPageContent(String pageContent) { + this.pageContent = pageContent; + } + + public String getPageName() { + return pageName; + } + + public void setPageName(String pageName) { + this.pageName = pageName; + } + +} Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/project.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/project.xml 2006-05-12 12:55:53 UTC (rev 4208) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/project.xml 2006-05-12 16:43:04 UTC (rev 4209) @@ -33,12 +33,11 @@ </organization> <dependencies> - - <dependency> - <groupId>aslibs</groupId> - <artifactId>javax.servlet</artifactId> + <dependency> + <groupId>jboss</groupId> + <artifactId>jboss-j2ee</artifactId> <version>1.0</version> - <jar>javax.servlet.jar</jar> + <jar>jboss-j2ee.jar</jar> </dependency> <dependency> @@ -52,10 +51,10 @@ </dependency> <dependency> - <groupId>aslibs</groupId> - <artifactId>javax.servlet.jsp</artifactId> + <groupId>jboss</groupId> + <artifactId>jboss-mail</artifactId> <version>1.0</version> - <jar>javax.servlet.jsp.jar</jar> + <jar>mail.jar</jar> </dependency> <dependency> @@ -99,23 +98,19 @@ </dependency> <dependency> - <groupId>jboss</groupId> - <artifactId>jboss-annotations-ejb3</artifactId> - <version>1.0</version> - <jar>jboss-annotations-ejb3.jar</jar> - </dependency> - - <dependency> - <id>portlet-api</id> - <version>1.0</version> + <groupId>jboss</groupId> + <artifactId>jboss-annotations-ejb3</artifactId> + <version>1.0</version> + <jar>jboss-annotations-ejb3.jar</jar> </dependency> + <dependency> - <groupId>jboss</groupId> - <artifactId>jboss-jmx</artifactId> - <version>1.0</version> - <jar>jboss-jmx.jar</jar> - </dependency> + <groupId>jboss</groupId> + <artifactId>jboss-jmx</artifactId> + <version>1.0</version> + <jar>jboss-jmx.jar</jar> + </dependency> <dependency> <groupId>jboss</groupId> @@ -144,5 +139,6 @@ <version>1.0</version> <jar>portal-portlet-lib.jar</jar> </dependency> + </dependencies> </project> Added: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/src/java/org/jboss/wiki/MailNotificationBean.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/src/java/org/jboss/wiki/MailNotificationBean.java 2006-05-12 12:55:53 UTC (rev 4208) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/src/java/org/jboss/wiki/MailNotificationBean.java 2006-05-12 16:43:04 UTC (rev 4209) @@ -0,0 +1,107 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.wiki; + +import java.util.Date; + +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.ObjectMessage; +import javax.mail.Address; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.Message.RecipientType; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import javax.naming.InitialContext; +import javax.rmi.PortableRemoteObject; +import javax.ejb.MessageDriven; + +import org.jboss.logging.Logger; +import org.jboss.wiki.management.NotificationMsg; + +public @MessageDriven(activateConfig = { + @javax.ejb.ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), + @javax.ejb.ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/mdb") }) +class MailNotificationBean implements MessageListener { + + private final static String EMAIL_ADDRESS = "sz...@o2..."; + + private Logger log = Logger.getLogger(this.getClass()); + + public void onMessage(Message msg) { + + log.info("Mail"); + + try { + + ObjectMessage omsg = (ObjectMessage) msg; + Session session = null; + + try { + session = (Session) PortableRemoteObject + .narrow(new InitialContext().lookup("java:Mail"), + Session.class); + try { + if (omsg.getObject() instanceof NotificationMsg) { + NotificationMsg notifications = (NotificationMsg) omsg + .getObject(); + + log.info("Got email notification msg"); + + for (String email : notifications.getEmails()) { + log.info("MDB for: " + email); + + StringBuffer buffer = null; + Address[] to = null; + MimeMessage m = new MimeMessage(session); + + if (email != null) { + m.setFrom(new InternetAddress(EMAIL_ADDRESS)); + to = new InternetAddress[] { new InternetAddress( + email) }; + m.setRecipients(RecipientType.TO, to); + m.setSubject("[JBossWiki] Page change notification: " + notifications.getPageName()); + + m.setSentDate(new Date()); + buffer = new StringBuffer(); + + buffer.append("This message is generated automaticcaly. Please do not reply. To remove yourself from the watch list please go to www.\n\n"); + buffer.append(notifications.getPageContent()); + + m.setContent(buffer.toString(), "text/html; charset=\"UTF-8\""); + Transport.send(m); + } + } + } + } catch (javax.mail.MessagingException e) { + log.error(e); + } + } catch (javax.naming.NamingException e) { + log.error(e); + } + } catch (Exception e) { + log.error(e); + } + + } +} |