public String save()

in app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/GlobalConfig.java [154:252]


    public String save() {
        if (!"POST".equals(httpMethod)) {
            return ERROR;
        }

        // only set values for properties that are already defined
        RuntimeConfigProperty updProp;
        String incomingProp;
        for (String propName : getProperties().keySet()) {
            updProp = getProperties().get(propName);
            incomingProp = this.getParameter(updProp.getName());

            PropertyDef propertyDef = globalConfigDef.getPropertyDef( propName );
            if ( propertyDef == null) {
                // we're only processing defined properties, i.e. ones shown in the UI
                continue;
            }

            if ( propertyDef.getType().equals("boolean") ) {

                try {
                    if (incomingProp == null) {
                        updProp.setValue("false");
                    } else {
                        boolean value = Boolean.parseBoolean(incomingProp);
                        updProp.setValue(Boolean.toString(value));
                    }
                    log.debug("Set boolean " + propName + " = " + incomingProp);
                } catch ( Exception nfe ) {
                    String propDesc = bundle.getString( propertyDef.getKey() );
                    addError("ConfigForm.invalidBooleanProperty",
                            Arrays.asList(propDesc, propName));
                }

            } else if ( incomingProp != null && propertyDef.getType().equals("integer") ) {

                try {
                    Integer.parseInt(incomingProp);
                    updProp.setValue(incomingProp);
                    log.debug("Set integer " + propName + " = " + incomingProp);
                } catch ( NumberFormatException nfe ) {
                    String propDesc = bundle.getString( propertyDef.getKey() );
                    addError("ConfigForm.invalidIntegerProperty",
                            Arrays.asList(propDesc, propName));
                }

            } else if ( incomingProp != null && propertyDef.getType().equals("float") ) {

                try {
                    Float.parseFloat(incomingProp);
                    updProp.setValue(incomingProp);
                    log.debug("Set float " + propName + " = " + incomingProp);
                } catch ( NumberFormatException nfe ) {
                    String propDesc = bundle.getString(propertyDef.getKey());
                    addError("ConfigForm.invalidFloatProperty",
                        Arrays.asList(propDesc, propName));
                }

            } else if ( incomingProp != null ){
                updProp.setValue( incomingProp.trim() );
                log.debug("Set something " + propName + " = " + incomingProp);

            } else if ( propertyDef.getName().equals("users.comments.plugins") ) {
                // not a problem

            } else {
                addError("ConfigForm.invalidProperty", propName);
            }

        }

        if ( this.hasActionErrors() ) {
            return ERROR;
        }

        // special handling for comment plugins
        String enabledPlugins = "";
        if (getCommentPlugins().length > 0) {
            enabledPlugins = StringUtils.join(getCommentPlugins(), ",");
        }
        RuntimeConfigProperty prop = getProperties().get("users.comments.plugins");
        prop.setValue(enabledPlugins);

        try {
            // save 'em and flush
            PropertiesManager mgr = WebloggerFactory.getWeblogger().getPropertiesManager();
            mgr.saveProperties(getProperties());
            WebloggerFactory.getWeblogger().flush();

            // notify user of our success
            addMessage("generic.changes.saved");

        } catch (WebloggerException ex) {
            log.error("Error saving roller properties", ex);
            addError("generic.error.check.logs");
        }

        return SUCCESS;
    }