portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r725977 [13/48] - in /portals/jetspeed-2/portal/trunk: ./ app-servers/security/jboss/src/java/META-INF/jboss-secsvc/ app-servers/security/jboss/src/java/org/apache/jetspeed/appservers/security/jboss/ applications/jetspeed/src/main/javascrip...
Date Fri, 12 Dec 2008 12:07:04 GMT
Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java?rev=725977&r1=725976&r2=725977&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java Fri Dec 12 04:06:29 2008
@@ -1,500 +1,500 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You 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 org.apache.jetspeed.administration;
-
-import java.io.FileReader;
-import java.io.StringWriter;
-import java.security.PrivilegedAction;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletRequest;
-import javax.portlet.PortletResponse;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jetspeed.Jetspeed;
-import org.apache.jetspeed.PortalReservedParameters;
-import org.apache.jetspeed.exception.JetspeedException;
-import org.apache.jetspeed.om.folder.Folder;
-import org.apache.jetspeed.om.folder.FolderNotFoundException;
-import org.apache.jetspeed.om.folder.InvalidFolderException;
-import org.apache.jetspeed.page.PageManager;
-import org.apache.jetspeed.page.document.NodeException;
-import org.apache.jetspeed.profiler.Profiler;
-import org.apache.jetspeed.profiler.rules.ProfilingRule;
-import org.apache.jetspeed.request.RequestContext;
-import org.apache.jetspeed.security.GroupManager;
-import org.apache.jetspeed.security.JSSubject;
-import org.apache.jetspeed.security.PasswordCredential;
-import org.apache.jetspeed.security.RoleManager;
-import org.apache.jetspeed.security.SecurityAttributes;
-import org.apache.jetspeed.security.SecurityException;
-import org.apache.jetspeed.security.User;
-import org.apache.jetspeed.security.UserManager;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.VelocityEngine;
-import org.springframework.mail.MailException;
-import org.springframework.mail.SimpleMailMessage;
-import org.springframework.mail.javamail.JavaMailSender;
-
-/**
- * PortalAdministrationImpl
- * Implements aggregate portal administration functions:
- *  - Emails
- *  - Registration
- *  - Password Generation
- *  - 
- * 
- * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
- * @author <a href="mailto:chris@bluesunrise.com">Chris Schaefer</a>
- * @version $Id: $
- */
-
-public class PortalAdministrationImpl implements PortalAdministration
-{
-    private final static Log log = LogFactory.getLog(PortalAdministrationImpl.class);
-    
-    /** administration services */
-    protected Configuration config;
-    protected UserManager userManager;
-    protected RoleManager roleManager;
-    protected GroupManager groupManager;
-    protected PageManager pageManager;
-    protected Profiler profiler;
-    protected JavaMailSender mailSender;
-    protected VelocityEngine velocityEngine;
-    protected AdminUtil adminUtil;
-    
-    /** list of default roles for a registered user */
-    protected List defaultRoles;
-    /** list of default groups for a registered user */
-    protected List defaultGroups;
-    /** map of default profiling rules for a registered user */
-    protected Map defaultRules;
-    /** name of PSML Folder Template to clone from when registering new user */
-    protected String folderTemplate;
-    /** default administrative user */
-    protected String adminUser;
-        
-    public PortalAdministrationImpl( UserManager userManager,
-                                     RoleManager roleManager,
-                                     GroupManager groupManager, 
-                                     PageManager pageManager,
-                                     Profiler profiler,
-                                     JavaMailSender mailSender,
-                                     VelocityEngine velocityEngine)
-    {
-        this.userManager = userManager;
-        this.roleManager = roleManager;
-        this.groupManager = groupManager;
-        this.pageManager = pageManager;
-        this.profiler = profiler;
-        this.mailSender = mailSender;
-        this.velocityEngine = velocityEngine;
-        this.adminUtil = new AdminUtil();
-    }
-
-    public void start()
-    {
-        this.config = (Configuration) Jetspeed.getComponentManager().getComponent("portal_configuration");
-        
-        this.defaultRoles = 
-            config.getList(PortalConfigurationConstants.REGISTRATION_ROLES_DEFAULT);
-        this.defaultGroups = 
-            config.getList(PortalConfigurationConstants.REGISTRATION_GROUPS_DEFAULT);
-    
-        Object[] profileRuleNames = config.getList(PortalConfigurationConstants.PROFILER_RULE_NAMES_DEFAULT).toArray();
-        Object[] profileRuleValues = config.getList(PortalConfigurationConstants.PROFILER_RULE_VALUES_DEFAULT).toArray();
-        defaultRules = new HashMap();
-        if (profileRuleNames != null && profileRuleValues != null)
-        {
-            for (int ix = 0; ix < ((profileRuleNames.length < profileRuleValues.length) ? profileRuleNames.length : profileRuleValues.length); ix++)
-            {
-                defaultRules.put(profileRuleNames[ix], profileRuleValues[ix]);
-            }
-        }
-        this.folderTemplate = 
-            config.getString(PortalConfigurationConstants.PSML_TEMPLATE_FOLDER);
-        this.adminUser = config.getString(PortalConfigurationConstants.USERS_DEFAULT_ADMIN);
-        
-    }
-    
-    public void registerUser(String userName, String password)
-    throws RegistrationException
-    {
-        registerUser(userName, password, (List)null, null, null, null, null);
-    }
-
-    public void registerUser(
-            String userName, 
-            String password, 
-            List roles, 
-            List groups, 
-            Map userInfo, 
-            Map rules, 
-            String folderTemplate)
-    throws RegistrationException    
-    {
-        registerUser(userName, password, roles, groups, userInfo, rules, folderTemplate, null);
-    }
-    
-    /* (non-Javadoc)
-     * @see org.apache.jetspeed.administration.PortalAdministration#registerUser(java.lang.String, java.lang.String, java.util.Map, java.awt.List, java.awt.List, java.lang.String)
-     */    
-    public void registerUser(
-            String userName, 
-            String password, 
-            List roles, 
-            List groups, 
-            Map userInfo, 
-            Map rules, 
-            String folderTemplate,
-            String subsite)
-    throws RegistrationException    
-    {
-        try 
-        {
-            // create the user
-            User user =  userManager.addUser(userName);
-            PasswordCredential pwc = userManager.getPasswordCredential(user);
-            pwc.setPassword(null, password);
-                       
-            // assign roles to user
-            if (roles == null || roles.isEmpty())
-            {
-                roles = this.defaultRoles;
-            }
-            if (roles != null)
-            {
-                Iterator roleList = roles.iterator();
-                while (roleList.hasNext())
-                {
-                    String role = (String)roleList.next();
-                    if (role.trim().length() > 0)
-                        roleManager.addRoleToUser(userName, role);
-                }
-            }
-            
-            // assign groups to user
-            if (groups == null || groups.isEmpty())
-            {
-                groups = this.defaultGroups;
-            }
-            if (groups != null)
-            {
-                Iterator groupsList = groups.iterator();
-                while (groupsList.hasNext())
-                {
-                    String group = (String)groupsList.next();
-                    if (group.trim().length() > 0)
-                    {
-                        groupManager.addUserToGroup(userName, group);
-                    }
-                }
-            }
-            
-            // assign user attributes to user
-            if (userInfo != null)
-            {
-                SecurityAttributes userAttrs = user.getSecurityAttributes();
-                Iterator info = userInfo.entrySet().iterator();
-                
-                while (info.hasNext())
-                {           
-                    Map.Entry entry = (Map.Entry) info.next();
-                    userAttrs.getAttribute((String) entry.getKey(), true).setStringValue((String) entry.getValue());
-                }
-            }
-            
-            // assign profiling rules to user
-            if (rules == null || rules.isEmpty())
-            {
-                rules = this.defaultRules;
-            }
-            if (rules != null)
-            {
-                Iterator ruleEntries = rules.entrySet().iterator();
-                while (ruleEntries.hasNext())
-                {           
-                    Map.Entry entry = (Map.Entry)ruleEntries.next();                    
-                    ProfilingRule rule = profiler.getRule((String)entry.getValue());
-                    if (rule != null)
-                    {
-                        profiler.setRuleForPrincipal(user, rule, (String)entry.getKey());
-                    }
-                }
-            }
-            
-            if (folderTemplate == null)
-            {
-                folderTemplate = this.folderTemplate; 
-            }
-            
-            if (subsite == null)
-            {
-                subsite = Folder.USER_FOLDER + userName;
-            }
-            else
-            {
-                subsite  = subsite + Folder.USER_FOLDER +  userName;
-            }            
-            
-            
-            // This next chunk of code is the fancy way to force the creation of the user
-            // template pages to be created with subject equal to the new user
-            // otherwise it would be created as guest, and guest does not have enough privs.
-            final String innerFolderTemplate = folderTemplate;
-            final String innerSubsite = subsite;
-            final PageManager innerPageManager = pageManager;
-            final String innerUserName = userName;
-            final User innerUser = user;
-            User powerUser = userManager.getUser(this.adminUser);
-            JetspeedException pe = (JetspeedException) JSSubject.doAsPrivileged(userManager.getSubject(powerUser), new PrivilegedAction()
-                {
-                    public Object run() 
-                    {
-                        try
-                        {
-                            if (innerSubsite != null)
-                            {
-                                innerUser.getSecurityAttributes().getAttribute(User.JETSPEED_USER_SUBSITE_ATTRIBUTE, true).setStringValue(innerSubsite);
-                                userManager.updateUser(innerUser);
-                            }                                         
-                            // create user's home folder                        
-                            // deep copy from the default folder template tree, creating a deep-copy of the template
-                            // in the new user's folder tree
-                            Folder source = innerPageManager.getFolder(innerFolderTemplate);
-                            
-                            
-                            innerPageManager.deepCopyFolder(source, innerSubsite, innerUserName);
-                            Folder newFolder = pageManager.getFolder(innerSubsite);                            
-                            newFolder.setTitle("Home Folder");
-                            newFolder.setShortTitle("Home");
-                             
-                            return null;
-                        }
-                        catch (SecurityException s1)
-                        {
-                            return s1;
-                        }
-                        catch (FolderNotFoundException e1) 
-                        {
-                            return e1;
-                        }
-                        catch (InvalidFolderException e1)
-                        {
-                            return e1;
-                        }
-                        catch (NodeException e1)
-                        {
-                            return e1;
-                        } 
-                    }
-                }, null);
-                
-            if(pe != null)
-            {
-                // rollback user creation and cascade roles, groups, etc
-                try
-                {
-                    if (userManager.getUser(userName) != null)
-                    {
-                        userManager.removeUser(userName);
-                    }
-                }
-                catch (Exception e)
-                {
-                    log.error("Registration Error: Failed to rollback user " + userName);
-                }
-                log.error("Registration Error: Failed to create user folders for " + userName + ", " + pe.toString());
-                throw pe;
-            }
-                        
-        }
-        catch (Exception e) 
-        {
-            log.error("Registration Error: Failed to create registered user " + userName + ", " + e.toString());
-            throw new RegistrationException(e); 
-        }        
-    }
-    
-    
-    /* (non-Javadoc)
-     * @see org.apache.jetspeed.administration.PortalAdministration#generatePassword()
-     */
-    public String generatePassword()
-    {
-        return adminUtil.generatePassword();
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.jetspeed.administration.PortalAdministration#sendPassword(java.lang.String)
-     */
-    public void sendEmail(PortletConfig  portletConfig,
-                          String emailAddress, 
-                          String localizedSubject, 
-                          String localizedTemplatePath,
-                          Map userAttributes)                            
-    throws AdministrationEmailException    
-    {       
-        
-        String from = config.getString(PortalConfigurationConstants.EMAIL_SENDER);
-        String subject = localizedSubject;
-        String to = emailAddress;
-        String text = mergeEmailTemplate(portletConfig, userAttributes, "map", localizedTemplatePath);
-        sendEmail(from, subject, to, text);
-        
-    }
-    
-    /**
-     * @param from
-     * @param subject
-     * @param to
-     * @param text
-     * @throws AdministrationEmailException
-     */
-    public void sendEmail(String from, String subject, String to, String text) throws AdministrationEmailException
-    {
-        SimpleMailMessage msg = new SimpleMailMessage();
-        if(from == null) 
-        {
-            from = "jetspeed-admin@apache.org";
-        }
-        msg.setFrom(from);
-        if(subject == null) 
-        {
-            subject = "message from jetspeed";
-        }
-        msg.setSubject(subject);
-        msg.setTo(to);
-        msg.setText(text);
-        try
-        {
-            mailSender.send(msg);
-        } 
-        catch (MailException ex)
-        {
-            throw new AdministrationEmailException(
-                    "Failed to send forgotten password email to user with email address because "+ex.getMessage()
-                            ); //+ user.getEmail());
-        }
-    }
-    
-    public String mergeEmailTemplate(PortletConfig  portletConfig, Map attributes, String attributesName, String template)
-    throws AdministrationEmailException
-    {
-        VelocityContext context = new VelocityContext();
-        context.put(attributesName, attributes);
-        StringWriter writer = new StringWriter();
-        
-        try
-        {
-            String realTemplatePath = portletConfig.getPortletContext().getRealPath(template);
-            FileReader templateReader = new FileReader(realTemplatePath);
-            velocityEngine.evaluate(context, writer, "UserEmailProcessor", templateReader);
-        } catch (Exception e)
-        {
-            throw new AdministrationEmailException(
-                    "Failed to generate email text for email template "
-                            + template, e);
-        }
-        
-        String buffer = writer.getBuffer().toString();
-        
-        return buffer;
-    }
-    
-    private static final String USER_NOT_FOUND_FROM_EMAIL = "User not found for Email address: ";
-    
-    public User lookupUserFromEmail(String email)
-        throws AdministrationEmailException    
-    {
-        Collection<User> users;
-        try
-        {
-            users = userManager.lookupUsers("user.business-info.online.email", email);
-        } 
-        catch (SecurityException e)
-        {
-            throw new AdministrationEmailException(e);        
-        }
-        if (users.isEmpty())
-        {
-            throw new AdministrationEmailException(USER_NOT_FOUND_FROM_EMAIL + email);
-        }
-        return users.iterator().next(); // return the first one and hopefully the only (FIXME: need unique constraints)
-    }
-
-    /**
-     * Helper for admin portlets to generate portal urls
-     */
-    public String getPortalURL(PortletRequest request, PortletResponse response, String path)
-    {
-        // get internal request context
-        RequestContext context = (RequestContext)
-            request.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
-        String baseUrl = context.getPortalURL().getBaseURL();
-        String jetspeedPath = adminUtil.concatenatePaths(baseUrl, context.getPortalURL().getBasePath());
-        if (path == null)
-            return jetspeedPath;
-        return adminUtil.concatenatePaths(jetspeedPath, response.encodeURL(path));
-    }
-        
-    
-    Map forgottenPasswordData = new HashMap();
-
-    /* (non-Javadoc)
-     * @see org.apache.jetspeed.administration.PortalAdministration#getNewLoginInfo(java.lang.String)
-     */
-    public Map getNewLoginInfo(String guid)
-    {
-        synchronized(forgottenPasswordData) {
-            return (Map) forgottenPasswordData.get(guid);
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.jetspeed.administration.PortalAdministration#setNewLoginInfo(java.lang.String, org.apache.jetspeed.administration.PortalAdministration.ResetPasswordInfo)
-     */
-    public void putNewLoginInfo(String guid, Map info)
-    {
-        synchronized(forgottenPasswordData) {
-            forgottenPasswordData.put(guid,info);
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.jetspeed.administration.PortalAdministration#removeNewLoginInfo(java.lang.String)
-     */
-    public void removeNewLoginInfo(String guid)
-    {
-        synchronized(forgottenPasswordData) {
-            forgottenPasswordData.remove(guid);
-        }
-    }
-    
-    
-    
-    
-    
-}
+ * 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 org.apache.jetspeed.administration;
+
+import java.io.FileReader;
+import java.io.StringWriter;
+import java.security.PrivilegedAction;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.Jetspeed;
+import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.exception.JetspeedException;
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.om.folder.FolderNotFoundException;
+import org.apache.jetspeed.om.folder.InvalidFolderException;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.page.document.NodeException;
+import org.apache.jetspeed.profiler.Profiler;
+import org.apache.jetspeed.profiler.rules.ProfilingRule;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.security.GroupManager;
+import org.apache.jetspeed.security.JSSubject;
+import org.apache.jetspeed.security.PasswordCredential;
+import org.apache.jetspeed.security.RoleManager;
+import org.apache.jetspeed.security.SecurityAttributes;
+import org.apache.jetspeed.security.SecurityException;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserManager;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.springframework.mail.MailException;
+import org.springframework.mail.SimpleMailMessage;
+import org.springframework.mail.javamail.JavaMailSender;
+
+/**
+ * PortalAdministrationImpl
+ * Implements aggregate portal administration functions:
+ *  - Emails
+ *  - Registration
+ *  - Password Generation
+ *  - 
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @author <a href="mailto:chris@bluesunrise.com">Chris Schaefer</a>
+ * @version $Id: $
+ */
+
+public class PortalAdministrationImpl implements PortalAdministration
+{
+    private final static Log log = LogFactory.getLog(PortalAdministrationImpl.class);
+    
+    /** administration services */
+    protected Configuration config;
+    protected UserManager userManager;
+    protected RoleManager roleManager;
+    protected GroupManager groupManager;
+    protected PageManager pageManager;
+    protected Profiler profiler;
+    protected JavaMailSender mailSender;
+    protected VelocityEngine velocityEngine;
+    protected AdminUtil adminUtil;
+    
+    /** list of default roles for a registered user */
+    protected List defaultRoles;
+    /** list of default groups for a registered user */
+    protected List defaultGroups;
+    /** map of default profiling rules for a registered user */
+    protected Map defaultRules;
+    /** name of PSML Folder Template to clone from when registering new user */
+    protected String folderTemplate;
+    /** default administrative user */
+    protected String adminUser;
+        
+    public PortalAdministrationImpl( UserManager userManager,
+                                     RoleManager roleManager,
+                                     GroupManager groupManager, 
+                                     PageManager pageManager,
+                                     Profiler profiler,
+                                     JavaMailSender mailSender,
+                                     VelocityEngine velocityEngine)
+    {
+        this.userManager = userManager;
+        this.roleManager = roleManager;
+        this.groupManager = groupManager;
+        this.pageManager = pageManager;
+        this.profiler = profiler;
+        this.mailSender = mailSender;
+        this.velocityEngine = velocityEngine;
+        this.adminUtil = new AdminUtil();
+    }
+
+    public void start()
+    {
+        this.config = (Configuration) Jetspeed.getComponentManager().getComponent("portal_configuration");
+        
+        this.defaultRoles = 
+            config.getList(PortalConfigurationConstants.REGISTRATION_ROLES_DEFAULT);
+        this.defaultGroups = 
+            config.getList(PortalConfigurationConstants.REGISTRATION_GROUPS_DEFAULT);
+    
+        Object[] profileRuleNames = config.getList(PortalConfigurationConstants.PROFILER_RULE_NAMES_DEFAULT).toArray();
+        Object[] profileRuleValues = config.getList(PortalConfigurationConstants.PROFILER_RULE_VALUES_DEFAULT).toArray();
+        defaultRules = new HashMap();
+        if (profileRuleNames != null && profileRuleValues != null)
+        {
+            for (int ix = 0; ix < ((profileRuleNames.length < profileRuleValues.length) ? profileRuleNames.length : profileRuleValues.length); ix++)
+            {
+                defaultRules.put(profileRuleNames[ix], profileRuleValues[ix]);
+            }
+        }
+        this.folderTemplate = 
+            config.getString(PortalConfigurationConstants.PSML_TEMPLATE_FOLDER);
+        this.adminUser = config.getString(PortalConfigurationConstants.USERS_DEFAULT_ADMIN);
+        
+    }
+    
+    public void registerUser(String userName, String password)
+    throws RegistrationException
+    {
+        registerUser(userName, password, (List)null, null, null, null, null);
+    }
+
+    public void registerUser(
+            String userName, 
+            String password, 
+            List roles, 
+            List groups, 
+            Map userInfo, 
+            Map rules, 
+            String folderTemplate)
+    throws RegistrationException    
+    {
+        registerUser(userName, password, roles, groups, userInfo, rules, folderTemplate, null);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.administration.PortalAdministration#registerUser(java.lang.String, java.lang.String, java.util.Map, java.awt.List, java.awt.List, java.lang.String)
+     */    
+    public void registerUser(
+            String userName, 
+            String password, 
+            List roles, 
+            List groups, 
+            Map userInfo, 
+            Map rules, 
+            String folderTemplate,
+            String subsite)
+    throws RegistrationException    
+    {
+        try 
+        {
+            // create the user
+            User user =  userManager.addUser(userName);
+            PasswordCredential pwc = userManager.getPasswordCredential(user);
+            pwc.setPassword(null, password);
+                       
+            // assign roles to user
+            if (roles == null || roles.isEmpty())
+            {
+                roles = this.defaultRoles;
+            }
+            if (roles != null)
+            {
+                Iterator roleList = roles.iterator();
+                while (roleList.hasNext())
+                {
+                    String role = (String)roleList.next();
+                    if (role.trim().length() > 0)
+                        roleManager.addRoleToUser(userName, role);
+                }
+            }
+            
+            // assign groups to user
+            if (groups == null || groups.isEmpty())
+            {
+                groups = this.defaultGroups;
+            }
+            if (groups != null)
+            {
+                Iterator groupsList = groups.iterator();
+                while (groupsList.hasNext())
+                {
+                    String group = (String)groupsList.next();
+                    if (group.trim().length() > 0)
+                    {
+                        groupManager.addUserToGroup(userName, group);
+                    }
+                }
+            }
+            
+            // assign user attributes to user
+            if (userInfo != null)
+            {
+                SecurityAttributes userAttrs = user.getSecurityAttributes();
+                Iterator info = userInfo.entrySet().iterator();
+                
+                while (info.hasNext())
+                {           
+                    Map.Entry entry = (Map.Entry) info.next();
+                    userAttrs.getAttribute((String) entry.getKey(), true).setStringValue((String) entry.getValue());
+                }
+            }
+            
+            // assign profiling rules to user
+            if (rules == null || rules.isEmpty())
+            {
+                rules = this.defaultRules;
+            }
+            if (rules != null)
+            {
+                Iterator ruleEntries = rules.entrySet().iterator();
+                while (ruleEntries.hasNext())
+                {           
+                    Map.Entry entry = (Map.Entry)ruleEntries.next();                    
+                    ProfilingRule rule = profiler.getRule((String)entry.getValue());
+                    if (rule != null)
+                    {
+                        profiler.setRuleForPrincipal(user, rule, (String)entry.getKey());
+                    }
+                }
+            }
+            
+            if (folderTemplate == null)
+            {
+                folderTemplate = this.folderTemplate; 
+            }
+            
+            if (subsite == null)
+            {
+                subsite = Folder.USER_FOLDER + userName;
+            }
+            else
+            {
+                subsite  = subsite + Folder.USER_FOLDER +  userName;
+            }            
+            
+            
+            // This next chunk of code is the fancy way to force the creation of the user
+            // template pages to be created with subject equal to the new user
+            // otherwise it would be created as guest, and guest does not have enough privs.
+            final String innerFolderTemplate = folderTemplate;
+            final String innerSubsite = subsite;
+            final PageManager innerPageManager = pageManager;
+            final String innerUserName = userName;
+            final User innerUser = user;
+            User powerUser = userManager.getUser(this.adminUser);
+            JetspeedException pe = (JetspeedException) JSSubject.doAsPrivileged(userManager.getSubject(powerUser), new PrivilegedAction()
+                {
+                    public Object run() 
+                    {
+                        try
+                        {
+                            if (innerSubsite != null)
+                            {
+                                innerUser.getSecurityAttributes().getAttribute(User.JETSPEED_USER_SUBSITE_ATTRIBUTE, true).setStringValue(innerSubsite);
+                                userManager.updateUser(innerUser);
+                            }                                         
+                            // create user's home folder                        
+                            // deep copy from the default folder template tree, creating a deep-copy of the template
+                            // in the new user's folder tree
+                            Folder source = innerPageManager.getFolder(innerFolderTemplate);
+                            
+                            
+                            innerPageManager.deepCopyFolder(source, innerSubsite, innerUserName);
+                            Folder newFolder = pageManager.getFolder(innerSubsite);                            
+                            newFolder.setTitle("Home Folder");
+                            newFolder.setShortTitle("Home");
+                             
+                            return null;
+                        }
+                        catch (SecurityException s1)
+                        {
+                            return s1;
+                        }
+                        catch (FolderNotFoundException e1) 
+                        {
+                            return e1;
+                        }
+                        catch (InvalidFolderException e1)
+                        {
+                            return e1;
+                        }
+                        catch (NodeException e1)
+                        {
+                            return e1;
+                        } 
+                    }
+                }, null);
+                
+            if(pe != null)
+            {
+                // rollback user creation and cascade roles, groups, etc
+                try
+                {
+                    if (userManager.getUser(userName) != null)
+                    {
+                        userManager.removeUser(userName);
+                    }
+                }
+                catch (Exception e)
+                {
+                    log.error("Registration Error: Failed to rollback user " + userName);
+                }
+                log.error("Registration Error: Failed to create user folders for " + userName + ", " + pe.toString());
+                throw pe;
+            }
+                        
+        }
+        catch (Exception e) 
+        {
+            log.error("Registration Error: Failed to create registered user " + userName + ", " + e.toString());
+            throw new RegistrationException(e); 
+        }        
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.administration.PortalAdministration#generatePassword()
+     */
+    public String generatePassword()
+    {
+        return adminUtil.generatePassword();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.administration.PortalAdministration#sendPassword(java.lang.String)
+     */
+    public void sendEmail(PortletConfig  portletConfig,
+                          String emailAddress, 
+                          String localizedSubject, 
+                          String localizedTemplatePath,
+                          Map userAttributes)                            
+    throws AdministrationEmailException    
+    {       
+        
+        String from = config.getString(PortalConfigurationConstants.EMAIL_SENDER);
+        String subject = localizedSubject;
+        String to = emailAddress;
+        String text = mergeEmailTemplate(portletConfig, userAttributes, "map", localizedTemplatePath);
+        sendEmail(from, subject, to, text);
+        
+    }
+    
+    /**
+     * @param from
+     * @param subject
+     * @param to
+     * @param text
+     * @throws AdministrationEmailException
+     */
+    public void sendEmail(String from, String subject, String to, String text) throws AdministrationEmailException
+    {
+        SimpleMailMessage msg = new SimpleMailMessage();
+        if(from == null) 
+        {
+            from = "jetspeed-admin@apache.org";
+        }
+        msg.setFrom(from);
+        if(subject == null) 
+        {
+            subject = "message from jetspeed";
+        }
+        msg.setSubject(subject);
+        msg.setTo(to);
+        msg.setText(text);
+        try
+        {
+            mailSender.send(msg);
+        } 
+        catch (MailException ex)
+        {
+            throw new AdministrationEmailException(
+                    "Failed to send forgotten password email to user with email address because "+ex.getMessage()
+                            ); //+ user.getEmail());
+        }
+    }
+    
+    public String mergeEmailTemplate(PortletConfig  portletConfig, Map attributes, String attributesName, String template)
+    throws AdministrationEmailException
+    {
+        VelocityContext context = new VelocityContext();
+        context.put(attributesName, attributes);
+        StringWriter writer = new StringWriter();
+        
+        try
+        {
+            String realTemplatePath = portletConfig.getPortletContext().getRealPath(template);
+            FileReader templateReader = new FileReader(realTemplatePath);
+            velocityEngine.evaluate(context, writer, "UserEmailProcessor", templateReader);
+        } catch (Exception e)
+        {
+            throw new AdministrationEmailException(
+                    "Failed to generate email text for email template "
+                            + template, e);
+        }
+        
+        String buffer = writer.getBuffer().toString();
+        
+        return buffer;
+    }
+    
+    private static final String USER_NOT_FOUND_FROM_EMAIL = "User not found for Email address: ";
+    
+    public User lookupUserFromEmail(String email)
+        throws AdministrationEmailException    
+    {
+        Collection<User> users;
+        try
+        {
+            users = userManager.lookupUsers("user.business-info.online.email", email);
+        } 
+        catch (SecurityException e)
+        {
+            throw new AdministrationEmailException(e);        
+        }
+        if (users.isEmpty())
+        {
+            throw new AdministrationEmailException(USER_NOT_FOUND_FROM_EMAIL + email);
+        }
+        return users.iterator().next(); // return the first one and hopefully the only (FIXME: need unique constraints)
+    }
+
+    /**
+     * Helper for admin portlets to generate portal urls
+     */
+    public String getPortalURL(PortletRequest request, PortletResponse response, String path)
+    {
+        // get internal request context
+        RequestContext context = (RequestContext)
+            request.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
+        String baseUrl = context.getPortalURL().getBaseURL();
+        String jetspeedPath = adminUtil.concatenatePaths(baseUrl, context.getPortalURL().getBasePath());
+        if (path == null)
+            return jetspeedPath;
+        return adminUtil.concatenatePaths(jetspeedPath, response.encodeURL(path));
+    }
+        
+    
+    Map forgottenPasswordData = new HashMap();
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.administration.PortalAdministration#getNewLoginInfo(java.lang.String)
+     */
+    public Map getNewLoginInfo(String guid)
+    {
+        synchronized(forgottenPasswordData) {
+            return (Map) forgottenPasswordData.get(guid);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.administration.PortalAdministration#setNewLoginInfo(java.lang.String, org.apache.jetspeed.administration.PortalAdministration.ResetPasswordInfo)
+     */
+    public void putNewLoginInfo(String guid, Map info)
+    {
+        synchronized(forgottenPasswordData) {
+            forgottenPasswordData.put(guid,info);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.administration.PortalAdministration#removeNewLoginInfo(java.lang.String)
+     */
+    public void removeNewLoginInfo(String guid)
+    {
+        synchronized(forgottenPasswordData) {
+            forgottenPasswordData.remove(guid);
+        }
+    }
+    
+    
+    
+    
+    
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAuthenticationConfigurationImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalConfigurationImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/FileServerValve.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/FileServerValve.java?rev=725977&r1=725976&r2=725977&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/FileServerValve.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/FileServerValve.java Fri Dec 12 04:06:29 2008
@@ -1,79 +1,79 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You 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 org.apache.jetspeed.aggregator;
-
-import org.apache.jetspeed.PortalReservedParameters;
-import org.apache.jetspeed.pipeline.PipelineException;
-import org.apache.jetspeed.pipeline.valve.AbstractValve;
-import org.apache.jetspeed.pipeline.valve.ValveContext;
-import org.apache.jetspeed.request.RequestContext;
-
-/**
- * FileServerValve
- *
- * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
- * @version $Id: $
- */
-public class FileServerValve extends AbstractValve
-{
-    private String portletName;
-    private String portletEntity;
-    
-    public FileServerValve(String portletName, String portletEntity)
-    {
-        this.portletName = portletName;
-        this.portletEntity = portletEntity;
-    }
-        
-    public void invoke( RequestContext request, ValveContext context )
-        throws PipelineException
-    {
-        try
-        {
-            String entity = request.getRequestParameter(PortalReservedParameters.PORTLET_ENTITY);
-            if (entity == null)
-            {
-                entity = (String)request.getAttribute(PortalReservedParameters.PORTLET_ENTITY);
-            }
-            if (entity == null)
-            {
-                request.setAttribute(PortalReservedParameters.PORTLET_ENTITY, portletEntity);
-            }        
-
-            String name = request.getRequestParameter(PortalReservedParameters.PORTLET);
-            if (name == null)
-            {
-                name = (String)request.getAttribute(PortalReservedParameters.PORTLET);
-            }
-            if (name == null)
-            {
-                request.setAttribute(PortalReservedParameters.PORTLET, portletName);
-            }        
-        }
-        catch (Exception e)
-        {
-            throw new PipelineException(e);
-        }
-        // Pass control to the next Valve in the Pipeline
-        context.invokeNext( request );
-    }
-
-    public String toString()
-    {
-        return "FileServerValve";
-    }
-}
+ * 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 org.apache.jetspeed.aggregator;
+
+import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.pipeline.PipelineException;
+import org.apache.jetspeed.pipeline.valve.AbstractValve;
+import org.apache.jetspeed.pipeline.valve.ValveContext;
+import org.apache.jetspeed.request.RequestContext;
+
+/**
+ * FileServerValve
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class FileServerValve extends AbstractValve
+{
+    private String portletName;
+    private String portletEntity;
+    
+    public FileServerValve(String portletName, String portletEntity)
+    {
+        this.portletName = portletName;
+        this.portletEntity = portletEntity;
+    }
+        
+    public void invoke( RequestContext request, ValveContext context )
+        throws PipelineException
+    {
+        try
+        {
+            String entity = request.getRequestParameter(PortalReservedParameters.PORTLET_ENTITY);
+            if (entity == null)
+            {
+                entity = (String)request.getAttribute(PortalReservedParameters.PORTLET_ENTITY);
+            }
+            if (entity == null)
+            {
+                request.setAttribute(PortalReservedParameters.PORTLET_ENTITY, portletEntity);
+            }        
+
+            String name = request.getRequestParameter(PortalReservedParameters.PORTLET);
+            if (name == null)
+            {
+                name = (String)request.getAttribute(PortalReservedParameters.PORTLET);
+            }
+            if (name == null)
+            {
+                request.setAttribute(PortalReservedParameters.PORTLET, portletName);
+            }        
+        }
+        catch (Exception e)
+        {
+            throw new PipelineException(e);
+        }
+        // Pass control to the next Valve in the Pipeline
+        context.invokeNext( request );
+    }
+
+    public String toString()
+    {
+        return "FileServerValve";
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/FileServerValve.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/HeaderAggregatorValve.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/HeaderAggregatorValve.java?rev=725977&r1=725976&r2=725977&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/HeaderAggregatorValve.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/HeaderAggregatorValve.java Fri Dec 12 04:06:29 2008
@@ -1,60 +1,60 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You 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 org.apache.jetspeed.aggregator;
-
-import org.apache.jetspeed.pipeline.PipelineException;
-import org.apache.jetspeed.pipeline.valve.AbstractValve;
-import org.apache.jetspeed.pipeline.valve.ValveContext;
-import org.apache.jetspeed.request.RequestContext;
-
-/**
- * Invokes the header aggregator service in the request pipeline
- *
- * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
- * @version $Id: $
- */
-public class HeaderAggregatorValve
-       extends AbstractValve
-{
-    private Aggregator aggregator;
-    
-    public HeaderAggregatorValve(Aggregator aggregator)
-    {
-        this.aggregator = aggregator;
-    }
-        
-    public void invoke( RequestContext request, ValveContext context )
-        throws PipelineException
-    {
-        try
-        {
-            aggregator.build(request);
-        }
-        catch (Exception e)
-        {
-            throw new PipelineException(e.toString(), e);
-        }
-        // Pass control to the next Valve in the Pipeline
-        context.invokeNext( request );
-    }
-
-    public String toString()
-    {
-        return "HeaderAggregatorValve";
-    }
+ * 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 org.apache.jetspeed.aggregator;
+
+import org.apache.jetspeed.pipeline.PipelineException;
+import org.apache.jetspeed.pipeline.valve.AbstractValve;
+import org.apache.jetspeed.pipeline.valve.ValveContext;
+import org.apache.jetspeed.request.RequestContext;
+
+/**
+ * Invokes the header aggregator service in the request pipeline
+ *
+ * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class HeaderAggregatorValve
+       extends AbstractValve
+{
+    private Aggregator aggregator;
+    
+    public HeaderAggregatorValve(Aggregator aggregator)
+    {
+        this.aggregator = aggregator;
+    }
+        
+    public void invoke( RequestContext request, ValveContext context )
+        throws PipelineException
+    {
+        try
+        {
+            aggregator.build(request);
+        }
+        catch (Exception e)
+        {
+            throw new PipelineException(e.toString(), e);
+        }
+        // Pass control to the next Valve in the Pipeline
+        context.invokeNext( request );
+    }
+
+    public String toString()
+    {
+        return "HeaderAggregatorValve";
+    }
 }
\ No newline at end of file

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/HeaderAggregatorValve.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/AsyncPageAggregatorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/BaseAggregatorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/CommonjWorkerMonitorImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/CommonjWorkerMonitorImpl.java?rev=725977&r1=725976&r2=725977&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/CommonjWorkerMonitorImpl.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/CommonjWorkerMonitorImpl.java Fri Dec 12 04:06:29 2008
@@ -1,500 +1,500 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.jetspeed.aggregator.impl;
-
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Arrays;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jetspeed.aggregator.RenderingJob;
-import org.apache.jetspeed.aggregator.Worker;
-import org.apache.jetspeed.aggregator.WorkerMonitor;
-import org.apache.jetspeed.aggregator.PortletContent;
-
-import org.apache.jetspeed.container.PortletWindow;
-
-import commonj.work.WorkManager;
-import commonj.work.Work;
-import commonj.work.WorkItem;
-import commonj.work.WorkListener;
-import commonj.work.WorkEvent;
-
-/**
- * The CommonjWorkerMonitorImpl is responsible for dispatching jobs to workers
- * It wraps CommonJ WorkManager supported by IBM WebSphere and BEA WebLogic sever.
- *
- * @author <a href="mailto:woon_san@apache.org">Woonsan Ko</a>
- * @version $Id: CommonjWorkerMonitorImpl.java 568339 2007-08-22 00:14:51Z ate $
- */
-public class CommonjWorkerMonitorImpl implements WorkerMonitor, WorkListener
-{
-
-    public static final String ACCESS_CONTROL_CONTEXT_WORKER_ATTR = AccessControlContext.class.getName();
-    public static final String COMMONJ_WORK_ITEM_ATTR = WorkItem.class.getName();
-    public static final String WORKER_THREAD_ATTR = Worker.class.getName();
-    
-    /** CommonJ Work Manamger provided by JavaEE container */
-    protected WorkManager workManager;
-
-    /** If true, invoke interrupt() on the worker thread when the job is timeout. */
-    protected boolean interruptOnTimeout = true;
-    
-    /** Enable rendering job works monitor thread for timeout checking */
-    protected boolean jobWorksMonitorEnabled = true;
-    
-    /** Rendering job works to be monitored for timeout checking */
-    protected Map jobWorksMonitored = Collections.synchronizedMap(new HashMap());
-    
-    public CommonjWorkerMonitorImpl(WorkManager workManager)
-    {
-        this(workManager, true);
-    }
-    
-    public CommonjWorkerMonitorImpl(WorkManager workManager, boolean jobWorksMonitorEnabled)
-    {
-        this(workManager, jobWorksMonitorEnabled, true);
-    }
-    
-    public CommonjWorkerMonitorImpl(WorkManager workManager, boolean jobWorksMonitorEnabled, boolean interruptOnTimeout)
-    {
-        this.workManager = workManager;
-        this.jobWorksMonitorEnabled = jobWorksMonitorEnabled;
-        this.interruptOnTimeout = interruptOnTimeout;
-    }
-    
-    /** Commons logging */
-    protected final static Log log = LogFactory.getLog(CommonjWorkerMonitorImpl.class);
-    
-    /** Renering Job Timeout monitor */
-    protected CommonjWorkerRenderingJobTimeoutMonitor jobMonitor = null;
-    
-    public void start()
-    {
-        if (this.jobWorksMonitorEnabled)
-        {
-            jobMonitor = new CommonjWorkerRenderingJobTimeoutMonitor(1000);
-            jobMonitor.start();
-        }
-    }
-
-    public void stop()
-    {
-        if (jobMonitor != null)
-        {
-            jobMonitor.endThread();
-        }
-
-        jobMonitor = null;
-    }
-    
-    /**
-     * Assign a job to a worker and execute it or queue the job if no
-     * worker is available.
-     *
-     * @param job the Job to process
-     */
-    public void process(RenderingJob job)
-    {
-        AccessControlContext context = AccessController.getContext();
-        job.setWorkerAttribute(ACCESS_CONTROL_CONTEXT_WORKER_ATTR, context);
-        
-        try
-        {
-            RenderingJobCommonjWork jobWork = new RenderingJobCommonjWork(job);
-            WorkItem workItem = this.workManager.schedule(jobWork, this);
-            job.setWorkerAttribute(COMMONJ_WORK_ITEM_ATTR, workItem);
-            
-            if (this.jobWorksMonitorEnabled)
-            {
-                this.jobWorksMonitored.put(workItem, jobWork);
-            }
-        }
-        catch (Throwable t)
-        {
-            log.error("Worker exception", t);
-        }
-    }
-
-    public int getQueuedJobsCount()
-    {
-        return 0;
-    }
-    
-    /**
-     * Wait for all rendering jobs in the collection to finish successfully or otherwise. 
-     * @param renderingJobs the Collection of rendering job objects to wait for.
-     */
-    public void waitForRenderingJobs(List renderingJobs)
-    {
-        if (this.jobWorksMonitorEnabled)
-        {
-            try 
-            {
-                for (Iterator iter = renderingJobs.iterator(); iter.hasNext(); )
-                {
-                    RenderingJob job = (RenderingJob) iter.next();
-                    PortletContent portletContent = job.getPortletContent();
-                    
-                    synchronized (portletContent) 
-                    {
-                        if (!portletContent.isComplete()) 
-                        {
-                            portletContent.wait();
-                        }
-                    }
-                }
-            }
-            catch (Exception e)
-            {
-                log.error("Exception during synchronizing all portlet rendering jobs.", e);
-            }
-        }
-        else
-        {
-            // We cannot use WorkingManager#waitForAll(workitems, timeout_ms) for timeout.
-            // The second argument could be either WorkManager.IMMEDIATE or WorkManager.INDEFINITE.
-            
-            try
-            {
-                if (!renderingJobs.isEmpty())
-                {
-                    Object lock = new Object();
-                    MonitoringJobCommonjWork monitoringWork = new MonitoringJobCommonjWork(lock, renderingJobs);
-                    
-                    synchronized (lock)
-                    {
-                        WorkItem monitorWorkItem = this.workManager.schedule(monitoringWork, this);
-                        lock.wait();
-                    }
-                }
-            }
-            catch (Exception e)
-            {
-                log.error("Exception during synchronizing all portlet rendering jobs.", e);
-            }
-        }
-    }
-    
-    /**
-     * Returns a snapshot of the available jobs
-     * @return available jobs
-     */
-    public int getAvailableJobsCount()
-    {
-        return 0;
-    }
-    
-    public int getRunningJobsCount()
-    {
-        return 0;
-    }
-    
-    // commonj.work.WorkListener implementations
-    
-    public void workAccepted(WorkEvent we)
-    {
-        WorkItem workItem = we.getWorkItem();
-        if (log.isDebugEnabled()) log.debug("[CommonjWorkMonitorImpl] workAccepted: " + workItem);
-    }
-
-    public void workRejected(WorkEvent we)
-    {
-        WorkItem workItem = we.getWorkItem();
-        if (log.isDebugEnabled()) log.debug("[CommonjWorkMonitorImpl] workRejected: " + workItem);
-        
-        if (this.jobWorksMonitorEnabled)
-        {
-            removeMonitoredJobWork(workItem);
-        }
-    }
-
-    public void workStarted(WorkEvent we)
-    {
-        WorkItem workItem = we.getWorkItem();
-        if (log.isDebugEnabled()) log.debug("[CommonjWorkMonitorImpl] workStarted: " + workItem);
-    }
-
-    public void workCompleted(WorkEvent we)
-    {
-        WorkItem workItem = we.getWorkItem();
-        if (log.isDebugEnabled()) log.debug("[CommonjWorkMonitorImpl] workCompleted: " + workItem);
-        
-        if (this.jobWorksMonitorEnabled)
-        {
-            removeMonitoredJobWork(workItem);
-        }
-    }
-    
-    protected Object removeMonitoredJobWork(WorkItem workItem)
-    {
-        return this.jobWorksMonitored.remove(workItem);
-    }
-    
-    class RenderingJobCommonjWork implements Work
-    {
-
-        protected RenderingJob job;
-
-        public RenderingJobCommonjWork(RenderingJob job)
-        {
-            this.job = job;
-        }
-
-        public boolean isDaemon()
-        {
-            return false;
-        }
-        
-        public void run()
-        {
-            if (jobWorksMonitorEnabled || interruptOnTimeout)
-            {
-                this.job.setWorkerAttribute(WORKER_THREAD_ATTR, Thread.currentThread());
-            }
-            
-            this.job.run();
-        }
-        
-        public void release()
-        {
-        }
-        
-        public RenderingJob getRenderingJob()
-        {
-            return this.job;
-        }
-    }
-
-    class MonitoringJobCommonjWork implements Work
-    {
-        
-        protected Object lock;
-        protected List renderingJobs;
-
-        public MonitoringJobCommonjWork(Object lock, List jobs)
-        {
-            this.lock = lock;
-            this.renderingJobs = new ArrayList(jobs);
-        }
-        
-        public boolean isDaemon()
-        {
-            return false;
-        }
-        
-        public void run()
-        {
-            try
-            {
-                while (!this.renderingJobs.isEmpty())
-                {
-                    for (Iterator it = this.renderingJobs.iterator(); it.hasNext(); )
-                    {
-                        RenderingJob job = (RenderingJob) it.next();
-                        WorkItem workItem = (WorkItem) job.getWorkerAttribute(COMMONJ_WORK_ITEM_ATTR);
-                        int status = WorkEvent.WORK_ACCEPTED;
-                        
-                        if (workItem != null)
-                        {
-                            status = workItem.getStatus();
-                        }
-                        
-                        boolean isTimeout = job.isTimeout();
-                        
-                        if (isTimeout)
-                        {
-                            PortletContent content = job.getPortletContent();
-                            
-                            if (interruptOnTimeout)
-                            {
-                                Thread worker = (Thread) job.getWorkerAttribute(WORKER_THREAD_ATTR);
-                                
-                                if (worker != null)
-                                {
-                                    synchronized (content)
-                                    {
-                                        if (!content.isComplete()) {
-                                            worker.interrupt();
-                                            content.wait();
-                                        }
-                                    }
-                                }
-                            }
-                            else
-                            {
-                                synchronized (content)
-                                {
-                                    content.completeWithError();
-                                }
-                            }
-                        }
-                        
-                        if (status == WorkEvent.WORK_COMPLETED || status == WorkEvent.WORK_REJECTED || isTimeout)
-                        {
-                            it.remove();
-                        }                    
-                    }
-                    
-                    if (!this.renderingJobs.isEmpty())
-                    {
-                        synchronized (this)
-                        {
-                            wait(100);
-                        }
-                    }
-                }
-                
-                synchronized (this.lock)
-                {
-                    this.lock.notify();
-                }
-            }
-            catch (Exception e)
-            {
-                log.error("Exceptiong during job timeout monitoring.", e);
-            }
-        }
-        
-        public void release()
-        {
-        }
-        
-    }
-
-    class CommonjWorkerRenderingJobTimeoutMonitor extends Thread {
-
-        long interval = 1000;
-        boolean shouldRun = true;
-        
-        CommonjWorkerRenderingJobTimeoutMonitor(long interval) 
-        {
-            super("CommonjWorkerRenderingJobTimeoutMonitor");
-
-            if (interval > 0) 
-            {
-                this.interval = interval;
-            }
-        }
-        /**
-         * Thread.stop() is deprecated.
-         * This method achieves the same by setting the run varaible "shouldRun" to false and interrupting the Thread, 
-         * effectively causing the thread to shutdown correctly.
-         *
-         */
-        public void endThread()
-        {
-        	shouldRun = false;
-        	this.interrupt();
-        }
-        
-        public void run() {
-            while (shouldRun) {
-                try 
-                {
-                    List timeoutJobWorks = new ArrayList();
-                    Collection jobWorks = Arrays.asList(jobWorksMonitored.values().toArray());
-                    
-                    for (Iterator it = jobWorks.iterator(); it.hasNext(); )
-                    {
-                        RenderingJobCommonjWork jobWork = (RenderingJobCommonjWork) it.next();
-                        RenderingJob job = jobWork.getRenderingJob();
-                        
-                        if (job.isTimeout())
-                        {
-                            timeoutJobWorks.add(jobWork);
-                        }
-                    }
-                    
-                    // Now, we can kill the timeout worker(s).
-                    for (Iterator it = timeoutJobWorks.iterator(); it.hasNext(); )
-                    {
-                        RenderingJobCommonjWork jobWork = (RenderingJobCommonjWork) it.next();
-                        RenderingJob job = jobWork.getRenderingJob();
-
-                        // If the job is just completed, then do not kill the worker.
-                        if (job.isTimeout())
-                        {
-                            killJobWork(jobWork);
-                        }
-                    }
-                } 
-                catch (Exception e) 
-                {
-                    log.error("Exception during job monitoring.", e);
-                }
-               
-                try 
-                {
-                    synchronized (this) 
-                    {
-                        wait(this.interval);
-                    }
-                } 
-                catch (InterruptedException e) 
-                {
-                    ;
-                }
-            }
-        }
-        
-        public void killJobWork(RenderingJobCommonjWork jobWork) {
-            RenderingJob job = jobWork.getRenderingJob();
-            
-            try {
-                if (log.isWarnEnabled()) {
-                    PortletWindow window = job.getWindow();
-                    log.warn("Portlet Rendering job to be interrupted by timeout (" + job.getTimeout() + "ms)" + (window != null ? ": "+window.getId().getStringId() : ""));
-                }
-
-                PortletContent content = job.getPortletContent();
-                Thread worker = (Thread) job.getWorkerAttribute(WORKER_THREAD_ATTR);
-                
-                if (worker != null)
-                {
-                    synchronized (content)
-                    {
-                        if (!content.isComplete()) {
-                            worker.interrupt();
-                            content.wait();
-                        }
-                    }
-                }
-            } catch (Exception e) {
-                log.error("Exceptiong during job killing.", e);
-            } finally {
-                WorkItem workItem = (WorkItem) job.getWorkerAttribute(COMMONJ_WORK_ITEM_ATTR);
-                
-                if (workItem != null)
-                {
-                    removeMonitoredJobWork(workItem);
-                }
-            }
-        }
-        
-    }
-    
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.jetspeed.aggregator.impl;
+
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Arrays;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.aggregator.RenderingJob;
+import org.apache.jetspeed.aggregator.Worker;
+import org.apache.jetspeed.aggregator.WorkerMonitor;
+import org.apache.jetspeed.aggregator.PortletContent;
+
+import org.apache.jetspeed.container.PortletWindow;
+
+import commonj.work.WorkManager;
+import commonj.work.Work;
+import commonj.work.WorkItem;
+import commonj.work.WorkListener;
+import commonj.work.WorkEvent;
+
+/**
+ * The CommonjWorkerMonitorImpl is responsible for dispatching jobs to workers
+ * It wraps CommonJ WorkManager supported by IBM WebSphere and BEA WebLogic sever.
+ *
+ * @author <a href="mailto:woon_san@apache.org">Woonsan Ko</a>
+ * @version $Id: CommonjWorkerMonitorImpl.java 568339 2007-08-22 00:14:51Z ate $
+ */
+public class CommonjWorkerMonitorImpl implements WorkerMonitor, WorkListener
+{
+
+    public static final String ACCESS_CONTROL_CONTEXT_WORKER_ATTR = AccessControlContext.class.getName();
+    public static final String COMMONJ_WORK_ITEM_ATTR = WorkItem.class.getName();
+    public static final String WORKER_THREAD_ATTR = Worker.class.getName();
+    
+    /** CommonJ Work Manamger provided by JavaEE container */
+    protected WorkManager workManager;
+
+    /** If true, invoke interrupt() on the worker thread when the job is timeout. */
+    protected boolean interruptOnTimeout = true;
+    
+    /** Enable rendering job works monitor thread for timeout checking */
+    protected boolean jobWorksMonitorEnabled = true;
+    
+    /** Rendering job works to be monitored for timeout checking */
+    protected Map jobWorksMonitored = Collections.synchronizedMap(new HashMap());
+    
+    public CommonjWorkerMonitorImpl(WorkManager workManager)
+    {
+        this(workManager, true);
+    }
+    
+    public CommonjWorkerMonitorImpl(WorkManager workManager, boolean jobWorksMonitorEnabled)
+    {
+        this(workManager, jobWorksMonitorEnabled, true);
+    }
+    
+    public CommonjWorkerMonitorImpl(WorkManager workManager, boolean jobWorksMonitorEnabled, boolean interruptOnTimeout)
+    {
+        this.workManager = workManager;
+        this.jobWorksMonitorEnabled = jobWorksMonitorEnabled;
+        this.interruptOnTimeout = interruptOnTimeout;
+    }
+    
+    /** Commons logging */
+    protected final static Log log = LogFactory.getLog(CommonjWorkerMonitorImpl.class);
+    
+    /** Renering Job Timeout monitor */
+    protected CommonjWorkerRenderingJobTimeoutMonitor jobMonitor = null;
+    
+    public void start()
+    {
+        if (this.jobWorksMonitorEnabled)
+        {
+            jobMonitor = new CommonjWorkerRenderingJobTimeoutMonitor(1000);
+            jobMonitor.start();
+        }
+    }
+
+    public void stop()
+    {
+        if (jobMonitor != null)
+        {
+            jobMonitor.endThread();
+        }
+
+        jobMonitor = null;
+    }
+    
+    /**
+     * Assign a job to a worker and execute it or queue the job if no
+     * worker is available.
+     *
+     * @param job the Job to process
+     */
+    public void process(RenderingJob job)
+    {
+        AccessControlContext context = AccessController.getContext();
+        job.setWorkerAttribute(ACCESS_CONTROL_CONTEXT_WORKER_ATTR, context);
+        
+        try
+        {
+            RenderingJobCommonjWork jobWork = new RenderingJobCommonjWork(job);
+            WorkItem workItem = this.workManager.schedule(jobWork, this);
+            job.setWorkerAttribute(COMMONJ_WORK_ITEM_ATTR, workItem);
+            
+            if (this.jobWorksMonitorEnabled)
+            {
+                this.jobWorksMonitored.put(workItem, jobWork);
+            }
+        }
+        catch (Throwable t)
+        {
+            log.error("Worker exception", t);
+        }
+    }
+
+    public int getQueuedJobsCount()
+    {
+        return 0;
+    }
+    
+    /**
+     * Wait for all rendering jobs in the collection to finish successfully or otherwise. 
+     * @param renderingJobs the Collection of rendering job objects to wait for.
+     */
+    public void waitForRenderingJobs(List renderingJobs)
+    {
+        if (this.jobWorksMonitorEnabled)
+        {
+            try 
+            {
+                for (Iterator iter = renderingJobs.iterator(); iter.hasNext(); )
+                {
+                    RenderingJob job = (RenderingJob) iter.next();
+                    PortletContent portletContent = job.getPortletContent();
+                    
+                    synchronized (portletContent) 
+                    {
+                        if (!portletContent.isComplete()) 
+                        {
+                            portletContent.wait();
+                        }
+                    }
+                }
+            }
+            catch (Exception e)
+            {
+                log.error("Exception during synchronizing all portlet rendering jobs.", e);
+            }
+        }
+        else
+        {
+            // We cannot use WorkingManager#waitForAll(workitems, timeout_ms) for timeout.
+            // The second argument could be either WorkManager.IMMEDIATE or WorkManager.INDEFINITE.
+            
+            try
+            {
+                if (!renderingJobs.isEmpty())
+                {
+                    Object lock = new Object();
+                    MonitoringJobCommonjWork monitoringWork = new MonitoringJobCommonjWork(lock, renderingJobs);
+                    
+                    synchronized (lock)
+                    {
+                        WorkItem monitorWorkItem = this.workManager.schedule(monitoringWork, this);
+                        lock.wait();
+                    }
+                }
+            }
+            catch (Exception e)
+            {
+                log.error("Exception during synchronizing all portlet rendering jobs.", e);
+            }
+        }
+    }
+    
+    /**
+     * Returns a snapshot of the available jobs
+     * @return available jobs
+     */
+    public int getAvailableJobsCount()
+    {
+        return 0;
+    }
+    
+    public int getRunningJobsCount()
+    {
+        return 0;
+    }
+    
+    // commonj.work.WorkListener implementations
+    
+    public void workAccepted(WorkEvent we)
+    {
+        WorkItem workItem = we.getWorkItem();
+        if (log.isDebugEnabled()) log.debug("[CommonjWorkMonitorImpl] workAccepted: " + workItem);
+    }
+
+    public void workRejected(WorkEvent we)
+    {
+        WorkItem workItem = we.getWorkItem();
+        if (log.isDebugEnabled()) log.debug("[CommonjWorkMonitorImpl] workRejected: " + workItem);
+        
+        if (this.jobWorksMonitorEnabled)
+        {
+            removeMonitoredJobWork(workItem);
+        }
+    }
+
+    public void workStarted(WorkEvent we)
+    {
+        WorkItem workItem = we.getWorkItem();
+        if (log.isDebugEnabled()) log.debug("[CommonjWorkMonitorImpl] workStarted: " + workItem);
+    }
+
+    public void workCompleted(WorkEvent we)
+    {
+        WorkItem workItem = we.getWorkItem();
+        if (log.isDebugEnabled()) log.debug("[CommonjWorkMonitorImpl] workCompleted: " + workItem);
+        
+        if (this.jobWorksMonitorEnabled)
+        {
+            removeMonitoredJobWork(workItem);
+        }
+    }
+    
+    protected Object removeMonitoredJobWork(WorkItem workItem)
+    {
+        return this.jobWorksMonitored.remove(workItem);
+    }
+    
+    class RenderingJobCommonjWork implements Work
+    {
+
+        protected RenderingJob job;
+
+        public RenderingJobCommonjWork(RenderingJob job)
+        {
+            this.job = job;
+        }
+
+        public boolean isDaemon()
+        {
+            return false;
+        }
+        
+        public void run()
+        {
+            if (jobWorksMonitorEnabled || interruptOnTimeout)
+            {
+                this.job.setWorkerAttribute(WORKER_THREAD_ATTR, Thread.currentThread());
+            }
+            
+            this.job.run();
+        }
+        
+        public void release()
+        {
+        }
+        
+        public RenderingJob getRenderingJob()
+        {
+            return this.job;
+        }
+    }
+
+    class MonitoringJobCommonjWork implements Work
+    {
+        
+        protected Object lock;
+        protected List renderingJobs;
+
+        public MonitoringJobCommonjWork(Object lock, List jobs)
+        {
+            this.lock = lock;
+            this.renderingJobs = new ArrayList(jobs);
+        }
+        
+        public boolean isDaemon()
+        {
+            return false;
+        }
+        
+        public void run()
+        {
+            try
+            {
+                while (!this.renderingJobs.isEmpty())
+                {
+                    for (Iterator it = this.renderingJobs.iterator(); it.hasNext(); )
+                    {
+                        RenderingJob job = (RenderingJob) it.next();
+                        WorkItem workItem = (WorkItem) job.getWorkerAttribute(COMMONJ_WORK_ITEM_ATTR);
+                        int status = WorkEvent.WORK_ACCEPTED;
+                        
+                        if (workItem != null)
+                        {
+                            status = workItem.getStatus();
+                        }
+                        
+                        boolean isTimeout = job.isTimeout();
+                        
+                        if (isTimeout)
+                        {
+                            PortletContent content = job.getPortletContent();
+                            
+                            if (interruptOnTimeout)
+                            {
+                                Thread worker = (Thread) job.getWorkerAttribute(WORKER_THREAD_ATTR);
+                                
+                                if (worker != null)
+                                {
+                                    synchronized (content)
+                                    {
+                                        if (!content.isComplete()) {
+                                            worker.interrupt();
+                                            content.wait();
+                                        }
+                                    }
+                                }
+                            }
+                            else
+                            {
+                                synchronized (content)
+                                {
+                                    content.completeWithError();
+                                }
+                            }
+                        }
+                        
+                        if (status == WorkEvent.WORK_COMPLETED || status == WorkEvent.WORK_REJECTED || isTimeout)
+                        {
+                            it.remove();
+                        }                    
+                    }
+                    
+                    if (!this.renderingJobs.isEmpty())
+                    {
+                        synchronized (this)
+                        {
+                            wait(100);
+                        }
+                    }
+                }
+                
+                synchronized (this.lock)
+                {
+                    this.lock.notify();
+                }
+            }
+            catch (Exception e)
+            {
+                log.error("Exceptiong during job timeout monitoring.", e);
+            }
+        }
+        
+        public void release()
+        {
+        }
+        
+    }
+
+    class CommonjWorkerRenderingJobTimeoutMonitor extends Thread {
+
+        long interval = 1000;
+        boolean shouldRun = true;
+        
+        CommonjWorkerRenderingJobTimeoutMonitor(long interval) 
+        {
+            super("CommonjWorkerRenderingJobTimeoutMonitor");
+
+            if (interval > 0) 
+            {
+                this.interval = interval;
+            }
+        }
+        /**
+         * Thread.stop() is deprecated.
+         * This method achieves the same by setting the run varaible "shouldRun" to false and interrupting the Thread, 
+         * effectively causing the thread to shutdown correctly.
+         *
+         */
+        public void endThread()
+        {
+        	shouldRun = false;
+        	this.interrupt();
+        }
+        
+        public void run() {
+            while (shouldRun) {
+                try 
+                {
+                    List timeoutJobWorks = new ArrayList();
+                    Collection jobWorks = Arrays.asList(jobWorksMonitored.values().toArray());
+                    
+                    for (Iterator it = jobWorks.iterator(); it.hasNext(); )
+                    {
+                        RenderingJobCommonjWork jobWork = (RenderingJobCommonjWork) it.next();
+                        RenderingJob job = jobWork.getRenderingJob();
+                        
+                        if (job.isTimeout())
+                        {
+                            timeoutJobWorks.add(jobWork);
+                        }
+                    }
+                    
+                    // Now, we can kill the timeout worker(s).
+                    for (Iterator it = timeoutJobWorks.iterator(); it.hasNext(); )
+                    {
+                        RenderingJobCommonjWork jobWork = (RenderingJobCommonjWork) it.next();
+                        RenderingJob job = jobWork.getRenderingJob();
+
+                        // If the job is just completed, then do not kill the worker.
+                        if (job.isTimeout())
+                        {
+                            killJobWork(jobWork);
+                        }
+                    }
+                } 
+                catch (Exception e) 
+                {
+                    log.error("Exception during job monitoring.", e);
+                }
+               
+                try 
+                {
+                    synchronized (this) 
+                    {
+                        wait(this.interval);
+                    }
+                } 
+                catch (InterruptedException e) 
+                {
+                    ;
+                }
+            }
+        }
+        
+        public void killJobWork(RenderingJobCommonjWork jobWork) {
+            RenderingJob job = jobWork.getRenderingJob();
+            
+            try {
+                if (log.isWarnEnabled()) {
+                    PortletWindow window = job.getWindow();
+                    log.warn("Portlet Rendering job to be interrupted by timeout (" + job.getTimeout() + "ms)" + (window != null ? ": "+window.getId().getStringId() : ""));
+                }
+
+                PortletContent content = job.getPortletContent();
+                Thread worker = (Thread) job.getWorkerAttribute(WORKER_THREAD_ATTR);
+                
+                if (worker != null)
+                {
+                    synchronized (content)
+                    {
+                        if (!content.isComplete()) {
+                            worker.interrupt();
+                            content.wait();
+                        }
+                    }
+                }
+            } catch (Exception e) {
+                log.error("Exceptiong during job killing.", e);
+            } finally {
+                WorkItem workItem = (WorkItem) job.getWorkerAttribute(COMMONJ_WORK_ITEM_ATTR);
+                
+                if (workItem != null)
+                {
+                    removeMonitoredJobWork(workItem);
+                }
+            }
+        }
+        
+    }
+    
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/CommonjWorkerMonitorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/aggregator/impl/HeaderAggregatorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message