Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 94   Methods: 4
NCLOC: 51   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LastModified.java 50% 70% 75% 66.7%
coverage coverage
 1    /*
 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
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 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.
 16    */
 17   
 18    package org.apache.xindice.webadmin.webdav.components.props;
 19   
 20    import org.apache.xindice.core.Collection;
 21    import org.apache.xindice.core.DBException;
 22    import org.apache.xindice.core.data.Entry;
 23    import org.apache.xindice.core.meta.MetaData;
 24    import org.apache.xindice.webadmin.PartialResponse;
 25    import org.apache.commons.logging.Log;
 26    import org.apache.commons.logging.LogFactory;
 27   
 28    import java.text.SimpleDateFormat;
 29    import java.util.Locale;
 30    import java.util.Date;
 31    import java.util.TimeZone;
 32   
 33    /**
 34    * LastModified creates a response node that contains the time when resource
 35    * was last modified in the format "EEE, dd MMM yyyy HH:mm:ss zzz" if last
 36    * modification time is available.<br/><br/>
 37    * See {@link java.text.SimpleDateFormat} for date format information.<br>
 38    * <br>
 39    * Example:
 40    * <pre>
 41    * &lt;getlastmodified&gt;
 42    * Wednesday, 9 May 2007 09:22:00 GMT
 43    * &lt;/getlastmodified&gt;
 44    * </pre>
 45    *
 46    * @version $Revision: 541515 $, $Date: 2007-05-24 19:45:06 -0700 (Thu, 24 May 2007) $
 47    */
 48    public class LastModified implements DAVProperty {
 49    private static final String MODIFICATION_TIME = "getlastmodified";
 50    private static final String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
 51    private static final Log log = LogFactory.getLog(LastModified.class);
 52   
 53  2 public String getName() {
 54  2 return MODIFICATION_TIME;
 55    }
 56   
 57  0 public PartialResponse.Content getRootProperty() {
 58  0 return null;
 59    }
 60   
 61  8 public PartialResponse.Content getProperty(Collection col) {
 62  8 try {
 63  8 MetaData meta = col.getCollectionMeta();
 64  8 if (meta == null) {
 65  0 return null;
 66    }
 67   
 68  8 long date = meta.getLastModifiedTime();
 69  8 if (date != 0) {
 70  8 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
 71  8 sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
 72  8 return new PartialResponse.Content(MODIFICATION_TIME, sdf.format(new Date(date)));
 73    }
 74   
 75    } catch (DBException e) {
 76  0 log.error("Getting last modified time for collection " + col.getCanonicalName() + " failed", e);
 77  0 return null;
 78    }
 79   
 80  0 return null;
 81    }
 82   
 83  5 public PartialResponse.Content getProperty(Entry entry) {
 84  5 long date = entry.getModificationTime();
 85  5 if (date != 0) {
 86  5 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
 87  5 sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
 88  5 return new PartialResponse.Content(MODIFICATION_TIME, sdf.format(new Date(date)));
 89    } else {
 90  0 return null;
 91    }
 92    }
 93   
 94    }