cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r563008 - /cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java
Date Mon, 06 Aug 2007 02:40:01 GMT
Author: vgritsenko
Date: Sun Aug  5 19:40:00 2007
New Revision: 563008

URL: http://svn.apache.org/viewvc?view=rev&rev=563008
Log:
kill tabs

Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java?view=diff&rev=563008&r1=563007&r2=563008
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java
Sun Aug  5 19:40:00 2007
@@ -36,50 +36,51 @@
 
 /**
  * Implementation of a {@link Source} that gets its content by invoking the Servlet.
- * 
+ *
  * @version $Id$
  */
 public class ServletSource extends AbstractSource implements PostableSource {
 
-	private transient Log logger = LogFactory.getLog(getClass());
+    private transient Log logger = LogFactory.getLog(getClass());
 
-	private ServletConnection servletConnection;
-	private String location;
-	
-	/**
-	 * The store is used to store values of Last-Modified header (if it exists). This store
is required because in
-	 * {@link #getValidity()} we need value of Last-Modified header of previous response in
order to perform conditional
-	 * GET.
-	 * 
-	 * @see Broken caching of servlet: source in some cases thread
-	 *      (http://news.gmane.org/find-root.php?group=gmane.text.xml.cocoon.devel&article=72801)
-	 */
-	private Store store;
-
-	private boolean connected;
-
-	public ServletSource(String location, Store store) throws IOException {
-		// the systemId (returned by getURI()) is by default null
-		// using the block uri is a little bit questionable as it only is valid
-		// whithin the current block, not globally
-		this.store = store;
-		setSystemId(location);
-		this.location = location;
-		this.servletConnection = new ServletConnection(location);
-		connected = false;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.excalibur.source.impl.AbstractSource#getInputStream()
-	 */
-	public InputStream getInputStream() throws IOException, SourceException {
-		try {
-			connect();
-			// FIXME: This is not the most elegant solution
+    private ServletConnection servletConnection;
+    private String location;
+
+    /**
+     * The store is used to store values of Last-Modified header (if it exists).
+     * This store is required because in {@link #getValidity()} we need value
+     * of Last-Modified header of previous response in order to perform conditional
+     * GET.
+     *
+     * @see Broken caching of servlet: source in some cases thread
+     *      (http://news.gmane.org/find-root.php?group=gmane.text.xml.cocoon.devel&article=72801)
+     */
+    private Store store;
+
+    private boolean connected;
+
+    public ServletSource(String location, Store store) throws IOException {
+        // the systemId (returned by getURI()) is by default null
+        // using the block uri is a little bit questionable as it only is valid
+        // whithin the current block, not globally
+        this.store = store;
+        setSystemId(location);
+        this.location = location;
+        this.servletConnection = new ServletConnection(location);
+        connected = false;
+    }
+
+    /*
+      * (non-Javadoc)
+      *
+      * @see org.apache.excalibur.source.impl.AbstractSource#getInputStream()
+      */
+    public InputStream getInputStream() throws IOException, SourceException {
+        try {
+            connect();
+            // FIXME: This is not the most elegant solution
             if (servletConnection.getResponseCode() != HttpServletResponse.SC_OK) {
-				//most probably, servlet returned 304 (not modified) and we need to perform second request
to get data
+                //most probably, servlet returned 304 (not modified) and we need to perform
second request to get data
 
                 //
                 // FIXME This does not work: previous instance of servletConnection
@@ -89,170 +90,173 @@
                 //
 
                 servletConnection = new ServletConnection(location);
-				servletConnection.connect();
-			}
-			return this.servletConnection.getInputStream();
-		} catch (ServletException e) {
-			throw new CascadingIOException(e.getMessage(), e);
-		}
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.excalibur.source.impl.AbstractSource#getValidity()
-	 */
-	public SourceValidity getValidity() {
-		try {
-			connect();
-			return servletConnection.getLastModified() > 0 ? new ServletValidity(servletConnection.getResponseCode())
: null;
-		} catch (Exception e) {
-			if (logger.isDebugEnabled())
-				logger.debug("Exception occured while making servlet request", e);
-			return null;
-		}
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.excalibur.source.impl.AbstractSource#getLastModified()
-	 */
-	public long getLastModified() {
-		try {
-			connect();
-			return servletConnection.getLastModified() > 0 ? servletConnection.getLastModified()
: 0;
-		} catch (Exception e) {
-			if (logger.isDebugEnabled())
-				logger.debug("Exception occured while making servlet request", e);
-			return 0;
-		}
-	}
-	
+                servletConnection.connect();
+            }
+            return this.servletConnection.getInputStream();
+        } catch (ServletException e) {
+            throw new CascadingIOException(e.getMessage(), e);
+        }
+    }
+
+    /*
+      * (non-Javadoc)
+      *
+      * @see org.apache.excalibur.source.impl.AbstractSource#getValidity()
+      */
+    public SourceValidity getValidity() {
+        try {
+            connect();
+            return servletConnection.getLastModified() > 0 ? new ServletValidity(servletConnection.getResponseCode())
: null;
+        } catch (Exception e) {
+            if (logger.isDebugEnabled())
+                logger.debug("Exception occured while making servlet request", e);
+            return null;
+        }
+    }
+
+    /*
+      * (non-Javadoc)
+      *
+      * @see org.apache.excalibur.source.impl.AbstractSource#getLastModified()
+      */
+    public long getLastModified() {
+        try {
+            connect();
+            return servletConnection.getLastModified() > 0 ? servletConnection.getLastModified()
: 0;
+        } catch (Exception e) {
+            if (logger.isDebugEnabled())
+                logger.debug("Exception occured while making servlet request", e);
+            return 0;
+        }
+    }
+
     /**
      * The mime-type of the content described by this object.
      * If the source is not able to determine the mime-type by itself
      * this can be null.
      */
     public String getMimeType() {
-    	try {
-			connect();
-			return servletConnection.getContentType();
-		} catch (Exception e) {
-			if (logger.isDebugEnabled())
-				logger.debug("Exception occured while making servlet request", e);
-			return null;
-		}
-    }
-
-	/**
-	 * Returns true always.
-	 * 
-	 * @see org.apache.excalibur.source.Source#exists()
-	 */
-	public boolean exists() {
-		return true;
-	}
-
-	public OutputStream getOutputStream() throws IOException {
-		return servletConnection.getOutputStream();
-	}
-
-	private void connect() throws IOException, ServletException {
-		if (connected)
-			return;
-		long lastModified = getStoredLastModified();
-		if (lastModified > 0)
-			servletConnection.setIfModifiedSince(lastModified);
-		servletConnection.connect();
-		connected = true;
-		// If header is present, Last-Modified value will be stored for further
-		// use in conditional gets
-		setStoredLastModified(servletConnection.getLastModified());
-	}
-
-	/**
-	 * Returns Last-Modified value from previous response if present. Otherwise 0 is returned.
-	 * 
-	 * @return Last-Modified value from previous response if present. Otherwise 0 is returned.
-	 */
-	private long getStoredLastModified() {
-		Long lastModified = (Long) store.get(calculateInternalKey());
-		return lastModified != null ? lastModified.longValue() : 0;
-	}
-
-	/**
-	 * Stores value of Last-Modified header in {@link #store}.
-	 * 
-	 * @param lastModified
-	 *            value that will be stored in {@link #store}. Only positive values will be
stored.
-	 * @throws IOException
-	 *             if exception occured while storing value
-	 */
-	private void setStoredLastModified(long lastModified) throws IOException {
-		String key = calculateInternalKey();
-		store.remove(key);
-		if (lastModified > 0)
-			store.store(key, new Long(lastModified));
-	}
-
-	/**
-	 * @return key that will be used to store value of Last-Modified header
-	 */
-	private String calculateInternalKey() {
-		return ServletSource.class.getName() + "$" + getURI();
-	}
-
-	private final class ServletValidity implements SourceValidity {
-
-		/**
-		 * 
-		 */
-		private static final long serialVersionUID = 1793646888814956538L;
-
-		private int responseCode;
-
-		public ServletValidity(int responseCode) {
-			setResponseCode(responseCode);
-		}
-
-		/*
-		 * (non-Javadoc)
-		 * 
-		 * @see org.apache.excalibur.source.SourceValidity#isValid()
-		 */
-		public int isValid() {
-			return 0;
-		}
-
-		/*
-		 * (non-Javadoc)
-		 * 
-		 * @see org.apache.excalibur.source.SourceValidity#isValid(org.apache.excalibur.source.SourceValidity)
-		 */
-		public int isValid(SourceValidity newValidity) {
-			if (newValidity instanceof ServletValidity) {
-				ServletValidity newServletValidity = (ServletValidity) newValidity;
-
-				switch (newServletValidity.getResponseCode()) {
-				case HttpServletResponse.SC_NOT_MODIFIED:
-					return SourceValidity.VALID;
-				case HttpServletResponse.SC_OK:
-					return SourceValidity.INVALID;
-				default:
-					return 0;
-				}
-			}
-			return SourceValidity.UNKNOWN;
-		}
-
-		public int getResponseCode() {
-			return responseCode;
-		}
-
-		public void setResponseCode(int responseCode) {
-			this.responseCode = responseCode;
-		}
-	}
+        try {
+            connect();
+            return servletConnection.getContentType();
+        } catch (Exception e) {
+            if (logger.isDebugEnabled())
+                logger.debug("Exception occured while making servlet request", e);
+            return null;
+        }
+    }
+
+    /**
+     * Returns true always.
+     *
+     * @see org.apache.excalibur.source.Source#exists()
+     */
+    public boolean exists() {
+        return true;
+    }
 
+    public OutputStream getOutputStream() throws IOException {
+        return servletConnection.getOutputStream();
+    }
+
+    private void connect() throws IOException, ServletException {
+        if (connected) {
+            return;
+        }
+
+        long lastModified = getStoredLastModified();
+        if (lastModified > 0) {
+            servletConnection.setIfModifiedSince(lastModified);
+        }
+
+        servletConnection.connect();
+        connected = true;
+        // If header is present, Last-Modified value will be stored for further
+        // use in conditional gets
+        setStoredLastModified(servletConnection.getLastModified());
+    }
+
+    /**
+     * Returns Last-Modified value from previous response if present. Otherwise 0 is returned.
+     *
+     * @return Last-Modified value from previous response if present. Otherwise 0 is returned.
+     */
+    private long getStoredLastModified() {
+        Long lastModified = (Long) store.get(calculateInternalKey());
+        return lastModified != null ? lastModified.longValue() : 0;
+    }
+
+    /**
+     * Stores value of Last-Modified header in {@link #store}.
+     *
+     * @param lastModified
+     *            value that will be stored in {@link #store}. Only positive values will
be stored.
+     * @throws IOException
+     *             if exception occured while storing value
+     */
+    private void setStoredLastModified(long lastModified) throws IOException {
+        String key = calculateInternalKey();
+        store.remove(key);
+        if (lastModified > 0)
+            store.store(key, new Long(lastModified));
+    }
+
+    /**
+     * @return key that will be used to store value of Last-Modified header
+     */
+    private String calculateInternalKey() {
+        return ServletSource.class.getName() + "$" + getURI();
+    }
+
+    private final class ServletValidity implements SourceValidity {
+
+        /**
+         *
+         */
+        private static final long serialVersionUID = 1793646888814956538L;
+
+        private int responseCode;
+
+        public ServletValidity(int responseCode) {
+            setResponseCode(responseCode);
+        }
+
+        /*
+           * (non-Javadoc)
+           *
+           * @see org.apache.excalibur.source.SourceValidity#isValid()
+           */
+        public int isValid() {
+            return 0;
+        }
+
+        /*
+           * (non-Javadoc)
+           *
+           * @see org.apache.excalibur.source.SourceValidity#isValid(org.apache.excalibur.source.SourceValidity)
+           */
+        public int isValid(SourceValidity newValidity) {
+            if (newValidity instanceof ServletValidity) {
+                ServletValidity newServletValidity = (ServletValidity) newValidity;
+
+                switch (newServletValidity.getResponseCode()) {
+                    case HttpServletResponse.SC_NOT_MODIFIED:
+                        return SourceValidity.VALID;
+                    case HttpServletResponse.SC_OK:
+                        return SourceValidity.INVALID;
+                    default:
+                        return 0;
+                }
+            }
+            return SourceValidity.UNKNOWN;
+        }
+
+        public int getResponseCode() {
+            return responseCode;
+        }
+
+        public void setResponseCode(int responseCode) {
+            this.responseCode = responseCode;
+        }
+    }
 }



Mime
View raw message