/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xindice.webadmin.webdav.components.props;
import org.apache.xindice.core.Collection;
import org.apache.xindice.core.DBException;
import org.apache.xindice.core.data.Entry;
import org.apache.xindice.core.meta.MetaData;
import org.apache.xindice.webadmin.PartialResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.text.SimpleDateFormat;
/**
* CreationDate creates a response node that contains the time when resource
* was created in the format "yyyy-MM-dd'T'HH:mm:ss'Z'" if creation time is
* available.<br/><br/>
* See {@link java.text.SimpleDateFormat} for date format information.<br>
* <br>
* Example:
* <pre>
* <creationdate>
* 2007-05-09T09:22:00Z
* </creationdate>
* </pre>
*
* @version $Revision: 541515 $, $Date: 2007-05-24 22:45:06 -0400 (Thu, 24 May 2007) $
*/
public class CreationDate implements DAVProperty {
private static final String CREATION_TIME = "creationdate";
private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private static final Log log = LogFactory.getLog(CreationDate.class);
public String getName() {
return CREATION_TIME;
}
public PartialResponse.Content getRootProperty() {
return null;
}
public PartialResponse.Content getProperty(Collection col) {
try {
MetaData meta = col.getCollectionMeta();
long date = meta.getCreatedTime();
if (date != 0) {
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
return new PartialResponse.Content(CREATION_TIME, sdf.format(new Date(date)));
}
} catch (DBException e) {
log.error("Getting creation time for collection " + col.getCanonicalName() + " failed", e);
return null;
}
return null;
}
public PartialResponse.Content getProperty(Entry entry) {
long date = entry.getCreationTime();
if (date != 0) {
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
return new PartialResponse.Content(CREATION_TIME, sdf.format(new Date(date)));
} else {
// creation time is not available
return null;
}
}
}