001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.resource;
014:
015: import java.util.Collection;
016: import java.util.Set;
017:
018: import org.apache.commons.logging.Log;
019: import org.apache.commons.logging.LogFactory;
020: import org.wings.RequestURL;
021: import org.wings.Resource;
022: import org.wings.SFrame;
023: import org.wings.SimpleURL;
024: import org.wings.externalizer.ExternalizeManager;
025: import org.wings.session.PropertyService;
026: import org.wings.session.SessionManager;
027:
028: /**
029: * Dynamic Resources are web resources representing rendered components
030: * and are individually loaded by Browsers as different 'files'.
031: * Dynamic Resources include therefore frames, cascading stylesheets or
032: * script files. The externalizer gives them a uniqe name.
033: * The resources may change in the consequence of some internal change of
034: * the components. This invalidation process yields a new 'version', called
035: * epoch here. The epoch is part of the externalized name.
036: */
037: public abstract class DynamicResource extends Resource {
038: private final transient static Log log = LogFactory
039: .getLog(DynamicResource.class);
040:
041: /**
042: * The frame, to which this resource belongs.
043: */
044: private SFrame frame;
045:
046: private PropertyService propertyService;
047:
048: protected DynamicResource(String extension, String mimeType) {
049: super (extension, mimeType);
050: }
051:
052: public DynamicResource(SFrame frame) {
053: this (frame, "", "");
054: }
055:
056: public DynamicResource(SFrame frame, String extension,
057: String mimeType) {
058: super (extension, mimeType);
059: this .frame = frame;
060: }
061:
062: /**
063: * Return the frame, to which this resource belongs.
064: */
065: public final SFrame getFrame() {
066: return frame;
067: }
068:
069: public String getId() {
070: if (id == null) {
071: ExternalizeManager ext = SessionManager.getSession()
072: .getExternalizeManager();
073: id = ext.getId(ext.externalize(this ));
074: log.debug("new " + getClass().getName() + " with id " + id);
075: }
076: return id;
077: }
078:
079: public SimpleURL getURL() {
080: RequestURL requestURL = (RequestURL) SessionManager
081: .getSession().getProperty("request.url");
082: if (requestURL != null) {
083: requestURL = (RequestURL) requestURL.clone();
084: requestURL.setResource(getId());
085: }
086: return requestURL;
087: }
088:
089: public String toString() {
090: return getId() + " " + getFrame().getEventEpoch();
091: }
092:
093: /**
094: * Get additional http-headers.
095: * Returns <tt>null</tt>, if there are no additional headers to be set.
096: *
097: * @return Set of {@link java.util.Map.Entry} (key-value pairs)
098: */
099: public Collection<HttpHeader> getHeaders() {
100: return null;
101: }
102: }
|