⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tempuserfile.java

📁 一个日本流行的,功能较全的开源Web办公管理(Groupware)系统。
💻 JAVA
字号:
package jp.co.sjts.gsession.main;

/*
 * 僥儞億儔儕僼傽僀儖屄恖忣曬僼傽僀儖  TempUserFile.java
 * Copyright (C) 1999-2000 Japan Total System Co,LTD
 *    Satoru K  <koni@sjts.co.jp>
 */

import java.io.IOException;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.HashSet;
import java.util.Set;
import java.util.Iterator;
import jp.co.sjts.gsession.tools.*;

public class TempUserFile extends UserFile
{
	public static final String FILENAME = "user.tmp";
	public static final String SHASHINNAME = "shashin.gif.tmp";

	
	public static final String UID = "uid";
	public static final String PASSWD = "passwd";
	public static final String GROUPS = "groups";

	protected String uid;
	protected String passwd;
	protected Set Groups;
	protected boolean existsShashin=false;


	public TempUserFile(String dir)
	{
		super(dir);
		Groups = new HashSet(10);
	}

	protected String getFilename()
	{
		return FILENAME;
	}

	public void setContent(byte[] content) throws GSException
	{
		try{
			FileOutputStream fos = new FileOutputStream(getShashinGifFilePath());
			BufferedOutputStream bos = new BufferedOutputStream(fos,content.length+1);
			bos.write(content,0,content.length);
			bos.flush();
			bos.close();
		}catch(FileNotFoundException e){
			throw new GSException("僼傽僀儖偑尒偮偐傝傑偣傫丅",e);
		}catch(IOException e){
			throw new GSException("IO僄儔乕偱偡丅",e);
		}
		existsShashin = true;
		setShashin(true);
	}

	public void delShashin() throws GSException
	{
		if(existsShashin){
			File file = new File(getShashinGifFilePath());
			if(file.exists())
				file.delete();
			existsShashin = false;
			setShashin(false);
		}
	}

	public String getShashinGifFilePath()
	{
		String path = file.getParent();
		if(path==null)
			return null;

		return path+File.separator+SHASHINNAME;
	}

	// 幨恀偑僙僢僩偝傟偰偄傞偐
	public boolean existsShashin()
	{
		return existsShashin;
	}

	public boolean exists()
	{
		if(file==null)
			return false;

		return file.exists();
	}

	public boolean delete()
	{

		if(file==null)
			return false;

		try {
			if(!(file.delete()))
				return false;
		} catch(SecurityException e) {
		}

		// gif僼傽僀儖偑偁傞応崌偼gif僼傽僀儖傕幪偰傞
		File gifFile = new File(getShashinGifFilePath());
		if(gifFile.exists())
		try {
			return gifFile.delete();
		} catch(SecurityException e) {
		}
		return false;
	}

	public void setUid(String uid)
	{
		this.uid = uid;
	}

	public String getUid()
	{
		return uid;
	}

	public void setPasswd(String passwd)
	{
		if(passwd==null)
			return;
		if(passwd.length()<=0){
			this.passwd = null;
			return;
		}

		String buf="";
		try {
			buf = Password.encode(passwd.getBytes());
		} catch(GSException e) {
		}
		this.passwd = buf.replace('=','-');
	}

	public String getPasswd()
	{
		if(passwd == null)
			return "";
		return passwd.replace('-','=');
	}

	public void addGroup(int GID)
	{
		Groups.add(new Integer(GID));
	}

	public void delGroup(int GID)
	{
		Groups.remove(new Integer(GID));
	}

	/* 巜掕偝傟偨僌儖乕僾ID偑奿擺偝傟偰偄傞偐
	* in:	GID(int)		僌儖乕僾ID
	*
	* out:	(boolean)		奿擺偝傟偰偄偨応崌 true
	*/
	public boolean containsGourp(int GID)
	{
		return Groups.contains(new Integer(GID));
	}

	public Iterator getGroupIterator()
	{
		return Groups.iterator();
	}

	public int[] getGroupArray()
	{
		int gid[] = new int[Groups.size()];
		Iterator it = getGroupIterator();
		for(int i=0;it.hasNext();i++)
			gid[i]=((Integer)it.next()).intValue();
		return gid;
	}

	public boolean existGoup(int GID)
	{
		boolean ret = false;
		Iterator it = Groups.iterator();
		while(it.hasNext())
		{
			Integer i = (Integer)it.next();
			if(GID == i.intValue())
				ret = true;
		}
		return ret;
	}

	protected boolean checkStore(String label,String value)
	{
		boolean ret = false;
		String buf;
		if(label.equals(super.SHASHIN))
			if(value.length()>0)
				existsShashin=true;
		if(!super.checkStore(label,value))
		{
			if(label.equals(GROUPS)){
				StringTokenizer st = new StringTokenizer(value,":");
				while(st.hasMoreTokens())
				{
					buf = st.nextToken();
					Groups.add(new Integer(buf));
				}
				ret = true;
			}else if(label.equals(PASSWD)){
				this.passwd = value;
				ret = true;
			}else if(label.equals(UID)){
				this.setUid(value);
				ret = true;
			}		}
		return ret;
	}

	protected void _write(PrintWriter pw)
	{
		super._write(pw);

		String buf=new String(GROUPS+"=");

		Iterator it = Groups.iterator();
		while(it.hasNext())
		{
			Integer gid = (Integer)it.next();
			buf += gid.toString()+":";
		}
		pw.println(buf);

		pw.println(PASSWD + "=" + this.passwd);

		pw.println(UID + "=" + this.uid);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -