Update of /cvsroot/roller/roller/src/org/roller/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10958/src/org/roller/util
Modified Files:
RollerConfigFile.java
Log Message:
Finished password encryption feature - defaults to "on" for new installs.
Index: RollerConfigFile.java
===================================================================
RCS file: /cvsroot/roller/roller/src/org/roller/util/RollerConfigFile.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RollerConfigFile.java 2 Mar 2004 03:42:35 -0000 1.2
--- RollerConfigFile.java 20 Mar 2004 22:20:25 -0000 1.3
***************
*** 1,794 ****
!
! package org.roller.util;
!
! import java.beans.IntrospectionException;
! import java.io.File;
! import java.io.FileInputStream;
! import java.io.FileNotFoundException;
! import java.io.FileOutputStream;
! import java.io.IOException;
! import java.io.InputStream;
! import java.io.OutputStream;
! import java.lang.reflect.AccessibleObject;
! import java.lang.reflect.Field;
! import java.util.ArrayList;
! import java.util.Arrays;
! import java.util.List;
!
! import org.apache.commons.betwixt.io.BeanReader;
! import org.apache.commons.betwixt.io.BeanWriter;
! import org.apache.commons.logging.Log;
! import org.apache.commons.logging.LogFactory;
! import org.roller.RollerException;
! import org.roller.pojos.RollerConfig;
! import org.xml.sax.SAXException;
!
! /**
! * Configuration object for Roller. Reads and writes roller-config.xml.
! *
! */
! public class RollerConfigFile
! implements java.io.Serializable
! {
! private static Log mLogger =
! LogFactory.getFactory().getInstance(RollerConfigFile.class);
!
! /**
! * Absolute URL for site, for cases where infered absolute URL doesn't
work.
! */
! protected String mAbsoluteURL = null;
!
! /**
! * Should Roller cache return RSS pages.
! */
! protected boolean mRssUseCache = false;
!
! /**
! * Duration to cache RSS pages (in seconds).
! */
! protected int mRssCacheTime = 3000;
!
! /**
! * Does Roller allow the creation of new users.
! */
! protected boolean mNewUserAllowed = false;
!
! /**
! * List of usernames with Admin priviledges.
! */
! protected List mAdminUsers = new ArrayList();
!
! /**
! * Where to get data for creating new users (new-user.xml).
! */
! protected String mNewUserData = "/templates";
!
! /**
! * Where to get Themes presented to new users.
! */
! protected String mNewUserThemes = "/themes";
!
! /**
! * List of "editor pages" for the Weblog entry editor.
! */
! protected List mEditorPages = new ArrayList();
!
! /**
! * Dis/enble RSS aggregation capabilities.
! */
! protected boolean mEnableAggregator = false;
!
! /**
! * Are file uploads enabled.
! */
! protected boolean mUploadEnabled = false;
!
! /**
! * The maximum size of each user's upload directory.
! */
! protected Float mUploadMaxDirMB = new Float("2");
!
! /**
! * The maximum size allowed per uploaded file.
! */
! protected Float mUploadMaxFileMB = new Float(".5");
!
! /**
! * List of permitted file extensions (not including the "dot").
! * This attribute is mutually exclusive with uploadForbid.
! */
! protected List mUploadAllow = new ArrayList();
!
! /**
! * List of forbidden file extensions (not including the "dot").
! * This attribute is mutually exclusive with uploadAllow.
! */
! protected List mUploadForbid = new ArrayList();
!
! /**
! * Directory where uploaded files will be stored.
! * May end with a slash. Optional, this value will
! * default to RollerContext.USER_RESOURCES. If specified,
! * should be a full path on the system harddrive or
! * relative to the WebApp.
! */
! protected String mUploadDir = "";
!
! /**
! * The path from which the webserver will serve upload files.
! * This values must not end in a slash.
! */
! protected String uploadPath = "/resources";
!
! protected boolean mMemDebug = false;
!
! /**
! * Determines if the Comment page will "autoformat"
! * comments. That is, replace carriage-returns with <br />.
! */
! protected boolean mAutoformatComments = false;
!
! /**
! * Determines if the Comment page will escape html in comments.
! */
! protected boolean mEscapeCommentHtml = false;
!
! /**
! * Determines if e-mailing comments is enabled.
! */
! protected boolean mEmailComments = false;
!
! /**
! * Enable linkback extraction.
! */
! protected boolean mEnableLinkback = false;
!
! /**
! * Name of this site
! */
! protected String mSiteName = "Roller-based Site";
!
! /**
! * Description of this site
! */
! protected String mSiteDescription = "Roller-based Site";
!
! /**
! * Site administrator's email address
! */
! protected String mEmailAddress = "";
!
! /**
! * Lucene index directory
! */
! protected String mIndexDir = "${user.home}" + File.separator
! + "roller-index";
!
! public RollerConfigFile()
! {
! }
!
! public RollerConfigFile(RollerConfig rConfig)
! {
! this.setAbsoluteURL ( rConfig.getAbsoluteURL() );
! this.setRssUseCache ( rConfig.getRssUseCache().booleanValue() );
! this.setRssCacheTime ( rConfig.getRssCacheTime().intValue() );
! this.setNewUserAllowed( rConfig.getNewUserAllowed().booleanValue() );
! this.setAdminUsers ( Arrays.asList(rConfig.adminUsersArray()) );
! this.setNewUserThemes ( rConfig.getUserThemes() );
! this.setEditorPages ( rConfig.getEditorPagesList() );
! this.setEnableAggregator (
rConfig.getEnableAggregator().booleanValue() );
! this.setUploadEnabled ( rConfig.getUploadEnabled().booleanValue() );
! this.setUploadMaxDirMB ( new
Float(rConfig.getUploadMaxDirMB().doubleValue()) );
! this.setUploadMaxFileMB ( new
Float(rConfig.getUploadMaxFileMB().doubleValue()) );
! this.setUploadAllow ( Arrays.asList( rConfig.uploadAllowArray()) );
! this.setUploadForbid ( Arrays.asList( rConfig.uploadForbidArray()) );
! this.setUploadDir ( rConfig.getUploadDir() );
! this.setUploadPath ( rConfig.getUploadPath() );
! this.setMemDebug ( rConfig.getMemDebug().booleanValue() );
! this.setAutoformatComments (
rConfig.getAutoformatComments().booleanValue() );
! this.setEscapeCommentHtml (
rConfig.getEscapeCommentHtml().booleanValue() );
! this.setEmailComments ( rConfig.getEmailComments().booleanValue() );
! this.setEnableLinkback ( rConfig.getEnableLinkback().booleanValue() );
! this.setSiteName ( rConfig.getSiteName() );
! this.setSiteDescription ( rConfig.getSiteDescription() );
! this.setEmailAddress ( rConfig.getEmailAddress() );
! this.setIndexDir ( rConfig.getIndexDir() );
! }
!
! //-------------------------------------- begin requisite getters & setters
!
! /** @ejb:persistent-field */
! public String getAbsoluteURL()
! {
! return mAbsoluteURL;
! }
! /** @ejb:persistent-field */
! public void setAbsoluteURL(String string)
! {
! mAbsoluteURL = string;
! }
!
! /** @ejb:persistent-field */
! public boolean getRssUseCache()
! {
! return mRssUseCache;
! }
! /** @ejb:persistent-field */
! public void setRssUseCache(boolean use)
! {
! mRssUseCache = use;
! }
!
! /** @ejb:persistent-field */
! public int getRssCacheTime()
! {
! return mRssCacheTime;
! }
! /** @ejb:persistent-field */
! public void setRssCacheTime(int cacheTime)
! {
! mRssCacheTime = cacheTime;
! }
!
! /** @ejb:persistent-field */
! public boolean getNewUserAllowed()
! {
! return mNewUserAllowed;
! }
! /** @ejb:persistent-field */
! public void setNewUserAllowed(boolean use)
! {
! mNewUserAllowed = use;
! }
!
! /** @ejb:persistent-field */
! public List getAdminUsers()
! {
! return mAdminUsers;
! }
! /** @ejb:persistent-field */
! public void setAdminUsers(List _adminUsers)
! {
! mAdminUsers = _adminUsers;
! }
! /** @ejb:persistent-field */
! public void addAdminUsers(String ignore)
! {
! mAdminUsers.add(ignore);
! }
!
! /** @ejb:persistent-field */
! public String getNewUserData()
! {
! return mNewUserData;
! }
! /** @ejb:persistent-field */
! public void setNewUserData(String str)
! {
! mNewUserData = str;
! }
!
! /** @ejb:persistent-field */
! public String getNewUserThemes()
! {
! return mNewUserThemes;
! }
! /** @ejb:persistent-field */
! public void setNewUserThemes(String str)
! {
! mNewUserThemes = str;
! }
!
! /** @ejb:persistent-field */
! public List getEditorPages()
! {
! return mEditorPages;
! }
! /** @ejb:persistent-field */
! public void setEditorPages(List _editorPages)
! {
! mEditorPages = _editorPages;
! }
! /** @ejb:persistent-field */
! public void addEditorPages(String ignore)
! {
! mEditorPages.add(ignore);
! }
!
! /** @ejb:persistent-field */
! public boolean getEnableAggregator()
! {
! return mEnableAggregator;
! }
! /** @ejb:persistent-field */
! public void setEnableAggregator(boolean use)
! {
! mEnableAggregator = use;
! }
!
! /** @ejb:persistent-field */
! public boolean getUploadEnabled()
! {
! return mUploadEnabled;
! }
! /** @ejb:persistent-field */
! public void setUploadEnabled(boolean use)
! {
! mUploadEnabled = use;
! }
!
! /** @ejb:persistent-field */
! public Float getUploadMaxDirMB()
! {
! return mUploadMaxDirMB;
! }
! /** @ejb:persistent-field */
! public void setUploadMaxDirMB(Float use)
! {
! mUploadMaxDirMB = use;
! }
!
! /** @ejb:persistent-field */
! public Float getUploadMaxFileMB()
! {
! return mUploadMaxFileMB;
! }
! /** @ejb:persistent-field */
! public void setUploadMaxFileMB(Float use)
! {
! mUploadMaxFileMB = use;
! }
!
! /** @ejb:persistent-field */
! public List getUploadAllow()
! {
! return mUploadAllow;
! }
! /** @ejb:persistent-field */
! public void setUploadAllow(List _uploadAllow)
! {
! mUploadAllow = _uploadAllow;
! }
! /** @ejb:persistent-field */
! public void addUploadAllow(String ignore)
! {
! mUploadAllow.add(ignore);
! }
!
! /** @ejb:persistent-field */
! public List getUploadForbid()
! {
! return mUploadForbid;
! }
! /** @ejb:persistent-field */
! public void setUploadForbid(List _uploadForbid)
! {
! mUploadForbid = _uploadForbid;
! }
! /** @ejb:persistent-field */
! public void addUploadForbid(String ignore)
! {
! mUploadForbid.add(ignore);
! }
!
! /** @ejb:persistent-field */
! public String getUploadDir()
! {
! return mUploadDir;
! }
! /** @ejb:persistent-field */
! public void setUploadDir(String str)
! {
! mUploadDir = str;
! }
!
! /** @ejb:persistent-field */
! public String getUploadPath()
! {
! return uploadPath;
! }
! /** @ejb:persistent-field */
! public void setUploadPath(String str)
! {
! uploadPath = str;
! }
!
! /** @ejb:persistent-field */
! public boolean getMemDebug() { return mMemDebug; }
!
! /**
! * Set memory debugging on or off.
! * @param mMemDebug The mMemDebug to set
! * @ejb:persistent-field
! */
! public void setMemDebug(boolean memDebug)
! {
! mMemDebug = memDebug;
! }
!
! /** @ejb:persistent-field */
! public boolean getAutoformatComments()
! {
! return mAutoformatComments;
! }
! /** @ejb:persistent-field */
! public void setAutoformatComments(boolean value)
! {
! mAutoformatComments = value;
! }
!
! /** @ejb:persistent-field */
! public boolean getEscapeCommentHtml()
! {
! return mEscapeCommentHtml;
! }
! /** @ejb:persistent-field */
! public void setEscapeCommentHtml(boolean value)
! {
! mEscapeCommentHtml = value;
! }
!
! /**
! * @return boolean
! * @ejb:persistent-field
! */
! public boolean getEmailComments()
! {
! return mEmailComments;
! }
!
! /**
! * Sets the emailComments.
! * @param emailComments The emailComments to set
! * @ejb:persistent-field
! */
! public void setEmailComments(boolean emailComments)
! {
! this.mEmailComments = emailComments;
! }
!
! /**
! * Enable linkback.
! * @ejb:persistent-field
! */
! public boolean isEnableLinkback()
! {
! return mEnableLinkback;
! }
!
! /**
! * Enable linkback.
! * @ejb:persistent-field
! */
! public void setEnableLinkback(boolean b)
! {
! mEnableLinkback = b;
! }
!
!
! /**
! * @return
! * @ejb:persistent-field
! */
! public String getSiteDescription()
! {
! return mSiteDescription;
! }
!
! /**
! * @return
! * @ejb:persistent-field
! */
! public String getSiteName()
! {
! return mSiteName;
! }
!
! /**
! * @param string
! * @ejb:persistent-field
! */
! public void setSiteDescription(String string)
! {
! mSiteDescription = string;
! }
!
! /**
! * @param string
! * @ejb:persistent-field
! */
! public void setSiteName(String string)
! {
! mSiteName = string;
! }
!
! /**
! * @return
! * @ejb:persistent-field
! */
! public String getEmailAddress()
! {
! return mEmailAddress;
! }
!
! /**
! * @param string
! * @ejb:persistent-field
! */
! public void setEmailAddress(String emailAddress)
! {
! mEmailAddress = emailAddress;
! }
!
! /**
! * @return the index directory
! * @ejb:persistent-field
! */
! public String getIndexDir() {
!
! return mIndexDir;
! }
!
! /**
! * @param the new index directory
! * @ejb:persistent-field
! */
! public void setIndexDir(String indexDir)
! {
! mIndexDir = indexDir;
! }
!
! //---------------------------------------- end requisite getters & setters
!
! /**
! * Convenience method for getAdminUsers.
! **/
! public String[] adminUsersArray()
! {
! if (mAdminUsers == null) mAdminUsers = new ArrayList();
! return (String[])mAdminUsers.toArray( new String[ mAdminUsers.size()
] );
! }
!
! /**
! * Convenience method for getEditorPages.
! **/
! public String[] editorPagesArray()
! {
! if (mEditorPages == null) mEditorPages = new ArrayList();
! return (String[])mEditorPages.toArray( new String[
mEditorPages.size() ] );
! }
!
! /**
! * Convenience method for getUploadAllow.
! **/
! public String[] uploadAllowArray()
! {
! if (mUploadAllow == null) mUploadAllow = new ArrayList();
! return (String[])mUploadAllow.toArray( new String[
mUploadAllow.size() ] );
! }
!
! /**
! * Convenience method for getUploadForbid.
! **/
! public String[] uploadForbidArray()
! {
! if (mUploadForbid == null) mUploadForbid = new ArrayList();
! return (String[])mUploadForbid.toArray( new String[
mUploadForbid.size() ] );
! }
!
! public void updateValues( RollerConfigFile child )
! {
! this.mAbsoluteURL = child.getAbsoluteURL();
! this.mRssUseCache = child.getRssUseCache();
! this.mRssCacheTime = child.getRssCacheTime();
! this.mNewUserAllowed = child.getNewUserAllowed();
! this.mAdminUsers = child.getAdminUsers();
! this.mNewUserData = child.getNewUserData();
! this.mNewUserThemes = child.getNewUserThemes();
! this.mEditorPages = child.getEditorPages();
! this.mEnableAggregator = child.getEnableAggregator();
! this.mUploadEnabled = child.getUploadEnabled();
! this.mUploadMaxDirMB = child.getUploadMaxDirMB();
! this.mUploadMaxFileMB = child.getUploadMaxFileMB();
! this.mUploadAllow = child.getUploadAllow();
! this.mUploadForbid = child.getUploadForbid();
! this.mUploadDir = child.getUploadDir();
! this.uploadPath = child.getUploadPath();
! this.mMemDebug = child.getMemDebug();
! this.mAutoformatComments = child.getAutoformatComments();
! this.mEscapeCommentHtml = child.getEscapeCommentHtml();
! this.mEmailComments = child.getEmailComments();
! this.mEnableLinkback = child.isEnableLinkback();
! this.mSiteName = child.getSiteName();
! this.mSiteDescription = child.getSiteDescription();
! this.mEmailAddress = child.getEmailAddress();
! this.mIndexDir = child.getIndexDir();
! }
!
! /** nice output for debugging */
! public String toString()
! {
! StringBuffer buf = new StringBuffer();
! buf.append("RollerConfig \n");
! Class clazz = getClass();
! Field[] fields = clazz.getDeclaredFields();
!
! try {
! AccessibleObject.setAccessible(fields, true);
! for (int i = 0; i < fields.length; i++) {
! buf.append(
! "\t["
! + fields[i].getName()
! + "="
! + fields[i].get(this)
! + "], \n");
! }
! } catch (Exception e) {
! // ignored!
! }
!
! return buf.toString();
! }
!
! /**
! * Read the RollerConfig from a file,
! * as specified by a String path.
! */
! public static RollerConfigFile readConfig(String path)
! {
! InputStream in = null;
! try
! {
! in = new FileInputStream( path );
! return RollerConfigFile.readConfig( in );
! }
! catch (Exception e)
! {
! System.out.println("Exception reading RollerConfig: " +
e.getMessage());
! }
! finally
! {
! try
! {
! if (in != null) in.close();
! }
! catch (java.io.IOException ioe)
! {
! System.err.println("RollerConfig.writeConfig() unable to
close InputStream");
! }
! }
! return new RollerConfigFile();
! }
!
! /**
! * Read the RollerConfig from a file, as specified by an InputStream.
! */
! public static RollerConfigFile readConfig(InputStream in)
! {
! try
! {
! BeanReader reader = new BeanReader();
! reader.registerBeanClass( RollerConfigFile.class );
! return (RollerConfigFile)reader.parse( in );
! }
! catch (IOException e)
! {
! throw new RuntimeException(
! "FATAL ERROR reading RollerConfig inputstream.",e);
! }
! catch (SAXException e)
! {
! throw new RuntimeException(
! "FATAL ERROR parsing RollerConfig, file is corrupted?",e);
! }
! catch (IntrospectionException e)
! {
! throw new RuntimeException(
! "FATAL ERROR introspecting RollerConfig bean.",e);
! }
! }
!
! /**
! * Write RollerConfig to file, as specified by a String path.
! */
! public void writeConfig(String path) throws RollerException
! {
! FileOutputStream out = null;
! try
! {
! out = new FileOutputStream(path);
! writeConfig( out );
! }
! catch (FileNotFoundException e)
! {
! throw new RollerException("ERROR file not found: " + path, e);
! }
! finally
! {
! try
! {
! if (out != null) out.close();
! }
! catch (java.io.IOException ioe)
! {
! System.err.println("RollerConfig.writeConfig() unable to
close OutputStream");
! }
! }
! }
!
! /**
! * Write RollerConfig to file, as specified by an OutputStream.
! */
! public void writeConfig(OutputStream out) throws RollerException
! {
! BeanWriter writer = new BeanWriter(out);
! writer.enablePrettyPrint();
! writer.setIndent(" ");
! writer.setWriteIDs(false);
! try
! {
! writer.write(this);
! }
! catch (IOException e)
! {
! throw new RollerException(
! "ERROR writing to roller-config.xml stream.", e);
! }
! catch (SAXException e)
! {
! throw new RollerException(
! "ERROR writing to roller-config.xml stream.", e);
! }
! catch (IntrospectionException e)
! {
! throw new RollerException(
! "ERROR introspecting RollerConfig bean.", e);
! }
! }
!
! /*** test stuff ***/
! public static void main(String[] args)
! {
! String basedir = System.getProperty("basedir");
! String path = "build/roller/WEB-INF/roller-config.xml";
! path = new java.io.File(basedir,path).getAbsolutePath();
! if (args.length > 0 && args[0].equals("read"))
! {
! RollerConfigFile.readConfig( path );
! }
! else if (args.length > 0 && args[0].equals("write")) // write
! {
! path = "build/roller/WEB-INF/roller-config-test.xml";
! path = new java.io.File(basedir,path).getAbsolutePath();
!
! RollerConfigFile bean = new RollerConfigFile();
! try
! {
! bean.writeConfig(path);
! }
! catch (Exception e)
! {
! mLogger.error("Unexpected exception",e);
! }
! }
! else // both
! {
! RollerConfigFile bean = RollerConfigFile.readConfig( path );
! path = "build/roller/WEB-INF/roller-config-test.xml";
! path = new java.io.File(basedir,path).getAbsolutePath();
!
! try
! {
! bean.writeConfig(path);
! }
! catch (Exception e)
! {
! mLogger.error("Unexpected exception",e);
! }
! }
! System.out.println("RollerConfig.main completed");
!
! }
!
! }
--- 1 ----
! package org.roller.util;
import java.beans.IntrospectionException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.betwixt.io.BeanReader;
import org.apache.commons.betwixt.io.BeanWriter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.roller.RollerException;
import org.roller.pojos.RollerConfig;
import org.xml.sax.SAXException;
/**
* Configuration object for Roller. Reads and writes roller-config.xml.
*/
public class RollerConfigFile implements java.io.Serializable
{
private static Log mLogger =
LogFactory.getFactory().getInstance( RollerConfigFile.class );
/**
* Absolute URL for site, for cases where infered absolute URL doesn't
* work.
*/
protected String mAbsoluteURL = null;
/** Should Roller cache return RSS pages. */
protected boolean mRssUseCache = false;
/** Duration to cache RSS pages (in seconds). */
protected int mRssCacheTime = 3000;
/** Does Roller allow the creation of new users. */
protected boolean mNewUserAllowed = false;
/** List of usernames with Admin priviledges. */
protected List mAdminUsers = new ArrayList();
/** Where to get data for creating new users (new-user.xml). */
protected String mNewUserData = "/templates";
/** Where to get Themes presented to new users. */
protected String mNewUserThemes = "/themes";
/** List of "editor pages" for the Weblog entry editor. */
protected List mEditorPages = new ArrayList();
/** Dis/enble RSS aggregation capabilities. */
protected boolean mEnableAggregator = false;
/** Are file uploads enabled. */
protected boolean mUploadEnabled = false;
/** The maximum size of each user's upload directory. */
protected Float mUploadMaxDirMB = new Float( "2" );
/** The maximum size allowed per uploaded file. */
protected Float mUploadMaxFileMB = new Float( ".5" );
/**
* List of permitted file extensions (not including the "dot"). This
* attribute is mutually exclusive with uploadForbid.
*/
protected List mUploadAllow = new ArrayList();
/**
* List of forbidden file extensions (not including the "dot"). This
* attribute is mutually exclusive with uploadAllow.
*/
protected List mUploadForbid = new ArrayList();
/**
* Directory where uploaded files will be stored. May end with a slash.
* Optional, this value will default to RollerContext.USER_RESOURCES. If
* specified, should be a full path on the system harddrive or relative to
* the WebApp.
*/
protected String mUploadDir = "";
/**
* The path from which the webserver will serve upload files. This values
* must not end in a slash.
*/
protected String uploadPath = "/resources";
protected boolean mMemDebug = false;
/**
* Determines if the Comment page will "autoformat" comments. That is,
* replace carriage-returns with <br />.
*/
protected boolean mAutoformatComments = false;
/** Determines if the Comment page will escape html in comments. */
protected boolean mEscapeCommentHtml = false;
/** Determines if e-mailing comments is enabled. */
protected boolean mEmailComments = false;
/** Enable linkback extraction. */
protected boolean mEnableLinkback = false;
/** Name of this site */
protected String mSiteName = "Roller-based Site";
/** Description of this site */
protected String mSiteDescription = "Roller-based Site";
/** Site administrator's email address */
protected String mEmailAddress = "";
/** Lucene index directory */
protected String mIndexDir =
"${user.home}" + File.separator + "roller-index";
/**
* Flag for encrypting passwords
*/
protected boolean mEncryptPasswords = false;
/** Algorithm for encrypting passwords */
protected String mAlgorithm = "SHA";
public RollerConfigFile()
{
}
public RollerConfigFile( RollerConfig rConfig )
{
this.setAbsoluteURL( rConfig.getAbsoluteURL() );
this.setRssUseCache( rConfig.getRssUseCache().booleanValue() );
this.setRssCacheTime( rConfig.getRssCacheTime().intValue() );
this.setNewUserAllowed( rConfig.getNewUserAllowed().booleanValue() );
this.setAdminUsers( Arrays.asList( rConfig.adminUsersArray() ) );
this.setNewUserThemes( rConfig.getUserThemes() );
this.setEditorPages( rConfig.getEditorPagesList() );
this.setEnableAggregator( rConfig.getEnableAggregator().booleanValue()
);
this.setUploadEnabled( rConfig.getUploadEnabled().booleanValue() );
this.setUploadMaxDirMB( new Float( rConfig.getUploadMaxDirMB()
.doubleValue() ) );
this.setUploadMaxFileMB( new Float( rConfig.getUploadMaxFileMB()
.doubleValue() ) );
this.setUploadAllow( Arrays.asList( rConfig.uploadAllowArray() ) );
this.setUploadForbid( Arrays.asList( rConfig.uploadForbidArray() ) );
this.setUploadDir( rConfig.getUploadDir() );
this.setUploadPath( rConfig.getUploadPath() );
this.setMemDebug( rConfig.getMemDebug().booleanValue() );
this.setAutoformatComments( rConfig.getAutoformatComments()
.booleanValue() );
this.setEscapeCommentHtml( rConfig.getEscapeCommentHtml()
.booleanValue() );
this.setEmailComments( rConfig.getEmailComments().booleanValue() );
this.setEnableLinkback( rConfig.getEnableLinkback().booleanValue() );
this.setSiteName( rConfig.getSiteName() );
this.setSiteDescription( rConfig.getSiteDescription() );
this.setEmailAddress( rConfig.getEmailAddress() );
this.setIndexDir( rConfig.getIndexDir() );
this.setEncryptPasswords( rConfig.getEncryptPasswords().booleanValue()
);
this.setAlgorithm( rConfig.getAlgorithm() );
}
//-------------------------------------- begin requisite getters & setters
public String getAbsoluteURL()
{
return mAbsoluteURL;
}
public void setAbsoluteURL( String string )
{
mAbsoluteURL = string;
}
public boolean getRssUseCache()
{
return mRssUseCache;
}
public void setRssUseCache( boolean use )
{
mRssUseCache = use;
}
public int getRssCacheTime()
{
return mRssCacheTime;
}
public void setRssCacheTime( int cacheTime )
{
mRssCacheTime = cacheTime;
}
public boolean getNewUserAllowed()
{
return mNewUserAllowed;
}
public void setNewUserAllowed( boolean use )
{
mNewUserAllowed = use;
}
public List getAdminUsers()
{
return mAdminUsers;
}
/**
* @param _adminUsers
*/
public void setAdminUsers( List _adminUsers )
{
mAdminUsers = _adminUsers;
}
/**
* @param ignore
*/
public void addAdminUsers( String ignore )
{
mAdminUsers.add( ignore );
}
public String getNewUserData()
{
return mNewUserData;
}
/**
* @param str
*/
public void setNewUserData( String str )
{
mNewUserData = str;
}
public String getNewUserThemes()
{
return mNewUserThemes;
}
/**
* @param str
*/
public void setNewUserThemes( String str )
{
mNewUserThemes = str;
}
public List getEditorPages()
{
return mEditorPages;
}
/**
* @param _editorPages
*/
public void setEditorPages( List _editorPages )
{
mEditorPages = _editorPages;
}
/**
* @param ignore
*/
public void addEditorPages( String ignore )
{
mEditorPages.add( ignore );
}
public boolean getEnableAggregator()
{
return mEnableAggregator;
}
public void setEnableAggregator( boolean use )
{
mEnableAggregator = use;
}
public boolean getUploadEnabled()
{
return mUploadEnabled;
}
public void setUploadEnabled( boolean use )
{
mUploadEnabled = use;
}
public Float getUploadMaxDirMB()
{
return mUploadMaxDirMB;
}
public void setUploadMaxDirMB( Float use )
{
mUploadMaxDirMB = use;
}
public Float getUploadMaxFileMB()
{
return mUploadMaxFileMB;
}
public void setUploadMaxFileMB( Float use )
{
mUploadMaxFileMB = use;
}
public List getUploadAllow()
{
return mUploadAllow;
}
/**
* @param _uploadAllow
*/
public void setUploadAllow( List _uploadAllow )
{
mUploadAllow = _uploadAllow;
}
/**
* @param ignore
*/
public void addUploadAllow( String ignore )
{
mUploadAllow.add( ignore );
}
public List getUploadForbid()
{
return mUploadForbid;
}
/**
* @param _uploadForbid
*/
public void setUploadForbid( List _uploadForbid )
{
mUploadForbid = _uploadForbid;
}
/**
* @param ignore
*/
public void addUploadForbid( String ignore )
{
mUploadForbid.add( ignore );
}
public String getUploadDir()
{
return mUploadDir;
}
/**
* @param str
*/
public void setUploadDir( String str )
{
mUploadDir = str;
}
public String getUploadPath()
{
return uploadPath;
}
/**
* @param str
*/
public void setUploadPath( String str )
{
uploadPath = str;
}
public boolean getMemDebug()
{
return mMemDebug;
}
/**
* Set memory debugging on or off.
*
* @param memDebug The mMemDebug to set
*/
public void setMemDebug( boolean memDebug )
{
mMemDebug = memDebug;
}
public boolean getAutoformatComments()
{
return mAutoformatComments;
}
/**
* @param value
*/
public void setAutoformatComments( boolean value )
{
mAutoformatComments = value;
}
public boolean getEscapeCommentHtml()
{
return mEscapeCommentHtml;
}
/**
* @param value
*/
public void setEscapeCommentHtml( boolean value )
{
mEscapeCommentHtml = value;
}
/**
* @return boolean
*/
public boolean getEmailComments()
{
return mEmailComments;
}
/**
* Sets the emailComments.
*
* @param emailComments The emailComments to set
*/
public void setEmailComments( boolean emailComments )
{
this.mEmailComments = emailComments;
}
/**
* Enable linkback.
*
* @return
*/
public boolean isEnableLinkback()
{
return mEnableLinkback;
}
/**
* Enable linkback.
*
* @param b
*/
public void setEnableLinkback( boolean b )
{
mEnableLinkback = b;
}
/**
* @return
*/
public String getSiteDescription()
{
return mSiteDescription;
}
/**
* @return
*/
public String getSiteName()
{
return mSiteName;
}
/**
* @param string
*/
public void setSiteDescription( String string )
{
mSiteDescription = string;
}
/**
* @param string
*/
public void setSiteName( String string )
{
mSiteName = string;
}
/**
* @return
*/
public String getEmailAddress()
{
return mEmailAddress;
}
/**
* @param emailAddress
*/
public void setEmailAddress( String emailAddress )
{
mEmailAddress = emailAddress;
}
/**
* @return the index directory
*/
public String getIndexDir()
{
return mIndexDir;
}
/**
* @param indexDir new index directory
*/
public void setIndexDir( String indexDir )
{
mIndexDir = indexDir;
}
public boolean getEncryptPasswords()
{
return mEncryptPasswords;
}
public void setEncryptPasswords( boolean use )
{
mEncryptPasswords = use;
}
/**
* @return the algorithm for encrypting passwords
*/
public String getAlgorithm()
{
return mAlgorithm;
}
/**
* @param algorithm, the new algorithm
*/
public void setAlgorithm( String algorithm )
{
mAlgorithm = algorithm;
}
//---------------------------------------- end requisite getters & setters
/**
* Convenience method for getAdminUsers.
*
* @return
*/
public String[] adminUsersArray()
{
if ( mAdminUsers == null )
{
mAdminUsers = new ArrayList();
}
return (String[]) mAdminUsers.toArray( new String[mAdminUsers.size()] );
}
/**
* Convenience method for getEditorPages.
*
* @return
*/
public String[] editorPagesArray()
{
if ( mEditorPages == null )
{
mEditorPages = new ArrayList();
}
return (String[]) mEditorPages.toArray( new String[mEditorPages.size()]
);
}
/**
* Convenience method for getUploadAllow.
*
* @return
*/
public String[] uploadAllowArray()
{
if ( mUploadAllow == null )
{
mUploadAllow = new ArrayList();
}
return (String[]) mUploadAllow.toArray( new String[mUploadAllow.size()]
);
}
/**
* Convenience method for getUploadForbid.
*
* @return
*/
public String[] uploadForbidArray()
{
if ( mUploadForbid == null )
{
mUploadForbid = new ArrayList();
}
return (String[]) mUploadForbid.toArray( new
String[mUploadForbid.size()] );
}
public void updateValues( RollerConfigFile child )
{
this.mAbsoluteURL = child.getAbsoluteURL();
this.mRssUseCache = child.getRssUseCache();
this.mRssCacheTime = child.getRssCacheTime();
this.mNewUserAllowed = child.getNewUserAllowed();
this.mAdminUsers = child.getAdminUsers();
this.mNewUserData = child.getNewUserData();
this.mNewUserThemes = child.getNewUserThemes();
this.mEditorPages = child.getEditorPages();
this.mEnableAggregator = child.getEnableAggregator();
this.mUploadEnabled = child.getUploadEnabled();
this.mUploadMaxDirMB = child.getUploadMaxDirMB();
this.mUploadMaxFileMB = child.getUploadMaxFileMB();
this.mUploadAllow = child.getUploadAllow();
this.mUploadForbid = child.getUploadForbid();
this.mUploadDir = child.getUploadDir();
this.uploadPath = child.getUploadPath();
this.mMemDebug = child.getMemDebug();
this.mAutoformatComments = child.getAutoformatComments();
this.mEscapeCommentHtml = child.getEscapeCommentHtml();
this.mEmailComments = child.getEmailComments();
this.mEnableLinkback = child.isEnableLinkback();
this.mSiteName = child.getSiteName();
this.mSiteDescription = child.getSiteDescription();
this.mEmailAddress = child.getEmailAddress();
this.mIndexDir = child.getIndexDir();
this.mEncryptPasswords = child.getEncryptPasswords();
this.mAlgorithm = child.getAlgorithm();
}
/**
* nice output for debugging
*
* @return
*/
public String toString()
{
StringBuffer buf = new StringBuffer();
buf.append( "RollerConfig \n" );
Class clazz = getClass();
Field[] fields = clazz.getDeclaredFields();
try
{
AccessibleObject.setAccessible( fields, true );
for ( int i = 0; i < fields.length; i++ )
{
buf.append( "\t[" + fields[i].getName() + "=" +
fields[i].get( this ) + "], \n" );
}
}
catch ( Exception e )
{
// ignored!
}
return buf.toString();
}
/**
* Read the RollerConfig from a file, as specified by a String path.
*
* @param path
*
* @return
*/
public static RollerConfigFile readConfig( String path )
{
InputStream in = null;
try
{
in = new FileInputStream( path );
return RollerConfigFile.readConfig( in );
}
catch ( Exception e )
{
System.out.println( "Exception reading RollerConfig: " +
e.getMessage() );
}
finally
{
try
{
if ( in != null )
{
in.close();
}
}
catch ( java.io.IOException ioe )
{
System.err.println( "RollerConfig.writeConfig() unable to close
InputStream" );
}
}
return new RollerConfigFile();
}
/**
* Read the RollerConfig from a file, as specified by an InputStream.
*
* @param in
*
* @return
*
* @throws RuntimeException
*/
public static RollerConfigFile readConfig( InputStream in )
{
try
{
BeanReader reader = new BeanReader();
reader.registerBeanClass( RollerConfigFile.class );
return (RollerConfigFile) reader.parse( in );
}
catch ( IOException e )
{
throw new RuntimeException( "FATAL ERROR reading RollerConfig
inputstream.",
e );
}
catch ( SAXException e )
{
throw new RuntimeException( "FATAL ERROR parsing RollerConfig, file
is corrupted?",
e );
}
catch ( IntrospectionException e )
{
throw new RuntimeException( "FATAL ERROR introspecting RollerConfig
bean.",
e );
}
}
/**
* Write RollerConfig to file, as specified by a String path.
*
* @param path
*
* @throws RollerException
*/
public void writeConfig( String path ) throws RollerException
{
FileOutputStream out = null;
try
{
out = new FileOutputStream( path );
writeConfig( out );
}
catch ( FileNotFoundException e )
{
throw new RollerException( "ERROR file not found: " + path, e );
}
finally
{
try
{
if ( out != null )
{
out.close();
}
}
catch ( java.io.IOException ioe )
{
System.err.println( "RollerConfig.writeConfig() unable to close
OutputStream" );
}
}
}
/**
* Write RollerConfig to file, as specified by an OutputStream.
*
* @param out
*
* @throws RollerException
*/
public void writeConfig( OutputStream out ) throws RollerException
{
BeanWriter writer = new BeanWriter( out );
writer.enablePrettyPrint();
writer.setIndent( " " );
writer.setWriteIDs( false );
try
{
writer.write( this );
}
catch ( IOException e )
{
throw new RollerException( "ERROR writing to roller-config.xml
stream.",
e );
}
catch ( SAXException e )
{
throw new RollerException( "ERROR writing to roller-config.xml
stream.",
e );
}
catch ( IntrospectionException e )
{
throw new RollerException( "ERROR introspecting RollerConfig bean.",
e );
}
}
/**
* test stuff
*
* @param args
*/
public static void main( String[] args )
{
String basedir = System.getProperty( "basedir" );
String path = "build/roller/WEB-INF/roller-config.xml";
path = new java.io.File( basedir, path ).getAbsolutePath();
if ( ( args.length > 0 ) && args[0].equals( "read" ) )
{
RollerConfigFile.readConfig( path );
}
else if ( ( args.length > 0 ) && args[0].equals( "write" ) ) // write
{
path = "build/roller/WEB-INF/roller-config-test.xml";
path = new java.io.File( basedir, path ).getAbsolutePath();
RollerConfigFile bean = new RollerConfigFile();
try
{
bean.writeConfig( path );
}
catch ( Exception e )
{
mLogger.error( "Unexpected exception", e );
}
}
else // both
{
RollerConfigFile bean = RollerConfigFile.readConfig( path );
path = "build/roller/WEB-INF/roller-config-test.xml";
path = new java.io.File( basedir, path ).getAbsolutePath();
try
{
bean.writeConfig( path );
}
catch ( Exception e )
{
mLogger.error( "Unexpected exception", e );
}
}
System.out.println( "RollerConfig.main completed" );
}
}
\ No newline at end of file
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
|