putlistresource.java
来自「很棒的web服务器源代码」· Java 代码 · 共 769 行 · 第 1/2 页
JAVA
769 行
// PutListResource.java// $Id: PutListResource.java,v 1.13 2000/08/16 21:37:32 ylafon Exp $// (c) COPYRIGHT MIT and INRIA, 1996.// Please first read the full copyright statement in file COPYRIGHT.htmlpackage org.w3c.jigedit.filters;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.io.PrintStream;import java.io.Reader;import java.io.Writer;import java.util.Enumeration;import java.util.Hashtable;import java.util.Properties;import java.util.Vector;import java.net.URL;import org.w3c.util.IO;import org.w3c.util.ObservableProperties;import org.w3c.tools.resources.Attribute;import org.w3c.tools.resources.AttributeHolder;import org.w3c.tools.resources.AttributeRegistry;import org.w3c.tools.resources.BooleanAttribute;import org.w3c.tools.resources.FileAttribute;import org.w3c.tools.resources.FileResource;import org.w3c.tools.resources.FramedResource;import org.w3c.tools.resources.IntegerAttribute;import org.w3c.tools.resources.InvalidResourceException;import org.w3c.tools.resources.Resource;import org.w3c.tools.resources.ResourceReference;import org.w3c.tools.resources.ServerInterface;import org.w3c.tools.resources.serialization.Serializer;import org.w3c.tools.resources.ProtocolException;import org.w3c.cvs.CVS;import org.w3c.cvs.CvsDirectory;import org.w3c.cvs.CvsException;import org.w3c.cvs.UncheckedOutException;import org.w3c.jigsaw.auth.AuthFilter;import org.w3c.jigsaw.http.Request;import org.w3c.www.http.HttpRequestMessage;public class PutListResource extends FramedResource { protected static final boolean debug = true; /** * status: File published */ public static final int FILE_PB = 1; /** * status: File unchanged */ public static final int FILE_UC = 2; /** * status: File merged */ public static final int FILE_MG = 3; /** * status: conflict */ public static final int FILE_CF = 4; /** * status: deleted */ public static final int FILE_DEL = 5; /** * Attribute index - The file used to store the modification list. */ protected static int ATTR_FILE = -1; /** * Attribute index - The user's local space. */ protected static int ATTR_SPACE = -1; /** * Attribute index - The web server public space. */ protected static int ATTR_ROOT = -1; /** * Attribute index - The auto publish flag */ protected static int ATTR_AUTO_PUBLISH = -1; /** * Attribute index - The auto delete flag */ protected static int ATTR_AUTO_DELETE = -1; /** * Attribute index - The max number of published entries stored */ protected static int ATTR_MAX_PUBLISHED = -1; static { Class c = null; Attribute a = null; try { c = Class.forName("org.w3c.jigedit.filters.PutListResource"); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } // Register the file attribute: a = new FileAttribute("file" , null , Attribute.EDITABLE|Attribute.MANDATORY); ATTR_FILE = AttributeRegistry.registerAttribute(c, a); // Register the space attribute: a = new FileAttribute("space" , null , Attribute.EDITABLE|Attribute.MANDATORY); ATTR_SPACE = AttributeRegistry.registerAttribute(c, a); // Register the server root: a = new FileAttribute("root" , null , Attribute.EDITABLE| Attribute.MANDATORY); ATTR_ROOT = AttributeRegistry.registerAttribute(c, a); // Register the auto publish flag a = new BooleanAttribute("auto-publish", Boolean.FALSE, Attribute.EDITABLE); ATTR_AUTO_PUBLISH = AttributeRegistry.registerAttribute(c, a); // Register the auto delete flag a = new BooleanAttribute("auto-delete", Boolean.FALSE, Attribute.EDITABLE); ATTR_AUTO_DELETE = AttributeRegistry.registerAttribute(c, a); // Register the max number of published entries stored a = new IntegerAttribute("max-published", new Integer(10), Attribute.EDITABLE); ATTR_MAX_PUBLISHED = AttributeRegistry.registerAttribute(c, a); } protected static Serializer serializer = null; static { serializer = new org.w3c.tools.resources.serialization.xml.XMLSerializer(); } /** * Get our auto publish flag. * @return a boolean. */ public boolean getAutoPublishFlag() { return getBoolean(ATTR_AUTO_PUBLISH, false); } /** * Enable or disable the auto publish feature. * @param onoff if onoff is true auto publish is enable. */ protected void setAutoPublish(boolean onoff) { setValue(ATTR_AUTO_PUBLISH, new Boolean(onoff)); } /** * Get our auto delete flag. * @return a boolean. */ public boolean getAutoDeleteFlag() { return getBoolean(ATTR_AUTO_DELETE, false); } /** * Enable or disable the auto delete feature. * @param onoff if onoff is true auto publish is enable. */ protected void setAutoDelete(boolean onoff) { setValue(ATTR_AUTO_DELETE, new Boolean(onoff)); } /** * Get the max number of published entries stored in the putlist. * @return an int. */ public int getMaxPublishedEntryStored() { return getInt(ATTR_MAX_PUBLISHED, 10); } /** * Set the max number of published entries stored in the putlist. * @param max This number. */ protected void setMaxPublishedEntryStored(int max) { setValue(ATTR_MAX_PUBLISHED, new Integer(max)); } /** * Known entries. */ private Hashtable entries = null; /** * Known "todelete" entries. */ private Hashtable dentries = null; /** * Published */ private Hashtable published = null; /** * Our server context properties. */ ObservableProperties props = null; /** * Get the modified entries. * @return an enumeration of PutedEntry * @see PutedEntry */ protected Enumeration getEntries() { return entries.elements(); } /** * Get the modified entries keys * @return an enumeration of String */ protected Enumeration getEntriesKeys() { return entries.keys(); } /** * Get the modified entry relative to the given key. * @param key The key relative to the PutedEntry * @return a PutedEntry * @see PutedEntry */ protected PutedEntry getEntry(String key) { return (PutedEntry) entries.get(key); } /** * Add an entry into the putlist * @param e the entry to add */ protected void addEntry(PutedEntry e) { entries.put(e.getKey(), e); } /** * Remove a modified entry from the putlist * @param key the key of the entry to remove */ protected void removeEntry(String key) { entries.remove(key); } /** * Get the deleted entries. * @return an enumeration of DeletedEntry * @see DeletedEntry */ protected Enumeration getDelEntries() { return dentries.elements(); } /** * Get the deleted entries keys * @return an enumeration of String */ protected Enumeration getDelEntriesKeys() { return dentries.keys(); } /** * Get the deleted entry relative to the given key. * @param key The key relative to the DeletedEntry * @return a DeletedEntry * @see DeletedEntry */ protected DeletedEntry getDelEntry(String key) { return (DeletedEntry) dentries.get(key); } /** * Add an entry into the putlist * @param e the entry to add */ protected void addDelEntry(DeletedEntry e) { dentries.put(e.getKey(), e); } /** * Remove a deleted entry from the putlist * @param key the key of the entry to remove */ protected void removeDelEntry(String key) { dentries.remove(key); } //--- /** * Get the published entries. * @return an enumeration of PutedEntry * @see PutedEntry */ protected Enumeration getPublishedEntries() { return published.elements(); } /** * Remove the oldest published entry from the putlist. */ protected void removeOldestPublishedEntry() { //Could be optimized, but it is significant? Enumeration enum = published.elements(); PutedEntry oldest = null; PutedEntry current = null; if (enum.hasMoreElements()) oldest = (PutedEntry) enum.nextElement(); else return; while (enum.hasMoreElements()) { current = (PutedEntry) enum.nextElement(); if (current.getTime() < oldest.getTime()) oldest = current; } published.remove(oldest.getKey()); } /** * Add a published entry into the putlist. * @param e The published entry to add. * @see PutedEntry */ protected synchronized void addPubEntry(PutedEntry e) { while (published.size() >= getMaxPublishedEntryStored()) removeOldestPublishedEntry(); published.put(e.getKey(), e); } /** * Remove a published entry from the putlist * @param key the key of the entry to remove */ protected synchronized void removePubEntry(String key) { published.remove(key); } /** * Compute the path of the public file for the given local file. * This method uses the <em>space</em> and <em>root</em> attributes * to translate the path of the given file from the user's local space * to the public (server) space. * @return A File instance, or <strong>null</strong>. */ protected File getServerFile(File file) { String fpath = file.getAbsolutePath(); String fspace = getCvsSpace().getAbsolutePath(); if ( ! fpath.startsWith(fspace) ) return null; return new File(getRoot(), fpath.substring(fspace.length())); } /** * Get the file to use to store the edited list of files. * @return The file. */ public File getFile() { return (File) getValue(ATTR_FILE, null); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?