Author: tv
Date: Wed Aug  1 20:54:29 2018
New Revision: 1837263

URL: http://svn.apache.org/viewvc?rev=1837263&view=rev
Log:
Modernize

Modified:
    turbine/core/trunk/src/java/org/apache/turbine/Turbine.java
    
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonBaseFactory.java
    
turbine/core/trunk/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java
    turbine/core/trunk/src/java/org/apache/turbine/util/ObjectUtils.java
    turbine/core/trunk/src/java/org/apache/turbine/util/ServletUtils.java

Modified: turbine/core/trunk/src/java/org/apache/turbine/Turbine.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/Turbine.java?rev=1837263&r1=1837262&r2=1837263&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/Turbine.java (original)
+++ turbine/core/trunk/src/java/org/apache/turbine/Turbine.java Wed Aug  1 
20:54:29 2018
@@ -120,16 +120,18 @@ import org.apache.turbine.util.uri.URICo
 
 public class Turbine extends HttpServlet
 {
-    /** Serialversion */
+    /** Serial version */
     private static final long serialVersionUID = -6317118078613623990L;
 
     /**
      * Name of path info parameter used to indicate the redirected stage of
      * a given user's initial Turbine request
      */
+    @Deprecated // not used
     public static final String REDIRECTED_PATHINFO_NAME = "redirected";
 
     /** The base directory key */
+    @Deprecated // not used
     public static final String BASEDIR_KEY = "basedir";
 
     /**
@@ -816,10 +818,6 @@ public class Turbine extends HttpServlet
                        pipeline.invoke(pipelineData);
 
         }
-        catch (Exception e)
-        {
-            handleException(pipelineData, res, e);
-        }
         catch (Throwable t)
         {
             handleException(pipelineData, res, t);

Modified: 
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonBaseFactory.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonBaseFactory.java?rev=1837263&r1=1837262&r2=1837263&view=diff
==============================================================================
--- 
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonBaseFactory.java
 (original)
+++ 
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonBaseFactory.java
 Wed Aug  1 20:54:29 2018
@@ -99,13 +99,9 @@ public abstract class PythonBaseFactory<
 
         if (f.exists())
         {
-            PythonInterpreter interp = null;
-
-            try
+            // We try to open the Py Interpreter
+            try (PythonInterpreter interp = new PythonInterpreter())
             {
-                // We try to open the Py Interpreter
-                interp = new PythonInterpreter();
-
                 // Make sure the Py Interpreter use the right classloader
                 // This is necessary for servlet engines generally has
                 // their own classloader implementations and servlets aren't
@@ -155,13 +151,6 @@ public abstract class PythonBaseFactory<
                 log.error("PYTHON SCRIPT SCREEN LOADER ERROR:", e);
                 throw e;
             }
-            finally
-            {
-                if (interp != null)
-                {
-                    interp.close();
-                }
-            }
         }
         return assembler;
     }

Modified: 
turbine/core/trunk/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java?rev=1837263&r1=1837262&r2=1837263&view=diff
==============================================================================
--- 
turbine/core/trunk/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java
 (original)
+++ 
turbine/core/trunk/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java
 Wed Aug  1 20:54:29 2018
@@ -22,7 +22,6 @@ package org.apache.turbine.services.velo
 
 
 import java.io.ByteArrayOutputStream;
-import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
@@ -281,14 +280,11 @@ public class TurbineVelocityService
         throws TurbineException
     {
         String results = null;
-        ByteArrayOutputStream bytes = null;
         OutputStreamWriter writer = null;
         String charset = getOutputCharSet(context);
 
-        try
+        try (ByteArrayOutputStream bytes = new ByteArrayOutputStream())
         {
-            bytes = new ByteArrayOutputStream();
-
             writer = new OutputStreamWriter(bytes, charset);
 
             executeRequest(context, filename, writer);
@@ -299,20 +295,7 @@ public class TurbineVelocityService
         {
             renderingError(filename, e);
         }
-        finally
-        {
-            try
-            {
-                if (bytes != null)
-                {
-                    bytes.close();
-                }
-            }
-            catch (IOException ignored)
-            {
-                // do nothing.
-            }
-        }
+
         return results;
     }
 
@@ -334,34 +317,17 @@ public class TurbineVelocityService
             throws TurbineException
     {
         String charset  = getOutputCharSet(context);
-        OutputStreamWriter writer = null;
 
-        try
+        try (OutputStreamWriter writer = new OutputStreamWriter(output, 
charset))
         {
-            writer = new OutputStreamWriter(output, charset);
             executeRequest(context, filename, writer);
         }
         catch (Exception e)
         {
             renderingError(filename, e);
         }
-        finally
-        {
-            try
-            {
-                if (writer != null)
-                {
-                    writer.flush();
-                }
-            }
-            catch (Exception ignored)
-            {
-                // do nothing.
-            }
-        }
     }
 
-
     /**
      * Process the request and fill in the template with the values
      * you set in the Context.

Modified: turbine/core/trunk/src/java/org/apache/turbine/util/ObjectUtils.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/util/ObjectUtils.java?rev=1837263&r1=1837262&r2=1837263&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/util/ObjectUtils.java 
(original)
+++ turbine/core/trunk/src/java/org/apache/turbine/util/ObjectUtils.java Wed 
Aug  1 20:54:29 2018
@@ -21,7 +21,6 @@ package org.apache.turbine.util;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
@@ -58,30 +57,14 @@ public abstract class ObjectUtils
             }
         }
 
-        ByteArrayOutputStream baos = null;
-        ObjectOutputStream out = null;
-        try
+        try (ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+             ObjectOutputStream out = new ObjectOutputStream(baos))
         {
-            // These objects are closed in the finally.
-            baos = new ByteArrayOutputStream(1024);
-            out  = new ObjectOutputStream(baos);
-
             out.writeObject(map);
             out.flush();
 
             byteArray = baos.toByteArray();
         }
-        finally
-        {
-            if (out != null)
-            {
-                out.close();
-            }
-            if (baos != null)
-            {
-                baos.close();
-            }
-        }
 
         return byteArray;
     }
@@ -100,14 +83,9 @@ public abstract class ObjectUtils
 
         if (objectData != null)
         {
-            // These streams are closed in finally.
-            ObjectInputStream in = null;
-            ByteArrayInputStream bin = new ByteArrayInputStream(objectData);
-
-            try
+            try (ByteArrayInputStream bin = new 
ByteArrayInputStream(objectData);
+                 ObjectInputStream in = new ObjectInputStream(bin))
             {
-                in = new ObjectInputStream(bin);
-
                 // If objectData has not been initialized, an
                 // exception will occur.
                 object = (T)in.readObject();
@@ -116,22 +94,8 @@ public abstract class ObjectUtils
             {
                 // ignore
             }
-            finally
-            {
-                try
-                {
-                    if (in != null)
-                    {
-                        in.close();
-                    }
-                    bin.close();
-                }
-                catch (IOException e)
-                {
-                    // ignore
-                }
-            }
         }
+
         return object;
     }
 }

Modified: turbine/core/trunk/src/java/org/apache/turbine/util/ServletUtils.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/util/ServletUtils.java?rev=1837263&r1=1837262&r2=1837263&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/util/ServletUtils.java 
(original)
+++ turbine/core/trunk/src/java/org/apache/turbine/util/ServletUtils.java Wed 
Aug  1 20:54:29 2018
@@ -1,6 +1,8 @@
 package org.apache.turbine.util;
 
 
+import java.io.File;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -75,7 +77,7 @@ public class ServletUtils
         String base = context.getRealPath("/");
 
         base = (StringUtils.isEmpty(base))
-            ? config.getInitParameter(Turbine.BASEDIR_KEY)
+            ? Turbine.getApplicationRoot()
             : base;
 
         if (StringUtils.isEmpty(base))
@@ -83,17 +85,14 @@ public class ServletUtils
             return text;
         }
 
-        String separator = System.getProperty("path.separator");
-
-        StringTokenizer tokenizer = new StringTokenizer(text,
-                separator);
+        StringTokenizer tokenizer = new StringTokenizer(text, 
File.pathSeparator);
         StringBuilder buffer = new StringBuilder();
         while (tokenizer.hasMoreTokens())
         {
             buffer.append(base).append(tokenizer.nextToken());
             if (tokenizer.hasMoreTokens())
             {
-                buffer.append(separator);
+                buffer.append(File.pathSeparator);
             }
         }
         return buffer.toString();


Reply via email to