Package org.apache.xindice.webadmin.webdav.components.props

Source Code of org.apache.xindice.webadmin.webdav.components.props.LastModified

/*
* 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.text.SimpleDateFormat;
import java.util.Locale;
import java.util.Date;
import java.util.TimeZone;

/**
* LastModified creates a response node that contains the time when resource
* was last modified in the format "EEE, dd MMM yyyy HH:mm:ss zzz" if last
* modification time is available.<br/><br/>
* See {@link java.text.SimpleDateFormat} for date format information.<br>
* <br>
* Example:
* <pre>
* &lt;getlastmodified&gt;
*     Wednesday, 9 May 2007 09:22:00 GMT
* &lt;/getlastmodified&gt;
* </pre>
*
* @version $Revision: 541515 $, $Date: 2007-05-24 22:45:06 -0400 (Thu, 24 May 2007) $
*/
public class LastModified implements DAVProperty {
    private static final String MODIFICATION_TIME = "getlastmodified";
    private static final String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
    private static final Log log = LogFactory.getLog(LastModified.class);

    public String getName() {
        return MODIFICATION_TIME;
    }

    public PartialResponse.Content getRootProperty() {
        return null;
    }

    public PartialResponse.Content getProperty(Collection col) {
        try {
            MetaData meta = col.getCollectionMeta();
            if (meta == null) {
                return null;
            }

            long date = meta.getLastModifiedTime();
            if (date != 0) {
                SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
                sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
                return new PartialResponse.Content(MODIFICATION_TIME, sdf.format(new Date(date)));
            }

        } catch (DBException e) {
            log.error("Getting last modified time for collection " + col.getCanonicalName() + " failed", e);
            return null;
        }

        return null;
    }

    public PartialResponse.Content getProperty(Entry entry) {
        long date = entry.getModificationTime();
        if (date != 0) {
            SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
            sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
            return new PartialResponse.Content(MODIFICATION_TIME, sdf.format(new Date(date)));
        } else {
            return null;
        }
    }

}
TOP

Related Classes of org.apache.xindice.webadmin.webdav.components.props.LastModified

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.