@RequestMapping(method = RequestMethod.POST, params = "action=addTab")
    public ModelAndView addTab(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam("widths[]") String[] widths)
            throws IOException {

        IUserInstance ui = userInstanceManager.getUserInstance(request);
        IPerson person = getPerson(ui, response);
        UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
        IUserLayoutManager ulm = upm.getUserLayoutManager();

        // Verify that the user has permission to add this tab
        final IAuthorizationPrincipal authPrincipal = this.getUserPrincipal(person.getUserName());
        if (!authPrincipal.hasPermission(
                IPermission.PORTAL_SYSTEM, IPermission.ADD_TAB_ACTIVITY, IPermission.ALL_TARGET)) {
            logger.warn(
                    "Attempt to add a tab through the REST API by unauthorized user '"
                            + person.getUserName()
                            + "'");
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return new ModelAndView(
                    "jsonView", Collections.singletonMap("error", "Add tab disabled"));
        }

        // construct a brand new tab
        String id = "tbd";
        String tabName = request.getParameter("tabName");
        if (StringUtils.isBlank(tabName)) tabName = DEFAULT_TAB_NAME;
        IUserLayoutFolderDescription newTab = new UserLayoutFolderDescription();
        newTab.setName(tabName);
        newTab.setId(id);
        newTab.setFolderType(IUserLayoutFolderDescription.REGULAR_TYPE);
        newTab.setHidden(false);
        newTab.setUnremovable(false);
        newTab.setImmutable(false);

        // add the tab to the layout
        ulm.addNode(newTab, ulm.getRootFolderId(), null);

        try {
            // save the user's layout
            ulm.saveUserLayout();
        } catch (PortalException e) {
            return handlePersistError(request, response, e);
        }

        // get the id of the newly added tab
        String tabId = newTab.getId();

        for (String width : widths) {

            // create new column element
            IUserLayoutFolderDescription newColumn = new UserLayoutFolderDescription();
            newColumn.setName("Column");
            newColumn.setId("tbd");
            newColumn.setFolderType(IUserLayoutFolderDescription.REGULAR_TYPE);
            newColumn.setHidden(false);
            newColumn.setUnremovable(false);
            newColumn.setImmutable(false);

            // add the column to our layout
            ulm.addNode(newColumn, tabId, null);

            this.stylesheetUserPreferencesService.setLayoutAttribute(
                    request,
                    PreferencesScope.STRUCTURE,
                    newColumn.getId(),
                    CLASSIC_COLUMNS_WIDTH_USER_PREFERENCE_NAME,
                    width + "%");
            try {
                // This sets the column attribute in memory but doesn't persist it.  Comment says
                // saves changes "prior to persisting"
                Element folder = ulm.getUserLayoutDOM().getElementById(newColumn.getId());
                UserPrefsHandler.setUserPreference(
                        folder, CLASSIC_COLUMNS_WIDTH_USER_PREFERENCE_NAME, person);
            } catch (Exception e) {
                logger.error("Error saving new column widths", e);
            }
        }

        // ## 'tabGroup' value (optional feature)
        // Set the 'tabGroup' attribute on the folder element that describes
        // this new tab;  use the currently active tabGroup.
        if (request.getParameter(TAB_GROUP_PARAMETER) != null) {

            String tabGroup = request.getParameter(TAB_GROUP_PARAMETER).trim();
            if (logger.isDebugEnabled()) {
                logger.debug(TAB_GROUP_PARAMETER + "=" + tabGroup);
            }

            if (!TAB_GROUP_DEFAULT.equals(tabGroup) && tabGroup.length() != 0) {
                // Persists SSUP values to the database
                this.stylesheetUserPreferencesService.setLayoutAttribute(
                        request, PreferencesScope.STRUCTURE, tabId, TAB_GROUP_PARAMETER, tabGroup);
            }
        }

        try {
            // save the user's layout
            ulm.saveUserLayout();
        } catch (PortalException e) {
            return handlePersistError(request, response, e);
        }

        return new ModelAndView("jsonView", Collections.singletonMap("tabId", tabId));
    }
@ RequestMapping ( method = RequestMethod . POST , params = "action=addTab" ) public ModelAndView addTab ( HttpServletRequest request , HttpServletResponse response , @ RequestParam ( "widths[]" ) String [ ] widths ) throws IOException { IUserInstance ui = userInstanceManager . getUserInstance ( request ) ; IPerson person = getPerson ( ui , response ) ; UserPreferencesManager upm = ( UserPreferencesManager ) ui . getPreferencesManager ( ) ; IUserLayoutManager ulm = upm . getUserLayoutManager ( ) ; final IAuthorizationPrincipal authPrincipal = this . getUserPrincipal ( person . getUserName ( ) ) ; if ( ! authPrincipal . hasPermission ( IPermission . PORTAL_SYSTEM , IPermission . ADD_TAB_ACTIVITY , IPermission . ALL_TARGET ) ) { logger . warn ( "Attempt to add a tab through the REST API by unauthorized user '" + person . getUserName ( ) + "'" ) ; response . sendError ( HttpServletResponse . SC_FORBIDDEN ) ; return new ModelAndView ( "jsonView" , Collections . singletonMap ( "error" , "Add tab disabled" ) ) ; } String id = "tbd" ; String tabName = request . getParameter ( "tabName" ) ; if ( StringUtils . isBlank ( tabName ) ) tabName = DEFAULT_TAB_NAME ; IUserLayoutFolderDescription newTab = new UserLayoutFolderDescription ( ) ; newTab . setName ( tabName ) ; newTab . setId ( id ) ; newTab . setFolderType ( IUserLayoutFolderDescription . REGULAR_TYPE ) ; newTab . setHidden ( false ) ; newTab . setUnremovable ( false ) ; newTab . setImmutable ( false ) ; ulm . addNode ( newTab , ulm . getRootFolderId ( ) , null ) ; try { ulm . saveUserLayout ( ) ; } catch ( PortalException e ) { return handlePersistError ( request , response , e ) ; } String tabId = newTab . getId ( ) ; for ( String width : widths ) { IUserLayoutFolderDescription newColumn = new UserLayoutFolderDescription ( ) ; newColumn . setName ( "Column" ) ; newColumn . setId ( "tbd" ) ; newColumn . setFolderType ( IUserLayoutFolderDescription . REGULAR_TYPE ) ; newColumn . setHidden ( false ) ; newColumn . setUnremovable ( false ) ; newColumn . setImmutable ( false ) ; ulm . addNode ( newColumn , tabId , null ) ; this . stylesheetUserPreferencesService . setLayoutAttribute ( request , PreferencesScope . STRUCTURE , newColumn . getId ( ) , CLASSIC_COLUMNS_WIDTH_USER_PREFERENCE_NAME , width + "%" ) ; try { Element folder = ulm . getUserLayoutDOM ( ) . getElementById ( newColumn . getId ( ) ) ; UserPrefsHandler . setUserPreference ( folder , CLASSIC_COLUMNS_WIDTH_USER_PREFERENCE_NAME , person ) ; } catch ( Exception e ) { logger . error ( "Error saving new column widths" , e ) ; } } if ( request . getParameter ( TAB_GROUP_PARAMETER ) != null ) { String tabGroup = request . getParameter ( TAB_GROUP_PARAMETER ) . trim ( ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( TAB_GROUP_PARAMETER + "=" + tabGroup ) ; } if ( ! TAB_GROUP_DEFAULT . equals ( tabGroup ) && tabGroup . length ( ) != 0 ) { this . stylesheetUserPreferencesService . setLayoutAttribute ( request , PreferencesScope . STRUCTURE , tabId , TAB_GROUP_PARAMETER , tabGroup ) ; } } try { ulm . saveUserLayout ( ) ; } catch ( PortalException e ) { return handlePersistError ( request , response , e ) ; } return new ModelAndView ( "jsonView" , Collections . singletonMap ( "tabId" , tabId ) ) ; }
Add a new tab to the layout. The new tab will be appended to the end of the list and named
with the BLANK_TAB_NAME variable.

@param request
@throws IOException