2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package gr.ebs.gss.server.webdav;
19 import java.util.Date;
20 import java.util.Enumeration;
21 import java.util.Vector;
24 * Holds a lock information.
29 // -------------------------------------------------------- Constructor
40 // ------------------------------------------------- Instance Variables
50 String type = "write";
54 String scope = "exclusive";
66 Vector<String> tokens = new Vector<String>();
74 Date creationDate = new Date();
77 // ----------------------------------------------------- Public Methods
81 * Get a String representation of this lock token.
84 public String toString() {
86 String result = "Type:" + type + "\n";
87 result += "Scope:" + scope + "\n";
88 result += "Depth:" + depth + "\n";
89 result += "Owner:" + owner + "\n";
90 result += "Expiration:"
91 + FastHttpDateFormat.formatDate(expiresAt, null) + "\n";
92 Enumeration tokensList = tokens.elements();
93 while (tokensList.hasMoreElements())
94 result += "Token:" + tokensList.nextElement() + "\n";
101 * Return true if the lock has expired.
102 * @return true if the lock has expired.
104 public boolean hasExpired() {
105 return System.currentTimeMillis() > expiresAt;
110 * Return true if the lock is exclusive.
111 * @return true if the lock is exclusive.
113 public boolean isExclusive() {
115 return scope.equals("exclusive");
121 * Get an XML representation of this lock token. This method will
122 * append an XML fragment to the given XML writer.
123 * @param generatedXML the generated XML writer
125 public void toXML(XMLWriter generatedXML) {
127 generatedXML.writeElement(null, "activelock", XMLWriter.OPENING);
129 generatedXML.writeElement(null, "locktype", XMLWriter.OPENING);
130 generatedXML.writeElement(null, type, XMLWriter.NO_CONTENT);
131 generatedXML.writeElement(null, "locktype", XMLWriter.CLOSING);
133 generatedXML.writeElement(null, "lockscope", XMLWriter.OPENING);
134 generatedXML.writeElement(null, scope, XMLWriter.NO_CONTENT);
135 generatedXML.writeElement(null, "lockscope", XMLWriter.CLOSING);
137 generatedXML.writeElement(null, "depth", XMLWriter.OPENING);
138 if (depth == Webdav.INFINITY)
139 generatedXML.writeText("Infinity");
141 generatedXML.writeText("0");
142 generatedXML.writeElement(null, "depth", XMLWriter.CLOSING);
144 generatedXML.writeElement(null, "owner", XMLWriter.OPENING);
145 generatedXML.writeText(owner);
146 generatedXML.writeElement(null, "owner", XMLWriter.CLOSING);
148 generatedXML.writeElement(null, "timeout", XMLWriter.OPENING);
149 long timeout = (expiresAt - System.currentTimeMillis()) / 1000;
150 generatedXML.writeText("Second-" + timeout);
151 generatedXML.writeElement(null, "timeout", XMLWriter.CLOSING);
153 generatedXML.writeElement(null, "locktoken", XMLWriter.OPENING);
154 Enumeration tokensList = tokens.elements();
155 while (tokensList.hasMoreElements()) {
156 generatedXML.writeElement(null, "href", XMLWriter.OPENING);
157 generatedXML.writeText("opaquelocktoken:"
158 + tokensList.nextElement());
159 generatedXML.writeElement(null, "href", XMLWriter.CLOSING);
161 generatedXML.writeElement(null, "locktoken", XMLWriter.CLOSING);
163 generatedXML.writeElement(null, "activelock", XMLWriter.CLOSING);