com.pureinfo.force.fileserver.PathConfig.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.force.fileserver.PathConfig.java

Source

/**
 * PureInfo Force
 * @(#)PathConfig.java   1.0 Oct 21, 2005
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

package com.pureinfo.force.fileserver;

import java.io.File;

import org.dom4j.Element;

import com.pureinfo.force.exception.PureException;
import com.pureinfo.force.lang.StrUtil;
import com.pureinfo.force.xml.IXMLSupporter;

/**
 * <P>
 * Created on Oct 21, 2005 10:28:08 PM <BR>
 * Last modified on Oct 21, 2005
 * </P>
 * PathConfig: file path config.
 * 
 * @author Why
 * @version 1.0, Oct 21, 2005
 * @since Force 1.0
 */
public class PathConfig implements IXMLSupporter {
    /** the length of flag */
    public final static int FLAG_LENGTH = 2; //

    private String m_sFlag;

    private String m_sDesc;

    private String m_sLocalPath;

    private String m_sHttpPath;

    /**
     * Constructor: default
     */
    public PathConfig() {
        super();
    }

    /**
     * Returns the flag of this path.
     * 
     * @return the flag of this path.
     */
    public String getFlag() {
        return m_sFlag;
    }

    /**
     * Sets this path flag.
     * 
     * @param _sFlag
     *            flag of this path.
     */
    public void setFlag(String _sFlag) {
        if (_sFlag.length() > FLAG_LENGTH) {
            m_sFlag = _sFlag.substring(0, FLAG_LENGTH);
        } else {
            m_sFlag = _sFlag;
        }
    }

    /**
     * Returns the description.
     * 
     * @return the description.
     */
    public String getDesc() {
        return m_sDesc;
    }

    /**
     * Sets the description.
     * 
     * @param _sDesc
     *            the description.
     */
    public void setDesc(String _sDesc) {
        m_sDesc = _sDesc;
    }

    public String getLocalPath() {
        return m_sLocalPath;
    }

    /**
     * Sets the local path.
     * 
     * @param _sLocalPath
     *            the local path.
     */
    public void setLocalPath(String _sLocalPath) {
        m_sLocalPath = StrUtil.setStrEndWith(_sLocalPath, File.separatorChar);
    }

    /**
     * Returns the http path.
     * 
     * @return the http path.
     */
    public String getHttpPath() {
        return m_sHttpPath;
    }

    /**
     * Sets the http path.
     * 
     * @param _sHttpPath
     *            the http path.
     */
    public void setHttpPath(String _sHttpPath) {
        m_sHttpPath = _sHttpPath;
    }

    /**
     * @see java.lang.Object#toString()
     */
    public String toString() {
        StringBuffer sbuff = new StringBuffer();
        try {
            sbuff.append("flag=").append(m_sFlag);
            sbuff.append(" desc=").append(m_sDesc);
            sbuff.append(" local=").append(m_sLocalPath);
            if (m_sHttpPath != null) {
                sbuff.append(" http=").append(m_sHttpPath);
            }
            return sbuff.toString();
        } finally {
            sbuff.setLength(0);
        }
    }

    //=========================================================================
    //XML support

    /**
     * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element)
     */
    public void toXMLElement(Element _element) throws PureException {
        _element.addAttribute("flag", m_sFlag);
        _element.addAttribute("desc", m_sDesc);
        _element.addAttribute("local", m_sLocalPath);
        if (m_sHttpPath != null) {
            _element.addAttribute("http", m_sHttpPath);
        }
    }

    /**
     * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
     */
    public void fromXML(Element _element) throws PureException {
        this.setFlag(_element.attributeValue("flag"));
        this.setDesc(_element.attributeValue("desc"));
        this.setLocalPath(_element.attributeValue("local"));
        this.setHttpPath(_element.attributeValue("http"));
    }
}