diff --git a/launcher/src/main/java/helma/main/launcher/Commandline.java b/launcher/src/main/java/helma/main/launcher/Commandline.java index 3f87bc53..5dc211bd 100644 --- a/launcher/src/main/java/helma/main/launcher/Commandline.java +++ b/launcher/src/main/java/helma/main/launcher/Commandline.java @@ -41,8 +41,8 @@ public class Commandline { ClassLoader loader = Main.createClassLoader(installDir); // get the main server class - Class clazz = loader.loadClass("helma.main.CommandlineRunner"); - Class[] cargs = new Class[]{args.getClass()}; + Class clazz = loader.loadClass("helma.main.CommandlineRunner"); + Class[] cargs = new Class[]{args.getClass()}; Method main = clazz.getMethod("main", cargs); Object[] nargs = new Object[]{args}; diff --git a/launcher/src/main/java/helma/main/launcher/Main.java b/launcher/src/main/java/helma/main/launcher/Main.java index 13e36c02..d7060eda 100644 --- a/launcher/src/main/java/helma/main/launcher/Main.java +++ b/launcher/src/main/java/helma/main/launcher/Main.java @@ -35,10 +35,10 @@ import java.util.ArrayList; * be able to set up class and install paths. */ public class Main { - private Class serverClass; + private Class serverClass; private Object server; - private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; /** @@ -60,7 +60,7 @@ public class Main { ClassLoader loader = createClassLoader(installDir); // get the main server class serverClass = loader.loadClass("helma.main.Server"); - Class[] cargs = new Class[]{args.getClass()}; + Class[] cargs = new Class[]{args.getClass()}; Method loadServer = serverClass.getMethod("loadServer", cargs); Object[] nargs = new Object[]{args}; // and invoke the static loadServer(String[]) method @@ -111,17 +111,17 @@ public class Main { } } - static void addJars(ArrayList jarlist, File dir) throws MalformedURLException { + static void addJars(ArrayList jarlist, File dir) throws MalformedURLException { File[] files = dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { String n = name.toLowerCase(); - return n.endsWith(".jar") || n.endsWith(".zip"); + return n.endsWith(".jar") || n.endsWith(".zip"); //$NON-NLS-1$//$NON-NLS-2$ } }); if (files != null) { for (int i = 0; i < files.length; i++) { - jarlist.add(new URL("file:" + files[i].getAbsolutePath())); + jarlist.add(new URL("file:" + files[i].getAbsolutePath())); //$NON-NLS-1$ } } } @@ -143,13 +143,13 @@ public class Main { // set up the class path File libdir = new File(installDir, "lib"); - ArrayList jarlist = new ArrayList<>(); + ArrayList jarlist = new ArrayList(); // add all jar files from the lib directory addJars(jarlist, libdir); // add all jar files from the lib/ext directory - addJars(jarlist, new File(libdir, "ext")); + addJars(jarlist, new File(libdir, "ext")); //$NON-NLS-1$ URL[] urls = new URL[jarlist.size()]; @@ -199,7 +199,7 @@ public class Main { // try to get Helma installation directory if (installDir == null) { URL launcherUrl = ClassLoader.getSystemClassLoader() - .getResource("helma/main/launcher/Main.class"); + .getResource("helma/main/launcher/Main.class"); //$NON-NLS-1$ // this is a JAR URL of the form // jar:!/{entry} diff --git a/src/main/java/helma/extensions/HelmaExtension.java b/src/main/java/helma/extensions/HelmaExtension.java index 13f827d6..7bb0fa26 100644 --- a/src/main/java/helma/extensions/HelmaExtension.java +++ b/src/main/java/helma/extensions/HelmaExtension.java @@ -59,7 +59,7 @@ public abstract class HelmaExtension { * with pairs of varname and ESObjects. This method should be synchronized, if it * performs any other self-initialization outside the scripting environment. */ - public abstract HashMap initScripting(Application app, ScriptingEngine engine) + public abstract HashMap initScripting(Application app, ScriptingEngine engine) throws ConfigurationException; /** diff --git a/src/main/java/helma/extensions/demo/DemoExtension.java b/src/main/java/helma/extensions/demo/DemoExtension.java index 1c5c14d1..dbc35cae 100644 --- a/src/main/java/helma/extensions/demo/DemoExtension.java +++ b/src/main/java/helma/extensions/demo/DemoExtension.java @@ -42,7 +42,7 @@ public class DemoExtension extends HelmaExtension { public void init(Server server) throws ConfigurationException { try { // just a demo with the server class itself (which is always there, obviously) - Class.forName("helma.main.Server"); + Class check = Class.forName("helma.main.Server"); } catch (ClassNotFoundException e) { throw new ConfigurationException("helma-library not present in classpath. make sure helma.jar is included. get it from http://www.helma.org/"); } @@ -87,7 +87,7 @@ public class DemoExtension extends HelmaExtension { * * @throws ConfigurationException ... */ - public HashMap initScripting(Application app, ScriptingEngine engine) + public HashMap initScripting(Application app, ScriptingEngine engine) throws ConfigurationException { if (!(engine instanceof RhinoEngine)) { throw new ConfigurationException("scripting engine " + engine.toString() + @@ -98,7 +98,7 @@ public class DemoExtension extends HelmaExtension { engine.toString()); // initialize prototypes and global vars here - HashMap globals = new HashMap<>(); + HashMap globals = new HashMap(); globals.put("demo", Server.getServer()); diff --git a/src/main/java/helma/framework/RequestTrans.java b/src/main/java/helma/framework/RequestTrans.java index 9a46e0bd..83665ba8 100644 --- a/src/main/java/helma/framework/RequestTrans.java +++ b/src/main/java/helma/framework/RequestTrans.java @@ -603,11 +603,11 @@ public class RequestTrans implements Serializable { StringTokenizer tok; - if (auth.startsWith("Basic ")) { + if (auth.startsWith("Basic ")) { //$NON-NLS-1$ tok = new StringTokenizer(new String(Base64.decodeBase64(auth.substring(6))), - ":"); + ":"); //$NON-NLS-1$ } else { - tok = new StringTokenizer(new String(Base64.decodeBase64(auth)), ":"); + tok = new StringTokenizer(new String(Base64.decodeBase64(auth)), ":"); //$NON-NLS-1$ } try { diff --git a/src/main/java/helma/framework/ResponseTrans.java b/src/main/java/helma/framework/ResponseTrans.java index 0853b7ee..af65a4c1 100644 --- a/src/main/java/helma/framework/ResponseTrans.java +++ b/src/main/java/helma/framework/ResponseTrans.java @@ -714,7 +714,7 @@ public final class ResponseTrans extends Writer implements Serializable { // if (contentType != null) // digest.update (contentType.getBytes()); byte[] b = this.digest.digest(this.response); - this.etag = "\"" + new String(Base64.encodeBase64(b)) + "\""; + this.etag = "\"" + new String(Base64.encodeBase64(b)) + "\""; //$NON-NLS-1$ //$NON-NLS-2$ // only set response to 304 not modified if no cookies were set if (reqtrans.hasETag(etag) && countCookies() == 0) { response = new byte[0]; diff --git a/src/main/java/helma/framework/core/Application.java b/src/main/java/helma/framework/core/Application.java index b78d519e..be41d21a 100644 --- a/src/main/java/helma/framework/core/Application.java +++ b/src/main/java/helma/framework/core/Application.java @@ -47,7 +47,7 @@ public final class Application implements Runnable { private String name; // application sources - ArrayList repositories; + ArrayList repositories; // properties and db-properties ResourceProperties props; @@ -96,15 +96,15 @@ public final class Application implements Runnable { /** * Collections for evaluator thread pooling */ - protected Stack freeThreads; - protected Vector allThreads; + protected Stack freeThreads; + protected Vector allThreads; boolean running = false; boolean debug; long starttime; - Hashtable dbSources; + Hashtable dbSources; // map of app modules reflected at app.modules - Map modules; + Map modules; // internal worker thread for scheduler, session cleanup etc. Thread worker; @@ -113,10 +113,10 @@ public final class Application implements Runnable { ThreadGroup threadgroup; // threadlocal variable for the current RequestEvaluator - ThreadLocal currentEvaluator = new ThreadLocal<>(); + ThreadLocal currentEvaluator = new ThreadLocal(); // Map of requesttrans -> active requestevaluators - Hashtable activeRequests; + Hashtable activeRequests; String logDir; @@ -165,15 +165,15 @@ public final class Application implements Runnable { private long lastPropertyRead = -1L; // the set of prototype/function pairs which are allowed to be called via XML-RPC - private HashSet xmlrpcAccess; + private HashSet xmlrpcAccess; // the name under which this app serves XML-RPC requests. Defaults to the app name private String xmlrpcHandlerName; // the list of currently active cron jobs - Hashtable activeCronJobs = null; + Hashtable activeCronJobs = null; // the list of custom cron jobs - Hashtable customCronJobs = null; + Hashtable customCronJobs = null; private ResourceComparator resourceComparator; private Resource currentCodeResource; @@ -230,7 +230,7 @@ public final class Application implements Runnable { this.caseInsensitive = "true".equalsIgnoreCase(server.getAppsProperties(name).getProperty("caseInsensitive")); - this.repositories = new ArrayList<>(); + this.repositories = new ArrayList(); this.repositories.addAll(Arrays.asList(repositories)); resourceComparator = new ResourceComparator(this); @@ -304,7 +304,7 @@ public final class Application implements Runnable { updateProperties(); - dbSources = new Hashtable<>(); + dbSources = new Hashtable(); modules = new SystemMap(); } @@ -366,9 +366,7 @@ public final class Application implements Runnable { private void initInternal() throws DatabaseException, IllegalAccessException, - InstantiationException, ClassNotFoundException, - IllegalArgumentException, InvocationTargetException, - NoSuchMethodException, SecurityException { + InstantiationException, ClassNotFoundException { running = true; // create and init type mananger typemgr = new TypeManager(Application.this, ignoreDirs); @@ -383,7 +381,7 @@ public final class Application implements Runnable { } if (Server.getServer() != null) { - Vector extensions = Server.getServer().getExtensions(); + Vector extensions = Server.getServer().getExtensions(); for (int i = 0; i < extensions.size(); i++) { HelmaExtension ext = (HelmaExtension) extensions.get(i); @@ -398,12 +396,12 @@ public final class Application implements Runnable { } // create and init evaluator/thread lists - freeThreads = new Stack<>(); - allThreads = new Vector<>(); + freeThreads = new Stack(); + allThreads = new Vector(); - activeRequests = new Hashtable<>(); - activeCronJobs = new Hashtable<>(); - customCronJobs = new Hashtable<>(); + activeRequests = new Hashtable(); + activeCronJobs = new Hashtable(); + customCronJobs = new Hashtable(); // create the skin manager skinmgr = new SkinManager(Application.this); @@ -444,13 +442,7 @@ public final class Application implements Runnable { // create and init session manager String sessionMgrImpl = props.getProperty("sessionManagerImpl", "helma.framework.core.SessionManager"); - try { - sessionMgr = (SessionManager) Class.forName(sessionMgrImpl) - .getDeclaredConstructor() - .newInstance(); - } catch (NoSuchMethodException | InvocationTargetException e) { - throw new RuntimeException("Error initializing session manager", e); - } + sessionMgr = (SessionManager) Class.forName(sessionMgrImpl).newInstance(); logEvent("Using session manager class " + sessionMgrImpl); sessionMgr.init(Application.this); @@ -887,7 +879,7 @@ public final class Application implements Runnable { } else { String rootClass = classMapping.getProperty("root"); Class c = typemgr.getClassLoader().loadClass(rootClass); - rootObject = c.getDeclaredConstructor().newInstance(); + rootObject = c.newInstance(); } } catch (Exception e) { throw new RuntimeException("Error creating root object: " + diff --git a/src/main/java/helma/framework/core/RequestEvaluator.java b/src/main/java/helma/framework/core/RequestEvaluator.java index c62f3e7d..e8b6051c 100644 --- a/src/main/java/helma/framework/core/RequestEvaluator.java +++ b/src/main/java/helma/framework/core/RequestEvaluator.java @@ -100,7 +100,7 @@ public final class RequestEvaluator implements Runnable { app.setCurrentRequestEvaluator(this); Class clazz = app.getClassLoader().loadClass(engineClassName); - scriptingEngine = (ScriptingEngine) clazz.getDeclaredConstructor().newInstance(); + scriptingEngine = (ScriptingEngine) clazz.newInstance(); scriptingEngine.init(app, this); } catch (Exception x) { Throwable t = x; @@ -566,7 +566,7 @@ public final class RequestEvaluator implements Runnable { int base = 800 * tries; Thread.sleep((long) (base + (Math.random() * base * 2))); } catch (InterruptedException interrupt) { - // we got interrrupted, create minimal error message + // we got interrrupted, create minimal error message res.reportError(interrupt); done = true; // and release resources and thread diff --git a/src/main/java/helma/image/ImageGenerator.java b/src/main/java/helma/image/ImageGenerator.java index 61839013..c7d85a96 100644 --- a/src/main/java/helma/image/ImageGenerator.java +++ b/src/main/java/helma/image/ImageGenerator.java @@ -27,7 +27,7 @@ import java.net.URL; /** * Factory class for generating Image objects from various sources. - * + * */ public abstract class ImageGenerator { protected static ImageGenerator generator = null; @@ -72,7 +72,7 @@ public abstract class ImageGenerator { "The imageGenerator class cannot be found: " + className); } try { - generator = (ImageGenerator) generatorClass.getDeclaredConstructor().newInstance(); + generator = (ImageGenerator)generatorClass.newInstance(); } catch (Exception e) { throw new RuntimeException( "The ImageGenerator instance could not be created: " @@ -85,7 +85,7 @@ public abstract class ImageGenerator { /** * @param w ... * @param h ... - * + * * @return ... */ public ImageWrapper createImage(int w, int h) { @@ -95,7 +95,7 @@ public abstract class ImageGenerator { /** * @param src ... - * + * * @return ... * @throws IOException */ @@ -103,10 +103,10 @@ public abstract class ImageGenerator { Image img = read(src); return img != null ? new ImageWrapper(img, this) : null; } - + /** * @param filenamne ... - * + * * @return ... * @throws IOException */ @@ -118,7 +118,7 @@ public abstract class ImageGenerator { /** * @param url ... - * + * * @return ... * @throws MalformedURLException * @throws IOException @@ -144,14 +144,14 @@ public abstract class ImageGenerator { /** * @param iw ... * @param filter ... - * + * * @return ... */ public ImageWrapper createImage(ImageWrapper iw, ImageFilter filter) { // use the ImagFilterOp wrapper for ImageFilters that works directly // on BufferedImages. The filtering is much faster like that. // Attention: needs testing with all the filters! - + return createImage(iw, new ImageFilterOp(filter)); // Image img = ImageWaiter.waitForImage( // Toolkit.getDefaultToolkit().createImage( @@ -162,7 +162,7 @@ public abstract class ImageGenerator { /** * @param iw ... * @param imageOp ... - * + * * @return ... */ public ImageWrapper createImage(ImageWrapper iw, BufferedImageOp imageOp) { @@ -212,7 +212,7 @@ public abstract class ImageGenerator { /** * Saves the image. Image format is deduced from filename. - * + * * @param wrapper * @param filename * @param quality @@ -224,7 +224,7 @@ public abstract class ImageGenerator { /** * Saves the image. Image format is deduced from the dataSource. - * + * * @param wrapper * @param out * @param quality @@ -233,4 +233,4 @@ public abstract class ImageGenerator { */ public abstract void write(ImageWrapper wrapper, OutputStream out, String type, float quality, boolean alpha) throws IOException; -} +} \ No newline at end of file diff --git a/src/main/java/helma/image/ImageInfo.java b/src/main/java/helma/image/ImageInfo.java index b9a9d324..1de5f211 100644 --- a/src/main/java/helma/image/ImageInfo.java +++ b/src/main/java/helma/image/ImageInfo.java @@ -6,7 +6,7 @@ * A Java class to determine image width, height and color depth for * a number of image file formats. * - * Written by Marco Schmidt + * Written by Marco Schmidt * . * * Contributed to the Public Domain. @@ -24,53 +24,47 @@ import java.net.URL; import java.util.Vector; /** - * Get file format, image resolution, number of bits per pixel and optionally - * number of images, comments and physical resolution from - * JPEG, GIF, BMP, PCX, PNG, IFF, RAS, PBM, PGM, PPM, PSD and SWF files + * Get file format, image resolution, number of bits per pixel and optionally + * number of images, comments and physical resolution from + * JPEG, GIF, BMP, PCX, PNG, IFF, RAS, PBM, PGM, PPM, PSD and SWF files * (or input streams). *

* Use the class like this: - * *

  * ImageInfo ii = new ImageInfo();
  * ii.setInput(in); // in can be InputStream or RandomAccessFile
  * ii.setDetermineImageNumber(true); // default is false
  * ii.setCollectComments(true); // default is false
  * if (!ii.check()) {
- * 	System.err.println("Not a supported image file format.");
- * 	return;
+ *   System.err.println("Not a supported image file format.");
+ *   return;
  * }
- * System.out.println(ii.getFormatName() + ", " + ii.getMimeType() +
- * 		", " + ii.getWidth() + " x " + ii.getHeight() + " pixels, " +
- * 		ii.getBitsPerPixel() + " bits per pixel, " + ii.getNumberOfImages() +
- * 		" image(s), " + ii.getNumberOfComments() + " comment(s).");
- * // there are other properties, check out the API documentation
+ * System.out.println(ii.getFormatName() + ", " + ii.getMimeType() + 
+ *   ", " + ii.getWidth() + " x " + ii.getHeight() + " pixels, " + 
+ *   ii.getBitsPerPixel() + " bits per pixel, " + ii.getNumberOfImages() +
+ *   " image(s), " + ii.getNumberOfComments() + " comment(s).");
+ *  // there are other properties, check out the API documentation
  * 
- * * You can also use this class as a command line program. * Call it with a number of image file names and URLs as parameters: - * *
  *   java ImageInfo *.jpg *.png *.gif http://somesite.tld/image.jpg
  * 
- * * or call it without parameters and pipe data to it: - * *
- *   java ImageInfo < image.jpg
+ *   java ImageInfo < image.jpg  
  * 
*

* Known limitations: *

    - *
  • When the determination of the number of images is turned off, GIF bits - * per pixel are only read from the global header. - * For some GIFs, local palettes change this to a typically larger - * value. To be certain to get the correct color depth, call - * setDetermineImageNumber(true) before calling check(). - * The complete scan over the GIF file will take additional time.
  • + *
  • When the determination of the number of images is turned off, GIF bits + * per pixel are only read from the global header. + * For some GIFs, local palettes change this to a typically larger + * value. To be certain to get the correct color depth, call + * setDetermineImageNumber(true) before calling check(). + * The complete scan over the GIF file will take additional time.
  • *
  • Transparency information is not included in the bits per pixel count. - * Actually, it was my decision not to include those bits, so it's a feature! - * ;-)
  • + * Actually, it was my decision not to include those bits, so it's a feature! ;-) *
*

* Requirements: @@ -78,12 +72,9 @@ import java.util.Vector; *

  • Java 1.1 or higher
  • * *

    - * The latest version can be found at http://www.geocities.com/marcoschmidt.geo/image-info.html. + * The latest version can be found at http://www.geocities.com/marcoschmidt.geo/image-info.html. *

    - * Written by - * Marco - * Schmidt. + * Written by Marco Schmidt. *

    * This class is contributed to the Public Domain. * Use it at your own risk. @@ -93,57 +84,39 @@ import java.util.Vector; * History: *

      *
    • 2001-08-24 Initial version.
    • - *
    • 2001-10-13 Added support for the file formats BMP and - * PCX.
    • - *
    • 2001-10-16 Fixed bug in read(int[], int, int) that - * returned - *
    • 2002-01-22 Added support for file formats Amiga IFF and - * Sun Raster (RAS).
    • - *
    • 2002-01-24 Added support for file formats Portable - * Bitmap / Graymap / Pixmap (PBM, PGM, PPM) and Adobe Photoshop (PSD). - * Added new method getMimeType() to return the MIME type associated with a - * particular file format.
    • - *
    • 2002-03-15 Added support to recognize number of images - * in file. Only works with GIF. - * Use {@link #setDetermineImageNumber} with true as argument to - * identify animated GIFs - * ({@link #getNumberOfImages()} will return a value larger than - * 1).
    • - *
    • 2002-04-10 Fixed a bug in the feature 'determine number - * of images in animated GIF' introduced with version 1.1. - * Thanks to Marcelo P. Lima for sending in the bug report. - * Released as 1.1.1.
    • - *
    • 2002-04-18 Added {@link #setCollectComments(boolean)}. - * That new method lets the user specify whether textual comments are to be - * stored in an internal list when encountered in an input image file / stream. - * Added two methods to return the physical width and height of the image in - * dpi: - * {@link #getPhysicalWidthDpi()} and {@link #getPhysicalHeightDpi()}. - * If the physical resolution could not be retrieved, these methods return - * -1. - *
    • - *
    • 2002-04-23 Added support for the new properties physical - * resolution and - * comments for some formats. Released as 1.2.
    • - *
    • 2002-06-17 Added support for SWF, sent in by Michael - * Aird. - * Changed checkJpeg() so that other APP markers than APP0 will not lead to a - * failure anymore. - * Released as 1.3.
    • - *
    • 2003-07-28 Bug fix - skip method now takes return values - * into consideration. - * Less bytes than necessary may have been skipped, leading to flaws in the - * retrieved information in some cases. - * Thanks to Bernard Bernstein for pointing that out. - * Released as 1.4.
    • - *
    • 2004-02-29 Added support for recognizing progressive - * JPEG and - * interlaced PNG and GIF. A new method {@link #isProgressive()} returns whether - * ImageInfo - * has found that the storage type is progressive (or interlaced). - * Thanks to Joe Germuska for suggesting the feature. - * Bug fix: BMP physical resolution is now correctly determined. - * Released as 1.5.
    • + *
    • 2001-10-13 Added support for the file formats BMP and PCX.
    • + *
    • 2001-10-16 Fixed bug in read(int[], int, int) that returned + *
    • 2002-01-22 Added support for file formats Amiga IFF and Sun Raster (RAS).
    • + *
    • 2002-01-24 Added support for file formats Portable Bitmap / Graymap / Pixmap (PBM, PGM, PPM) and Adobe Photoshop (PSD). + * Added new method getMimeType() to return the MIME type associated with a particular file format.
    • + *
    • 2002-03-15 Added support to recognize number of images in file. Only works with GIF. + * Use {@link #setDetermineImageNumber} with true as argument to identify animated GIFs + * ({@link #getNumberOfImages()} will return a value larger than 1).
    • + *
    • 2002-04-10 Fixed a bug in the feature 'determine number of images in animated GIF' introduced with version 1.1. + * Thanks to Marcelo P. Lima for sending in the bug report. + * Released as 1.1.1.
    • + *
    • 2002-04-18 Added {@link #setCollectComments(boolean)}. + * That new method lets the user specify whether textual comments are to be + * stored in an internal list when encountered in an input image file / stream. + * Added two methods to return the physical width and height of the image in dpi: + * {@link #getPhysicalWidthDpi()} and {@link #getPhysicalHeightDpi()}. + * If the physical resolution could not be retrieved, these methods return -1. + *
    • + *
    • 2002-04-23 Added support for the new properties physical resolution and + * comments for some formats. Released as 1.2.
    • + *
    • 2002-06-17 Added support for SWF, sent in by Michael Aird. + * Changed checkJpeg() so that other APP markers than APP0 will not lead to a failure anymore. + * Released as 1.3.
    • + *
    • 2003-07-28 Bug fix - skip method now takes return values into consideration. + * Less bytes than necessary may have been skipped, leading to flaws in the retrieved information in some cases. + * Thanks to Bernard Bernstein for pointing that out. + * Released as 1.4.
    • + *
    • 2004-02-29 Added support for recognizing progressive JPEG and + * interlaced PNG and GIF. A new method {@link #isProgressive()} returns whether ImageInfo + * has found that the storage type is progressive (or interlaced). + * Thanks to Joe Germuska for suggesting the feature. + * Bug fix: BMP physical resolution is now correctly determined. + * Released as 1.5.
    • *
    */ public class ImageInfo { @@ -152,7 +125,7 @@ public class ImageInfo { * ImageInfo can extract physical resolution and comments * from JPEGs (only from APP0 headers). * Only one image can be stored in a file. - * It is determined whether the JPEG stream is progressive + * It is determined whether the JPEG stream is progressive * (see {@link #isProgressive()}). */ public static final int FORMAT_JPEG = 0; @@ -163,10 +136,8 @@ public class ImageInfo { * of images (GIFs with more than one image are animations). * If you know of a place where GIFs store the physical resolution * of an image, please - * send me a - * mail! - * It is determined whether the GIF stream is interlaced (see - * {@link #isProgressive()}). + * send me a mail! + * It is determined whether the GIF stream is interlaced (see {@link #isProgressive()}). */ public static final int FORMAT_GIF = 1; @@ -175,8 +146,7 @@ public class ImageInfo { * PNG only supports one image per file. * Both physical resolution and comments can be stored with PNG, * but ImageInfo is currently not able to extract those. - * It is determined whether the PNG stream is interlaced (see - * {@link #isProgressive()}). + * It is determined whether the PNG stream is interlaced (see {@link #isProgressive()}). */ public static final int FORMAT_PNG = 2; @@ -225,7 +195,7 @@ public class ImageInfo { public static final int COLOR_TYPE_UNKNOWN = -1; public static final int COLOR_TYPE_TRUECOLOR_RGB = 0; public static final int COLOR_TYPE_PALETTED = 1; - public static final int COLOR_TYPE_GRAYSCALE = 2; + public static final int COLOR_TYPE_GRAYSCALE= 2; public static final int COLOR_TYPE_BLACK_AND_WHITE = 3; /** @@ -233,30 +203,32 @@ public class ImageInfo { * The FORMAT_xyz int constants can be used as index values for * this array. */ - private static final String[] FORMAT_NAMES = { "JPEG", "GIF", "PNG", "BMP", "PCX", - "IFF", "RAS", "PBM", "PGM", "PPM", - "PSD", "SWF" }; + private static final String[] FORMAT_NAMES = + {"JPEG", "GIF", "PNG", "BMP", "PCX", + "IFF", "RAS", "PBM", "PGM", "PPM", + "PSD", "SWF"}; /** * The names of the MIME types for all supported file formats. * The FORMAT_xyz int constants can be used as index values for * this array. */ - private static final String[] MIME_TYPE_STRINGS = { "image/jpeg", "image/gif", "image/png", "image/bmp", - "image/pcx", - "image/iff", "image/ras", "image/x-portable-bitmap", "image/x-portable-graymap", "image/x-portable-pixmap", - "image/psd", "application/x-shockwave-flash" }; + private static final String[] MIME_TYPE_STRINGS = + {"image/jpeg", "image/gif", "image/png", "image/bmp", "image/pcx", + "image/iff", "image/ras", "image/x-portable-bitmap", "image/x-portable-graymap", "image/x-portable-pixmap", + "image/psd", "application/x-shockwave-flash"}; private int width; private int height; private int bitsPerPixel; - private int numColors; + private int numColors; + private int colorType = COLOR_TYPE_UNKNOWN; private boolean progressive; private int format; private InputStream in; private DataInput din; private boolean collectComments = true; - private Vector comments; + private Vector comments; private boolean determineNumberOfImages; private int numberOfImages; private int physicalHeightDpi; @@ -266,7 +238,7 @@ public class ImageInfo { private void addComment(String s) { if (comments == null) { - comments = new Vector(); + comments = new Vector(); } comments.addElement(s); } @@ -276,7 +248,6 @@ public class ImageInfo { * using {@link #setInput(InputStream)} or {@link #setInput(DataInput)}. * If true is returned, the file format was known and information * on the file's content can be retrieved using the various getXyz methods. - * * @return if information could be retrieved from input */ public boolean check() { @@ -287,32 +258,51 @@ public class ImageInfo { numberOfImages = 1; physicalHeightDpi = -1; physicalWidthDpi = -1; - numColors = -1; + numColors = -1; comments = null; try { int b1 = read() & 0xff; int b2 = read() & 0xff; if (b1 == 0x47 && b2 == 0x49) { return checkGif(); - } else if (b1 == 0x89 && b2 == 0x50) { + } + else + if (b1 == 0x89 && b2 == 0x50) { return checkPng(); - } else if (b1 == 0xff && b2 == 0xd8) { + } + else + if (b1 == 0xff && b2 == 0xd8) { return checkJpeg(); - } else if (b1 == 0x42 && b2 == 0x4d) { + } + else + if (b1 == 0x42 && b2 == 0x4d) { return checkBmp(); - } else if (b1 == 0x0a && b2 < 0x06) { + } + else + if (b1 == 0x0a && b2 < 0x06) { return checkPcx(); - } else if (b1 == 0x46 && b2 == 0x4f) { + } + else + if (b1 == 0x46 && b2 == 0x4f) { return checkIff(); - } else if (b1 == 0x59 && b2 == 0xa6) { + } + else + if (b1 == 0x59 && b2 == 0xa6) { return checkRas(); - } else if (b1 == 0x50 && b2 >= 0x31 && b2 <= 0x36) { + } + else + if (b1 == 0x50 && b2 >= 0x31 && b2 <= 0x36) { return checkPnm(b2 - '0'); - } else if (b1 == 0x38 && b2 == 0x42) { + } + else + if (b1 == 0x38 && b2 == 0x42) { return checkPsd(); - } else if (b1 == 0x46 && b2 == 0x57) { + } + else + if (b1 == 0x46 && b2 == 0x57) { return checkSwf(); - } else { + } + else { return false; } } catch (IOException ioe) { @@ -332,15 +322,15 @@ public class ImageInfo { } bitsPerPixel = getShortLittleEndian(a, 26); if (bitsPerPixel != 1 && bitsPerPixel != 4 && - bitsPerPixel != 8 && bitsPerPixel != 16 && - bitsPerPixel != 24 && bitsPerPixel != 32) { - return false; + bitsPerPixel != 8 && bitsPerPixel != 16 && + bitsPerPixel != 24 && bitsPerPixel != 32) { + return false; } - int x = (int) (getIntLittleEndian(a, 36) * 0.0254); + int x = (int)(getIntLittleEndian(a, 36) * 0.0254); if (x > 0) { setPhysicalWidthDpi(x); } - int y = (int) (getIntLittleEndian(a, 40) * 0.0254); + int y = (int)(getIntLittleEndian(a, 40) * 0.0254); if (y > 0) { setPhysicalHeightDpi(y); } @@ -349,14 +339,14 @@ public class ImageInfo { } private boolean checkGif() throws IOException { - final byte[] GIF_MAGIC_87A = { 0x46, 0x38, 0x37, 0x61 }; - final byte[] GIF_MAGIC_89A = { 0x46, 0x38, 0x39, 0x61 }; + final byte[] GIF_MAGIC_87A = {0x46, 0x38, 0x37, 0x61}; + final byte[] GIF_MAGIC_89A = {0x46, 0x38, 0x39, 0x61}; byte[] a = new byte[11]; // 4 from the GIF signature + 7 from the global header if (read(a) != 11) { return false; } if ((!equals(a, 0, GIF_MAGIC_89A, 0, 4)) && - (!equals(a, 0, GIF_MAGIC_87A, 0, 4))) { + (!equals(a, 0, GIF_MAGIC_87A, 0, 4))) { return false; } format = FORMAT_GIF; @@ -367,18 +357,20 @@ public class ImageInfo { progressive = (flags & 0x02) != 0; // skip global color palette if ((flags & 0x80) != 0) { - numColors = (1 << ((flags & 7) + 1)); + numColors = (1 << ((flags & 7) + 1)); skip(numColors * 3); } - if (!determineNumberOfImages) { - return true; - } + if (!determineNumberOfImages) { + return true; + } numberOfImages = 0; int blockType; - do { + do + { blockType = read(); - switch (blockType) { - case (0x2c): // image separator + switch(blockType) + { + case(0x2c): // image separator { if (read(a, 0, 9) != 9) { return false; @@ -389,32 +381,37 @@ public class ImageInfo { bitsPerPixel = localBitsPerPixel; } if ((flags & 0x80) != 0) { - int localNumColors = 1 << localBitsPerPixel; - skip(localNumColors * 3); - if (localNumColors > numColors) { - numColors = localNumColors; - } + int localNumColors = 1 << localBitsPerPixel; + skip(localNumColors * 3); + if (localNumColors > numColors) { + numColors = localNumColors; + } } skip(1); // initial code length int n; - do { + do + { n = read(); if (n > 0) { skip(n); - } else if (n == -1) { + } + else + if (n == -1) { return false; } - } while (n > 0); + } + while (n > 0); numberOfImages++; break; } - case (0x21): // extension + case(0x21): // extension { int extensionType = read(); if (collectComments && extensionType == 0xfe) { StringBuffer sb = new StringBuffer(); int n; - do { + do + { n = read(); if (n == -1) { return false; @@ -425,50 +422,57 @@ public class ImageInfo { if (ch == -1) { return false; } - sb.append((char) ch); + sb.append((char)ch); } } - } while (n > 0); + } + while (n > 0); } else { int n; - do { + do + { n = read(); if (n > 0) { skip(n); - } else if (n == -1) { + } + else + if (n == -1) { return false; } - } while (n > 0); + } + while (n > 0); } break; } - case (0x3b): // end of file + case(0x3b): // end of file { break; } - default: { + default: + { return false; } } - } while (blockType != 0x3b); + } + while (blockType != 0x3b); return true; } private boolean checkIff() throws IOException { byte[] a = new byte[10]; - // read remaining 2 bytes of file id, 4 bytes file size + // read remaining 2 bytes of file id, 4 bytes file size // and 4 bytes IFF subformat if (read(a, 0, 10) != 10) { return false; } - final byte[] IFF_RM = { 0x52, 0x4d }; + final byte[] IFF_RM = {0x52, 0x4d}; if (!equals(a, 0, IFF_RM, 0, 2)) { return false; } int type = getIntBigEndian(a, 6); if (type != 0x494c424d && // type must be ILBM... - type != 0x50424d20) { // ...or PBM - return false; + type != 0x50424d20) { // ...or PBM + return false; } // loop chunks to find BMHD chunk do { @@ -506,28 +510,32 @@ public class ImageInfo { if ((marker & 0xff00) != 0xff00) { return false; // not a valid marker } - if (marker == 0xffe0) { // APPx + if (marker == 0xffe0) { // APPx if (size < 14) { return false; // APPx header must be >= 14 bytes } if (read(data, 0, 12) != 12) { return false; } - final byte[] APP0_ID = { 0x4a, 0x46, 0x49, 0x46, 0x00 }; + final byte[] APP0_ID = {0x4a, 0x46, 0x49, 0x46, 0x00}; if (equals(APP0_ID, 0, data, 0, 5)) { - // System.out.println("data 7=" + data[7]); + //System.out.println("data 7=" + data[7]); if (data[7] == 1) { setPhysicalWidthDpi(getShortBigEndian(data, 8)); setPhysicalHeightDpi(getShortBigEndian(data, 10)); - } else if (data[7] == 2) { + } + else + if (data[7] == 2) { int x = getShortBigEndian(data, 8); int y = getShortBigEndian(data, 10); - setPhysicalWidthDpi((int) (x * 2.54f)); - setPhysicalHeightDpi((int) (y * 2.54f)); + setPhysicalWidthDpi((int)(x * 2.54f)); + setPhysicalHeightDpi((int)(y * 2.54f)); } } skip(size - 14); - } else if (collectComments && size > 2 && marker == 0xfffe) { // comment + } + else + if (collectComments && size > 2 && marker == 0xfffe) { // comment size -= 2; byte[] chars = new byte[size]; if (read(chars, 0, size) != size) { @@ -536,14 +544,16 @@ public class ImageInfo { String comment = new String(chars, "iso-8859-1"); comment = comment.trim(); addComment(comment); - } else if (marker >= 0xffc0 && marker <= 0xffcf && marker != 0xffc4 && marker != 0xffc8) { + } + else + if (marker >= 0xffc0 && marker <= 0xffcf && marker != 0xffc4 && marker != 0xffc8) { if (read(data, 0, 6) != 6) { return false; } format = FORMAT_JPEG; bitsPerPixel = (data[0] & 0xff) * (data[5] & 0xff); progressive = marker == 0xffc2 || marker == 0xffc6 || - marker == 0xffca || marker == 0xffce; + marker == 0xffca || marker == 0xffce; width = getShortBigEndian(data, 3); height = getShortBigEndian(data, 1); return true; @@ -575,10 +585,11 @@ public class ImageInfo { int bits = a[1]; int planes = a[63]; if (planes == 1 && - (bits == 1 || bits == 2 || bits == 4 || bits == 8)) { + (bits == 1 || bits == 2 || bits == 4 || bits == 8)) { // paletted bitsPerPixel = bits; - } else if (planes == 3 && bits == 8) { + } else + if (planes == 3 && bits == 8) { // RGB truecolor bitsPerPixel = 24; } else { @@ -591,7 +602,7 @@ public class ImageInfo { } private boolean checkPng() throws IOException { - final byte[] PNG_MAGIC = { 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a }; + final byte[] PNG_MAGIC = {0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a}; byte[] a = new byte[27]; if (read(a) != 27) { return false; @@ -615,11 +626,12 @@ public class ImageInfo { if (id < 1 || id > 6) { return false; } - final int[] PNM_FORMATS = { FORMAT_PBM, FORMAT_PGM, FORMAT_PPM }; + final int[] PNM_FORMATS = {FORMAT_PBM, FORMAT_PGM, FORMAT_PPM}; format = PNM_FORMATS[(id - 1) % 3]; boolean hasPixelResolution = false; String s; - while (true) { + while (true) + { s = readLine(); if (s != null) { s = s.trim(); @@ -658,7 +670,9 @@ public class ImageInfo { return true; } hasPixelResolution = true; - } else { + } + else + { int maxSample; try { maxSample = Integer.parseInt(s); @@ -687,7 +701,7 @@ public class ImageInfo { if (read(a) != a.length) { return false; } - final byte[] PSD_MAGIC = { 0x50, 0x53 }; + final byte[] PSD_MAGIC = {0x50, 0x53}; if (!equals(a, 0, PSD_MAGIC, 0, 2)) { return false; } @@ -705,7 +719,7 @@ public class ImageInfo { if (read(a) != a.length) { return false; } - final byte[] RAS_MAGIC = { 0x6a, (byte) 0x95 }; + final byte[] RAS_MAGIC = {0x6a, (byte)0x95}; if (!equals(a, 0, RAS_MAGIC, 0, 2)) { return false; } @@ -718,18 +732,19 @@ public class ImageInfo { // Written by Michael Aird. private boolean checkSwf() throws IOException { - // get rid of the last byte of the signature, the byte of the version and 4 - // bytes of the size + //get rid of the last byte of the signature, the byte of the version and 4 bytes of the size byte[] a = new byte[6]; if (read(a) != a.length) { return false; } format = FORMAT_SWF; - int bitSize = (int) readUBits(5); - int maxX = (int) readSBits(bitSize); - int maxY = (int) readSBits(bitSize); - width = maxX / 20; // cause we're in twips - height = maxY / 20; // cause we're in twips + int bitSize = (int)readUBits( 5 ); + int minX = (int)readSBits( bitSize ); + int maxX = (int)readSBits( bitSize ); + int minY = (int)readSBits( bitSize ); + int maxY = (int)readSBits( bitSize ); + width = maxX/20; //cause we're in twips + height = maxY/20; //cause we're in twips setPhysicalWidthDpi(72); setPhysicalHeightDpi(72); return (width > 0 && height > 0); @@ -759,44 +774,39 @@ public class ImageInfo { return true; } - /** - * If {@link #check()} was successful, returns the image's number of bits per - * pixel. + /** + * If {@link #check()} was successful, returns the image's number of bits per pixel. * Does not include transparency information like the alpha channel. - * * @return number of bits per image pixel */ public int getBitsPerPixel() { return bitsPerPixel; } - /** - * @return number of colors, for palette based images - */ - public int getNumColors() { - return numColors; - } + /** + * @return number of colors, for palette based images + */ + public int getNumColors() { + return numColors; + } - /** + /** * Returns the index'th comment retrieved from the image. - * - * @throws IllegalArgumentException if index is smaller than 0 or larger than or - * equal - * to the number of comments retrieved + * @throws IllegalArgumentException if index is smaller than 0 or larger than or equal + * to the number of comments retrieved * @see #getNumberOfComments */ public String getComment(int index) { if (comments == null || index < 0 || index >= comments.size()) { throw new IllegalArgumentException("Not a valid comment index: " + index); } - return (String) comments.elementAt(index); + return (String)comments.elementAt(index); } /** * If {@link #check()} was successful, returns the image format as one * of the FORMAT_xyz constants from this class. * Use {@link #getFormatName()} to get a textual description of the file format. - * * @return file format as a FORMAT_xyz constant */ public int getFormat() { @@ -806,7 +816,6 @@ public class ImageInfo { /** * If {@link #check()} was successful, returns the image format's name. * Use {@link #getFormat()} to get a unique number. - * * @return file format name */ public String getFormatName() { @@ -817,10 +826,9 @@ public class ImageInfo { } } - /** + /** * If {@link #check()} was successful, returns one the image's vertical * resolution in pixels. - * * @return image height in pixels */ public int getHeight() { @@ -828,28 +836,30 @@ public class ImageInfo { } private int getIntBigEndian(byte[] a, int offs) { - return (a[offs] & 0xff) << 24 | - (a[offs + 1] & 0xff) << 16 | - (a[offs + 2] & 0xff) << 8 | - a[offs + 3] & 0xff; + return + (a[offs] & 0xff) << 24 | + (a[offs + 1] & 0xff) << 16 | + (a[offs + 2] & 0xff) << 8 | + a[offs + 3] & 0xff; } private int getIntLittleEndian(byte[] a, int offs) { - return (a[offs + 3] & 0xff) << 24 | - (a[offs + 2] & 0xff) << 16 | - (a[offs + 1] & 0xff) << 8 | - a[offs] & 0xff; + return + (a[offs + 3] & 0xff) << 24 | + (a[offs + 2] & 0xff) << 16 | + (a[offs + 1] & 0xff) << 8 | + a[offs] & 0xff; } - /** + /** * If {@link #check()} was successful, returns a String with the * MIME type of the format. - * * @return MIME type, e.g. image/jpeg */ public String getMimeType() { if (format >= 0 && format < MIME_TYPE_STRINGS.length) { - if (format == FORMAT_JPEG && progressive) { + if (format == FORMAT_JPEG && progressive) + { return "image/pjpeg"; } return MIME_TYPE_STRINGS[format]; @@ -859,16 +869,15 @@ public class ImageInfo { } /** - * If {@link #check()} was successful and {@link #setCollectComments(boolean)} - * was called with - * true as argument, returns the number of comments retrieved + * If {@link #check()} was successful and {@link #setCollectComments(boolean)} was called with + * true as argument, returns the number of comments retrieved * from the input image stream / file. * Any number >= 0 and smaller than this number of comments is then a * valid argument for the {@link #getComment(int)} method. - * * @return number of comments retrieved from input image */ - public int getNumberOfComments() { + public int getNumberOfComments() + { if (comments == null) { return 0; } else { @@ -880,12 +889,11 @@ public class ImageInfo { * Returns the number of images in the examined file. * Assumes that setDetermineImageNumber(true); was called before * a successful call to {@link #check()}. - * This value can currently be only different from 1 for GIF - * images. - * + * This value can currently be only different from 1 for GIF images. * @return number of images in file */ - public int getNumberOfImages() { + public int getNumberOfImages() + { return numberOfImages; } @@ -893,7 +901,6 @@ public class ImageInfo { * Returns the physical height of this image in dots per inch (dpi). * Assumes that {@link #check()} was successful. * Returns -1 on failure. - * * @return physical height (in dpi) * @see #getPhysicalWidthDpi() * @see #getPhysicalHeightInch() @@ -903,10 +910,8 @@ public class ImageInfo { } /** - * If {@link #check()} was successful, returns the physical width of this image - * in dpi (dots per inch) + * If {@link #check()} was successful, returns the physical width of this image in dpi (dots per inch) * or -1 if no value could be found. - * * @return physical height (in dpi) * @see #getPhysicalHeightDpi() * @see #getPhysicalWidthDpi() @@ -916,17 +921,15 @@ public class ImageInfo { int h = getHeight(); int ph = getPhysicalHeightDpi(); if (h > 0 && ph > 0) { - return ((float) h) / ((float) ph); + return ((float)h) / ((float)ph); } else { return -1.0f; } } /** - * If {@link #check()} was successful, returns the physical width of this image - * in dpi (dots per inch) + * If {@link #check()} was successful, returns the physical width of this image in dpi (dots per inch) * or -1 if no value could be found. - * * @return physical width (in dpi) * @see #getPhysicalHeightDpi() * @see #getPhysicalWidthInch() @@ -940,7 +943,6 @@ public class ImageInfo { * Returns the physical width of an image in inches, or * -1.0f if width information is not available. * Assumes that {@link #check} has been called successfully. - * * @return physical width in inches or -1.0f on failure * @see #getPhysicalWidthDpi * @see #getPhysicalHeightInch @@ -949,25 +951,25 @@ public class ImageInfo { int w = getWidth(); int pw = getPhysicalWidthDpi(); if (w > 0 && pw > 0) { - return ((float) w) / ((float) pw); + return ((float)w) / ((float)pw); } else { return -1.0f; } } private int getShortBigEndian(byte[] a, int offs) { - return (a[offs] & 0xff) << 8 | - (a[offs + 1] & 0xff); + return + (a[offs] & 0xff) << 8 | + (a[offs + 1] & 0xff); } private int getShortLittleEndian(byte[] a, int offs) { return (a[offs] & 0xff) | (a[offs + 1] & 0xff) << 8; } - /** + /** * If {@link #check()} was successful, returns one the image's horizontal * resolution in pixels. - * * @return image width in pixels */ public int getWidth() { @@ -975,22 +977,20 @@ public class ImageInfo { } /** - * Returns whether the image is stored in a progressive (also called: - * interlaced) way. - * + * Returns whether the image is stored in a progressive (also called: interlaced) way. * @return true for progressive/interlaced, false otherwise */ - public boolean isProgressive() { + public boolean isProgressive() + { return progressive; } /** - * To use this class as a command line application, give it either + * To use this class as a command line application, give it either * some file names as parameters (information on them will be * printed to standard output, one line per file) or call * it with no parameters. It will then check data given to it * via standard input. - * * @param args the program arguments which must be file names */ public static void main(String[] args) { @@ -1034,17 +1034,18 @@ public class ImageInfo { private static void printCompact(String sourceName, ImageInfo imageInfo) { System.out.println( - imageInfo.getFormatName() + ";" + - imageInfo.getMimeType() + ";" + - imageInfo.getWidth() + ";" + - imageInfo.getHeight() + ";" + - imageInfo.getBitsPerPixel() + ";" + - imageInfo.getNumberOfImages() + ";" + - imageInfo.getPhysicalWidthDpi() + ";" + - imageInfo.getPhysicalHeightDpi() + ";" + - imageInfo.getPhysicalWidthInch() + ";" + - imageInfo.getPhysicalHeightInch() + ";" + - imageInfo.isProgressive()); + imageInfo.getFormatName() + ";" + + imageInfo.getMimeType() + ";" + + imageInfo.getWidth() + ";" + + imageInfo.getHeight() + ";" + + imageInfo.getBitsPerPixel() + ";" + + imageInfo.getNumberOfImages() + ";" + + imageInfo.getPhysicalWidthDpi() + ";" + + imageInfo.getPhysicalHeightDpi() + ";" + + imageInfo.getPhysicalWidthInch() + ";" + + imageInfo.getPhysicalHeightInch() + ";" + + imageInfo.isProgressive() + ); } private static void printLine(int indentLevels, String text, float value, float minValidValue) { @@ -1132,19 +1133,20 @@ public class ImageInfo { int value = read(); finished = (value == -1 || value == 10); if (!finished) { - sb.append((char) value); + sb.append((char)value); } } while (!finished); return sb.toString(); } - private long readUBits(int numBits) throws IOException { + private long readUBits( int numBits ) throws IOException + { if (numBits == 0) { return 0; } int bitsLeft = numBits; long result = 0; - if (bitPos == 0) { // no value in the buffer - read a byte + if (bitPos == 0) { //no value in the buffer - read a byte if (in != null) { bitBuf = in.read(); } else { @@ -1152,46 +1154,64 @@ public class ImageInfo { } bitPos = 8; } + + while( true ) + { + int shift = bitsLeft - bitPos; + if( shift > 0 ) + { + // Consume the entire buffer + result |= bitBuf << shift; + bitsLeft -= bitPos; - while (true) { - int shift = bitsLeft - bitPos; - if (shift > 0) { - // Consume the entire buffer - result |= bitBuf << shift; - bitsLeft -= bitPos; + // Get the next byte from the input stream + if (in != null) { + bitBuf = in.read(); + } else { + bitBuf = din.readByte(); + } + bitPos = 8; + } + else + { + // Consume a portion of the buffer + result |= bitBuf >> -shift; + bitPos -= bitsLeft; + bitBuf &= 0xff >> (8 - bitPos); // mask off the consumed bits - // Get the next byte from the input stream - if (in != null) { - bitBuf = in.read(); - } else { - bitBuf = din.readByte(); - } - bitPos = 8; - } else { - // Consume a portion of the buffer - result |= bitBuf >> -shift; - bitPos -= bitsLeft; - bitBuf &= 0xff >> (8 - bitPos); // mask off the consumed bits + return result; + } + } + } + + /** + * Read a signed value from the given number of bits + */ + private int readSBits( int numBits ) throws IOException + { + // Get the number as an unsigned value. + long uBits = readUBits( numBits ); - return result; - } - } + // Is the number negative? + if( ( uBits & (1L << (numBits - 1))) != 0 ) + { + // Yes. Extend the sign. + uBits |= -1L << numBits; + } + + return (int)uBits; + } + + private void synchBits() + { + bitBuf = 0; + bitPos = 0; } - /** - * Read a signed value from the given number of bits - */ - private int readSBits(int numBits) throws IOException { - // Get the number as an unsigned value. - long uBits = readUBits(numBits); - - // Is the number negative? - if ((uBits & (1L << (numBits - 1))) != 0) { - // Yes. Extend the sign. - uBits |= -1L << numBits; - } - - return (int) uBits; + private String readLine(int firstChar) throws IOException { + StringBuffer result = new StringBuffer(); + result.append((char)firstChar); + return readLine(result); } private static void run(String sourceName, InputStream in, ImageInfo imageInfo, boolean verbose) { @@ -1207,12 +1227,12 @@ public class ImageInfo { * Specify whether textual comments are supposed to be extracted from input. * Default is false. * If enabled, comments will be added to an internal list. - * * @param newValue if true, this class will read comments * @see #getNumberOfComments * @see #getComment */ - public void setCollectComments(boolean newValue) { + public void setCollectComments(boolean newValue) + { collectComments = newValue; } @@ -1224,22 +1244,21 @@ public class ImageInfo { * task. * Not all file formats support more than one image. * If this method is called with true as argument, - * the actual number of images can be queried via + * the actual number of images can be queried via * {@link #getNumberOfImages()} after a successful call to * {@link #check()}. - * * @param newValue will the number of images be determined? * @see #getNumberOfImages */ - public void setDetermineImageNumber(boolean newValue) { + public void setDetermineImageNumber(boolean newValue) + { determineNumberOfImages = newValue; } /** - * Set the input stream to the argument stream (or file). + * Set the input stream to the argument stream (or file). * Note that {@link java.io.RandomAccessFile} implements * {@link java.io.DataInput}. - * * @param dataInput the input stream to read from */ public void setInput(DataInput dataInput) { @@ -1249,7 +1268,6 @@ public class ImageInfo { /** * Set the input stream to the argument stream (or file). - * * @param inputStream the input stream to read from */ public void setInput(InputStream inputStream) { diff --git a/src/main/java/helma/image/imageio/gif/GIFImageWriterSpi.java b/src/main/java/helma/image/imageio/gif/GIFImageWriterSpi.java index d2f349c0..778b7ce7 100644 --- a/src/main/java/helma/image/imageio/gif/GIFImageWriterSpi.java +++ b/src/main/java/helma/image/imageio/gif/GIFImageWriterSpi.java @@ -24,10 +24,9 @@ import java.io.*; import java.util.*; import javax.imageio.*; import javax.imageio.spi.*; -import javax.imageio.stream.ImageOutputStream; public class GIFImageWriterSpi extends ImageWriterSpi { - + public GIFImageWriterSpi() { super( "Helma Object Publisher, http://helma.org/", @@ -36,7 +35,7 @@ public class GIFImageWriterSpi extends ImageWriterSpi { new String[] {"gif", "GIF"}, new String[] {"image/gif", "image/x-gif"}, "helma.image.imageio.gif.GIFImageWriter", - new Class[] {ImageOutputStream.class}, + STANDARD_OUTPUT_TYPE, null, false, null, null, null, null, false, null, null, null, null @@ -56,4 +55,4 @@ public class GIFImageWriterSpi extends ImageWriterSpi { // FIXME handle # colors return true; } -} +} \ No newline at end of file diff --git a/src/main/java/helma/main/ApplicationManager.java b/src/main/java/helma/main/ApplicationManager.java index 7a8977bf..2deb88ee 100644 --- a/src/main/java/helma/main/ApplicationManager.java +++ b/src/main/java/helma/main/ApplicationManager.java @@ -36,9 +36,9 @@ import helma.util.StringUtils; * This class is responsible for starting and stopping Helma applications. */ public class ApplicationManager implements XmlRpcHandler { - private Hashtable descriptors; - private Hashtable applications; - private Hashtable xmlrpcHandlers; + private Hashtable descriptors; + private Hashtable applications; + private Hashtable xmlrpcHandlers; private ResourceProperties props; private Server server; private long lastModified; @@ -54,9 +54,9 @@ public class ApplicationManager implements XmlRpcHandler { public ApplicationManager(ResourceProperties props, Server server) { this.props = props; this.server = server; - this.descriptors = new Hashtable(); - this.applications = new Hashtable(); - this.xmlrpcHandlers = new Hashtable(); + this.descriptors = new Hashtable(); + this.applications = new Hashtable(); + this.xmlrpcHandlers = new Hashtable(); this.lastModified = 0; this.jetty = server.jetty; } @@ -68,10 +68,10 @@ public class ApplicationManager implements XmlRpcHandler { protected void checkForChanges() { if (this.props.lastModified() > this.lastModified && this.server.getApplicationsOption() == null) { try { - for (Enumeration e = this.props.keys(); e.hasMoreElements();) { + for (Enumeration e = this.props.keys(); e.hasMoreElements();) { String appName = (String) e.nextElement(); - if ((appName.indexOf(".") == -1) && + if ((appName.indexOf(".") == -1) && //$NON-NLS-1$ (this.applications.get(appName) == null)) { AppDescriptor appDesc = new AppDescriptor(appName); appDesc.start(); @@ -80,7 +80,7 @@ public class ApplicationManager implements XmlRpcHandler { } // then stop deleted ones - for (Enumeration e = this.descriptors.elements(); e.hasMoreElements();) { + for (Enumeration e = this.descriptors.elements(); e.hasMoreElements();) { AppDescriptor appDesc = (AppDescriptor) e.nextElement(); // check if application has been removed and should be stopped @@ -146,10 +146,10 @@ public class ApplicationManager implements XmlRpcHandler { desc.start(); } } else { - for (Enumeration e = this.props.keys(); e.hasMoreElements();) { + for (Enumeration e = this.props.keys(); e.hasMoreElements();) { String appName = (String) e.nextElement(); - if (appName.indexOf(".") == -1) { + if (appName.indexOf(".") == -1) { //$NON-NLS-1$ String appValue = this.props.getProperty(appName); if (appValue != null && appValue.length() > 0) { @@ -162,7 +162,7 @@ public class ApplicationManager implements XmlRpcHandler { } } - for (Enumeration e = this.descriptors.elements(); e.hasMoreElements();) { + for (Enumeration e = this.descriptors.elements(); e.hasMoreElements();) { AppDescriptor appDesc = (AppDescriptor) e.nextElement(); appDesc.bind(); } @@ -178,7 +178,7 @@ public class ApplicationManager implements XmlRpcHandler { * Stop all running applications. */ public void stopAll() { - for (Enumeration en = this.descriptors.elements(); en.hasMoreElements();) { + for (Enumeration en = this.descriptors.elements(); en.hasMoreElements();) { try { AppDescriptor appDesc = (AppDescriptor) en.nextElement(); @@ -206,9 +206,9 @@ public class ApplicationManager implements XmlRpcHandler { /** * Implements org.apache.xmlrpc.XmlRpcHandler.execute() */ - public Object execute(String method, @SuppressWarnings("rawtypes") Vector params) + public Object execute(String method, Vector params) throws Exception { - int dot = method.indexOf("."); + int dot = method.indexOf("."); //$NON-NLS-1$ if (dot == -1) { throw new Exception("Method name \"" + method + @@ -224,7 +224,7 @@ public class ApplicationManager implements XmlRpcHandler { Application app = (Application) this.xmlrpcHandlers.get(handler); if (app == null) { - app = (Application) this.xmlrpcHandlers.get("*"); + app = (Application) this.xmlrpcHandlers.get("*"); //$NON-NLS-1$ // use the original method name, the handler is resolved within the app. method2 = method; } @@ -239,32 +239,32 @@ public class ApplicationManager implements XmlRpcHandler { private String getMountpoint(String mountpoint) { mountpoint = mountpoint.trim(); - if ("".equals(mountpoint)) { - return "/"; - } else if (!mountpoint.startsWith("/")) { - return "/" + mountpoint; + if ("".equals(mountpoint)) { //$NON-NLS-1$ + return "/"; //$NON-NLS-1$ + } else if (!mountpoint.startsWith("/")) { //$NON-NLS-1$ + return "/" + mountpoint; //$NON-NLS-1$ } return mountpoint; } private String joinMountpoint(String prefix, String suffix) { - if (prefix.endsWith("/") || suffix.startsWith("/")) { + if (prefix.endsWith("/") || suffix.startsWith("/")) { //$NON-NLS-1$//$NON-NLS-2$ return prefix+suffix; } - return prefix+"/"+suffix; + return prefix+"/"+suffix; //$NON-NLS-1$ } private String getPathPattern(String mountpoint) { - if (!mountpoint.startsWith("/")) { - mountpoint = "/"+mountpoint; + if (!mountpoint.startsWith("/")) { //$NON-NLS-1$ + mountpoint = "/"+mountpoint; //$NON-NLS-1$ } - if ("/".equals(mountpoint)) { - return "/"; + if ("/".equals(mountpoint)) { //$NON-NLS-1$ + return "/"; //$NON-NLS-1$ } - if (mountpoint.endsWith("/")) { + if (mountpoint.endsWith("/")) { //$NON-NLS-1$ return mountpoint.substring(0, mountpoint.length()-1); } @@ -335,56 +335,56 @@ public class ApplicationManager implements XmlRpcHandler { AppDescriptor(String name) { ResourceProperties conf = ApplicationManager.this.props.getSubProperties(name + '.'); this.appName = name; - this.mountpoint = getMountpoint(conf.getProperty("mountpoint", this.appName)); + this.mountpoint = getMountpoint(conf.getProperty("mountpoint", this.appName)); //$NON-NLS-1$ this.pathPattern = getPathPattern(this.mountpoint); - this.staticDir = conf.getProperty("static"); - this.staticMountpoint = getPathPattern(conf.getProperty("staticMountpoint", - joinMountpoint(this.mountpoint, "static"))); - this.staticIndex = "true".equalsIgnoreCase(conf.getProperty("staticIndex")); - String home = conf.getProperty("staticHome"); + this.staticDir = conf.getProperty("static"); //$NON-NLS-1$ + this.staticMountpoint = getPathPattern(conf.getProperty("staticMountpoint", //$NON-NLS-1$ + joinMountpoint(this.mountpoint, "static"))); //$NON-NLS-1$ + this.staticIndex = "true".equalsIgnoreCase(conf.getProperty("staticIndex")); //$NON-NLS-1$//$NON-NLS-2$ + String home = conf.getProperty("staticHome"); //$NON-NLS-1$ if (home == null) { - this.staticHome = new String[] {"index.html", "index.htm"}; + this.staticHome = new String[] {"index.html", "index.htm"}; //$NON-NLS-1$ //$NON-NLS-2$ } else { - this.staticHome = StringUtils.split(home, ","); + this.staticHome = StringUtils.split(home, ","); //$NON-NLS-1$ } - this.protectedStaticDir = conf.getProperty("protectedStatic"); + this.protectedStaticDir = conf.getProperty("protectedStatic"); //$NON-NLS-1$ - this.cookieDomain = conf.getProperty("cookieDomain"); - this.sessionCookieName = conf.getProperty("sessionCookieName"); - this.protectedSessionCookie = conf.getProperty("protectedSessionCookie"); - this.uploadLimit = conf.getProperty("uploadLimit"); - this.uploadSoftfail = conf.getProperty("uploadSoftfail"); - this.debug = conf.getProperty("debug"); - String appDirName = conf.getProperty("appdir"); + this.cookieDomain = conf.getProperty("cookieDomain"); //$NON-NLS-1$ + this.sessionCookieName = conf.getProperty("sessionCookieName"); //$NON-NLS-1$ + this.protectedSessionCookie = conf.getProperty("protectedSessionCookie"); //$NON-NLS-1$ + this.uploadLimit = conf.getProperty("uploadLimit"); //$NON-NLS-1$ + this.uploadSoftfail = conf.getProperty("uploadSoftfail"); //$NON-NLS-1$ + this.debug = conf.getProperty("debug"); //$NON-NLS-1$ + String appDirName = conf.getProperty("appdir"); //$NON-NLS-1$ this.appDir = (appDirName == null) ? null : getAbsoluteFile(appDirName); - String dbDirName = conf.getProperty("dbdir"); + String dbDirName = conf.getProperty("dbdir"); //$NON-NLS-1$ this.dbDir = (dbDirName == null) ? null : getAbsoluteFile(dbDirName); - this.servletClassName = conf.getProperty("servletClass"); + this.servletClassName = conf.getProperty("servletClass"); //$NON-NLS-1$ // got ignore dirs - this.ignoreDirs = conf.getProperty("ignore"); + this.ignoreDirs = conf.getProperty("ignore"); //$NON-NLS-1$ // read and configure app repositories - ArrayList repositoryList = new ArrayList<>(); - Class[] parameters = { String.class }; + ArrayList repositoryList = new ArrayList(); + Class[] parameters = { String.class }; for (int i = 0; true; i++) { - String repositoryArgs = conf.getProperty("repository." + i); + String repositoryArgs = conf.getProperty("repository." + i); //$NON-NLS-1$ if (repositoryArgs != null) { // lookup repository implementation - String repositoryImpl = conf.getProperty("repository." + i + - ".implementation"); + String repositoryImpl = conf.getProperty("repository." + i + //$NON-NLS-1$ + ".implementation"); //$NON-NLS-1$ if (repositoryImpl == null) { // implementation not set manually, have to guess it - if (repositoryArgs.endsWith(".zip")) { + if (repositoryArgs.endsWith(".zip")) { //$NON-NLS-1$ repositoryArgs = findResource(repositoryArgs); - repositoryImpl = "helma.framework.repository.ZipRepository"; - } else if (repositoryArgs.endsWith(".js")) { + repositoryImpl = "helma.framework.repository.ZipRepository"; //$NON-NLS-1$ + } else if (repositoryArgs.endsWith(".js")) { //$NON-NLS-1$ repositoryArgs = findResource(repositoryArgs); - repositoryImpl = "helma.framework.repository.SingleFileRepository"; + repositoryImpl = "helma.framework.repository.SingleFileRepository"; //$NON-NLS-1$ } else { repositoryArgs = findResource(repositoryArgs); - repositoryImpl = "helma.framework.repository.FileRepository"; + repositoryImpl = "helma.framework.repository.FileRepository"; //$NON-NLS-1$ } } @@ -491,42 +491,41 @@ public class ApplicationManager implements XmlRpcHandler { rhandler.setResourceBase(staticContent.getPath()); rhandler.setWelcomeFiles(staticHome); - staticContext = new ContextHandler(staticMountpoint); - ApplicationManager.this.context.addHandler(staticContext); + staticContext = ApplicationManager.this.context.addContext(staticMountpoint, ""); //$NON-NLS-1$ staticContext.setHandler(rhandler); staticContext.start(); } appContext = new ServletContextHandler(context, pathPattern, true, true); - Class servletClass = servletClassName == null ? - EmbeddedServletClient.class : Class.forName(servletClassName).asSubclass(EmbeddedServletClient.class); + Class servletClass = servletClassName == null ? + EmbeddedServletClient.class : Class.forName(servletClassName); ServletHolder holder = new ServletHolder(servletClass); holder.setInitParameter("application", appName); appContext.addServlet(holder, "/*"); if (this.cookieDomain != null) { - holder.setInitParameter("cookieDomain", this.cookieDomain); + holder.setInitParameter("cookieDomain", this.cookieDomain); //$NON-NLS-1$ } if (this.sessionCookieName != null) { - holder.setInitParameter("sessionCookieName", this.sessionCookieName); + holder.setInitParameter("sessionCookieName", this.sessionCookieName); //$NON-NLS-1$ } if (this.protectedSessionCookie != null) { - holder.setInitParameter("protectedSessionCookie", this.protectedSessionCookie); + holder.setInitParameter("protectedSessionCookie", this.protectedSessionCookie); //$NON-NLS-1$ } if (this.uploadLimit != null) { - holder.setInitParameter("uploadLimit", this.uploadLimit); + holder.setInitParameter("uploadLimit", this.uploadLimit); //$NON-NLS-1$ } if (this.uploadSoftfail != null) { - holder.setInitParameter("uploadSoftfail", this.uploadSoftfail); + holder.setInitParameter("uploadSoftfail", this.uploadSoftfail); //$NON-NLS-1$ } if (this.debug != null) { - holder.setInitParameter("debug", this.debug); + holder.setInitParameter("debug", this.debug); //$NON-NLS-1$ } if (protectedStaticDir != null) { @@ -584,7 +583,7 @@ public class ApplicationManager implements XmlRpcHandler { @Override public String toString() { - return "[AppDescriptor "+this.app+"]"; + return "[AppDescriptor "+this.app+"]"; //$NON-NLS-1$ //$NON-NLS-2$ } } } diff --git a/src/main/java/helma/main/CommandlineRunner.java b/src/main/java/helma/main/CommandlineRunner.java index eac3e922..aeaaee1f 100644 --- a/src/main/java/helma/main/CommandlineRunner.java +++ b/src/main/java/helma/main/CommandlineRunner.java @@ -41,10 +41,10 @@ public class CommandlineRunner { ServerConfig config = new ServerConfig(); String commandStr = null; - Vector funcArgs = new Vector<>(); - + Vector funcArgs = new Vector(); + // get possible environment setting for helma home - if (System.getProperty("helma.home") != null) { + if (System.getProperty("helma.home")!=null) { config.setHomeDir(new File(System.getProperty("helma.home"))); } @@ -110,7 +110,7 @@ public class CommandlineRunner { server.shutdown(); } - + /** * print the usage hints and prefix them with a message. diff --git a/src/main/java/helma/main/HelmaSecurityManager.java b/src/main/java/helma/main/HelmaSecurityManager.java index 61dc57c1..aebf5400 100644 --- a/src/main/java/helma/main/HelmaSecurityManager.java +++ b/src/main/java/helma/main/HelmaSecurityManager.java @@ -30,13 +30,11 @@ import java.util.HashSet; * a utility method getApplication that can be used to determine * the name of the application trying to execute the action in question, if any. */ -@Deprecated -@SuppressWarnings("removal") public class HelmaSecurityManager extends SecurityManager { // The set of actions forbidden to application code. - // We are pretty permissive, forbidding only System.exit() + // We are pretty permissive, forbidding only System.exit() // and setting the security manager. - private final static HashSet forbidden = new HashSet<>(); + private final static HashSet forbidden = new HashSet(); static { forbidden.add("exitVM"); @@ -51,7 +49,7 @@ public class HelmaSecurityManager extends SecurityManager { public void checkPermission(Permission p) { if (p instanceof RuntimePermission) { if (forbidden.contains(p.getName())) { - Class[] classes = getClassContext(); + Class[] classes = getClassContext(); for (int i = 0; i < classes.length; i++) { if (classes[i].getClassLoader() instanceof AppClassLoader) { @@ -100,7 +98,7 @@ public class HelmaSecurityManager extends SecurityManager { * @param status ... */ public void checkExit(int status) { - Class[] classes = getClassContext(); + Class[] classes = getClassContext(); for (int i = 0; i < classes.length; i++) { if (classes[i].getClassLoader() instanceof AppClassLoader) { @@ -289,7 +287,7 @@ public class HelmaSecurityManager extends SecurityManager { * @param clazz ... * @param which ... */ - public void checkMemberAccess(Class clazz, int which) { + public void checkMemberAccess(Class clazz, int which) { } /** @@ -306,7 +304,7 @@ public class HelmaSecurityManager extends SecurityManager { * does not belong to any application. */ protected String getApplication() { - Class[] classes = getClassContext(); + Class[] classes = getClassContext(); for (int i = 0; i < classes.length; i++) { if (classes[i].getClassLoader() instanceof AppClassLoader) { diff --git a/src/main/java/helma/main/HelmaShutdownHook.java b/src/main/java/helma/main/HelmaShutdownHook.java index 696f1176..f3eff903 100644 --- a/src/main/java/helma/main/HelmaShutdownHook.java +++ b/src/main/java/helma/main/HelmaShutdownHook.java @@ -16,6 +16,9 @@ package helma.main; +import helma.util.*; +import org.apache.commons.logging.LogFactory; + /** * ShutdownHook that shuts down all running Helma applications on exit. */ diff --git a/src/main/java/helma/main/JettyServer.java b/src/main/java/helma/main/JettyServer.java index 6c777224..88ba8c10 100644 --- a/src/main/java/helma/main/JettyServer.java +++ b/src/main/java/helma/main/JettyServer.java @@ -21,7 +21,6 @@ import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.xml.XmlConfiguration; import java.net.URL; @@ -48,7 +47,7 @@ public class JettyServer { http = new org.eclipse.jetty.server.Server(); try { - XmlConfiguration config = new XmlConfiguration(Resource.newResource(url)); + XmlConfiguration config = new XmlConfiguration(url); config.configure(http); } catch (IOException e) { @@ -60,7 +59,7 @@ public class JettyServer { private JettyServer(InetSocketAddress webPort, Server server) throws IOException { - + http = new org.eclipse.jetty.server.Server(); // start embedded web server if port is specified @@ -74,7 +73,7 @@ public class JettyServer { connector.setHost(webPort.getAddress().getHostAddress()); connector.setPort(webPort.getPort()); connector.setIdleTimeout(30000); - // Removed deprecated method setSoLingerTime + connector.setSoLingerTime(-1); connector.setAcceptorPriorityDelta(0); connector.setAcceptQueueSize(0); diff --git a/src/main/java/helma/main/Server.java b/src/main/java/helma/main/Server.java index 62fabf3b..88d70db7 100644 --- a/src/main/java/helma/main/Server.java +++ b/src/main/java/helma/main/Server.java @@ -29,6 +29,8 @@ import java.io.*; import java.util.*; import java.net.*; +import helma.util.ResourceProperties; + /** * Helma server main class. */ @@ -65,14 +67,14 @@ public class Server implements Runnable { // explicitly listed hosts. public boolean paranoid; private ApplicationManager appManager; - private Vector extensions; + private Vector extensions; private Thread mainThread; // configuration ServerConfig config; // map of server-wide database sources - Hashtable dbSources; + Hashtable dbSources; // the embedded web server // protected Serve websrv; @@ -430,10 +432,10 @@ public class Server implements Runnable { // logger.debug("TimeZone = " + // TimeZone.getDefault().getDisplayName(Locale.getDefault())); - dbSources = new Hashtable(); + dbSources = new Hashtable(); // try to load the extensions - extensions = new Vector(); + extensions = new Vector(); if (sysProps.getProperty("extensions") != null) { initExtensions(); } @@ -450,8 +452,8 @@ public class Server implements Runnable { String extClassName = tok.nextToken().trim(); try { - Class extClass = Class.forName(extClassName).asSubclass(HelmaExtension.class); - HelmaExtension ext = (HelmaExtension) extClass.getDeclaredConstructor().newInstance(); + Class extClass = Class.forName(extClassName); + HelmaExtension ext = (HelmaExtension) extClass.newInstance(); ext.init(this); extensions.add(ext); logger.info("Loaded: " + extClassName); @@ -570,9 +572,7 @@ public class Server implements Runnable { String secManClass = sysProps.getProperty("securityManager"); if (secManClass != null) { - @SuppressWarnings("removal") SecurityManager secMan = (SecurityManager) Class.forName(secManClass) - .getDeclaredConstructor() .newInstance(); System.setSecurityManager(secMan); @@ -764,7 +764,7 @@ public class Server implements Runnable { * * @return ... */ - public Vector getExtensions() { + public Vector getExtensions() { return extensions; } @@ -805,3 +805,5 @@ public class Server implements Runnable { return new InetSocketAddress(addr, port); } } + + diff --git a/src/main/java/helma/objectmodel/TransientNode.java b/src/main/java/helma/objectmodel/TransientNode.java index 011f8a35..e1410e17 100644 --- a/src/main/java/helma/objectmodel/TransientNode.java +++ b/src/main/java/helma/objectmodel/TransientNode.java @@ -18,6 +18,7 @@ package helma.objectmodel; import helma.framework.IPathElement; import helma.framework.core.Application; +import helma.framework.core.RequestEvaluator; import helma.objectmodel.db.DbMapping; import helma.objectmodel.db.Relation; import helma.objectmodel.db.Node; @@ -63,8 +64,7 @@ public class TransientNode implements INode, Serializable { created = lastmodified = System.currentTimeMillis(); this.app=app; } - - @SuppressWarnings("unused") + private TransientNode() { app=null; } @@ -75,7 +75,7 @@ public class TransientNode implements INode, Serializable { public TransientNode(Application app, String n) { id = generateID(); name = (n == null || n.length() == 0) ? id : n; - // HACK - decrease creation and last-modified timestamp by 1 so we notice + // HACK - decrease creation and last-modified timestamp by 1 so we notice // modifications that take place immediately after object creation created = lastmodified = System.currentTimeMillis() - 1; this.app = app; @@ -378,7 +378,7 @@ public class TransientNode implements INode, Serializable { } private TransientProperty getProperty(String propname) { - TransientProperty prop = (propMap == null) ? null + TransientProperty prop = (propMap == null) ? null : (TransientProperty) propMap.get(correctPropertyName(propname)); // check if we have to create a virtual node @@ -601,7 +601,7 @@ public class TransientNode implements INode, Serializable { public synchronized void clearCacheNode() { cacheNode = null; } - + private String correctPropertyName(String propname) { return app.correctPropertyName(propname); } diff --git a/src/main/java/helma/objectmodel/db/NodeManager.java b/src/main/java/helma/objectmodel/db/NodeManager.java index 5ba0edcd..83187981 100644 --- a/src/main/java/helma/objectmodel/db/NodeManager.java +++ b/src/main/java/helma/objectmodel/db/NodeManager.java @@ -22,7 +22,6 @@ import helma.objectmodel.*; import helma.objectmodel.dom.XmlDatabase; import java.io.*; -import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.sql.*; import java.util.*; @@ -60,25 +59,19 @@ public final class NodeManager { * Initialize the NodeManager for the given dbHome and * application properties. An embedded database will be * created in dbHome if one doesn't already exist. - * @throws SecurityException - * @throws NoSuchMethodException - * @throws InvocationTargetException - * @throws IllegalArgumentException */ public void init(File dbHome, Properties props) throws DatabaseException, ClassNotFoundException, - IllegalAccessException, InstantiationException, - IllegalArgumentException, InvocationTargetException, - NoSuchMethodException, SecurityException { + IllegalAccessException, InstantiationException { String cacheImpl = props.getProperty("cacheimpl", "helma.util.CacheMap"); - cache = (ObjectCache) Class.forName(cacheImpl).getDeclaredConstructor().newInstance(); + cache = (ObjectCache) Class.forName(cacheImpl).newInstance(); cache.init(app); String idgenImpl = props.getProperty("idGeneratorImpl"); if (idgenImpl != null) { - idgen = (IDGenerator) Class.forName(idgenImpl).getDeclaredConstructor().newInstance(); + idgen = (IDGenerator) Class.forName(idgenImpl).newInstance(); idgen.init(app); } diff --git a/src/main/java/helma/objectmodel/db/SubnodeList.java b/src/main/java/helma/objectmodel/db/SubnodeList.java index f69fd10b..bec94317 100644 --- a/src/main/java/helma/objectmodel/db/SubnodeList.java +++ b/src/main/java/helma/objectmodel/db/SubnodeList.java @@ -32,12 +32,11 @@ public class SubnodeList implements Serializable { transient protected long lastSubnodeFetch = 0; transient protected long lastSubnodeChange = 0; - + /** * Hide/disable zero argument constructor for subclasses */ - @SuppressWarnings("unused") private SubnodeList() {} /** diff --git a/src/main/java/helma/objectmodel/db/Transactor.java b/src/main/java/helma/objectmodel/db/Transactor.java index 5e324c0e..74f5e5c7 100644 --- a/src/main/java/helma/objectmodel/db/Transactor.java +++ b/src/main/java/helma/objectmodel/db/Transactor.java @@ -463,6 +463,8 @@ public class Transactor { node.clearWriteLock(); } + long now = System.currentTimeMillis(); + // set last subnode change times in parent nodes for (Iterator i = parentNodes.iterator(); i.hasNext(); ) { Node node = (Node) i.next(); diff --git a/src/main/java/helma/scripting/ScriptingException.java b/src/main/java/helma/scripting/ScriptingException.java index 3a3d7b36..2505891b 100644 --- a/src/main/java/helma/scripting/ScriptingException.java +++ b/src/main/java/helma/scripting/ScriptingException.java @@ -23,12 +23,12 @@ import java.io.*; /** * The base class for wrapped exceptions thrown by invocation of the scripting engine. * If the wrapped exception is a RhinoException, the script stack trace will be - * prepended to the actual java stack trace in stack dumps. + * prepended to the actual java stack trace in stack dumps. */ public class ScriptingException extends Exception { private static final long serialVersionUID = -7191341724784015678L; - + String scriptStack = null; /** @@ -48,7 +48,14 @@ public class ScriptingException extends Exception { */ private void setScriptStack(Throwable cause) { if (cause instanceof RhinoException) { - scriptStack = ((RhinoException) cause).getScriptStackTrace(); + FilenameFilter filter = new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.endsWith(".js") || + name.endsWith(".hac") || + name.endsWith(".hsp"); + } + }; + scriptStack = ((RhinoException) cause).getScriptStackTrace(filter); } } @@ -99,4 +106,4 @@ public class ScriptingException extends Exception { } } -} +} \ No newline at end of file diff --git a/src/main/java/helma/scripting/rhino/CompiledOrInterpretedModuleScriptProvider.java b/src/main/java/helma/scripting/rhino/CompiledOrInterpretedModuleScriptProvider.java index 9aa8b0fd..cec1e359 100644 --- a/src/main/java/helma/scripting/rhino/CompiledOrInterpretedModuleScriptProvider.java +++ b/src/main/java/helma/scripting/rhino/CompiledOrInterpretedModuleScriptProvider.java @@ -48,11 +48,11 @@ public class CompiledOrInterpretedModuleScriptProvider extends StrongCachingModu // unlikely, but possible exception during loading the module script without compilation Exception exception; // get the application's optimization level - boolean interpretedMode = cx.isInterpretedMode(); - + int optimizationLevel = cx.getOptimizationLevel(); + try { // set the optimization level to not compile, but interpret - cx.setInterpretedMode(true); + cx.setOptimizationLevel(-1); // load the module script with the newly set optimization level ModuleScript moduleScript = super.getModuleScript(cx, moduleId, moduleUri, baseUri, paths); // return the module script @@ -62,12 +62,12 @@ public class CompiledOrInterpretedModuleScriptProvider extends StrongCachingModu exception = e; } finally { // re-set the optimization - cx.setInterpretedMode(interpretedMode); + cx.setOptimizationLevel(optimizationLevel); } - - // re-throw the exception catched when trying to load the module script without compilation + + // re-throw the exception catched when trying to load the module script without compilation throw exception; } } -} +} \ No newline at end of file diff --git a/src/main/java/helma/scripting/rhino/HopObjectCtor.java b/src/main/java/helma/scripting/rhino/HopObjectCtor.java index 8f0bfcf5..9bcbafb9 100644 --- a/src/main/java/helma/scripting/rhino/HopObjectCtor.java +++ b/src/main/java/helma/scripting/rhino/HopObjectCtor.java @@ -39,7 +39,7 @@ public class HopObjectCtor extends FunctionObject { static Method hopObjCtor; - static long collectionId = 0; + static long collectionId = 0; static { try { @@ -51,7 +51,7 @@ public class HopObjectCtor extends FunctionObject { } static final int attr = DONTENUM | PERMANENT; - + /** * Create and install a HopObject constructor. * Part of this is copied from o.m.j.FunctionObject.addAsConstructor(). @@ -149,7 +149,7 @@ public class HopObjectCtor extends FunctionObject { private static final long serialVersionUID = -8041352998956882647L; public GetById(Scriptable scope) { - ScriptRuntime.setFunctionProtoAndParent(this, Context.getCurrentContext(), scope); + ScriptRuntime.setFunctionProtoAndParent(this, scope); } /** @@ -187,7 +187,7 @@ public class HopObjectCtor extends FunctionObject { } public int getArity() { - return 1; + return 1; } public int getLength() { @@ -201,7 +201,7 @@ public class HopObjectCtor extends FunctionObject { private static final long serialVersionUID = -4046933261468527204L; public HopCollection(Scriptable scope) { - ScriptRuntime.setFunctionProtoAndParent(this, Context.getCurrentContext(), scope); + ScriptRuntime.setFunctionProtoAndParent(this, scope); } public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { diff --git a/src/main/java/helma/scripting/rhino/JSAdapter.java b/src/main/java/helma/scripting/rhino/JSAdapter.java index 62c02826..8ddcd9ec 100644 --- a/src/main/java/helma/scripting/rhino/JSAdapter.java +++ b/src/main/java/helma/scripting/rhino/JSAdapter.java @@ -67,7 +67,7 @@ import org.mozilla.javascript.*; * @author A. Sundararajan * @since 1.6 */ -public final class JSAdapter implements Function { +public final class JSAdapter implements Scriptable, Function { private JSAdapter(Scriptable obj) { setAdaptee(obj); } diff --git a/src/main/java/helma/scripting/rhino/JSONModuleSource.java b/src/main/java/helma/scripting/rhino/JSONModuleSource.java index 43ca208b..89a3c480 100644 --- a/src/main/java/helma/scripting/rhino/JSONModuleSource.java +++ b/src/main/java/helma/scripting/rhino/JSONModuleSource.java @@ -19,16 +19,16 @@ public class JSONModuleSource extends ModuleSource { @Override public Reader getReader() { StringBuffer content = new StringBuffer(); - content.append("module.exports = "); - + content.append("module.exports = "); //$NON-NLS-1$ + try { - content.append(IOUtils.toString(this.getUri().toURL().openStream(), "UTF-8")); + content.append(IOUtils.toString(this.getUri().toURL().openStream())); } catch (IOException e) { - content.append("null"); + content.append("null"); //$NON-NLS-1$ } - - content.append(";"); - + + content.append(";"); //$NON-NLS-1$ + return new StringReader(content.toString()); } diff --git a/src/main/java/helma/scripting/rhino/JavaObject.java b/src/main/java/helma/scripting/rhino/JavaObject.java index 2670858a..b2f92076 100644 --- a/src/main/java/helma/scripting/rhino/JavaObject.java +++ b/src/main/java/helma/scripting/rhino/JavaObject.java @@ -17,6 +17,7 @@ package helma.scripting.rhino; import helma.framework.core.*; +import helma.framework.ResponseTrans; import helma.framework.repository.Resource; import org.mozilla.javascript.*; import java.lang.reflect.Method; @@ -82,7 +83,7 @@ public class JavaObject extends NativeJavaObject { Skin skin = engine.toSkin(skinobj, protoName); if (skin != null) { - skin.render(engine.reval, javaObject, + skin.render(engine.reval, javaObject, (paramobj == Undefined.instance) ? null : paramobj); } @@ -147,7 +148,7 @@ public class JavaObject extends NativeJavaObject { return overload.containsKey(name) || super.has(name, start); } - /** + /** * Get a named property from this object. */ public Object get(String name, Scriptable start) { diff --git a/src/main/java/helma/scripting/rhino/NodeModulesProvider.java b/src/main/java/helma/scripting/rhino/NodeModulesProvider.java index b23b824f..4ee114de 100644 --- a/src/main/java/helma/scripting/rhino/NodeModulesProvider.java +++ b/src/main/java/helma/scripting/rhino/NodeModulesProvider.java @@ -73,7 +73,7 @@ public class NodeModulesProvider extends UrlModuleSourceProvider { // check if the file exists and is a file if (file.exists() && file.isFile()) { // check if the file is a JSON file - if (file.getAbsolutePath().toLowerCase().endsWith(".json")) { + if (file.getAbsolutePath().toLowerCase().endsWith(".json")) { //$NON-NLS-1$ // return a JSON module source return new JSONModuleSource(null, file.toURI(), base, validator); } else { @@ -83,7 +83,7 @@ public class NodeModulesProvider extends UrlModuleSourceProvider { } // lets assume the module is a JS file - file = new File(new File(uri).getPath() + ".js"); + file = new File(new File(uri).getPath() + ".js"); //$NON-NLS-1$ // check if a file.js exists and is a file if (file.exists() && file.isFile()) { // do what would have been done anyways @@ -91,7 +91,7 @@ public class NodeModulesProvider extends UrlModuleSourceProvider { } // lets assume the module is a JSON file - file = new File(new File(uri).getPath() + ".json"); + file = new File(new File(uri).getPath() + ".json"); //$NON-NLS-1$ // check if a file.json exists and is a file if (file.exists() && file.isFile()) { // return a JSON module source @@ -135,17 +135,17 @@ public class NodeModulesProvider extends UrlModuleSourceProvider { ModuleSource moduleSource; // lets assume that there is a "package.json" file in the directory - File packageFile = new File(directory, "package.json"); + File packageFile = new File(directory, "package.json"); //$NON-NLS-1$ // check if the there is a "package.json" file in the directory if (packageFile.exists() && packageFile.isFile()) { // parse the JSON file - JsonObject json = JsonParser - .parseString(new String(Files.readAllBytes(packageFile.toPath()))).getAsJsonObject(); + JsonObject json = new JsonParser() + .parse(new String(Files.readAllBytes(packageFile.toPath()))).getAsJsonObject(); // check if the JSON file defines a main JS file - if (json.has("main")) { + if (json.has("main")) { //$NON-NLS-1$ // get the main JS file, removing the filename extension - String main = FilenameUtils.removeExtension(json.get("main").getAsString()); + String main = FilenameUtils.removeExtension(json.get("main").getAsString()); //$NON-NLS-1$ // load as file moduleSource = this.loadAsFile(new File(directory, main).toURI(), base, validator); @@ -158,7 +158,7 @@ public class NodeModulesProvider extends UrlModuleSourceProvider { } // load as index - moduleSource = this.loadAsFile(new File(directory, "index").toURI(), base, validator); + moduleSource = this.loadAsFile(new File(directory, "index").toURI(), base, validator); //$NON-NLS-1$ // check if something was loaded if (moduleSource != null) { // return the loaded module source diff --git a/src/main/java/helma/scripting/rhino/RhinoCore.java b/src/main/java/helma/scripting/rhino/RhinoCore.java index bf90fac2..a4ef63a2 100644 --- a/src/main/java/helma/scripting/rhino/RhinoCore.java +++ b/src/main/java/helma/scripting/rhino/RhinoCore.java @@ -44,6 +44,7 @@ import org.mozilla.javascript.Undefined; import org.mozilla.javascript.WrapFactory; import org.mozilla.javascript.Wrapper; import org.mozilla.javascript.commonjs.module.RequireBuilder; +import org.mozilla.javascript.commonjs.module.provider.StrongCachingModuleScriptProvider; import org.mozilla.javascript.tools.debugger.ScopeProvider; import java.io.*; @@ -1232,7 +1233,7 @@ public final class RhinoCore implements ScopeProvider { protected void onContextCreated(Context cx) { cx.setWrapFactory(wrapper); - cx.setInterpretedMode(optLevel < 0); + cx.setOptimizationLevel(optLevel); cx.setInstructionObserverThreshold(10000); if (Context.isValidLanguageVersion(languageVersion)) { cx.setLanguageVersion(languageVersion); diff --git a/src/main/java/helma/scripting/rhino/SerializationProxy.java b/src/main/java/helma/scripting/rhino/SerializationProxy.java index b558a32b..75d93d56 100644 --- a/src/main/java/helma/scripting/rhino/SerializationProxy.java +++ b/src/main/java/helma/scripting/rhino/SerializationProxy.java @@ -25,7 +25,7 @@ import java.io.Serializable; /** * Serialization proxy/placeholder interface. This is used for - * for various Helma and Rhino related classes.. + * for various Helma and Rhino related classes.. */ public interface SerializationProxy extends Serializable { public Object getObject(RhinoEngine engine); @@ -49,21 +49,19 @@ class ScriptBeanProxy implements SerializationProxy { * @return the object represented by this proxy */ public Object getObject(RhinoEngine engine) { - Object object = null; - try { - object = engine.global.get(name, engine.global); + Object object = engine.global.get(name, engine.global); } catch (Exception e) { System.out.println(name); } - - return object; + + return engine.global.get(name, engine.global); } } /** * Serialization proxy for the application object. - * + * * @author Daniel Ruthardt * @since 20170918 */ diff --git a/src/main/java/helma/scripting/rhino/debug/Profiler.java b/src/main/java/helma/scripting/rhino/debug/Profiler.java index 37a8a7ab..cd6d5c96 100644 --- a/src/main/java/helma/scripting/rhino/debug/Profiler.java +++ b/src/main/java/helma/scripting/rhino/debug/Profiler.java @@ -151,9 +151,7 @@ public class Profiler implements Debugger { name.substring(prefixLength) }; formatter.format("%1$7d ms %2$5d ms %3$6d %4$s%n", args); - String result = formatter.toString(); - formatter.close(); - return result; + return formatter.toString(); } } } diff --git a/src/main/java/helma/scripting/rhino/debug/Tracer.java b/src/main/java/helma/scripting/rhino/debug/Tracer.java index 18881307..81a9d29a 100644 --- a/src/main/java/helma/scripting/rhino/debug/Tracer.java +++ b/src/main/java/helma/scripting/rhino/debug/Tracer.java @@ -13,10 +13,11 @@ * $Revision$ * $Date$ */ - + package helma.scripting.rhino.debug; import helma.framework.ResponseTrans; +import helma.util.HtmlEncoder; import org.mozilla.javascript.*; import org.mozilla.javascript.debug.*; import java.util.ArrayList; @@ -84,7 +85,7 @@ public class Tracer implements Debugger { * Called when execution is ready to start bytecode interpretation * for entered a particular function or script. */ - public void onEnter(Context cx, Scriptable activation, + public void onEnter(Context cx, Scriptable activation, Scriptable thisObj, Object[] args) { time = System.currentTimeMillis(); @@ -127,7 +128,7 @@ public class Tracer implements Debugger { // Simplify Trace by dropping fast invocations. May be useful when looking // looking for bottlenecks, but not when trying to find out wtf is going on // if (time <= 1) - // return; + // return; StringBuffer b = new StringBuffer("Trace: "); for (int i = 0; i < depth; i++) b.append(". "); diff --git a/src/main/java/helma/scripting/rhino/extensions/DatabaseObject.java b/src/main/java/helma/scripting/rhino/extensions/DatabaseObject.java index 1dc9a3b8..0a5c180e 100644 --- a/src/main/java/helma/scripting/rhino/extensions/DatabaseObject.java +++ b/src/main/java/helma/scripting/rhino/extensions/DatabaseObject.java @@ -25,7 +25,6 @@ import java.util.Enumeration; import java.util.Vector; import java.io.IOException; import java.io.Reader; -import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.sql.*; @@ -63,13 +62,9 @@ public class DatabaseObject { * Create a new database object based on a driver name, with driver on the classpath * * @param driverName The class name of the JDBC driver - * @throws SecurityException - * @throws NoSuchMethodException - * @throws InvocationTargetException - * @throws IllegalArgumentException */ - DatabaseObject(String driverName) throws IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + DatabaseObject(String driverName) { this.driverName = driverName; try { Class driverClass = Class.forName(driverName); @@ -78,7 +73,7 @@ public class DatabaseObject { // System.err.println("##Bad class " + driverClass); lastError = new RuntimeException("Class " + driverClass + " is not a JDBC driver"); } - driverClass.getDeclaredConstructor().newInstance(); // may be needed by some drivers, harmless for others + driverClass.newInstance(); // may be needed by some drivers, harmless for others } catch (ClassNotFoundException e) { // System.err.println("##Cannot find driver class: " + e); // e.printStackTrace(); @@ -453,6 +448,51 @@ public class DatabaseObject { return null; } + /* FIXME: dunno if this method is still used somewhere + public Object getProperty(String propertyName, int hash) { + //System.err.println(" &&& Getting property '" + propertyName + "'"); + + // Length property is firsy checked + + // First return system or or prototype properties + if (propertyName.equals("length")) { + return Integer.valueOf(colNames.size()); + } else { + if (resultSet == null) { + lastError = new SQLException("Attempt to access a released result set"); + return null; + } + if (!firstRowSeen) { + lastError = new SQLException("Attempt to access data before the first row is read"); + return null; + } + try { + int index = -1; // indicates not a valid index value + try { + char c = propertyName.charAt(0); + if ('0' <= c && c <= '9') { + index = Integer.parseInt(propertyName); + } + } catch (NumberFormatException e) { + } catch (StringIndexOutOfBoundsException e) { // for charAt + } + if (index>=0) { + return getProperty(index); + } + Object value = resultSet.getObject(propertyName); + // IServer.getLogger().log("&& @VALUE : " + value); + lastError = null; + return value; + } catch (SQLException e) { + // System.err.println("##Cannot get property '" + propertyName + "' " + e); + // e.printStackTrace(); + lastError = e; + } + } + return null; + } + */ + public Object getProperty(int index) { if (!firstRowSeen) { lastError = new SQLException("Attempt to access data before the first row is read"); diff --git a/src/main/java/helma/scripting/rhino/extensions/MailObject.java b/src/main/java/helma/scripting/rhino/extensions/MailObject.java index 724c455e..2b2eaf07 100644 --- a/src/main/java/helma/scripting/rhino/extensions/MailObject.java +++ b/src/main/java/helma/scripting/rhino/extensions/MailObject.java @@ -39,7 +39,7 @@ import javax.mail.internet.MimeUtility; * A JavaScript wrapper around a JavaMail message class to send * mail via SMTP from Helma */ -public class MailObject extends ScriptableObject { +public class MailObject extends ScriptableObject implements Serializable { private static final long serialVersionUID = -4834981850233741039L; diff --git a/src/main/java/helma/scripting/rhino/extensions/XmlObject.java b/src/main/java/helma/scripting/rhino/extensions/XmlObject.java index 2ed32b46..3f7d4a0e 100644 --- a/src/main/java/helma/scripting/rhino/extensions/XmlObject.java +++ b/src/main/java/helma/scripting/rhino/extensions/XmlObject.java @@ -126,9 +126,7 @@ public class XmlObject { writer.setDatabaseMode(dbmode); writer.write(node); writer.flush(); - String result = out.toString("UTF-8"); - writer.close(); - return result; + return out.toString("UTF-8"); } /** diff --git a/src/main/java/helma/servlet/AbstractServletClient.java b/src/main/java/helma/servlet/AbstractServletClient.java index 15483425..3e3b3f59 100644 --- a/src/main/java/helma/servlet/AbstractServletClient.java +++ b/src/main/java/helma/servlet/AbstractServletClient.java @@ -217,7 +217,7 @@ public abstract class AbstractServletClient extends HttpServlet { parseParameters(request, reqtrans, encoding); // read file uploads - List uploads = null; + List uploads = null; ServletRequestContext reqcx = new ServletRequestContext(request); if (ServletFileUpload.isMultipartContent(reqcx)) { @@ -517,9 +517,9 @@ public abstract class AbstractServletClient extends HttpServlet { checksum[i] = (byte) (n); n >>>= 8; } - String etag = "\"" + new String(Base64.encodeBase64(checksum)) + "\""; - res.setHeader("ETag", etag); - String etagHeader = req.getHeader("If-None-Match"); + String etag = "\"" + new String(Base64.encodeBase64(checksum)) + "\""; //$NON-NLS-1$//$NON-NLS-2$ + res.setHeader("ETag", etag); //$NON-NLS-1$ + String etagHeader = req.getHeader("If-None-Match"); //$NON-NLS-1$ if (etagHeader != null) { StringTokenizer st = new StringTokenizer(etagHeader, ", \r\n"); while (st.hasMoreTokens()) { @@ -637,7 +637,7 @@ public abstract class AbstractServletClient extends HttpServlet { * Put name and value pair in map. When name already exist, add value * to array of values. */ - private static void putMapEntry(Map map, String name, String value) { + private static void putMapEntry(Map map, String name, String value) { String[] newValues = null; String[] oldValues = (String[]) map.get(name); @@ -653,9 +653,9 @@ public abstract class AbstractServletClient extends HttpServlet { map.put(name, newValues); } - protected List parseUploads(ServletRequestContext reqcx, RequestTrans reqtrans, - final UploadStatus uploadStatus, String encoding) - throws FileUploadException, UnsupportedEncodingException { + protected List parseUploads(ServletRequestContext reqcx, RequestTrans reqtrans, + final UploadStatus uploadStatus, String encoding) + throws FileUploadException, UnsupportedEncodingException { // handle file upload DiskFileItemFactory factory = new DiskFileItemFactory(); FileUpload upload = new FileUpload(factory); @@ -672,8 +672,8 @@ public abstract class AbstractServletClient extends HttpServlet { }); } - List uploads = upload.parseRequest(reqcx); - Iterator it = uploads.iterator(); + List uploads = upload.parseRequest(reqcx); + Iterator it = uploads.iterator(); while (it.hasNext()) { FileItem item = (FileItem) it.next(); @@ -705,7 +705,7 @@ public abstract class AbstractServletClient extends HttpServlet { return; } - HashMap parameters = new HashMap<>(); + HashMap parameters = new HashMap(); // Parse any query string parameters from the request if (queryString != null) { @@ -764,7 +764,7 @@ public abstract class AbstractServletClient extends HttpServlet { * * @exception UnsupportedEncodingException if the data is malformed */ - public static void parseParameters(Map map, byte[] data, String encoding, boolean isPost) + public static void parseParameters(Map map, byte[] data, String encoding, boolean isPost) throws UnsupportedEncodingException { if ((data != null) && (data.length > 0)) { int ix = 0; diff --git a/src/main/java/helma/servlet/EmbeddedServletClient.java b/src/main/java/helma/servlet/EmbeddedServletClient.java index 5723cb65..80b3cd6e 100644 --- a/src/main/java/helma/servlet/EmbeddedServletClient.java +++ b/src/main/java/helma/servlet/EmbeddedServletClient.java @@ -16,6 +16,7 @@ package helma.servlet; +import helma.framework.*; import helma.framework.core.Application; import helma.main.*; import javax.servlet.*; diff --git a/src/main/java/helma/util/CryptResource.java b/src/main/java/helma/util/CryptResource.java index c882a85e..7a7d5ab4 100644 --- a/src/main/java/helma/util/CryptResource.java +++ b/src/main/java/helma/util/CryptResource.java @@ -23,6 +23,7 @@ import java.util.StringTokenizer; import org.apache.commons.codec.digest.DigestUtils; +import helma.framework.repository.Resource; import helma.framework.repository.Resource; /**