Files
alfresco-community-repo/source/java/org/alfresco/web/app/Application.java
Dave Ward b2e7793c54 Merged V3.3 to HEAD
20128: Reverse part of previous build fix that breaks other tests ...
   20129: ALF-202, ALF-1488: Fixed portlets in alfresco.war
      - Stop excluding portlet.xml from alfresco.war
      - Used JSR 286 ResourceURL solution to get upload iframes to work in portlets
      - Removed horrific hacks concerning faces session map resolution in portlets and upload servlet
      - WebClientPortletAuthenticator now dispatches to a helper servlet, AuthenticatorServlet, allowing it to use identical servlet mechanisms to authenticate / sign-on the user
      - Portlet Authenticated user now set consistently in application-scoped attribute, so web client, web script portlets and client portlet share same notion of user ID
      - Application.inPortalServer flag now thread local (and thread safe!)
   20130: Merged BRANCHES/V2.2 to BRANCHES/V3.3
      13819: *RECORD ONLY* ACT-6420 - Office 2003 "Install for all users" - DO NOT MERGE
   20131: Merged BRANCHES/V3.1 to BRANCHES/V3.3
      19600: *RECORD ONLY* ALF-2205 - CLONE: Office Plugin: filename overlaps the plugin UI if longer than 40 characters without spaces
         Merged V3.2 to V3.1 (Adobe)
         17499: ETHREEOH-2322 - Office Plugin: filename overlaps the plugin UI if longer than 40 characters without spaces
         19443: ALF-2131 - Office webscripts: Missing close brace, '}'
   20132: ALF-2749 - temporarily skip couple of -ve checks (for MS SQL Server only)
   20133: Merged BRANCHES/V3.2 to BRANCHES/V3.3
      19550: *RECORD ONLY* ALF-1091 - Only 15 tags displayed in Tags section in Browser pane
   20134: Adding files missed during first commit of Meeting Workspace code
   20135: Merged V3.2 to V3.3
      19814: *RECORD ONLY* Fix for ALF-2322 - discussion topic containing non-ascii characters cannot be saved
      19934: *RECORD ONLY* Fix for ALF-2512 - ability to execute JavaScript via cmd servlet by a non-admin user disabled by default.
             - user script execution privileges can be reactivated if required via web-client-config flag <allow-user-script-execute>
      19935: *RECORD ONLY* Corrected imports for 3.2 compatability
   20136: Merge Dev to V3.3
      20104 : ALF-676 -  imapFolders patch fails if versionable aspect is mandatory on cm:content
   20137: Workaround for ALF-2639: Sharepoint: Share Edit Online uses Share protocol rather than Alfresco protocol to build link
      - Replace "https:" protocol with "http:" when generating "Edit Online" URL
   20138: Merged V3.1 to V3.3
      18204: *RECORD ONLY* Merged DEV/TEMPORARY to 3.1
         17837: ETHREEOH-3801: Creating users via the api does not add them to the user store
      18577: *RECORD ONLY* Fix for ETHREEOH-4117, based on CHK-11154
      19373: *RECORD ONLY* Merged V3.2 to V3.1
         19216: ENH-506 - allow script compilation to be disabled for repository tier. Fix to unreported issue with return aspect array from a ScriptNode.
   20139: Merged V2.2 to V3.3
      18518: *RECORD ONLY* Fix for ETWOTWO-1375
      18522: *RECORD ONLY* Merged DEV-TEMPORARY to V2.2
         18440: TinyMCE HTML Image gets invalid path
         18503: ETWOTWO-1035: Error message when bypassing the 'close' and directly clicking on breadcrumb link after a deployment
         18504: ETWOTWO-1035: Error message when bypassing the 'close' and directly clicking on breadcrumb link after a deployment
      18578: Merged DEV-TEMPORARY to V2.2
         18528: ETWOTWO-1114: Missing 'Required' items are not highlighted in the error when missed
      19094: *RECORD ONLY* Merged V3.1 to V2.2
         14015: Fixes for ETHREEOH-1864 and ETHREEOH-1840
   20140: Remove unwanted @overide
   20141: Lazy schema introspection to shave off a few seconds on startup
      - Saves about 5s on dev machine
      - Hibernate still has to look at the DB metadata, though
   20144: Merged V2.2 to V3.3
      18859: (RECORD ONLY) ALF-1882: Merged V3.2 to V2.2
         17292: ETHREEOH-1842: Ticket association with HttpSession IDs tracked so that we don't invalidate a ticket in use by multiple sessions prematurely
            - AuthenticationService validate, getCurrentTicket, etc. methods now take optional sessionId arguments
      18864: (RECORD ONLY) ALF-1882: Fixed compilation error from previous checkin.
   20145: Merged V3,1 to V3.3
      19584: (RECORD ONLY) ALF-2207: Merged V3.2 to V3.1 (Adobe)
         18277: Merged DEV_TEMPORARY to V3.2
            18178: ETHREEOH-3222: ERROR [org.alfresco.webdav.protocol] WebDAV method not implemented - PROPPATCH
      19660: (RECORD ONLY) ALF-2266: Merged V3.2 to V3.1 (Adobe)
         19562: Merged DEV/BELARUS/V3.2-2010_02_24 to V3.2
            19244: ALF-1816: Email templates can no longer be selected when creating a rule for the action 'Send email to specified users' following an upgrade
               - New patch has been created to create invite email templates and notify email templates folders if those are absent. Also it moves default notify and invite templates into appropriate folders. 
      19662: (RECORD ONLY) Incremented version label
      19663: (RECORD ONLY) Corrected version label
      19779: (RECORD ONLY) Incremented version label
   20148: Merged PATCHES/V3.2.r to V3.3
      20029: ALF-2624: Avoid NPE in LDAP sync when there are dangling references and improve logging
      20053: (RECORD ONLY) Incremented version number
   20151: ALF-2749 - unit test fix (re-arranged -ve checks for txn boundaries, functionally equivalent)
   20152: Merged HEAD to BRANCHES/V3.3: (RECORD ONLY)
      20050: Fix ALF-2637: objectTypeId updatability reported as "readonly" rather then "oncreate"
      20051: Fix for ALF-2609:  CMIS ACL mapping improvements
      20052: Fix for ALF-2609:  CMIS ACL mapping improvements
      20086: Fix re-opened ALF-2637: "objectTypeId" updatability reported as "readonly" rather then "oncreate"
      20125: Fix ALF-2728: AtomPub renditions are not rendered as part of cmis:object, although their rel links are.
   20153: Merged HEAD to BRANCHES/V3.3: (RECORD ONLY)
      20067: Fix ALF-2691: Choice display names in Type Definition are not escaped properly in AtomPub binding
   20154: ALF-1598: Share - Edit online missing on preview page
      - Note: The details page doesn't know when Office opens the file, so may show stale information.
   20156: Build/unit test - comment-out force re-index (IndexCheckServiceImplTest)
   20157: Office add-in: Missing i18n string found whilst investigating ALF-605: Script error appears when start typing not-existent user in "Assign to" filed
      - Changed behaviour slightly so that "start workflow" panel remains if error occurred during submit
   20164: Fix trailing commas that MSIE doesn't like. Plus fix for renamed webscript reference.
   20168: Attempting to fix failing test in ThumbnailService.
      The change adds some extra logging and exception info too.
   20169: Build/unit test - temporarily put back "force re-index" (IndexCheckServiceImplTest)
      - TODO: re-work test for build env
   20170: Fix NPE (AVMStoreImpl.createSnapshot)
      - see DBC-HEADPOSTGRESQL-34
   20173: Propagate IOExceptions from retryable write transactions in AlfrescoDiskDriver
   20176: Merge from V3.2 to V3.3. Merge ok'ed by Steve.
      20175: JMX configuration of enterprise logging broken
   20178: JodConverter loggers are now exposed in JMX.
      This follows on from check-ins 20175 (on V32) and 20176 (on V33) which fixed the JMX logging for enterprise code.
   20180: Fixes ALF-2021 by adding new date format properties and exposing YUI widget options.
   20185: Various core fixes and additional debug output. Part of ALF-1554.
   20186: Fix for OpenOffice multiple versions per edit problem. ALF-1554.
   20187: Merged BRANCHES/DEV/V3.3-BUG-FIX to BRANCHES/V3.3:
      20181: IndexCheckServiceImplTest - by default, check test store only (reduces current ent build time by nearly 1 hour !)
   20188: Fix -exploded build target for Share to copy core classes folder
   20191: Merged HEAD to BRANCHES/V3.3: (RECORD ONLY)
      20190: Fix ALF-2774: Atompub createDocument with versioningState=checkedout followed by checkin does not create major version, Fix ALF-2782: AtomPub binding incorrectly handles atom:title when no value is provided (often done for compliant atom entry)
   20193: Merge 3.2 to 3.3:
      19759: Fix for CIFS/CheckInOut.exe save of working copy breaks lock on original file. ALF-2028. (Record-only)
      19760: Fix for working copy checked out via CIFS is not accessible until FileStateReaper expires file state. ALF-962. (Record-only)
   20195: Form fields for numbers are now rendered much smaller that text fields following feedback from meetups. Must be included in 3.3 as requested by Paul.
   20197: Rules: Size property is now more userfriendly & IE bugs are solved
      - Numbers and booleans where posted as strings to the server making property comparisons against properties such as "Size" to fail on the server
      - Size, encoding & mimetype are now options by default in the "IF/Unless" drop downs
      - When comparing Size properties a "bytes" label is placed to the right of the text field
      - "Show more..." menu now displays aspect/type ids on mouse hover in the tree 
      - "Show more..." menu now displays a new column for the property name in the list next to the property displayLabel
      - The list in the "Show more..." menu now stays in its place instead of being pushed down in some browsers
      - IE css fixes to make rules look good in IE 6, 7 & 8
      - Fixed IE 6 & 7 issue with generateDomId & getAttribute("id") not being in sync
      - Fixed IE 6 & 7 issue where Selector.query only worked with "id" as root attribute
   20199: Merge 3.1 to 3.3 (All record-only):
      14483: Merged HEAD to v3.1:
                 13942 Added FTP IPv6 support. MOB-714.
      14484: Merged HEAD to v3.1:
                 13943 Added FTP IPv6 configuration. Added the ftp.ipv6 property. MOB-714.
      14523: Add trailing 'A' to CIFS server name, removed by recent checkin.
      14916: Fixes for local domain lookup when WINS is configured. ETHREEOH-2263.
      14921: Merge HEAD to V3.1:
                 14599: Fixes to file server ACL parsing, part of ETHREEOH-2177
      14930: Updated svn:mergeinfo
      15231: Fix for cut/paste file between folders on CIFS. ETHREEOH-2323.
      15570: Merge 3.2 to 3.1:
                 15548: CIFS server memory leak fixes (clear auth context, session close). ETHREEOH-2538
      15571: Merge 3.2 to 3.1:
                 15549: Check for null ClientInfo in the setCurrentUser() method and clear the auth context. Part of ETHREEOH-2538.
                 15550: Fixed performance issue in the continue search code, add warn level output of folder search timing.
      15572: Update svn:mergeinfo
      15627: Merge 3.2 to 3.1:
                 15626: Fixed NetBIOS reports an invalid packet during session connection, and connection stalls for a while. JLAN-86.
      15628: Update svn:mergeinfo
      15780: Fix for MS Office document locking issue. ETHREEOH-2579.
      15827: Fixed bug in delete node event processing.
      16160: Minor change to debug output
      16162: Add support for the . and .. pseudo entries in a folder search.
      16163: Added timstamp tracking via the file state cache, blend cached timestamps into file info/folder search results.
      16555: Fix for processing of NetBIOS packets over 64K in the older JNI code. Part of ETHREEOH-2882.
      16556: Fix for CIFS session leak and 100% CPU when connect/disconnecting quickly. ETHREEOH-2881.
      16559: Fix for ACL parsing in the standalone JLAN Server build. JLAN-89.
      16666: Fix for CIFS cannot handle requests over 64K in JNI code, causes session disconnect, standalone server. JLAN-91.
      16709: Fixed the FTP not logged on status return code, now uses reply code 530. JLAN-90.
      16710: Added CIFS NT status code/text for the 'account locked' status, 0xC0000234. ETHREEOH-2897.
      16717: Fixed setAllowConsoleShutdown setting in standalone server can cause infinite loop. JLAN-38.
      16718: Fix for Alfresco and AVM spaces are empty when viewed by FTP and Alfresco is run as non-root. ETHREEOH-2652.
      16727: Fix for unable to connect via FTP via Firefox (when anonymous logons are not enabled). ETHREEOH-2012.
      16987: Merge 2.2 to 3.1:
                 13089: (record-only) Fix "Read-Write transaction" exception, when the user does not exist. ETWOTWO-1055.
                 13091: (record-only) Fix for NFS server "Read-Write transaction started within read-only transaction" exception. ETWOTWO-1054.
                 14190: (record-only) Fix for cut/paste a folder from Alfresco CIFS to local drive loses folder contents. ETWOTWO-1159.
                 14191: (record-only) Additional fix for CIFS 'No more connections' error. ETWOTWO-556
                 14199: (record-only) Fix for NFS problem with Solaris doing an Access check on the share level handle. ETWOTWO-1225.
                 14210: (record-only) Added support for FTP EPRT and EPSV commands, on IPv4 only. ETWOTWO-325.
                 14216: (record-only) Fixed FTP character encoding, ported UTF8 normalizer code from v3.x. ETWOTWO-1151.
                 14229: (record-only) Remove unused import.
                 14655: (record-only) Convert content I/O exceptions to file server exceptions during write and truncate. ETWOTWO-1241.
                 14825: (record-only) Add support for the extended response to the CIFS NTCreateAndX call, back port of ETWOTWO-1232.
                 15869: (record-only) Port of desktop action client side EXE fixes from v3.x. ETWOTWO-1374.
      17130: Fix for cannot delete file via CIFS that has a thumbnail associated with it. ETHREEOH-3143 and ETHREEOH-3115.
      17359: Fix for CIFS/Kerberos/SPNEGO logon problem with Win2008/Win7 client. ETHREEOH-3225.
      17839: Rewrite the rename file logic to handle MS Office file rename patterns. ETHREEOH-1951.
      17842: Missing file from previous checkin.
      17843: Re-use open files for the same session/process id so that writes on each file handle go to the same file. Port of ETWOTWO-1250.
      17861: Merge 2.2 to 3.1:
                 17803: Re-use open files for the same session/process id so that writes on each file handle go to the same file. ETWOTWO-1250. (Record-only)
      18432: Added FTP data port range configuration via <dataPorts>n:n</dataPorts> config value. ETHREEOH-4103.
      18451: Fixed incorrect FTP debug level name.
   20200: Merge PATCHES/V3.2.1 to 3.3:
      20142: Added debug output to dump the restart file name for FindFirst/FindNext folder searches (via the 'Search' debug output level).
   20201: Merge PATCHES/V3.2.1 to 3.3:
      20143: Fix for files being skipped during a long folder listing via CIFS, ALF-2730.
   20202: Update svn:mergeinfo
   20219: Fix for ALF-2791 - correction to changes in rev 20129 so the upload file servlet path is generated for all cases.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20567 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2010-06-09 13:25:16 +00:00

1231 lines
41 KiB
Java

/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco 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 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.web.app;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.alfresco.repo.importer.ImporterBootstrap;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.web.app.portlet.AlfrescoFacesPortlet;
import org.alfresco.web.app.servlet.AuthenticationHelper;
import org.alfresco.web.app.servlet.FacesHelper;
import org.alfresco.web.bean.ErrorBean;
import org.alfresco.web.bean.SidebarBean;
import org.alfresco.web.bean.dashboard.DashboardManager;
import org.alfresco.web.bean.dialog.DialogManager;
import org.alfresco.web.bean.repository.PreferencesService;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.User;
import org.alfresco.web.bean.users.UserPreferencesBean;
import org.alfresco.web.bean.wizard.WizardManager;
import org.alfresco.web.config.ClientConfigElement;
import org.alfresco.web.config.LanguagesConfigElement;
import org.apache.commons.logging.Log;
import org.springframework.context.ApplicationContext;
import org.springframework.extensions.config.Config;
import org.springframework.extensions.config.ConfigService;
import org.springframework.extensions.surf.util.I18NUtil;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.jsf.FacesContextUtils;
/**
* Utilities class
*
* @author gavinc
*/
public class Application
{
private static final String LOCALE = "locale";
public static final String BEAN_CONFIG_SERVICE = "webClientConfigService";
public static final String BEAN_DATA_DICTIONARY = "dataDictionary";
public static final String BEAN_IMPORTER_BOOTSTRAP = "spacesBootstrap";
public static final String MESSAGE_BUNDLE = "alfresco.messages.webclient";
private static ThreadLocal<Boolean> inPortalServer = new ThreadLocal<Boolean>();
private static StoreRef repoStoreRef;
private static String rootPath;
private static String companyRootId;
private static String glossaryFolderName;
private static String spaceTemplatesFolderName;
private static String contentTemplatesFolderName;
private static String emailTemplatesFolderName;
private static String inviteEmailTemplatesFolderName;
private static String notifyEmailTemplatesFolderName;
private static String rssTemplatesFolderName;
private static String savedSearchesFolderName;
private static String scriptsFolderName;
private static String guestHomeFolderName;
private static String websitesFolderName;
private static String webContentFormsFolderName;
private static String contentFormsFolderName;
private static String projectsFolderName;
private static Boolean isDynamicConfig = null;
/**
* Private constructor to prevent instantiation of this class
*/
private Application()
{
}
/**
* Sets whether this application is running inside a portal server
*
* @param inPortal true to indicate the application is running as a portlet
*/
public static void setInPortalServer(boolean inPortal)
{
inPortalServer.set(inPortal ? Boolean.TRUE : null);
}
/**
* Determines whether the server is running in a portal
*
* @return true if we are running inside a portal server
*/
public static boolean inPortalServer()
{
Boolean result = inPortalServer.get();
return result == null ? false : result;
}
/**
* Handles errors thrown from servlets
*
* @param servletContext The servlet context
* @param request The HTTP request
* @param response The HTTP response
* @param error The exception
* @param logger The logger
*/
public static void handleServletError(ServletContext servletContext, HttpServletRequest request,
HttpServletResponse response, Throwable error, Log logger, String returnPage)
throws IOException, ServletException
{
// get the error bean from the session and set the error that occurred.
HttpSession session = request.getSession();
ErrorBean errorBean = (ErrorBean)session.getAttribute(ErrorBean.ERROR_BEAN_NAME);
if (errorBean == null)
{
errorBean = new ErrorBean();
session.setAttribute(ErrorBean.ERROR_BEAN_NAME, errorBean);
}
errorBean.setLastError(error);
errorBean.setReturnPage(returnPage);
// try and find the configured error page
boolean errorShown = false;
String errorPage = getErrorPage(servletContext);
if (errorPage != null)
{
if (logger.isDebugEnabled())
logger.debug("An error has occurred, redirecting to error page: " + errorPage);
if (response.isCommitted() == false)
{
errorShown = true;
response.sendRedirect(request.getContextPath() + errorPage);
}
else
{
if (logger.isDebugEnabled())
logger.debug("Response is already committed, re-throwing error");
}
}
else
{
if (logger.isDebugEnabled())
logger.debug("No error page defined, re-throwing error");
}
// if we could not show the error page for whatever reason, re-throw the error
if (!errorShown)
{
if (error instanceof IOException)
{
throw (IOException)error;
}
else if (error instanceof ServletException)
{
throw (ServletException)error;
}
else
{
throw new ServletException(error);
}
}
}
/**
* Retrieves the DialogManager managed bean
*
* @return DialogManager bean
*/
public static DialogManager getDialogManager()
{
return (DialogManager)FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), DialogManager.BEAN_NAME);
}
/**
* Retrieves the WizardManager managed bean
*
* @return WizardManager bean
*/
public static WizardManager getWizardManager()
{
return (WizardManager)FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), WizardManager.BEAN_NAME);
}
/**
* Retrieves the DashboardManager managed bean
*
* @return DashboardManager bean
*/
public static DashboardManager getDashboardManager()
{
return (DashboardManager)FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), DashboardManager.BEAN_NAME);
}
/**
* Retrieves the SidebarBean
*
* @return SidebarBean bean
*/
public static SidebarBean getSidebarBean()
{
return (SidebarBean)FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "SidebarBean");
}
/**
* Retrieves the configured error page for the application
*
* @param servletContext The servlet context
* @return The configured error page or null if the configuration is missing
*/
public static String getErrorPage(ServletContext servletContext)
{
return getErrorPage(WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext));
}
/**
* Retrieves the configured login page for the application
*
* @param servletContext The servlet context
* @return The configured login page or null if the configuration is missing
*/
public static String getLoginPage(ServletContext servletContext)
{
return getLoginPage(WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext));
}
/**
* @return Returns the User object representing the currently logged in user
*/
public static User getCurrentUser(HttpSession session)
{
return (User)session.getAttribute(AuthenticationHelper.AUTHENTICATION_USER);
}
/**
* @return Returns the User object representing the currently logged in user
*/
public static User getCurrentUser(FacesContext context)
{
if (inPortalServer())
{
User user = (User) AlfrescoFacesPortlet.getPortletSessionAttribute(context,
AuthenticationHelper.AUTHENTICATION_USER, true);
if (user != null)
{
return user;
}
}
return (User) context.getExternalContext().getSessionMap().get(AuthenticationHelper.AUTHENTICATION_USER);
}
public static void setCurrentUser(FacesContext context, User user)
{
if (inPortalServer())
{
AlfrescoFacesPortlet.setPortletSessionAttribute(context, AuthenticationHelper.AUTHENTICATION_USER, user, true);
}
else
{
context.getExternalContext().getSessionMap().put(AuthenticationHelper.AUTHENTICATION_USER, user);
}
}
/**
* @return Returns the repository store URL (retrieved from config service)
*/
public static StoreRef getRepositoryStoreRef(ServletContext context)
{
return getRepositoryStoreRef(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the repository store URL (retrieved from config service)
*/
public static StoreRef getRepositoryStoreRef(FacesContext context)
{
return getRepositoryStoreRef(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns id of the company root
*
* @deprecated Replace with user-context-specific getCompanyRootId (e.g. could be tenant-specific)
*/
public static String getCompanyRootId()
{
return companyRootId;
}
/**
* Sets the company root id. This is setup by the ContextListener.
*
* @param id The company root id
*
* @deprecated Replace with user-context-specific getCompanyRootId (e.g. could be tenant-specific)
*/
public static void setCompanyRootId(String id)
{
companyRootId = id;
}
/**
* @return Returns id of the company root
*/
public static String getCompanyRootId(FacesContext context)
{
User user = Application.getCurrentUser(context);
if (user != null)
{
String userCompanyRootId = user.getCompanyRootId();
if (userCompanyRootId == null)
{
userCompanyRootId = Repository.getCompanyRoot(context).getId();
user.setCompanyRootId(userCompanyRootId);
}
return userCompanyRootId;
}
else
{
return null;
}
}
/**
* @return Returns the root path for the application
*/
public static String getRootPath(ServletContext context)
{
return getRootPath(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the root path for the application
*/
public static String getRootPath(FacesContext context)
{
return getRootPath(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the glossary folder name
*/
public static String getGlossaryFolderName(ServletContext context)
{
return getGlossaryFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the glossary folder name
*/
public static String getGlossaryFolderName(FacesContext context)
{
return getGlossaryFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the Space templates folder name
*/
public static String getSpaceTemplatesFolderName(ServletContext context)
{
return getSpaceTemplatesFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the Space templates folder name
*/
public static String getSpaceTemplatesFolderName(FacesContext context)
{
return getSpaceTemplatesFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the Content templates folder name
*/
public static String getContentTemplatesFolderName(ServletContext context)
{
return getContentTemplatesFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the Content templates folder name
*/
public static String getContentTemplatesFolderName(FacesContext context)
{
return getContentTemplatesFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the Invite Email Templates folder name
*/
public static String getInviteEmailTemplatesFolderName(ServletContext context)
{
return getInviteEmailTemplatesFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the Invite Email Templates folder name
*/
public static String getInviteEmailTemplatesFolderName(FacesContext context)
{
return getInviteEmailTemplatesFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the Notify Email Templates folder name
*/
public static String getNotifyEmailTemplatesFolderName(ServletContext context)
{
return getNotifyEmailTemplatesFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the Notify Email Templates folder name
*/
public static String getNotifyEmailTemplatesFolderName(FacesContext context)
{
return getNotifyEmailTemplatesFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the Email templates folder name
*/
public static String getEmailTemplatesFolderName(ServletContext context)
{
return getEmailTemplatesFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the Email templates folder name
*/
public static String getEmailTemplatesFolderName(FacesContext context)
{
return getEmailTemplatesFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the RSS templates folder name
*/
public static String getRSSTemplatesFolderName(ServletContext context)
{
return getRSSTemplatesFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Returns the RSS templates folder name
*/
public static String getRSSTemplatesFolderName(FacesContext context)
{
return getRSSTemplatesFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Return the Saved Searches folder name
*/
public static String getSavedSearchesFolderName(ServletContext context)
{
return getSavedSearchesFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Return the Saved Searches folder name
*/
public static String getSavedSearchesFolderName(FacesContext context)
{
return getSavedSearchesFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Return the JavaScript scripts folder name
*/
public static String getScriptsFolderName(ServletContext context)
{
return getScriptsFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Return the JavaScript scripts folder name
*/
public static String getScriptsFolderName(FacesContext context)
{
return getScriptsFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Return the Guest Home folder name
*/
public static String getGuestHomeFolderName(ServletContext context)
{
return getGuestHomeFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return Return the Guest Home folder name
*/
public static String getGuestHomeFolderName(FacesContext context)
{
return getGuestHomeFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return the Websites folder name
*/
public static String getWebsitesFolderName(ServletContext context)
{
return getWebsitesFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return the Websites folder name
*/
public static String getWebsitesFolderName(FacesContext context)
{
return getWebsitesFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return the WCM Content Forms folder name
*/
public static String getWebContentFormsFolderName(ServletContext context)
{
return getWebContentFormsFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return the WCM Content Forms folder name
*/
public static String getWebContentFormsFolderName(FacesContext context)
{
return getWebContentFormsFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return the Content Forms folder name
*/
public static String getContentFormsFolderName(ServletContext context)
{
return getContentFormsFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return the Content Forms folder name
*/
public static String getContentFormsFolderName(FacesContext context)
{
return getContentFormsFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
<<<<<<< .working
* @return the Projects folder name
*/
public static String getProjectsFolderName(ServletContext context)
{
return getProjectsFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context));
}
/**
* @return the Projects folder name
*/
public static String getProjectsFolderName(FacesContext context)
{
return getProjectsFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}
/**
* Set the language locale for the current user context
*
* @param context FacesContext for current user
* @param code The ISO locale code to set
*/
@SuppressWarnings("unchecked")
public static void setLanguage(FacesContext context, String code)
{
Locale locale = I18NUtil.parseLocale(code);
// set locale for JSF framework usage
context.getViewRoot().setLocale(locale);
// set locale for our framework usage
context.getExternalContext().getSessionMap().put(LOCALE, locale);
// clear the current message bundle - so it's reloaded with new locale
context.getExternalContext().getSessionMap().remove(MESSAGE_BUNDLE);
// Set the current locale in the server thread
I18NUtil.setLocale(locale);
}
/**
* Set the language locale for the current user session.
*
* @param session HttpSession for current user
* @param code The ISO locale code to set
*/
@Deprecated
public static void setLanguage(HttpSession session, String code)
{
Locale locale = I18NUtil.parseLocale(code);
session.setAttribute(LOCALE, locale);
session.removeAttribute(MESSAGE_BUNDLE);
// Set the current locale in the server thread
I18NUtil.setLocale(locale);
}
/**
* Return the language Locale for the current user context
*
* @param context FacesContext for the current user
*
* @return Current language Locale set or the VM default if none set - never null
*/
public static Locale getLanguage(FacesContext fc)
{
Locale locale = (Locale)fc.getExternalContext().getSessionMap().get(LOCALE);
if (locale == null)
{
// first check saved user preferences
String strLocale = null;
if (getCurrentUser(fc) != null)
{
strLocale = (String)PreferencesService.getPreferences(fc).getValue(
UserPreferencesBean.PREF_INTERFACELANGUAGE);
if (strLocale != null)
{
locale = I18NUtil.parseLocale(strLocale);
}
else
{
// failing that, use the server default locale
locale = Locale.getDefault();
}
}
else
{
// else get from web-client config - the first item in the configured list of languages
Config config = Application.getConfigService(fc).getConfig("Languages");
LanguagesConfigElement langConfig = (LanguagesConfigElement)config.getConfigElement(
LanguagesConfigElement.CONFIG_ELEMENT_ID);
List<String> languages = langConfig.getLanguages();
if (languages != null && languages.size() != 0)
{
locale = I18NUtil.parseLocale(languages.get(0));
}
else
{
// failing that, use the server default locale
locale = Locale.getDefault();
}
}
// save in user session
fc.getExternalContext().getSessionMap().put(LOCALE, locale);
}
return locale;
}
/**
* Return the language Locale for the current user Session.
*
* @param session HttpSession for the current user
*
* @return Current language Locale set or the VM default if none set - never null
*/
public static Locale getLanguage(HttpSession session)
{
Locale locale = (Locale)session.getAttribute(LOCALE);
if (locale == null)
{
// first check saved user preferences
String strLocale = null;
if (getCurrentUser(session) != null)
{
strLocale = (String)PreferencesService.getPreferences(session).getValue(
UserPreferencesBean.PREF_INTERFACELANGUAGE);
if (strLocale != null)
{
locale = I18NUtil.parseLocale(strLocale);
}
else
{
// failing that, use the server default locale
locale = Locale.getDefault();
}
}
else
{
// else get from web-client config - the first item in the configured list of languages
locale = getLanguage(WebApplicationContextUtils.getRequiredWebApplicationContext(session.getServletContext()));
}
// save in user session
session.setAttribute(LOCALE, locale);
}
return locale;
}
/**
* Return the configured language Locale for the application context
*
* @param ctx
* the application context
* @return Current language Locale set or the VM default if none set - never null
*/
public static Locale getLanguage(ApplicationContext ctx)
{
// get from web-client config - the first item in the configured list of languages
Config config = ((ConfigService) ctx.getBean(Application.BEAN_CONFIG_SERVICE)).getConfig("Languages");
LanguagesConfigElement langConfig = (LanguagesConfigElement) config
.getConfigElement(LanguagesConfigElement.CONFIG_ELEMENT_ID);
List<String> languages = langConfig.getLanguages();
if (languages != null && languages.size() != 0)
{
return I18NUtil.parseLocale(languages.get(0));
}
else
{
// failing that, use the server default locale
return Locale.getDefault();
}
}
/**
* Get the specified I18N message string from the default message bundle for this user
*
* @param context FacesContext
* @param msg Message ID
*
* @return String from message bundle or $$msg$$ if not found
*/
public static String getMessage(FacesContext context, String msg)
{
return getBundle(context).getString(msg);
}
/**
* Get the specified I18N message string from the default message bundle for this user
*
* @param session HttpSession
* @param msg Message ID
*
* @return String from message bundle or $$msg$$ if not found
*/
public static String getMessage(HttpSession session, String msg)
{
return getBundle(session).getString(msg);
}
/**
* Get the specified the default message bundle for this user
*
* @param session HttpSession
*
* @return ResourceBundle for this user
*/
public static ResourceBundle getBundle(HttpSession session)
{
ResourceBundle bundle = (ResourceBundle)session.getAttribute(MESSAGE_BUNDLE);
if (bundle == null)
{
// get Locale from language selected by each user on login
Locale locale = (Locale)session.getAttribute(LOCALE);
if (locale == null)
{
locale = Locale.getDefault();
}
bundle = ResourceBundleWrapper.getResourceBundle(MESSAGE_BUNDLE, locale);
session.setAttribute(MESSAGE_BUNDLE, bundle);
}
return bundle;
}
/**
* Get the specified the default message bundle for this user
*
* @param context FacesContext
*
* @return ResourceBundle for this user
*/
@SuppressWarnings("unchecked")
public static ResourceBundle getBundle(FacesContext context)
{
// get the resource bundle for the current locale
// we store the bundle in the users session
// this makes it easy to add a locale per user support later
Map session = context.getExternalContext().getSessionMap();
ResourceBundle bundle = (ResourceBundle)session.get(MESSAGE_BUNDLE);
if (bundle == null)
{
// get Locale from language selected by each user on login
Locale locale = (Locale)session.get(LOCALE);
if (locale == null)
{
locale = Locale.getDefault();
}
bundle = ResourceBundleWrapper.getResourceBundle(MESSAGE_BUNDLE, locale);
session.put(MESSAGE_BUNDLE, bundle);
}
return bundle;
}
/**
* Helper to get the ConfigService instance
*
* @param context FacesContext
*
* @return ConfigService
*/
public static ConfigService getConfigService(FacesContext context)
{
return (ConfigService)FacesContextUtils.getRequiredWebApplicationContext(context).getBean(
Application.BEAN_CONFIG_SERVICE);
}
/**
* Helper to get the ConfigService instance
*
* @param context ServletContext
*
* @return ConfigService
*/
public static ConfigService getConfigService(ServletContext context)
{
return (ConfigService)WebApplicationContextUtils.getRequiredWebApplicationContext(context).getBean(
Application.BEAN_CONFIG_SERVICE);
}
/**
* Helper to get the client config element from the config service
*
* @param context FacesContext
* @return The ClientConfigElement
*/
public static ClientConfigElement getClientConfig(FacesContext context)
{
return (ClientConfigElement)getConfigService(context).getGlobalConfig().
getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID);
}
/**
* Helper to get the client config element from the config service
*
* @param context ServletContext
* @return The ClientConfigElement
*/
public static ClientConfigElement getClientConfig(ServletContext context)
{
return (ClientConfigElement)getConfigService(context).getGlobalConfig().
getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID);
}
/**
* Returns the repository store URL
*
* @param context The spring context
* @return The repository store URL to use
*/
private static StoreRef getRepositoryStoreRef(WebApplicationContext context)
{
if (repoStoreRef == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
repoStoreRef = bootstrap.getStoreRef();
}
return repoStoreRef;
}
/**
* Returns the root path for the application
*
* @param context The spring context
* @return The application root path
*/
private static String getRootPath(WebApplicationContext context)
{
if (rootPath == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
rootPath = configuration.getProperty("spaces.company_home.childname");
}
return rootPath;
}
/**
* Returns the glossary folder name
*
* @param context The spring context
* @return The glossary folder name
*/
private static String getGlossaryFolderName(WebApplicationContext context)
{
if (glossaryFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
glossaryFolderName = configuration.getProperty("spaces.dictionary.childname");
}
return glossaryFolderName;
}
/**
* Returns the Space Templates folder name
*
* @param context The spring context
* @return The templates folder name
*/
private static String getSpaceTemplatesFolderName(WebApplicationContext context)
{
if (spaceTemplatesFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
spaceTemplatesFolderName = configuration.getProperty("spaces.templates.childname");
}
return spaceTemplatesFolderName;
}
/**
* Returns the Content Templates folder name
*
* @param context The spring context
* @return The templates folder name
*/
private static String getContentTemplatesFolderName(WebApplicationContext context)
{
if (contentTemplatesFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
contentTemplatesFolderName = configuration.getProperty("spaces.templates.content.childname");
}
return contentTemplatesFolderName;
}
/**
* Returns the Email Templates folder name
*
* @param context The spring context
* @return The email folder name
*/
private static String getEmailTemplatesFolderName(WebApplicationContext context)
{
if (emailTemplatesFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
emailTemplatesFolderName = configuration.getProperty("spaces.templates.email.childname");
}
return emailTemplatesFolderName;
}
/**
* Returns the Invite Email Templates folder name
*
* @param context The spring context
* @return The invite email folder name
*/
private static String getInviteEmailTemplatesFolderName(WebApplicationContext context)
{
if (inviteEmailTemplatesFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap) context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
inviteEmailTemplatesFolderName = configuration.getProperty("spaces.templates.email.invite1.childname");
}
return inviteEmailTemplatesFolderName;
}
/**
* Returns the Notify Email Templates folder name
*
* @param context The spring context
* @return The notify email folder name
*/
private static String getNotifyEmailTemplatesFolderName(WebApplicationContext context)
{
if (notifyEmailTemplatesFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap) context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
notifyEmailTemplatesFolderName = configuration.getProperty("spaces.templates.email.notify.childname");
}
return notifyEmailTemplatesFolderName;
}
/**
* Returns the RSS Templates folder name
*
* @param context The spring context
* @return The RSS folder name
*/
private static String getRSSTemplatesFolderName(WebApplicationContext context)
{
if (rssTemplatesFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
rssTemplatesFolderName = configuration.getProperty("spaces.templates.rss.childname");
}
return rssTemplatesFolderName;
}
/**
* Returns the Saved Searches folder name
*
* @param context The spring context
* @return The saved searches folder name
*/
private static String getSavedSearchesFolderName(WebApplicationContext context)
{
/*
* This lookup is duplicated in a patch. If this logic changes, investigate the changes
* required for the patch(es).
*/
if (savedSearchesFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
savedSearchesFolderName = configuration.getProperty("spaces.savedsearches.childname");
}
return savedSearchesFolderName;
}
/**
* Returns the JavaScript scripts folder name
*
* @param context The spring context
* @return The scripts folder name
*/
private static String getScriptsFolderName(WebApplicationContext context)
{
if (scriptsFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
scriptsFolderName = configuration.getProperty("spaces.scripts.childname");
}
return scriptsFolderName;
}
/**
* Returns the Guest Home folder name name
*
* @param context The spring context
* @return The Guest Home folder name
*/
private static String getGuestHomeFolderName(WebApplicationContext context)
{
if (guestHomeFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
guestHomeFolderName = configuration.getProperty("spaces.guest_home.childname");
}
return guestHomeFolderName;
}
/**
* Returns the Websites folder name
*
* @param context The Spring context
* @return The Websites folder name
*/
private static String getWebsitesFolderName(WebApplicationContext context)
{
if (websitesFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
websitesFolderName = configuration.getProperty("spaces.wcm.childname");
}
return websitesFolderName;
}
/**
* Returns the Projects folder name
*
* @param context The Spring context
* @return The Projects folder name
*/
private static String getProjectsFolderName(WebApplicationContext context)
{
if (projectsFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
projectsFolderName = configuration.getProperty("spaces.projects.childname");
}
return projectsFolderName;
}
/**
* Returns the WCM Content Forms folder name
*
* @param context The Spring context
* @return The WCM Content Forms folder name
*/
private static String getWebContentFormsFolderName(WebApplicationContext context)
{
if (webContentFormsFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
webContentFormsFolderName = configuration.getProperty("spaces.wcm_content_forms.childname");
}
return webContentFormsFolderName;
}
/**
* Returns the Content Forms folder name
*
* @param context The Spring context
* @return The WCM Content Forms folder name
*/
private static String getContentFormsFolderName(WebApplicationContext context)
{
if (contentFormsFolderName == null)
{
ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP);
Properties configuration = bootstrap.getConfiguration();
contentFormsFolderName = configuration.getProperty("spaces.content_forms.childname");
}
return contentFormsFolderName;
}
/**
* Retrieves the configured error page for the application
*
* @param context The Spring context
* @return The configured error page or null if the configuration is missing
*/
public static String getErrorPage(ApplicationContext context)
{
String errorPage = null;
ConfigService svc = (ConfigService)context.getBean(BEAN_CONFIG_SERVICE);
ClientConfigElement clientConfig = (ClientConfigElement)svc.getGlobalConfig().
getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID);
if (clientConfig != null)
{
errorPage = clientConfig.getErrorPage();
}
return errorPage;
}
/**
* Retrieves the configured login page for the application
*
* @param context The Spring contexr
* @return The configured login page or null if the configuration is missing
*/
public static String getLoginPage(ApplicationContext context)
{
String loginPage = null;
ConfigService svc = (ConfigService)context.getBean(BEAN_CONFIG_SERVICE);
ClientConfigElement clientConfig = (ClientConfigElement)svc.getGlobalConfig().
getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID);
if (clientConfig != null)
{
loginPage = clientConfig.getLoginPage();
}
return loginPage;
}
public static boolean isDynamicConfig(FacesContext context)
{
if (isDynamicConfig == null)
{
String dynamicConfigParam = FacesContextUtils.getRequiredWebApplicationContext(context).getServletContext().getInitParameter("org.alfresco.webclient.dynamicConfig");
isDynamicConfig = new Boolean(((dynamicConfigParam == null) || (new Boolean(dynamicConfigParam).booleanValue() == true)));
}
return isDynamicConfig.booleanValue();
}
}