Saves alias changes to the database.<p>

@param saveRequest an object containing the alias changes to save

@return a validation error if the alias data is invalid, or null otherwise

@throws CmsException if something goes wrong
428767
public CmsAliasEditValidationReply saveAliases(CmsAliasSaveValidationRequest saveRequest) throws CmsException {

        CmsAliasEditValidationReply reply = validateAliases(saveRequest);
        if (m_hasErrors) {
            return reply;
        } else {
            List<CmsRewriteAliasTableRow> rewriteData = saveRequest.getRewriteData();
            OpenCms.getAliasManager().saveRewriteAliases(
                m_cms,
                m_cms.getRequestContext().getSiteRoot(),
                convertRewriteData(rewriteData));
            Set<CmsUUID> allTouchedIds = new HashSet<CmsUUID>();
            List<CmsAliasTableRow> rows = saveRequest.getEditedData();
            for (CmsAliasTableRow row : rows) {
                if (row.isEdited()) {
                    allTouchedIds.add(row.getStructureId());
                    if (row.getOriginalStructureId() != null) {
                        allTouchedIds.add(row.getOriginalStructureId());
                    }
                }
            }
            allTouchedIds.addAll(saveRequest.getDeletedIds());
            CmsAliasManager aliasManager = OpenCms.getAliasManager();
            String siteRoot = saveRequest.getSiteRoot();
            List<CmsAlias> aliases = aliasManager.getAliasesForSite(m_cms, siteRoot);
            Set<CmsAlias> aliasSet = new HashSet<CmsAlias>();
            Set<CmsAlias> editedAliasSet = new HashSet<CmsAlias>();
            aliasSet.addAll(aliases);
            for (CmsAliasTableRow row : rows) {
                CmsAlias editedAlias = new CmsAlias(row.getStructureId(), siteRoot, row.getAliasPath(), row.getMode());
                editedAliasSet.add(editedAlias);
            }
            Set<CmsAlias> toDelete = Sets.difference(aliasSet, editedAliasSet);
            toDelete = filterStructureId(toDelete, allTouchedIds);
            Set<CmsAlias> toAdd = Sets.difference(editedAliasSet, aliasSet);
            toAdd = filterStructureId(toAdd, allTouchedIds);

            aliasManager.updateAliases(m_cms, toDelete, toAdd);
            return null;
        }
    }
982509
public void actionSave() {

        HttpServletRequest request = getJsp().getRequest();
        // save initialized instance of this class in request attribute for included sub-elements
        request.setAttribute(SESSION_WORKPLACE_CLASS, this);

        // special case: set the preferred editor settings in the user settings object
        CmsUserSettings userSettings = new CmsUserSettings(getSettings().getUser());
        // first set the old preferred editors
        m_userSettings.setEditorSettings(userSettings.getEditorSettings());
        // also set the old start gallery settings
        m_userSettings.setStartGalleriesSetting(userSettings.getStartGalleriesSettings());
        // then set the old synchronization settings
        m_userSettings.setSynchronizeSettings(userSettings.getSynchronizeSettings());
        Enumeration<String> en = request.getParameterNames();
        while (en.hasMoreElements()) {
            // search all request parameters for the presence of the preferred editor parameters
            String paramName = en.nextElement();
            if (paramName.startsWith(PARAM_PREFERREDEDITOR_PREFIX)) {
                String paramValue = request.getParameter(paramName);
                if ((paramValue != null) && !INPUT_DEFAULT.equals(paramValue.trim())) {
                    // set selected editor for this resource type
                    m_userSettings.setPreferredEditor(
                        paramName.substring(PARAM_PREFERREDEDITOR_PREFIX.length()),
                        CmsEncoder.decode(paramValue));
                } else {
                    // reset preferred editor for this resource type
                    m_userSettings.setPreferredEditor(paramName.substring(PARAM_PREFERREDEDITOR_PREFIX.length()), null);
                }
            } else if (paramName.startsWith(PARAM_STARTGALLERY_PREFIX)) {
                String paramValue = request.getParameter(paramName);
                if (paramValue != null) {
                    // set the selected start gallery for the gallery type
                    m_userSettings.setStartGallery(
                        paramName.substring(PARAM_STARTGALLERY_PREFIX.length()),
                        CmsEncoder.decode(paramValue));
                }
            }
        }

        // set the current user in the settings object
        m_userSettings.setUser(getSettings().getUser());
        m_userSettings.setAdditionalPreferencesFrom(userSettings);

        try {
            // write the user settings to the db
            m_userSettings.save(getCms());
        } catch (CmsException e) {
            // should usually never happen
            if (LOG.isInfoEnabled()) {
                LOG.info(e.getLocalizedMessage());
            }
        }

        // update the preferences and project after saving
        updatePreferences(getCms(), getJsp().getRequest());

        try {
            String projectName = m_userSettings.getStartProject();
            CmsProject project = getCms().readProject(projectName);
            getCms().getRequestContext().setCurrentProject(project);
            getSettings().setProject(project.getUuid());
        } catch (Exception e) {
            // should usually never happen
            LOG.error(e.getLocalizedMessage());
        }

        // now determine if the dialog has to be closed or not
        try {
            if (DIALOG_SET.equals(getParamAction())) {
                // after "set" action, leave dialog open
                Map<String, String[]> params = new HashMap<String, String[]>();
                params.put(PARAM_TAB, new String[] {String.valueOf(getActiveTab())});
                params.put(PARAM_SETPRESSED, new String[] {Boolean.TRUE.toString()});
                sendForward(getJsp().getRequestContext().getUri(), params);
            } else {
                // forward to dialog with action set to reload the workplace
                Map<String, String[]> params = new HashMap<String, String[]>();
                params.put(PARAM_ACTION, new String[] {DIALOG_RELOAD});
                sendForward(getJsp().getRequestContext().getUri(), params);
            }
        } catch (IOException e) {
            // error during forward, do nothing
            if (LOG.isInfoEnabled()) {
                LOG.info(e.getLocalizedMessage());
            }
        } catch (ServletException e) {
            // error during forward, do nothing
            if (LOG.isInfoEnabled()) {
                LOG.info(e.getLocalizedMessage());
            }
        }
    }
310775
public void updateAndSave(List<CmsDetailPageInfo> infos, CmsUUID newId) throws CmsException {

        if (m_resource != null) {
            getDocument();
            removeOldValues();
            writeDetailPageInfos(infos, newId);
            m_document.setAutoCorrectionEnabled(true);
            m_document.correctXmlStructure(m_cms);
            byte[] content = m_document.marshal();
            m_file.setContents(content);
            m_cms.writeFile(m_file);
        }
    }
484542
public void actionSave(Locale locale) throws JspException {

        try {
            setEditorValues(locale);
            // check if content has errors
            if (!hasValidationErrors()) {
                // no errors found, write content and copy temp file contents
                writeContent();
                commitTempFile();
                // set the modified parameter
                setParamModified(Boolean.TRUE.toString());
                // update the offline search indices
                OpenCms.getSearchManager().updateOfflineIndexes();
            }
        } catch (CmsException e) {
            showErrorPage(e);
        }

    }
789137
public QueryDataDescResponse createDataDesc(CreateDataDescRequest createDataDescRequest) {
        Preconditions.checkNotNull(createDataDescRequest.getParserObjectUuid(), "ParserObjectUuid should not be null.");
        Preconditions.checkNotNull(createDataDescRequest.getLength(), "Length should not be null.");
        Preconditions.checkNotNull(createDataDescRequest.getAddress(), "Address should not be null.");
        Preconditions.checkNotNull(createDataDescRequest.getKind(), "Kind should not be null.");
        Preconditions.checkNotNull(createDataDescRequest.getName(), "Name should not be null.");
        if (createDataDescRequest.getBit() == null) {
            createDataDescRequest.setBit(-1);
        }
        if (createDataDescRequest.getUnit() == "N/A") {
            createDataDescRequest.setUnit("");
        }
        InternalRequest internalRequest = createRequest(createDataDescRequest, HttpMethodName.POST, DATA_DESCRIPTION);
        return this.invokeHttpClient(internalRequest, QueryDataDescResponse.class);
    }
368418
private void addAliasLinks(CmsUUID aliasStructureId) {

        try {
            CmsResource aliasTarget = m_guestCms.readResource(aliasStructureId);
            List<CmsProperty> properties = m_guestCms.readPropertyObjects(aliasTarget, true);
            double priority = getPriority(properties);
            String changeFrequency = getChangeFrequency(properties);
            Collection<CmsAlias> aliases = m_pageAliasesBelowBaseFolderByStructureId.get(aliasStructureId);
            for (CmsAlias alias : aliases) {
                String aliasLink = (m_siteRootLink + "/" + alias.getAliasPath()).replaceAll("(?<!:)//+", "/");
                CmsXmlSitemapUrlBean aliasUrlBean = new CmsXmlSitemapUrlBean(
                    replaceServerUri(aliasLink),
                    -1,
                    changeFrequency,
                    priority);
                aliasUrlBean.setOriginalResource(aliasTarget);
                addResult(aliasUrlBean, 1);
            }
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
57641
@Override
    public synchronized void savepoint(String name) {

        int index = sessionContext.savepoints.getIndex(name);

        if (index != -1) {
            sessionContext.savepoints.remove(name);
            sessionContext.savepointTimestamps.remove(index);
        }

        sessionContext.savepoints.add(name,
                                      ValuePool.getInt(rowActionList.size()));
        sessionContext.savepointTimestamps.addLast(actionTimestamp);

        try {
            database.logger.writeToLog(this, getSavepointSQL(name));
        } catch (HsqlException e) {}
    }
309779
protected CmsObject getCmsObject(HttpServletRequest req) throws CmsException {

        CmsObject cms = OpenCmsCore.getInstance().initCmsObjectFromSession(req);
        // use the guest user as fall back
        if (cms == null) {
            cms = OpenCmsCore.getInstance().initCmsObject(OpenCms.getDefaultUsers().getUserGuest());
            String siteRoot = OpenCmsCore.getInstance().getSiteManager().matchRequest(req).getSiteRoot();
            cms.getRequestContext().setSiteRoot(siteRoot);
        }
        String baseUri = getBaseUri(req, cms);
        if (baseUri != null) {
            cms.getRequestContext().setUri(baseUri);
        }
        return cms;
    }
227534
@Override
    public void actionEdit(HttpServletRequest request) throws JspException {

        // save initialized instance of this class in request attribute for included sub-elements
        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
        try {
            // save the changes only if resource is properly locked
            if (isEditable()) {
                performEditOperation(request);
            }
        } catch (Throwable e) {
            // Cms error defining property, show error dialog
            includeErrorpage(this, e);
        }
    }
176722
public void saveRewriteAliases(CmsObject cms, String siteRoot, List<CmsRewriteAlias> newAliases)
    throws CmsException {

        checkPermissionsForMassEdit(cms, siteRoot);
        m_securityManager.saveRewriteAliases(cms.getRequestContext(), siteRoot, newAliases);
    }
1092486
public CmsResource createResource() throws CmsException {

        String path = OpenCms.getResourceManager().getNameGenerator().getNewFileName(
            m_cms,
            m_pathWithPattern,
            5,
            m_explorerNameGeneration);
        Locale contentLocale = OpenCms.getLocaleManager().getDefaultLocale(m_cms, CmsResource.getFolderPath(path));
        CmsRequestContext context = m_cms.getRequestContext();
        if (m_modelResource != null) {
            context.setAttribute(CmsRequestContext.ATTRIBUTE_MODEL, m_modelResource.getRootPath());
        }
        context.setAttribute(CmsRequestContext.ATTRIBUTE_NEW_RESOURCE_LOCALE, contentLocale);
        CmsResource res = m_cms.createResource(
            path,
            OpenCms.getResourceManager().getResourceType(m_type),
            null,
            new ArrayList<CmsProperty>());
        if (m_propChanges != null) {
            CmsPropertyEditorHelper helper = new CmsPropertyEditorHelper(m_cms);
            helper.overrideStructureId(res.getStructureId());
            helper.saveProperties(m_propChanges);
        }
        // Path or other metadata may have changed
        m_createdResource = m_cms.readResource(res.getStructureId(), CmsResourceFilter.IGNORE_EXPIRATION);
        try {
            m_cms.unlockResource(m_createdResource);
        } catch (CmsException e) {
            LOG.info(e.getLocalizedMessage(), e);
        }
        for (I_Callback callback : m_callbacks) {
            callback.onResourceCreated(this);
        }
        return m_createdResource;
    }
325916
void saveAction() {

        Map<Object, Object> filters = getFilters();
        m_table.clearFilters();

        try {

            m_model.save();
            disableSaveButtons();

        } catch (CmsException e) {
            LOG.error(m_messages.key(Messages.ERR_SAVING_CHANGES_0), e);
            CmsErrorDialog.showErrorDialog(m_messages.key(Messages.ERR_SAVING_CHANGES_0), e);
        }

        setFilters(filters);

    }
1318923
public CmsUgcSession createSession(CmsObject cms, HttpServletRequest request, CmsUgcConfiguration config)
    throws CmsUgcException {

        CmsUgcSession session = createSession(cms, config);
        HttpSession httpSession = request.getSession(true);
        httpSession.setAttribute("" + session.getId(), session);
        return session;
    }
538502
@Override
	public void saveRequest(HttpServletRequest request, HttpServletResponse response) {
		if (anyRequestMatcher.matches(request) && !ajaxRequestMatcher.matches(request)) {
			DefaultSavedRequest savedRequest = new DefaultSavedRequest(request, portResolver);
			HttpUtils.setStateParam(Config.RETURNTO_COOKIE,
					Utils.base64enc(savedRequest.getRedirectUrl().getBytes()), request, response);
		}
	}
1176290
public void addAlias(final CmsAliasBean alias) {

        final HorizontalPanel hp = new HorizontalPanel();
        hp.getElement().getStyle().setMargin(2, Unit.PX);
        final CmsTextBox textbox = createTextBox();
        textbox.setFormValueAsString(alias.getSitePath());
        hp.add(textbox);

        CmsSelectBox selectbox = createSelectBox();
        selectbox.setFormValueAsString(alias.getMode().toString());
        hp.add(selectbox);
        PushButton deleteButton = createDeleteButton();
        hp.add(deleteButton);

        final AliasControls controls = new AliasControls(alias, textbox, selectbox);
        m_aliasControls.put(controls.getId(), controls);

        selectbox.addValueChangeHandler(new ValueChangeHandler<String>() {

            public void onValueChange(ValueChangeEvent<String> event) {

                onChangePath(controls);
            }
        });

        deleteButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent e) {

                m_aliasControls.remove(controls.getId());
                hp.removeFromParent();
                validateFull(m_structureId, getAliasPaths(), m_defaultValidationHandler);
            }
        });
        textbox.addValueChangeHandler(new ValueChangeHandler<String>() {

            public void onValueChange(ValueChangeEvent<String> e) {

                onChangePath(controls);
                validateFull(m_structureId, getAliasPaths(), m_defaultValidationHandler);
            }
        });

        textbox.addKeyPressHandler(new KeyPressHandler() {

            public void onKeyPress(KeyPressEvent event) {

                onChangePath(controls);
            }
        });
        m_changeBox.add(hp);
        CmsDomUtil.resizeAncestor(this);
    }
955359
private boolean performDialogOperation(HttpServletRequest request) throws CmsException {

        List<CmsPropertyDefinition> propertyDef = getCms().readAllPropertyDefinitions();
        boolean useTempfileProject = Boolean.valueOf(getParamUsetempfileproject()).booleanValue();
        try {
            if (useTempfileProject) {
                switchToTempProject();
            }
            Map<String, CmsProperty> activeProperties = getActiveProperties();
            String activeTab = getActiveTabName();
            List<CmsProperty> propertiesToWrite = new ArrayList<CmsProperty>();

            // check all property definitions of the resource for new values
            Iterator<CmsPropertyDefinition> i = propertyDef.iterator();
            while (i.hasNext()) {
                CmsPropertyDefinition curPropDef = i.next();
                String propName = CmsEncoder.escapeXml(curPropDef.getName());
                String valueStructure = null;
                String valueResource = null;

                if (key(Messages.GUI_PROPERTIES_INDIVIDUAL_0).equals(activeTab)) {
                    // get parameters from the structure tab
                    valueStructure = request.getParameter(PREFIX_VALUE + propName);
                    valueResource = request.getParameter(PREFIX_RESOURCE + propName);
                    if ((valueStructure != null)
                        && !"".equals(valueStructure.trim())
                        && valueStructure.equals(valueResource)) {
                        // the resource value was shown/entered in input field, set structure value to empty String
                        valueStructure = "";
                    }
                } else {
                    // get parameters from the resource tab
                    valueStructure = request.getParameter(PREFIX_STRUCTURE + propName);
                    valueResource = request.getParameter(PREFIX_VALUE + propName);
                }

                // check values for blanks and null
                if (valueStructure != null) {
                    valueStructure = valueStructure.trim();
                }

                if (valueResource != null) {
                    valueResource = valueResource.trim();
                }

                // create new CmsProperty object to store
                CmsProperty newProperty = new CmsProperty();
                newProperty.setName(curPropDef.getName());
                newProperty.setStructureValue(valueStructure);
                newProperty.setResourceValue(valueResource);

                // get the old property values
                CmsProperty oldProperty = activeProperties.get(curPropDef.getName());
                if (oldProperty == null) {
                    // property was not set, create new empty property object
                    oldProperty = new CmsProperty();
                    oldProperty.setName(curPropDef.getName());
                }

                boolean writeStructureValue = false;
                boolean writeResourceValue = false;
                String oldValue = oldProperty.getStructureValue();
                String newValue = newProperty.getStructureValue();

                // write the structure value if the existing structure value is not null and we want to delete the structure value
                writeStructureValue = ((oldValue != null) && newProperty.isDeleteStructureValue());
                // or if we want to write a value which is neither the delete value or an empty value
                writeStructureValue |= !newValue.equals(oldValue)
                    && !"".equalsIgnoreCase(newValue)
                    && !CmsProperty.DELETE_VALUE.equalsIgnoreCase(newValue);
                // set the structure value explicitly to null to leave it as is in the database
                if (!writeStructureValue) {
                    newProperty.setStructureValue(null);
                }

                oldValue = oldProperty.getResourceValue();
                newValue = newProperty.getResourceValue();

                // write the resource value if the existing resource value is not null and we want to delete the resource value
                writeResourceValue = ((oldValue != null) && newProperty.isDeleteResourceValue());
                // or if we want to write a value which is neither the delete value or an empty value
                writeResourceValue |= !newValue.equals(oldValue)
                    && !"".equalsIgnoreCase(newValue)
                    && !CmsProperty.DELETE_VALUE.equalsIgnoreCase(newValue);
                // set the resource value explicitly to null to leave it as is in the database
                if (!writeResourceValue) {
                    newProperty.setResourceValue(null);
                }

                if (writeStructureValue || writeResourceValue) {
                    // add property to list only if property values have changed
                    propertiesToWrite.add(newProperty);
                }
            }
            if (propertiesToWrite.size() > 0) {
                // lock resource if autolock is enabled
                checkLock(getParamResource());
                //write the new property values
                getCms().writePropertyObjects(getParamResource(), propertiesToWrite);
            }
        } finally {
            if (useTempfileProject) {
                switchToCurrentProject();
            }
        }
        return true;
    }
648621
public boolean actionInternalUse(HttpServletRequest request) {

        String internal = request.getParameter(PARAM_INTERNAL);

        CmsResource resource;
        boolean internalValue = false;
        if (internal != null) {
            internalValue = true;
        }
        try {
            resource = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);

            int flags = resource.getFlags();

            if (internalValue) {
                flags |= CmsResource.FLAG_INTERNAL;
            } else {
                flags &= ~CmsResource.FLAG_INTERNAL;
            }

            getCms().lockResource(getParamResource());
            getCms().chflags(getParamResource(), flags);

        } catch (CmsException e) {
            m_errorMessages.add(key(Messages.ERR_MODIFY_INTERNAL_FLAG_0));
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(), e);
            }
            return false;
        }
        return true;
    }