1 package ch
.cyberduck
.core
.openstack
;
4 * Copyright (c) 2002-2014 David Kocher. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to:
18 * feedback@cyberduck.io
21 import ch
.cyberduck
.core
.DefaultIOExceptionMappingService
;
22 import ch
.cyberduck
.core
.Path
;
23 import ch
.cyberduck
.core
.PathAttributes
;
24 import ch
.cyberduck
.core
.PathCache
;
25 import ch
.cyberduck
.core
.PathContainerService
;
26 import ch
.cyberduck
.core
.date
.InvalidDateException
;
27 import ch
.cyberduck
.core
.date
.RFC1123DateFormatter
;
28 import ch
.cyberduck
.core
.exception
.BackgroundException
;
29 import ch
.cyberduck
.core
.features
.Attributes
;
30 import ch
.cyberduck
.core
.io
.Checksum
;
32 import org
.apache
.commons
.lang3
.StringUtils
;
33 import org
.apache
.log4j
.Logger
;
35 import java
.io
.IOException
;
37 import ch
.iterate
.openstack
.swift
.Constants
;
38 import ch
.iterate
.openstack
.swift
.exception
.GenericException
;
39 import ch
.iterate
.openstack
.swift
.model
.ContainerInfo
;
40 import ch
.iterate
.openstack
.swift
.model
.ObjectMetadata
;
41 import ch
.iterate
.openstack
.swift
.model
.Region
;
46 public class SwiftAttributesFeature
implements Attributes
{
47 private static final Logger log
= Logger
.getLogger(SwiftAttributesFeature
.class);
49 private SwiftSession session
;
51 private PathContainerService containerService
52 = new SwiftPathContainerService();
54 private RFC1123DateFormatter dateParser
55 = new RFC1123DateFormatter();
57 public SwiftAttributesFeature(SwiftSession session
) {
58 this.session
= session
;
62 public PathAttributes
find(final Path file
) throws BackgroundException
{
63 final Region region
= new SwiftRegionService(session
).lookup(file
);
65 if(containerService
.isContainer(file
)) {
66 final ContainerInfo info
= session
.getClient().getContainerInfo(region
,
67 containerService
.getContainer(file
).getName());
68 final PathAttributes attributes
= new PathAttributes();
69 attributes
.setSize(info
.getTotalSize());
70 attributes
.setRegion(info
.getRegion().getRegionId());
74 final PathAttributes attributes
= new PathAttributes();
76 final ObjectMetadata metadata
= session
.getClient().getObjectMetaData(region
,
77 containerService
.getContainer(file
).getName(), containerService
.getKey(file
));
78 attributes
.setSize(Long
.valueOf(metadata
.getContentLength()));
80 attributes
.setModificationDate(dateParser
.parse(metadata
.getLastModified()).getTime());
82 catch(InvalidDateException e
) {
83 log
.warn(String
.format("%s is not RFC 1123 format %s", metadata
.getLastModified(), e
.getMessage()));
85 if(StringUtils
.isNotBlank(metadata
.getETag())) {
86 final String etag
= StringUtils
.removePattern(metadata
.getETag(), "\"");
87 attributes
.setETag(etag
);
88 if(metadata
.getMetaData().containsKey(Constants
.X_STATIC_LARGE_OBJECT
)) {
89 // For manifest files, the ETag in the response for a GET or HEAD on the manifest file is the MD5 sum of
90 // the concatenated string of ETags for each of the segments in the manifest.
91 attributes
.setChecksum(null);
94 attributes
.setChecksum(Checksum
.parse(etag
));
99 if(log
.isDebugEnabled()) {
100 log
.debug(String
.format("Return blank attributes for directory delimiter %s", file
));
105 if(log
.isDebugEnabled()) {
106 log
.debug(String
.format("Return blank attributes for directory delimiter %s", file
));
108 return new PathAttributes();
110 catch(GenericException e
) {
111 throw new SwiftExceptionMappingService().map("Failure to read attributes of {0}", e
, file
);
113 catch(IOException e
) {
114 throw new DefaultIOExceptionMappingService().map("Failure to read attributes of {0}", e
, file
);
119 public Attributes
withCache(final PathCache cache
) {