001/* 002 * Copyright 2011 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.ametys.plugins.explorer.resources.dom; 018 019import java.time.ZoneId; 020import java.util.Date; 021import java.util.Map; 022 023import org.w3c.dom.Element; 024 025import org.ametys.core.util.dom.AmetysAttribute; 026import org.ametys.plugins.explorer.resources.Resource; 027import org.ametys.runtime.parameter.ParameterHelper; 028 029/** 030 * DOM {@link Element} wrapping a {@link Resource}. 031 */ 032public class ResourceElement extends AbstractResourceElement<Resource> 033{ 034 /** 035 * Constructor. 036 * @param resource the wrapped resource. 037 * @param parent the parent collection. 038 */ 039 public ResourceElement(Resource resource, ResourceCollectionElement parent) 040 { 041 super(resource, parent); 042 } 043 044 @Override 045 public String getTagName() 046 { 047 return "resource"; 048 } 049 050 @Override 051 protected Map<String, AmetysAttribute> _lookupAttributes() 052 { 053 Map<String, AmetysAttribute> atts = super._lookupAttributes(); 054 atts.put("name", new AmetysAttribute("name", "name", null, _object.getName(), this)); 055 atts.put("id", new AmetysAttribute("id", "id", null, _object.getId(), this)); 056 atts.put("length", new AmetysAttribute("length", "length", null, String.valueOf(_object.getLength()), this)); 057 058 Date lastModified = _object.getLastModified(); 059 if (lastModified != null) 060 { 061 String lastModifiedStr = ParameterHelper.getISODateTimeFormatter().format(lastModified.toInstant().atZone(ZoneId.systemDefault())); 062 063 atts.put("last-modified", new AmetysAttribute("last-modified", "last-modified", null, lastModifiedStr, this)); 064 } 065 066 return atts; 067 } 068}