001: // PutedEntry.java
002: // $Id: PutedEntry.java,v 1.7 2000/08/17 10:15:11 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1997.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigedit.filters;
007:
008: import java.io.File;
009:
010: import org.w3c.jigsaw.auth.AuthFilter;
011:
012: import org.w3c.tools.resources.Attribute;
013: import org.w3c.tools.resources.AttributeHolder;
014: import org.w3c.tools.resources.AttributeRegistry;
015: import org.w3c.tools.resources.FileResource;
016: import org.w3c.tools.resources.InvalidResourceException;
017: import org.w3c.tools.resources.LongAttribute;
018: import org.w3c.tools.resources.Resource;
019: import org.w3c.tools.resources.ResourceReference;
020: import org.w3c.tools.resources.StringAttribute;
021:
022: import org.w3c.tools.sorter.Comparable;
023:
024: import org.w3c.jigsaw.http.Request;
025:
026: import org.w3c.www.http.HttpMessage;
027: import org.w3c.www.http.HttpRequestMessage;
028:
029: /**
030: * We want free pickling, hence the super class.
031: */
032:
033: public class PutedEntry extends AttributeHolder implements Comparable {
034: protected static int ATTR_AUTHOR = -1;
035: protected static int ATTR_URL = -1;
036: protected static int ATTR_FILENAME = -1;
037: protected static int ATTR_TIME = -1;
038:
039: static {
040: Class c = null;
041: Attribute a = null;
042:
043: try {
044: c = Class.forName("org.w3c.jigedit.filters.PutedEntry");
045: } catch (Exception ex) {
046: ex.printStackTrace();
047: System.exit(1);
048: }
049: // The author of change:
050: a = new StringAttribute("author", null, Attribute.EDITABLE);
051: ATTR_AUTHOR = AttributeRegistry.registerAttribute(c, a);
052: // The mandatory url:
053: a = new StringAttribute("url", null, Attribute.EDITABLE);
054: ATTR_URL = AttributeRegistry.registerAttribute(c, a);
055: // The optional absolute file name:
056: a = new StringAttribute("filename", null, Attribute.EDITABLE);
057: ATTR_FILENAME = AttributeRegistry.registerAttribute(c, a);
058: // The time of modification:
059: a = new LongAttribute("time", null, Attribute.EDITABLE);
060: ATTR_TIME = AttributeRegistry.registerAttribute(c, a);
061: }
062:
063: final String getAuthor() {
064: return getString(ATTR_AUTHOR, null);
065: }
066:
067: final String getURL() {
068: return getString(ATTR_URL, null);
069: }
070:
071: final String getFilename() {
072: return getString(ATTR_FILENAME, null);
073: }
074:
075: final long getTime() {
076: return getLong(ATTR_TIME, -1);
077: }
078:
079: public String getStringValue() {
080: return Long.toString(getTime());
081: }
082:
083: public boolean greaterThan(Comparable comp) {
084: return (getStringValue().compareTo(comp.getStringValue()) > 0);
085: }
086:
087: protected String getKey() {
088: String key = getFilename();
089: if (key == null)
090: return getURL();
091: return key;
092: }
093:
094: synchronized void update(Request request) {
095: String author = (String) request
096: .getState(AuthFilter.STATE_AUTHUSER);
097: if (author == null) {
098: author = "unknown";
099: }
100: long time = System.currentTimeMillis();
101: setValue(ATTR_AUTHOR, author);
102: setValue(ATTR_TIME, new Long(time));
103: }
104:
105: static PutedEntry makeEntry(Request request) {
106: ResourceReference rr = request.getTargetResource();
107: Resource r = null;
108: if (rr != null) {
109: try {
110: r = rr.lock();
111: // Build an entry:
112: PutedEntry e = new PutedEntry();
113: e.setValue(ATTR_URL, request.getURL().toExternalForm());
114: if (r instanceof FileResource)
115: e.setValue(ATTR_FILENAME, ((FileResource) r)
116: .getFile().getAbsolutePath());
117: // Update other infos:
118: e.update(request);
119: return e;
120: } catch (InvalidResourceException ex) {
121: return null;
122: } finally {
123: rr.unlock();
124: }
125: }
126: return null;
127: }
128:
129: }
|