View | Details | Raw Unified | Return to bug 44611
Collapse All | Expand All

(-)/home/hubick/data/eclipse-workspace/tomcat-trunk/java/org/apache/naming/resources/DirContextURLConnection.java (-4 / +55 lines)
Lines 23-30 Link Here
23
import java.io.InputStream;
23
import java.io.InputStream;
24
import java.io.FileNotFoundException;
24
import java.io.FileNotFoundException;
25
import java.security.Permission;
25
import java.security.Permission;
26
import java.util.ArrayList;
27
import java.util.Collections;
26
import java.util.Date;
28
import java.util.Date;
27
import java.util.Enumeration;
29
import java.util.Enumeration;
30
import java.util.HashMap;
31
import java.util.Map;
28
import java.util.Vector;
32
import java.util.Vector;
29
import javax.naming.NamingException;
33
import javax.naming.NamingException;
30
import javax.naming.NamingEnumeration;
34
import javax.naming.NamingEnumeration;
Lines 217-222 Link Here
217
        return 0;
221
        return 0;
218
    }
222
    }
219
    
223
    
224
225
    /**
226
     * Returns an unmodifiable Map of the header fields.
227
     */
228
    public Map getHeaderFields() {
229
230
      if (!connected) {
231
          // Try to connect (silently)
232
          try {
233
              connect();
234
          } catch (IOException e) {
235
          }
236
      }
237
238
      if (attributes == null)
239
          return (Collections.EMPTY_MAP);
240
241
      HashMap headerFields = new HashMap(attributes.size());
242
      NamingEnumeration attributeEnum = attributes.getIDs();
243
      try {
244
          while (attributeEnum.hasMore()) {
245
              String attributeID = (String)attributeEnum.next();
246
              Attribute attribute = attributes.get(attributeID);
247
              if (attribute == null) continue;
248
              ArrayList attributeValueList = new ArrayList(attribute.size());
249
              NamingEnumeration attributeValues = attribute.getAll();
250
              while (attributeValues.hasMore()) {
251
                  attributeValueList.add(attributeValues.next().toString());
252
              }
253
              attributeValueList.trimToSize(); // should be a no-op if attribute.size() didn't lie
254
              headerFields.put(attributeID, Collections.unmodifiableList(attributeValueList));
255
          }
256
      } catch (NamingException ne) {
257
            // Shouldn't happen
258
      }
259
260
      return Collections.unmodifiableMap(headerFields);
261
262
    }
263
    
220
    
264
    
221
    /**
265
    /**
222
     * Returns the name of the specified header field.
266
     * Returns the name of the specified header field.
Lines 234-244 Link Here
234
        if (attributes == null)
278
        if (attributes == null)
235
            return (null);
279
            return (null);
236
280
237
        Attribute attribute = attributes.get(name);
281
        NamingEnumeration attributeEnum = attributes.getIDs();
238
        try {
282
        try {
239
            return attribute.get().toString();
283
            while (attributeEnum.hasMore()) {
240
        } catch (Exception e) {
284
                String attributeID = (String)attributeEnum.next();
241
            // Shouldn't happen, unless the attribute has no value
285
                if (attributeID.equalsIgnoreCase(name)) {
286
                    Attribute attribute = attributes.get(attributeID);
287
                    if (attribute == null) return null;
288
                    return attribute.get(attribute.size()-1).toString();
289
                }
290
            }
291
        } catch (NamingException ne) {
292
            // Shouldn't happen
242
        }
293
        }
243
294
244
        return (null);
295
        return (null);
(-)/home/hubick/data/eclipse-workspace/tomcat-trunk/java/org/apache/naming/resources/ResourceAttributes.java (-31 / +88 lines)
Lines 263-269 Link Here
263
     */
263
     */
264
    public boolean isCollection() {
264
    public boolean isCollection() {
265
        if (attributes != null) {
265
        if (attributes != null) {
266
            return (getResourceType().equals(COLLECTION_TYPE));
266
            return (COLLECTION_TYPE.equals(getResourceType()));
267
        } else {
267
        } else {
268
            return (collection);
268
            return (collection);
269
        }
269
        }
Lines 683-689 Link Here
683
            if (collection)
683
            if (collection)
684
                result = COLLECTION_TYPE;
684
                result = COLLECTION_TYPE;
685
            else
685
            else
686
                result = "";
686
                result = null;
687
        }
687
        }
688
        return result;
688
        return result;
689
    }
689
    }
Lines 775-802 Link Here
775
    public Attribute get(String attrID) {
775
    public Attribute get(String attrID) {
776
        if (attributes == null) {
776
        if (attributes == null) {
777
            if (attrID.equals(CREATION_DATE)) {
777
            if (attrID.equals(CREATION_DATE)) {
778
                return new BasicAttribute(CREATION_DATE, getCreationDate());
778
                Date creationDate = getCreationDate();
779
                if (creationDate == null) return null;
780
                return new BasicAttribute(CREATION_DATE, creationDate);
779
            } else if (attrID.equals(ALTERNATE_CREATION_DATE)) {
781
            } else if (attrID.equals(ALTERNATE_CREATION_DATE)) {
780
                return new BasicAttribute(ALTERNATE_CREATION_DATE, 
782
                Date creationDate = getCreationDate();
781
                                          getCreationDate());
783
                if (creationDate == null) return null;
784
                return new BasicAttribute(ALTERNATE_CREATION_DATE, creationDate);
782
            } else if (attrID.equals(LAST_MODIFIED)) {
785
            } else if (attrID.equals(LAST_MODIFIED)) {
783
                return new BasicAttribute(LAST_MODIFIED, 
786
                Date lastModifiedDate = getLastModifiedDate();
784
                                          getLastModifiedDate());
787
                if (lastModifiedDate == null) return null;
788
                return new BasicAttribute(LAST_MODIFIED, lastModifiedDate);
785
            } else if (attrID.equals(ALTERNATE_LAST_MODIFIED)) {
789
            } else if (attrID.equals(ALTERNATE_LAST_MODIFIED)) {
786
                return new BasicAttribute(ALTERNATE_LAST_MODIFIED,
790
                Date lastModifiedDate = getLastModifiedDate();
787
                                          getLastModifiedDate());
791
                if (lastModifiedDate == null) return null;
792
                return new BasicAttribute(ALTERNATE_LAST_MODIFIED, lastModifiedDate);
788
            } else if (attrID.equals(NAME)) {
793
            } else if (attrID.equals(NAME)) {
789
                return new BasicAttribute(NAME, getName());
794
                String name = getName();
795
                if (name == null) return null;
796
                return new BasicAttribute(NAME, name);
790
            } else if (attrID.equals(TYPE)) {
797
            } else if (attrID.equals(TYPE)) {
791
                return new BasicAttribute(TYPE, getResourceType());
798
                String resourceType = getResourceType();
799
                if (resourceType == null) return null;
800
                return new BasicAttribute(TYPE, resourceType);
792
            } else if (attrID.equals(ALTERNATE_TYPE)) {
801
            } else if (attrID.equals(ALTERNATE_TYPE)) {
793
                return new BasicAttribute(ALTERNATE_TYPE, getResourceType());
802
                String resourceType = getResourceType();
803
                if (resourceType == null) return null;
804
                return new BasicAttribute(ALTERNATE_TYPE, resourceType);
794
            } else if (attrID.equals(CONTENT_LENGTH)) {
805
            } else if (attrID.equals(CONTENT_LENGTH)) {
795
                return new BasicAttribute(CONTENT_LENGTH, 
806
                long contentLength = getContentLength();
796
                                          new Long(getContentLength()));
807
                if (contentLength < 0) return null;
808
                return new BasicAttribute(CONTENT_LENGTH, new Long(contentLength));
797
            } else if (attrID.equals(ALTERNATE_CONTENT_LENGTH)) {
809
            } else if (attrID.equals(ALTERNATE_CONTENT_LENGTH)) {
798
                return new BasicAttribute(ALTERNATE_CONTENT_LENGTH, 
810
              long contentLength = getContentLength();
799
                                          new Long(getContentLength()));
811
              if (contentLength < 0) return null;
812
              return new BasicAttribute(ALTERNATE_CONTENT_LENGTH, new Long(contentLength));
800
            }
813
            }
801
        } else {
814
        } else {
802
            return attributes.get(attrID);
815
            return attributes.get(attrID);
Lines 851-865 Link Here
851
    public NamingEnumeration getAll() {
864
    public NamingEnumeration getAll() {
852
        if (attributes == null) {
865
        if (attributes == null) {
853
            Vector attributes = new Vector();
866
            Vector attributes = new Vector();
854
            attributes.addElement(new BasicAttribute
867
            Date creationDate = getCreationDate();
855
                                  (CREATION_DATE, getCreationDate()));
868
            if (creationDate != null) {
856
            attributes.addElement(new BasicAttribute
869
                attributes.addElement(new BasicAttribute
857
                                  (LAST_MODIFIED, getLastModifiedDate()));
870
                                      (CREATION_DATE, creationDate));
858
            attributes.addElement(new BasicAttribute(NAME, getName()));
871
                attributes.addElement(new BasicAttribute
859
            attributes.addElement(new BasicAttribute(TYPE, getResourceType()));
872
                                      (ALTERNATE_CREATION_DATE, creationDate));
860
            attributes.addElement
873
            }
861
                (new BasicAttribute(CONTENT_LENGTH, 
874
            Date lastModifiedDate = getLastModifiedDate();
862
                                    new Long(getContentLength())));
875
            if (lastModifiedDate != null) {
876
                attributes.addElement(new BasicAttribute
877
                                      (LAST_MODIFIED, lastModifiedDate));
878
                attributes.addElement(new BasicAttribute
879
                                      (ALTERNATE_LAST_MODIFIED, lastModifiedDate));
880
            }
881
            String name = getName();
882
            if (name != null) {
883
                attributes.addElement(new BasicAttribute(NAME, name));
884
            }
885
            String resourceType = getResourceType();
886
            if (resourceType != null) {
887
                attributes.addElement(new BasicAttribute(TYPE, resourceType));
888
                attributes.addElement(new BasicAttribute(ALTERNATE_TYPE, resourceType));
889
            }
890
            long contentLength = getContentLength();
891
            if (contentLength >= 0) {
892
                Long contentLengthLong = new Long(contentLength);
893
                attributes.addElement(new BasicAttribute(CONTENT_LENGTH, contentLengthLong));
894
                attributes.addElement(new BasicAttribute(ALTERNATE_CONTENT_LENGTH, contentLengthLong));
895
            }
863
            return new RecyclableNamingEnumeration(attributes);
896
            return new RecyclableNamingEnumeration(attributes);
864
        } else {
897
        } else {
865
            return attributes.getAll();
898
            return attributes.getAll();
Lines 873-883 Link Here
873
    public NamingEnumeration getIDs() {
906
    public NamingEnumeration getIDs() {
874
        if (attributes == null) {
907
        if (attributes == null) {
875
            Vector attributeIDs = new Vector();
908
            Vector attributeIDs = new Vector();
876
            attributeIDs.addElement(CREATION_DATE);
909
            Date creationDate = getCreationDate();
877
            attributeIDs.addElement(LAST_MODIFIED);
910
            if (creationDate != null) {
878
            attributeIDs.addElement(NAME);
911
                attributeIDs.addElement(CREATION_DATE);
879
            attributeIDs.addElement(TYPE);
912
                attributeIDs.addElement(ALTERNATE_CREATION_DATE);
880
            attributeIDs.addElement(CONTENT_LENGTH);
913
            }
914
            Date lastModifiedDate = getLastModifiedDate();
915
            if (lastModifiedDate != null) {
916
                attributeIDs.addElement(LAST_MODIFIED);
917
                attributeIDs.addElement(ALTERNATE_LAST_MODIFIED);
918
            }
919
            if (getName() != null) {
920
                attributeIDs.addElement(NAME);
921
            }
922
            String resourceType = getResourceType();
923
            if (resourceType != null) {
924
                attributeIDs.addElement(TYPE);
925
                attributeIDs.addElement(ALTERNATE_TYPE);
926
            }
927
            long contentLength = getContentLength();
928
            if (contentLength >= 0) {
929
                attributeIDs.addElement(CONTENT_LENGTH);
930
                attributeIDs.addElement(ALTERNATE_CONTENT_LENGTH);
931
            }
881
            return new RecyclableNamingEnumeration(attributeIDs);
932
            return new RecyclableNamingEnumeration(attributeIDs);
882
        } else {
933
        } else {
883
            return attributes.getIDs();
934
            return attributes.getIDs();
Lines 890-896 Link Here
890
     */
941
     */
891
    public int size() {
942
    public int size() {
892
        if (attributes == null) {
943
        if (attributes == null) {
893
            return 5;
944
            int size = 0;
945
            if (getCreationDate() != null) size += 2;
946
            if (getLastModifiedDate() != null) size += 2;
947
            if (getName() != null) size++;
948
            if (getResourceType() != null) size += 2;
949
            if (getContentLength() >= 0) size += 2;
950
            return size;
894
        } else {
951
        } else {
895
            return attributes.size();
952
            return attributes.size();
896
        }
953
        }

Return to bug 44611