From 7293879ec0ab50f0e79746ec134075c32123d9e2 Mon Sep 17 00:00:00 2001 From: mchung Date: Wed, 12 May 2010 14:41:10 -0700 Subject: 6951661: Eliminate jvmstat dependency on sun.management.counter Summary: jvmstat keeps its own copy of Units and Variability class Reviewed-by: alanb --- .../sun/jvmstat/monitor/AbstractMonitor.java | 3 - src/share/classes/sun/jvmstat/monitor/Monitor.java | 3 - src/share/classes/sun/jvmstat/monitor/Units.java | 128 +++++++++++++++++++++ .../classes/sun/jvmstat/monitor/Variability.java | 111 ++++++++++++++++++ .../perfdata/monitor/PerfByteArrayMonitor.java | 2 - .../perfdata/monitor/PerfIntegerMonitor.java | 2 - .../jvmstat/perfdata/monitor/PerfLongMonitor.java | 2 - .../monitor/PerfStringConstantMonitor.java | 1 - .../perfdata/monitor/PerfStringMonitor.java | 2 - .../monitor/PerfStringVariableMonitor.java | 1 - .../perfdata/monitor/v1_0/PerfDataBuffer.java | 2 - .../perfdata/monitor/v2_0/PerfDataBuffer.java | 2 - .../sun/tools/jstat/ExpressionResolver.java | 1 - src/share/classes/sun/tools/jstat/JStatLogger.java | 2 - src/share/classes/sun/tools/jstat/Jstat.java | 2 - 15 files changed, 239 insertions(+), 25 deletions(-) create mode 100644 src/share/classes/sun/jvmstat/monitor/Units.java create mode 100644 src/share/classes/sun/jvmstat/monitor/Variability.java (limited to 'src/share') diff --git a/src/share/classes/sun/jvmstat/monitor/AbstractMonitor.java b/src/share/classes/sun/jvmstat/monitor/AbstractMonitor.java index f8a92e25f..9dd898771 100644 --- a/src/share/classes/sun/jvmstat/monitor/AbstractMonitor.java +++ b/src/share/classes/sun/jvmstat/monitor/AbstractMonitor.java @@ -25,9 +25,6 @@ package sun.jvmstat.monitor; -import sun.management.counter.Units; -import sun.management.counter.Variability; - /** * The base class for Instrumentation Monitoring Objects. This base class * provides implementations of the {@link Monitor} methods that are common diff --git a/src/share/classes/sun/jvmstat/monitor/Monitor.java b/src/share/classes/sun/jvmstat/monitor/Monitor.java index 071a29b27..0d5dbadc8 100644 --- a/src/share/classes/sun/jvmstat/monitor/Monitor.java +++ b/src/share/classes/sun/jvmstat/monitor/Monitor.java @@ -25,9 +25,6 @@ package sun.jvmstat.monitor; -import sun.management.counter.Units; -import sun.management.counter.Variability; - /** * Interface provided by Instrumentation Monitoring Objects. * diff --git a/src/share/classes/sun/jvmstat/monitor/Units.java b/src/share/classes/sun/jvmstat/monitor/Units.java new file mode 100644 index 000000000..5e632196d --- /dev/null +++ b/src/share/classes/sun/jvmstat/monitor/Units.java @@ -0,0 +1,128 @@ +/* + * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package sun.jvmstat.monitor; + +/** + * Provides a typesafe enumeration for describing units of measurement + * attribute for instrumentation objects. + * + * @author Brian Doherty + */ +public class Units implements java.io.Serializable { + + /* The enumeration values for this typesafe enumeration must be + * kept in synchronization with the Units enum in the perfData.hpp file + * in the HotSpot source base. + */ + + private static final int NUNITS=8; + + private static Units[] map = new Units[NUNITS]; + + private final String name; + private final int value; + + /** + * An Invalid Units value. + */ + public static final Units INVALID = new Units("Invalid", 0); + + /** + * Units attribute representing unit-less quantities. + */ + public static final Units NONE = new Units("None", 1); + + /** + * Units attribute representing Bytes. + */ + public static final Units BYTES = new Units("Bytes", 2); + + /** + * Units attribute representing Ticks. + */ + public static final Units TICKS = new Units("Ticks", 3); + + /** + * Units attribute representing a count of events. + */ + public static final Units EVENTS = new Units("Events", 4); + + /** + * Units attribute representing String data. Although not really + * a unit of measure, this Units value serves to distinguish String + * instrumentation objects from instrumentation objects of other types. + */ + public static final Units STRING = new Units("String", 5); + + /** + * Units attribute representing Hertz (frequency). + */ + public static final Units HERTZ = new Units("Hertz", 6); + + /** + * Returns a string describing this Unit of measurement attribute + * + * @return String - a descriptive string for this enum. + */ + public String toString() { + return name; + } + + /** + * Returns the integer representation of this Units attribute + * + * @return int - an integer representation of this Units attribute. + */ + public int intValue() { + return value; + } + + /** + * Maps an integer value to its corresponding Units attribute. + * If the integer value does not have a corresponding Units enum + * value, then {@link Units#INVALID} is returned. + * + * @param value an integer representation of counter Units + * @return Units - the Units object for the given value + * or {@link Units#INVALID} if out of range. + */ + public static Units toUnits(int value) { + + if (value < 0 || value >= map.length || map[value] == null) { + return INVALID; + } + + return map[value]; + } + + private Units(String name, int value) { + this.name = name; + this.value = value; + map[value] = this; + } + + private static final long serialVersionUID = 6992337162326171013L; +} diff --git a/src/share/classes/sun/jvmstat/monitor/Variability.java b/src/share/classes/sun/jvmstat/monitor/Variability.java new file mode 100644 index 000000000..1323226d4 --- /dev/null +++ b/src/share/classes/sun/jvmstat/monitor/Variability.java @@ -0,0 +1,111 @@ +/* + * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package sun.jvmstat.monitor; + +/** + * Provides a typesafe enumeration for the Variability attribute for + * instrumentation objects. + * + * @author Brian Doherty + */ +public class Variability implements java.io.Serializable { + + /* The enumeration values for this typesafe enumeration must be + * kept in synchronization with the Variability enum in the perfData.hpp file + * in the HotSpot source base. + */ + + private static final int NATTRIBUTES = 4; + private static Variability[] map = new Variability[NATTRIBUTES]; + + private String name; + private int value; + + /** + * An invalid Variablity value. + */ + public static final Variability INVALID = new Variability("Invalid",0); + + /** + * Variability attribute representing Constant counters. + */ + public static final Variability CONSTANT = new Variability("Constant",1); + + /** + * Variability attribute representing a Monotonically changing counters. + */ + public static final Variability MONOTONIC = new Variability("Monotonic",2); + + /** + * Variability attribute representing Variable counters. + */ + public static final Variability VARIABLE = new Variability("Variable",3); + + /** + * Returns a string describing this Variability attribute. + * + * @return String - a descriptive string for this enum. + */ + public String toString() { + return name; + } + + /** + * Returns the integer representation of this Variability attribute. + * + * @return int - an integer representation of this Variability attribute. + */ + public int intValue() { + return value; + } + + /** + * Maps an integer value its corresponding Variability attribute. + * If the integer value does not have a corresponding Variability enum + * value, the {@link Variability#INVALID} is returned + * + * @param value an integer representation of a Variability attribute + * @return Variability - The Variability object for the given + * value or {@link Variability#INVALID} + * if out of range. + */ + public static Variability toVariability(int value) { + + if (value < 0 || value >= map.length || map[value] == null) { + return INVALID; + } + + return map[value]; + } + + private Variability(String name, int value) { + this.name = name; + this.value = value; + map[value]=this; + } + + private static final long serialVersionUID = 6992337162326171013L; +} diff --git a/src/share/classes/sun/jvmstat/perfdata/monitor/PerfByteArrayMonitor.java b/src/share/classes/sun/jvmstat/perfdata/monitor/PerfByteArrayMonitor.java index 39b3d35b3..15832778a 100644 --- a/src/share/classes/sun/jvmstat/perfdata/monitor/PerfByteArrayMonitor.java +++ b/src/share/classes/sun/jvmstat/perfdata/monitor/PerfByteArrayMonitor.java @@ -26,8 +26,6 @@ package sun.jvmstat.perfdata.monitor; import sun.jvmstat.monitor.*; -import sun.management.counter.Units; -import sun.management.counter.Variability; import java.nio.ByteBuffer; /** diff --git a/src/share/classes/sun/jvmstat/perfdata/monitor/PerfIntegerMonitor.java b/src/share/classes/sun/jvmstat/perfdata/monitor/PerfIntegerMonitor.java index 4730c3b5d..b69d7c6e0 100644 --- a/src/share/classes/sun/jvmstat/perfdata/monitor/PerfIntegerMonitor.java +++ b/src/share/classes/sun/jvmstat/perfdata/monitor/PerfIntegerMonitor.java @@ -26,8 +26,6 @@ package sun.jvmstat.perfdata.monitor; import sun.jvmstat.monitor.*; -import sun.management.counter.Units; -import sun.management.counter.Variability; import java.nio.IntBuffer; /** diff --git a/src/share/classes/sun/jvmstat/perfdata/monitor/PerfLongMonitor.java b/src/share/classes/sun/jvmstat/perfdata/monitor/PerfLongMonitor.java index c73073755..e8948b0b6 100644 --- a/src/share/classes/sun/jvmstat/perfdata/monitor/PerfLongMonitor.java +++ b/src/share/classes/sun/jvmstat/perfdata/monitor/PerfLongMonitor.java @@ -26,8 +26,6 @@ package sun.jvmstat.perfdata.monitor; import sun.jvmstat.monitor.*; -import sun.management.counter.Units; -import sun.management.counter.Variability; import java.nio.LongBuffer; /** diff --git a/src/share/classes/sun/jvmstat/perfdata/monitor/PerfStringConstantMonitor.java b/src/share/classes/sun/jvmstat/perfdata/monitor/PerfStringConstantMonitor.java index e20611230..f34376d39 100644 --- a/src/share/classes/sun/jvmstat/perfdata/monitor/PerfStringConstantMonitor.java +++ b/src/share/classes/sun/jvmstat/perfdata/monitor/PerfStringConstantMonitor.java @@ -26,7 +26,6 @@ package sun.jvmstat.perfdata.monitor; import sun.jvmstat.monitor.*; -import sun.management.counter.Variability; import java.nio.ByteBuffer; /** diff --git a/src/share/classes/sun/jvmstat/perfdata/monitor/PerfStringMonitor.java b/src/share/classes/sun/jvmstat/perfdata/monitor/PerfStringMonitor.java index 2119db994..0f1b5c4c2 100644 --- a/src/share/classes/sun/jvmstat/perfdata/monitor/PerfStringMonitor.java +++ b/src/share/classes/sun/jvmstat/perfdata/monitor/PerfStringMonitor.java @@ -26,8 +26,6 @@ package sun.jvmstat.perfdata.monitor; import sun.jvmstat.monitor.*; -import sun.management.counter.Units; -import sun.management.counter.Variability; import java.nio.ByteBuffer; import java.nio.charset.Charset; diff --git a/src/share/classes/sun/jvmstat/perfdata/monitor/PerfStringVariableMonitor.java b/src/share/classes/sun/jvmstat/perfdata/monitor/PerfStringVariableMonitor.java index fece6d9a6..252a5204b 100644 --- a/src/share/classes/sun/jvmstat/perfdata/monitor/PerfStringVariableMonitor.java +++ b/src/share/classes/sun/jvmstat/perfdata/monitor/PerfStringVariableMonitor.java @@ -26,7 +26,6 @@ package sun.jvmstat.perfdata.monitor; import sun.jvmstat.monitor.*; -import sun.management.counter.Variability; import java.nio.ByteBuffer; /** diff --git a/src/share/classes/sun/jvmstat/perfdata/monitor/v1_0/PerfDataBuffer.java b/src/share/classes/sun/jvmstat/perfdata/monitor/v1_0/PerfDataBuffer.java index a823ca68d..fea037d02 100644 --- a/src/share/classes/sun/jvmstat/perfdata/monitor/v1_0/PerfDataBuffer.java +++ b/src/share/classes/sun/jvmstat/perfdata/monitor/v1_0/PerfDataBuffer.java @@ -25,8 +25,6 @@ package sun.jvmstat.perfdata.monitor.v1_0; -import sun.management.counter.Units; -import sun.management.counter.Variability; import sun.jvmstat.monitor.*; import sun.jvmstat.perfdata.monitor.*; import java.util.*; diff --git a/src/share/classes/sun/jvmstat/perfdata/monitor/v2_0/PerfDataBuffer.java b/src/share/classes/sun/jvmstat/perfdata/monitor/v2_0/PerfDataBuffer.java index b090bc220..77b3c1a08 100644 --- a/src/share/classes/sun/jvmstat/perfdata/monitor/v2_0/PerfDataBuffer.java +++ b/src/share/classes/sun/jvmstat/perfdata/monitor/v2_0/PerfDataBuffer.java @@ -27,8 +27,6 @@ package sun.jvmstat.perfdata.monitor.v2_0; import sun.jvmstat.monitor.*; import sun.jvmstat.perfdata.monitor.*; -import sun.management.counter.Units; -import sun.management.counter.Variability; import java.util.*; import java.util.regex.*; import java.nio.*; diff --git a/src/share/classes/sun/tools/jstat/ExpressionResolver.java b/src/share/classes/sun/tools/jstat/ExpressionResolver.java index e53361350..f6006d64f 100644 --- a/src/share/classes/sun/tools/jstat/ExpressionResolver.java +++ b/src/share/classes/sun/tools/jstat/ExpressionResolver.java @@ -26,7 +26,6 @@ package sun.tools.jstat; import sun.jvmstat.monitor.*; -import sun.management.counter.Variability; /** * A class implementing the ExpressionEvaluator to resolve unresolved diff --git a/src/share/classes/sun/tools/jstat/JStatLogger.java b/src/share/classes/sun/tools/jstat/JStatLogger.java index 077dd9009..671f1c289 100644 --- a/src/share/classes/sun/tools/jstat/JStatLogger.java +++ b/src/share/classes/sun/tools/jstat/JStatLogger.java @@ -29,8 +29,6 @@ import java.util.*; import java.io.*; import sun.jvmstat.monitor.*; import sun.jvmstat.monitor.event.*; -import sun.management.counter.Units; -import sun.management.counter.Variability; import java.util.regex.PatternSyntaxException; /** diff --git a/src/share/classes/sun/tools/jstat/Jstat.java b/src/share/classes/sun/tools/jstat/Jstat.java index 43cbaa29a..c778212d0 100644 --- a/src/share/classes/sun/tools/jstat/Jstat.java +++ b/src/share/classes/sun/tools/jstat/Jstat.java @@ -28,8 +28,6 @@ package sun.tools.jstat; import java.util.*; import sun.jvmstat.monitor.*; import sun.jvmstat.monitor.event.*; -import sun.management.counter.Variability; -import sun.management.counter.Units; /** * Application to output jvmstat statistics exported by a target Java -- cgit v1.2.3 From 22ae01026f3c24a6591d4f67d5af56d68df567bd Mon Sep 17 00:00:00 2001 From: sherman Date: Thu, 13 May 2010 21:30:18 -0700 Subject: 6951064: Typo in javadoc for ZipException ctors Summary: fixed the doc typo Reviewed-by: martin --- src/share/classes/java/util/zip/ZipException.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/java/util/zip/ZipException.java b/src/share/classes/java/util/zip/ZipException.java index a5dbc12a1..bb9001d0b 100644 --- a/src/share/classes/java/util/zip/ZipException.java +++ b/src/share/classes/java/util/zip/ZipException.java @@ -1,5 +1,5 @@ /* - * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1995-2010 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,7 +40,7 @@ class ZipException extends IOException { private static final long serialVersionUID = 8000196834066748623L; /** - * Constructs an ZipException with null + * Constructs a ZipException with null * as its error detail message. */ public ZipException() { @@ -48,7 +48,7 @@ class ZipException extends IOException { } /** - * Constructs an ZipException with the specified detail + * Constructs a ZipException with the specified detail * message. * * @param s the detail message. -- cgit v1.2.3 From c2fb5c7984be31a906ae40abdcf7b59eaa83c999 Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 13 May 2010 21:56:13 -0700 Subject: 6952330: Fix for 6933217 broke contract of StringBuffer.ensureCapacity Summary: make sure to grow with size => size * 2 + 2 Reviewed-by: dholmes, chegar, ohair --- src/share/classes/java/lang/AbstractStringBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/share') diff --git a/src/share/classes/java/lang/AbstractStringBuilder.java b/src/share/classes/java/lang/AbstractStringBuilder.java index fd98eb040..fa9560701 100644 --- a/src/share/classes/java/lang/AbstractStringBuilder.java +++ b/src/share/classes/java/lang/AbstractStringBuilder.java @@ -117,7 +117,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { * size check or synchronization. */ void expandCapacity(int minimumCapacity) { - int newCapacity = value.length * 2; + int newCapacity = value.length * 2 + 2; if (newCapacity - minimumCapacity < 0) newCapacity = minimumCapacity; if (newCapacity < 0) { -- cgit v1.2.3 From 30a3f32c3237f00ba1fe35ce91131a3667b92f1e Mon Sep 17 00:00:00 2001 From: sherman Date: Fri, 14 May 2010 13:30:37 -0700 Subject: 6952701: Use http://www.ietf.org/rfc for rfc references in jdk public APIs Summary: replace www.isi.edu/in-notes with www.ietf.org/rfc Reviewed-by: martin --- src/share/classes/java/util/zip/package.html | 15 ++++++--------- src/share/classes/javax/naming/event/EventDirContext.java | 2 +- src/share/classes/javax/naming/ldap/Control.java | 2 +- src/share/classes/javax/naming/ldap/ControlFactory.java | 2 +- src/share/classes/javax/naming/ldap/ExtendedRequest.java | 2 +- src/share/classes/javax/naming/ldap/ExtendedResponse.java | 2 +- .../javax/naming/ldap/UnsolicitedNotification.java | 2 +- .../naming/ldap/UnsolicitedNotificationListener.java | 2 +- src/share/classes/javax/print/DocFlavor.java | 2 +- 9 files changed, 14 insertions(+), 17 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/java/util/zip/package.html b/src/share/classes/java/util/zip/package.html index 83d117de5..ec5ab0625 100644 --- a/src/share/classes/java/util/zip/package.html +++ b/src/share/classes/java/util/zip/package.html @@ -58,25 +58,22 @@ input streams. PKWARE ZIP File Format Specification - Language Encoding Flag (EFS) to encode ZIP entry filename and comment fields using UTF-8.

-

  • +
  • ZLIB Compressed Data Format Specification version 3.3   - - (PostScript) + (pdf) (RFC 1950)

    -

  • +
  • DEFLATE Compressed Data Format Specification version 1.3   - - (PostScript) + (pdf) (RFC 1951)

    -

  • +
  • GZIP file format specification version 4.3   - - (PostScript) + (pdf) (RFC 1952)

  • CRC-32 checksum is described in RFC 1952 (above) diff --git a/src/share/classes/javax/naming/event/EventDirContext.java b/src/share/classes/javax/naming/event/EventDirContext.java index 8cce0e7a9..715b2514d 100644 --- a/src/share/classes/javax/naming/event/EventDirContext.java +++ b/src/share/classes/javax/naming/event/EventDirContext.java @@ -34,7 +34,7 @@ import javax.naming.directory.SearchControls; * of events fired when objects named in a directory context changes. *

    * The methods in this interface support identification of objects by - * RFC 2254 + * RFC 2254 * search filters. * *

    Using the search filter, it is possible to register interest in objects diff --git a/src/share/classes/javax/naming/ldap/Control.java b/src/share/classes/javax/naming/ldap/Control.java index 31362a7b8..83016cbd8 100644 --- a/src/share/classes/javax/naming/ldap/Control.java +++ b/src/share/classes/javax/naming/ldap/Control.java @@ -27,7 +27,7 @@ package javax.naming.ldap; /** * This interface represents an LDAPv3 control as defined in - * RFC 2251. + * RFC 2251. *

    * The LDAPv3 protocol uses controls to send and receive additional data * to affect the behavior of predefined operations. diff --git a/src/share/classes/javax/naming/ldap/ControlFactory.java b/src/share/classes/javax/naming/ldap/ControlFactory.java index a95e77782..d9096899d 100644 --- a/src/share/classes/javax/naming/ldap/ControlFactory.java +++ b/src/share/classes/javax/naming/ldap/ControlFactory.java @@ -37,7 +37,7 @@ import com.sun.naming.internal.ResourceManager; /** * This abstract class represents a factory for creating LDAPv3 controls. * LDAPv3 controls are defined in - * RFC 2251. + * RFC 2251. *

    * When a service provider receives a response control, it uses control * factories to return the specific/appropriate control class implementation. diff --git a/src/share/classes/javax/naming/ldap/ExtendedRequest.java b/src/share/classes/javax/naming/ldap/ExtendedRequest.java index 10fb3accd..2c82a1f02 100644 --- a/src/share/classes/javax/naming/ldap/ExtendedRequest.java +++ b/src/share/classes/javax/naming/ldap/ExtendedRequest.java @@ -29,7 +29,7 @@ import javax.naming.NamingException; /** * This interface represents an LDAPv3 extended operation request as defined in - * RFC 2251. + * RFC 2251. *

       *     ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
       *              requestName      [0] LDAPOID,
    diff --git a/src/share/classes/javax/naming/ldap/ExtendedResponse.java b/src/share/classes/javax/naming/ldap/ExtendedResponse.java
    index 3426fd5ed..19dd70edc 100644
    --- a/src/share/classes/javax/naming/ldap/ExtendedResponse.java
    +++ b/src/share/classes/javax/naming/ldap/ExtendedResponse.java
    @@ -27,7 +27,7 @@ package javax.naming.ldap;
     
     /**
       * This interface represents an LDAP extended operation response as defined in
    -  * RFC 2251.
    +  * RFC 2251.
       * 
       *     ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
       *          COMPONENTS OF LDAPResult,
    diff --git a/src/share/classes/javax/naming/ldap/UnsolicitedNotification.java b/src/share/classes/javax/naming/ldap/UnsolicitedNotification.java
    index f669ae4ef..adf7b7724 100644
    --- a/src/share/classes/javax/naming/ldap/UnsolicitedNotification.java
    +++ b/src/share/classes/javax/naming/ldap/UnsolicitedNotification.java
    @@ -29,7 +29,7 @@ import javax.naming.NamingException;
     
     /**
      * This interface represents an unsolicited notification as defined in
    - * RFC 2251.
    + * RFC 2251.
      * An unsolicited notification is sent by the LDAP server to the LDAP
      * client without any provocation from the client.
      * Its format is that of an extended response (ExtendedResponse).
    diff --git a/src/share/classes/javax/naming/ldap/UnsolicitedNotificationListener.java b/src/share/classes/javax/naming/ldap/UnsolicitedNotificationListener.java
    index 820a9c0ce..c8c56b2d2 100644
    --- a/src/share/classes/javax/naming/ldap/UnsolicitedNotificationListener.java
    +++ b/src/share/classes/javax/naming/ldap/UnsolicitedNotificationListener.java
    @@ -30,7 +30,7 @@ import javax.naming.event.NamingListener;
     /**
      * This interface is for handling UnsolicitedNotificationEvent.
      * "Unsolicited notification" is defined in
    - * RFC 2251.
    + * RFC 2251.
      * It allows the server to send unsolicited notifications to the client.
      * A UnsolicitedNotificationListener must:
      *
      diff --git a/src/share/classes/javax/print/DocFlavor.java b/src/share/classes/javax/print/DocFlavor.java index e72970c9f..6f00b3e85 100644 --- a/src/share/classes/javax/print/DocFlavor.java +++ b/src/share/classes/javax/print/DocFlavor.java @@ -83,7 +83,7 @@ import java.io.Serializable; * doc flavor's MIME type is one of the standard media types telling how to * interpret the sequence of characters or bytes. For a list of standard media * types, see the Internet Assigned Numbers Authority's (IANA's) Media Types + * HREF="http://www.iana.org/assignments/media-types/">Media Types * Directory. Interface {@link Doc Doc} provides two utility operations, * {@link Doc#getReaderForText() getReaderForText} and * {@link Doc#getStreamForBytes() getStreamForBytes()}, to help a -- cgit v1.2.3 From d40bc0ae9bded32b427f714916d26bc97617a2cc Mon Sep 17 00:00:00 2001 From: sherman Date: Fri, 14 May 2010 13:46:53 -0700 Subject: 4263582: RFE: GZIPInputStream throws IOException on non-gzipped data Summary: throw ZipException instead of IOException Reviewed-by: martin --- src/share/classes/java/util/zip/GZIPInputStream.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/java/util/zip/GZIPInputStream.java b/src/share/classes/java/util/zip/GZIPInputStream.java index 724743bba..389bc6e4d 100644 --- a/src/share/classes/java/util/zip/GZIPInputStream.java +++ b/src/share/classes/java/util/zip/GZIPInputStream.java @@ -66,6 +66,9 @@ class GZIPInputStream extends InflaterInputStream { * Creates a new input stream with the specified buffer size. * @param in the input stream * @param size the input buffer size + * + * @exception ZipException if a GZIP format error has occurred or the + * compression method used is unsupported * @exception IOException if an I/O error has occurred * @exception IllegalArgumentException if size is <= 0 */ @@ -79,6 +82,9 @@ class GZIPInputStream extends InflaterInputStream { /** * Creates a new input stream with a default buffer size. * @param in the input stream + * + * @exception ZipException if a GZIP format error has occurred or the + * compression method used is unsupported * @exception IOException if an I/O error has occurred */ public GZIPInputStream(InputStream in) throws IOException { @@ -94,12 +100,14 @@ class GZIPInputStream extends InflaterInputStream { * @param len the maximum number of bytes read * @return the actual number of bytes read, or -1 if the end of the * compressed input stream is reached + * * @exception NullPointerException If buf is null. * @exception IndexOutOfBoundsException If off is negative, * len is negative, or len is greater than * buf.length - off - * @exception IOException if an I/O error has occurred or the compressed - * input data is corrupt + * @exception ZipException if the compressed input data is corrupt. + * @exception IOException if an I/O error has occurred. + * */ public int read(byte[] buf, int off, int len) throws IOException { ensureOpen(); @@ -151,11 +159,11 @@ class GZIPInputStream extends InflaterInputStream { crc.reset(); // Check header magic if (readUShort(in) != GZIP_MAGIC) { - throw new IOException("Not in GZIP format"); + throw new ZipException("Not in GZIP format"); } // Check compression method if (readUByte(in) != 8) { - throw new IOException("Unsupported compression method"); + throw new ZipException("Unsupported compression method"); } // Read flags int flg = readUByte(in); @@ -177,7 +185,7 @@ class GZIPInputStream extends InflaterInputStream { if ((flg & FHCRC) == FHCRC) { int v = (int)crc.getValue() & 0xffff; if (readUShort(in) != v) { - throw new IOException("Corrupt GZIP header"); + throw new ZipException("Corrupt GZIP header"); } } } @@ -196,7 +204,7 @@ class GZIPInputStream extends InflaterInputStream { if ((readUInt(in) != crc.getValue()) || // rfc1952; ISIZE is the input size modulo 2^32 (readUInt(in) != (inf.getBytesWritten() & 0xffffffffL))) - throw new IOException("Corrupt GZIP trailer"); + throw new ZipException("Corrupt GZIP trailer"); } /* -- cgit v1.2.3 From d20654ccbc12b090a18c4756f82c38584acddb27 Mon Sep 17 00:00:00 2001 From: sherman Date: Sun, 16 May 2010 21:22:07 -0700 Subject: 4465490: Suspicious about double-check locking idiom being used in the code Summary: to use volatile for the double-checked object Reviewed-by: weijun --- src/share/classes/java/util/jar/JarVerifier.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/share') diff --git a/src/share/classes/java/util/jar/JarVerifier.java b/src/share/classes/java/util/jar/JarVerifier.java index 1c88d226e..50c37752e 100644 --- a/src/share/classes/java/util/jar/JarVerifier.java +++ b/src/share/classes/java/util/jar/JarVerifier.java @@ -76,7 +76,7 @@ class JarVerifier { private ByteArrayOutputStream baos; /** The ManifestDigester object */ - private ManifestDigester manDig; + private volatile ManifestDigester manDig; /** the bytes for the manDig object */ byte manifestRawBytes[] = null; -- cgit v1.2.3 From 4785c7c09102ac9a353cb0abf98e7e82c1333236 Mon Sep 17 00:00:00 2001 From: rupashka Date: Mon, 17 May 2010 17:23:18 +0400 Subject: 6938481: 4906607 is not fixed for NIMBUS L&F Reviewed-by: alexp --- src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/share') diff --git a/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java b/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java index a2a4b2e5e..f10eb378b 100644 --- a/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java +++ b/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java @@ -788,7 +788,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { // for example /foo/bar/ becomes /foo/bar File canonical; try { - canonical = directory.getCanonicalFile(); + canonical = ShellFolder.getNormalizedFile(directory); } catch (IOException e) { // Maybe drive is not ready. Can't abort here. canonical = directory; -- cgit v1.2.3 From e32dac08ab86361ed53329725d7cc2d9aaaaf774 Mon Sep 17 00:00:00 2001 From: sherman Date: Mon, 17 May 2010 12:19:49 -0700 Subject: 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH Summary: Added new constructors to allow flush() work in Z_SYNC_FLUSH mode Reviewed-by: martin --- .../classes/java/util/zip/GZIPOutputStream.java | 63 ++++++++++++++++++++-- 1 file changed, 60 insertions(+), 3 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/java/util/zip/GZIPOutputStream.java b/src/share/classes/java/util/zip/GZIPOutputStream.java index 867eff0b1..7f7749617 100644 --- a/src/share/classes/java/util/zip/GZIPOutputStream.java +++ b/src/share/classes/java/util/zip/GZIPOutputStream.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2002 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1996-2010 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -54,25 +54,82 @@ class GZIPOutputStream extends DeflaterOutputStream { /** * Creates a new output stream with the specified buffer size. + * + *

      The new output stream instance is created as if by invoking + * the 3-argument constructor GZIPOutputStream(out, size, false). + * * @param out the output stream * @param size the output buffer size * @exception IOException If an I/O error has occurred. * @exception IllegalArgumentException if size is <= 0 + */ public GZIPOutputStream(OutputStream out, int size) throws IOException { - super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size); + this(out, size, false); + } + + /** + * Creates a new output stream with the specified buffer size and + * flush mode. + * + * @param out the output stream + * @param size the output buffer size + * @param syncFlush + * if {@code true} invocation of the inherited + * {@link DeflaterOutputStream#flush() flush()} method of + * this instance flushes the compressor with flush mode + * {@link Deflater#SYNC_FLUSH} before flushing the output + * stream, otherwise only flushes the output stream + * @exception IOException If an I/O error has occurred. + * @exception IllegalArgumentException if size is <= 0 + * + * @since 1.7 + */ + public GZIPOutputStream(OutputStream out, int size, boolean syncFlush) + throws IOException + { + super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true), + size, + syncFlush); usesDefaultDeflater = true; writeHeader(); crc.reset(); } + /** * Creates a new output stream with a default buffer size. + * + *

      The new output stream instance is created as if by invoking + * the 2-argument constructor GZIPOutputStream(out, false). + * * @param out the output stream * @exception IOException If an I/O error has occurred. */ public GZIPOutputStream(OutputStream out) throws IOException { - this(out, 512); + this(out, 512, false); + } + + /** + * Creates a new output stream with a default buffer size and + * the specified flush mode. + * + * @param out the output stream + * @param syncFlush + * if {@code true} invocation of the inherited + * {@link DeflaterOutputStream#flush() flush()} method of + * this instance flushes the compressor with flush mode + * {@link Deflater#SYNC_FLUSH} before flushing the output + * stream, otherwise only flushes the output stream + * + * @exception IOException If an I/O error has occurred. + * + * @since 1.7 + */ + public GZIPOutputStream(OutputStream out, boolean syncFlush) + throws IOException + { + this(out, 512, syncFlush); } /** -- cgit v1.2.3 From ab953ee8053577578e40f35507158b5741699faf Mon Sep 17 00:00:00 2001 From: sherman Date: Mon, 17 May 2010 16:18:13 -0700 Subject: 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method Summary: create a new header byte array for each header writeout Reviewed-by: martin --- .../classes/java/util/zip/GZIPOutputStream.java | 27 ++++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/java/util/zip/GZIPOutputStream.java b/src/share/classes/java/util/zip/GZIPOutputStream.java index 7f7749617..bcaad0150 100644 --- a/src/share/classes/java/util/zip/GZIPOutputStream.java +++ b/src/share/classes/java/util/zip/GZIPOutputStream.java @@ -179,22 +179,19 @@ class GZIPOutputStream extends DeflaterOutputStream { /* * Writes GZIP member header. */ - - private final static byte[] header = { - (byte) GZIP_MAGIC, // Magic number (short) - (byte)(GZIP_MAGIC >> 8), // Magic number (short) - Deflater.DEFLATED, // Compression method (CM) - 0, // Flags (FLG) - 0, // Modification time MTIME (int) - 0, // Modification time MTIME (int) - 0, // Modification time MTIME (int) - 0, // Modification time MTIME (int) - 0, // Extra flags (XFLG) - 0 // Operating system (OS) - }; - private void writeHeader() throws IOException { - out.write(header); + out.write(new byte[] { + (byte) GZIP_MAGIC, // Magic number (short) + (byte)(GZIP_MAGIC >> 8), // Magic number (short) + Deflater.DEFLATED, // Compression method (CM) + 0, // Flags (FLG) + 0, // Modification time MTIME (int) + 0, // Modification time MTIME (int) + 0, // Modification time MTIME (int) + 0, // Modification time MTIME (int) + 0, // Extra flags (XFLG) + 0 // Operating system (OS) + }); } /* -- cgit v1.2.3 From 69d0cdad33367dee19f98824514e4e5247096e00 Mon Sep 17 00:00:00 2001 From: peytoia Date: Tue, 18 May 2010 16:40:53 +0900 Subject: 6953294: Fix for 6909002 was incorrectly merged Reviewed-by: okutsu --- .../indicim/DevanagariInputMethodDescriptor.java | 102 ----- .../internal/indicim/DevanagariTables.java | 255 ----------- .../internal/indicim/IndicInputMethod.java | 436 ------------------- .../internal/indicim/IndicInputMethodImpl.java | 475 --------------------- .../indicim/java.awt.im.spi.InputMethodDescriptor | 1 - .../indicim/resources/DisplayNames.properties | 6 - .../indicim/resources/DisplayNames_de.properties | 5 - .../indicim/resources/DisplayNames_es.properties | 5 - .../indicim/resources/DisplayNames_fr.properties | 5 - .../indicim/resources/DisplayNames_it.properties | 5 - .../indicim/resources/DisplayNames_ja.properties | 5 - .../indicim/resources/DisplayNames_ko.properties | 5 - .../indicim/resources/DisplayNames_sv.properties | 5 - .../resources/DisplayNames_zh_CN.properties | 5 - .../resources/DisplayNames_zh_TW.properties | 5 - .../internal/thaiim/ThaiInputMethod.java | 437 ------------------- .../internal/thaiim/ThaiInputMethodDescriptor.java | 99 ----- .../internal/thaiim/ThaiInputMethodImpl.java | 235 ---------- .../inputmethods/internal/thaiim/ThaiRules.java | 348 --------------- .../thaiim/java.awt.im.spi.InputMethodDescriptor | 1 - .../thaiim/resources/DisplayNames.properties | 6 - 21 files changed, 2446 deletions(-) delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/DevanagariInputMethodDescriptor.java delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/DevanagariTables.java delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/IndicInputMethod.java delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/IndicInputMethodImpl.java delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/java.awt.im.spi.InputMethodDescriptor delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames.properties delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_de.properties delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_es.properties delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_fr.properties delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_it.properties delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_ja.properties delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_ko.properties delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_sv.properties delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_zh_CN.properties delete mode 100644 src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_zh_TW.properties delete mode 100644 src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiInputMethod.java delete mode 100644 src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiInputMethodDescriptor.java delete mode 100644 src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiInputMethodImpl.java delete mode 100644 src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiRules.java delete mode 100644 src/share/classes/com/sun/inputmethods/internal/thaiim/java.awt.im.spi.InputMethodDescriptor delete mode 100644 src/share/classes/com/sun/inputmethods/internal/thaiim/resources/DisplayNames.properties (limited to 'src/share') diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/DevanagariInputMethodDescriptor.java b/src/share/classes/com/sun/inputmethods/internal/indicim/DevanagariInputMethodDescriptor.java deleted file mode 100644 index 1371ff776..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/DevanagariInputMethodDescriptor.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -/* - * (C) Copyright IBM Corp. 2000 - All Rights Reserved - * - * The original version of this source code and documentation is - * copyrighted and owned by IBM. These materials are provided - * under terms of a License Agreement between IBM and Sun. - * This technology is protected by multiple US and International - * patents. This notice and attribution to IBM may not be removed. - * - */ - -package com.sun.inputmethods.internal.indicim; - -import java.awt.Image; -import java.awt.im.spi.InputMethod; -import java.awt.im.spi.InputMethodDescriptor; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -public class DevanagariInputMethodDescriptor implements InputMethodDescriptor { - - static final Locale HINDI = new Locale("hi", "IN"); - - public DevanagariInputMethodDescriptor() { - } - - /** - * @see java.awt.im.spi.InputMethodDescriptor#getAvailableLocales - */ - public Locale[] getAvailableLocales() { - return new Locale[] { HINDI }; - } - - /** - * @see java.awt.im.spi.InputMethodDescriptor#hasDynamicLocaleList - */ - public boolean hasDynamicLocaleList() { - return false; - } - - /** - * @see java.awt.im.spi.InputMethodDescriptor#getInputMethodDisplayName - */ - public synchronized String getInputMethodDisplayName(Locale inputLocale, Locale displayLanguage) { - try { - ResourceBundle resources = ResourceBundle.getBundle("com.sun.inputmethods.internal.indicim.resources.DisplayNames", displayLanguage); - return resources.getString("DisplayName.Devanagari"); - } catch (MissingResourceException mre) { - return "Devanagari Input Method"; - } - } - - /** - * @see java.awt.im.spi.InputMethodDescriptor#getInputMethodIcon - */ - public Image getInputMethodIcon(Locale inputLocale) { - return null; - } - - /** - * @see java.awt.im.spi.InputMethodDescriptor#createInputMethod - */ - public InputMethod createInputMethod() throws Exception { - IndicInputMethodImpl impl = new IndicInputMethodImpl( - DevanagariTables.keyboardMap, - DevanagariTables.joinWithNukta, - DevanagariTables.nuktaForm, - DevanagariTables.substitutionTable); - - return new IndicInputMethod(HINDI, impl); - } - - public String toString() { - return getClass().getName(); - } -} diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/DevanagariTables.java b/src/share/classes/com/sun/inputmethods/internal/indicim/DevanagariTables.java deleted file mode 100644 index 966660b99..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/DevanagariTables.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -/* - * (C) Copyright IBM Corp. 2000 - All Rights Reserved - * - * The original version of this source code and documentation is - * copyrighted and owned by IBM. These materials are provided - * under terms of a License Agreement between IBM and Sun. - * This technology is protected by multiple US and International - * patents. This notice and attribution to IBM may not be removed. - * - */ - -package com.sun.inputmethods.internal.indicim; - -class DevanagariTables { - - static final char[] keyboardMap = { - /* 00 */ '\u0000', - /* 01 */ '\u0001', - /* 02 */ '\u0002', - /* 03 */ '\u0003', - /* 04 */ '\u0004', - /* 05 */ '\u0005', - /* 06 */ '\u0006', - /* 07 */ '\u0007', - /* 08 */ '\u0008', - /* 09 */ '\u0009', - /* 0A */ '\012', - /* 0B */ '\u000B', - /* 0C */ '\u000C', - /* 0D */ '\015', - /* 0E */ '\u000E', - /* 0F */ '\u000F', - /* 10 */ '\u0010', - /* 11 */ '\u0011', - /* 12 */ '\u0012', - /* 13 */ '\u0013', - /* 14 */ '\u0014', - /* 15 */ '\u0015', - /* 16 */ '\u0016', - /* 17 */ '\u0017', - /* 18 */ '\u0018', - /* 19 */ '\u0019', - /* 1A */ '\u001A', - /* 1B */ '\u001B', - /* 1C */ '\u001C', - /* 1D */ '\u001D', - /* 1E */ '\u001E', - /* 1F */ '\u001F', - /* 20 */ '\u0020', - /* 21 */ '\u090D', // '!' - /* 22 */ '\u0920', // '"' - /* 23 */ '\uFF00', // '#' - /* 24 */ '\uFF01', // '$' - /* 25 */ '\uFF02', // '%' - /* 26 */ '\uFF04', // '&' - /* 27 */ '\u091F', // ''' - /* 28 */ '\u0028', // '(' - /* 29 */ '\u0029', // ')' - /* 2A */ '\uFF05', // '*' - /* 2B */ '\u090B', // '+' - /* 2C */ '\u002C', // ',' - /* 2D */ '\u002D', // '-' - /* 2E */ '\u002E', // '.' - /* 2F */ '\u092F', // '/' - /* 30 */ '\u0966', // '0' - /* 31 */ '\u0967', // '1' - /* 32 */ '\u0968', // '2' - /* 33 */ '\u0969', // '3' - /* 34 */ '\u096A', // '4' - /* 35 */ '\u096B', // '5' - /* 36 */ '\u096C', // '6' - /* 37 */ '\u096D', // '7' - /* 38 */ '\u096E', // '8' - /* 39 */ '\u096F', // '9' - /* 3A */ '\u091B', // ':' - /* 3B */ '\u091A', // ';' - /* 3C */ '\u0937', // '<' - /* 3D */ '\u0943', // '=' - /* 3E */ '\u0964', // '>' - /* 3F */ '\u095F', // '?' - /* 40 */ '\u0945', // '@' - /* 41 */ '\u0913', // 'A' - /* 42 */ '\u0934', // 'B' - /* 43 */ '\u0923', // 'C' - /* 44 */ '\u0905', // 'D' - /* 45 */ '\u0906', // 'E' - /* 46 */ '\u0907', // 'F' - /* 47 */ '\u0909', // 'G' - /* 48 */ '\u092B', // 'H' - /* 49 */ '\u0918', // 'I' - /* 4A */ '\u0931', // 'J' - /* 4B */ '\u0916', // 'K' - /* 4C */ '\u0925', // 'L' - /* 4D */ '\u0936', // 'M' - /* 4E */ '\u0933', // 'N' - /* 4F */ '\u0927', // 'O' - /* 50 */ '\u091D', // 'P' - /* 51 */ '\u0914', // 'Q' - /* 52 */ '\u0908', // 'R' - /* 53 */ '\u090F', // 'S' - /* 54 */ '\u090A', // 'T' - /* 55 */ '\u0919', // 'U' - /* 56 */ '\u0929', // 'V' - /* 57 */ '\u0910', // 'W' - /* 58 */ '\u0901', // 'X' - /* 59 */ '\u092D', // 'Y' - /* 5A */ '\u090E', // 'Z' - /* 5B */ '\u0921', // '[' - /* 5C */ '\u0949', // '\' - /* 5D */ '\u093C', // ']' - /* 5E */ '\uFF03', // '^' - /* 5F */ '\u0903', // '_' - /* 60 */ '\u094A', // '`' - /* 61 */ '\u094B', // 'a' - /* 62 */ '\u0935', // 'b' - /* 63 */ '\u092E', // 'c' - /* 64 */ '\u094D', // 'd' - /* 65 */ '\u093E', // 'e' - /* 66 */ '\u093F', // 'f' - /* 67 */ '\u0941', // 'g' - /* 68 */ '\u092A', // 'h' - /* 69 */ '\u0917', // 'i' - /* 6A */ '\u0930', // 'j' - /* 6B */ '\u0915', // 'k' - /* 6C */ '\u0924', // 'l' - /* 6D */ '\u0938', // 'm' - /* 6E */ '\u0932', // 'n' - /* 6F */ '\u0926', // 'o' - /* 70 */ '\u091C', // 'p' - /* 71 */ '\u094C', // 'q' - /* 72 */ '\u0940', // 'r' - /* 73 */ '\u0947', // 's' - /* 74 */ '\u0942', // 't' - /* 75 */ '\u0939', // 'u' - /* 76 */ '\u0928', // 'v' - /* 77 */ '\u0948', // 'w' - /* 78 */ '\u0902', // 'x' - /* 79 */ '\u092C', // 'y' - /* 7A */ '\u0946', // 'z' - /* 7B */ '\u0922', // '{' - /* 7C */ '\u0911', // '|' - /* 7D */ '\u091E', // '}' - /* 7E */ '\u0912', // '~' - /* 7F */ '\u007F' // -}; - - // the character substitutions for the meta characters. - static final char[] RA_SUB = {'\u094D', '\u0930'}; - static final char[] RA_SUP = {'\u0930', '\u094D'}; - static final char[] CONJ_JA_NYA = {'\u091C', '\u094D', '\u091E'}; - static final char[] CONJ_TA_RA = {'\u0924', '\u094D', '\u0930'}; - static final char[] CONJ_KA_SSA = {'\u0915', '\u094D', '\u0937'}; - static final char[] CONJ_SHA_RA = {'\u0936', '\u094D', '\u0930'}; - - static final char[][] substitutionTable = { - RA_SUB, RA_SUP, CONJ_JA_NYA, CONJ_TA_RA, CONJ_KA_SSA, CONJ_SHA_RA - }; - - // The following characters followed by Nukta should be replaced - // by the corresponding character as defined in ISCII91 - static final char SIGN_CANDRABINDU = '\u0901'; - static final char LETTER_I = '\u0907'; - static final char LETTER_II = '\u0908'; - static final char LETTER_VOCALIC_R = '\u090B'; - static final char LETTER_KA = '\u0915'; - static final char LETTER_KHA = '\u0916'; - static final char LETTER_GA = '\u0917'; - static final char LETTER_JA = '\u091C'; - static final char LETTER_DDA = '\u0921'; - static final char LETTER_DDHA = '\u0922'; - static final char LETTER_PHA = '\u092B'; - static final char VOWEL_SIGN_I = '\u093F'; - static final char VOWEL_SIGN_II = '\u0940'; - static final char VOWEL_SIGN_VOCALIC_R = '\u0943'; - static final char DANDA = '\u0964'; - - // The follwing characters replace the above characters followed by Nukta. These - // are defined in one to one correspondence order. - static final char SIGN_OM = '\u0950'; - static final char LETTER_VOCALIC_L = '\u090C'; - static final char LETTER_VOCALIC_LL = '\u0961'; - static final char LETTER_VOCALIC_RR = '\u0960'; - static final char LETTER_QA = '\u0958'; - static final char LETTER_KHHA = '\u0959'; - static final char LETTER_GHHA = '\u095A'; - static final char LETTER_ZA = '\u095B'; - static final char LETTER_DDDHA = '\u095C'; - static final char LETTER_RHA = '\u095D'; - static final char LETTER_FA = '\u095E'; - static final char VOWEL_SIGN_VOCALIC_L = '\u0962'; - static final char VOWEL_SIGN_VOCALIC_LL = '\u0963'; - static final char VOWEL_SIGN_VOCALIC_RR = '\u0944'; - static final char SIGN_AVAGRAHA = '\u093D'; - - static final char[] joinWithNukta = { - SIGN_CANDRABINDU, - LETTER_I, - LETTER_II, - LETTER_VOCALIC_R , - LETTER_KA, - LETTER_KHA, - LETTER_GA, - LETTER_JA, - LETTER_DDA, - LETTER_DDHA, - LETTER_PHA, - VOWEL_SIGN_I, - VOWEL_SIGN_II, - VOWEL_SIGN_VOCALIC_R, - DANDA - }; - - static final char[] nuktaForm = { - SIGN_OM, - LETTER_VOCALIC_L, - LETTER_VOCALIC_LL, - LETTER_VOCALIC_RR, - LETTER_QA, - LETTER_KHHA, - LETTER_GHHA, - LETTER_ZA, - LETTER_DDDHA, - LETTER_RHA, - LETTER_FA, - VOWEL_SIGN_VOCALIC_L, - VOWEL_SIGN_VOCALIC_LL, - VOWEL_SIGN_VOCALIC_RR, - SIGN_AVAGRAHA - }; -} diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/IndicInputMethod.java b/src/share/classes/com/sun/inputmethods/internal/indicim/IndicInputMethod.java deleted file mode 100644 index 4315358d1..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/IndicInputMethod.java +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -/* - * (C) Copyright IBM Corp. 2000 - All Rights Reserved - * - * The original version of this source code and documentation is - * copyrighted and owned by IBM. These materials are provided - * under terms of a License Agreement between IBM and Sun. - * This technology is protected by multiple US and International - * patents. This notice and attribution to IBM may not be removed. - * - */ - -package com.sun.inputmethods.internal.indicim; - -import java.awt.im.spi.InputMethod; -import java.awt.im.spi.InputMethodContext; - -import java.awt.AWTEvent; -import java.awt.Rectangle; - -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; - -import java.lang.Character.Subset; - -import java.util.Locale; - -class IndicInputMethod implements InputMethod { - - private IndicInputMethodImpl impl; - private Locale locale; - - IndicInputMethod(Locale theLocale, IndicInputMethodImpl theImplementation) { - locale = theLocale; - impl = theImplementation; - } - - /** - * Sets the input method context, which is used to dispatch input method - * events to the client component and to request information from - * the client component. - *

      - * This method is called once immediately after instantiating this input - * method. - * - * @param context the input method context for this input method - * @exception NullPointerException if context is null - */ - public void setInputMethodContext(InputMethodContext context) { - - impl.setInputMethodContext(context); - } - - /** - * Attempts to set the input locale. If the input method supports the - * desired locale, it changes its behavior to support input for the locale - * and returns true. - * Otherwise, it returns false and does not change its behavior. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}, - *
      • when switching to this input method through the user interface if the user - * specified a locale or if the previously selected input method's - * {@link java.awt.im.spi.InputMethod#getLocale getLocale} method - * returns a non-null value. - *
      - * - * @param locale locale to input - * @return whether the specified locale is supported - * @exception NullPointerException if locale is null - */ - public boolean setLocale(Locale locale) { - - if (locale.getLanguage().equals(this.locale.getLanguage())) { - //System.out.println("returning true for locale " + locale); - return true; - } - else { - //System.out.println("returning false for locale " + locale); - return false; - } - } - - /** - * Returns the current input locale. Might return null in exceptional cases. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#getLocale InputContext.getLocale} and - *
      • when switching from this input method to a different one through the - * user interface. - *
      - * - * @return the current input locale, or null - */ - public Locale getLocale() { - - return locale; - } - - /** - * Sets the subsets of the Unicode character set that this input method - * is allowed to input. Null may be passed in to indicate that all - * characters are allowed. - *

      - * This method is called - *

        - *
      • immediately after instantiating this input method, - *
      • when switching to this input method from a different one, and - *
      • by {@link java.awt.im.InputContext#setCharacterSubsets InputContext.setCharacterSubsets}. - *
      - * - * @param subsets the subsets of the Unicode character set from which - * characters may be input - */ - public void setCharacterSubsets(Subset[] subsets) { - } - - /** - * Enables or disables this input method for composition, - * depending on the value of the parameter enable. - *

      - * An input method that is enabled for composition interprets incoming - * events for both composition and control purposes, while a - * disabled input method does not interpret events for composition. - * Note however that events are passed on to the input method regardless - * whether it is enabled or not, and that an input method that is disabled - * for composition may still interpret events for control purposes, - * including to enable or disable itself for composition. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#setCompositionEnabled InputContext.setCompositionEnabled}, - *
      • when switching to this input method from a different one using the - * user interface or - * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}, - * if the previously selected input method's - * {@link java.awt.im.spi.InputMethod#isCompositionEnabled isCompositionEnabled} - * method returns without throwing an exception. - *
      - * - * @param enable whether to enable the input method for composition - * @throws UnsupportedOperationException if this input method does not - * support the enabling/disabling operation - * @see #isCompositionEnabled - */ - public void setCompositionEnabled(boolean enable) { - - throw new UnsupportedOperationException(); - } - - /** - * Determines whether this input method is enabled. - * An input method that is enabled for composition interprets incoming - * events for both composition and control purposes, while a - * disabled input method does not interpret events for composition. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#isCompositionEnabled InputContext.isCompositionEnabled} and - *
      • when switching from this input method to a different one using the - * user interface or - * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}. - *
      - * - * @return true if this input method is enabled for - * composition; false otherwise. - * @throws UnsupportedOperationException if this input method does not - * support checking whether it is enabled for composition - * @see #setCompositionEnabled - */ - public boolean isCompositionEnabled() { - - return true; - } - - /** - * Starts the reconversion operation. The input method obtains the - * text to be reconverted from the current client component using the - * {@link java.awt.im.InputMethodRequests#getSelectedText InputMethodRequests.getSelectedText} - * method. It can use other InputMethodRequests - * methods to request additional information required for the - * reconversion operation. The composed and committed text - * produced by the operation is sent to the client component as a - * sequence of InputMethodEvents. If the given text - * cannot be reconverted, the same text should be sent to the - * client component as committed text. - *

      - * This method is called by - * {@link java.awt.im.InputContext#reconvert() InputContext.reconvert}. - * - * @throws UnsupportedOperationException if the input method does not - * support the reconversion operation. - */ - public void reconvert() { - - throw new UnsupportedOperationException("This input method does not reconvert."); - } - - /** - * Dispatches the event to the input method. If input method support is - * enabled for the focussed component, incoming events of certain types - * are dispatched to the current input method for this component before - * they are dispatched to the component's methods or event listeners. - * The input method decides whether it needs to handle the event. If it - * does, it also calls the event's consume method; this - * causes the event to not get dispatched to the component's event - * processing methods or event listeners. - *

      - * Events are dispatched if they are instances of InputEvent or its - * subclasses. - * This includes instances of the AWT classes KeyEvent and MouseEvent. - *

      - * This method is called by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}. - * - * @param event the event being dispatched to the input method - * @exception NullPointerException if event is null - */ - public void dispatchEvent(AWTEvent event) { - - if (event instanceof KeyEvent) { - - KeyEvent keyEvent = (KeyEvent) event; - if (event.getID() == KeyEvent.KEY_TYPED) { - impl.handleKeyTyped(keyEvent); - } - //System.out.println("handled event " + event); - } - else { - //System.out.println("did not handle event " + event); - } - } - - /** - * Notifies this input method of changes in the client window - * location or state. This method is called while this input - * method is the current input method of its input context and - * notifications for it are enabled (see {@link - * InputMethodContext#enableClientWindowNotification - * InputMethodContext.enableClientWindowNotification}). Calls - * to this method are temporarily suspended if the input context's - * {@link java.awt.im.InputContext#removeNotify removeNotify} - * method is called, and resume when the input method is activated - * for a new client component. It is called in the following - * situations: - *

        - *
      • - * when the window containing the current client component changes - * in location, size, visibility, iconification state, or when the - * window is closed.
      • - *
      • - * from enableClientWindowNotification(inputMethod, - * true) if the current client component exists,
      • - *
      • - * when activating the input method for the first time after it - * called - * enableClientWindowNotification(inputMethod, - * true) if during the call no current client component was - * available,
      • - *
      • - * when activating the input method for a new client component - * after the input context's removeNotify method has been - * called.
      • - *
      - * @param bounds client window's {@link - * java.awt.Component#getBounds bounds} on the screen; or null if - * the client window is iconified or invisible - */ - public void notifyClientWindowChange(Rectangle bounds) { - } - - /** - * Activates the input method for immediate input processing. - *

      - * If an input method provides its own windows, it should make sure - * at this point that all necessary windows are open and visible. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent} - * when a client component receives a FOCUS_GAINED event, - *
      • when switching to this input method from a different one using the - * user interface or - * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}. - *
      - * The method is only called when the input method is inactive. - * A newly instantiated input method is assumed to be inactive. - */ - public void activate() { - //System.out.println("activated"); - } - - /** - * Deactivates the input method. - * The isTemporary argument has the same meaning as in - * {@link java.awt.event.FocusEvent#isTemporary FocusEvent.isTemporary}. - *

      - * If an input method provides its own windows, only windows that relate - * to the current composition (such as a lookup choice window) should be - * closed at this point. - * It is possible that the input method will be immediately activated again - * for a different client component, and closing and reopening more - * persistent windows (such as a control panel) would create unnecessary - * screen flicker. - * Before an instance of a different input method class is activated, - * {@link #hideWindows} is called on the current input method. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent} - * when a client component receives a FOCUS_LOST event, - *
      • when switching from this input method to a different one using the - * user interface or - * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}, - *
      • before {@link #removeNotify removeNotify} if the current client component is - * removed. - *
      - * The method is only called when the input method is active. - * - * @param isTemporary whether the focus change is temporary - */ - public void deactivate(boolean isTemporary) { - //System.out.println("deactivated"); - } - - /** - * Closes or hides all windows opened by this input method instance or - * its class. - *

      - * This method is called - *

        - *
      • before calling {@link #activate activate} on an instance of a different input - * method class, - *
      • before calling {@link #dispose dispose} on this input method. - *
      - * The method is only called when the input method is inactive. - */ - public void hideWindows() { - } - - /** - * Notifies the input method that a client component has been - * removed from its containment hierarchy, or that input method - * support has been disabled for the component. - *

      - * This method is called by {@link java.awt.im.InputContext#removeNotify InputContext.removeNotify}. - *

      - * The method is only called when the input method is inactive. - */ - public void removeNotify() { - } - - /** - * Ends any input composition that may currently be going on in this - * context. Depending on the platform and possibly user preferences, - * this may commit or delete uncommitted text. Any changes to the text - * are communicated to the active component using an input method event. - * - *

      - * A text editing component may call this in a variety of situations, - * for example, when the user moves the insertion point within the text - * (but outside the composed text), or when the component's text is - * saved to a file or copied to the clipboard. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#endComposition InputContext.endComposition}, - *
      • by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent} - * when switching to a different client component - *
      • when switching from this input method to a different one using the - * user interface or - * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}. - *
      - */ - public void endComposition() { - - impl.endComposition(); - } - - /** - * Disposes of the input method and releases the resources used by it. - * In particular, the input method should dispose windows and close files that are no - * longer needed. - *

      - * This method is called by {@link java.awt.im.InputContext#dispose InputContext.dispose}. - *

      - * The method is only called when the input method is inactive. - * No method of this interface is called on this instance after dispose. - */ - public void dispose() { - } - - /** - * Returns a control object from this input method, or null. A - * control object provides methods that control the behavior of the - * input method or obtain information from the input method. The type - * of the object is an input method specific class. Clients have to - * compare the result against known input method control object - * classes and cast to the appropriate class to invoke the methods - * provided. - *

      - * This method is called by - * {@link java.awt.im.InputContext#getInputMethodControlObject InputContext.getInputMethodControlObject}. - * - * @return a control object from this input method, or null - */ - public Object getControlObject() { - - return null; - } -} diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/IndicInputMethodImpl.java b/src/share/classes/com/sun/inputmethods/internal/indicim/IndicInputMethodImpl.java deleted file mode 100644 index 125440242..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/IndicInputMethodImpl.java +++ /dev/null @@ -1,475 +0,0 @@ -/* - * Copyright 2002-2004 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -/* - * (C) Copyright IBM Corp. 2000 - All Rights Reserved - * - * The original version of this source code and documentation is - * copyrighted and owned by IBM. These materials are provided - * under terms of a License Agreement between IBM and Sun. - * This technology is protected by multiple US and International - * patents. This notice and attribution to IBM may not be removed. - * - */ - -package com.sun.inputmethods.internal.indicim; - -import java.awt.im.spi.InputMethodContext; - -import java.awt.event.KeyEvent; -import java.awt.event.InputMethodEvent; -import java.awt.font.TextAttribute; -import java.awt.font.TextHitInfo; - -import java.text.AttributedCharacterIterator; - -import java.util.Hashtable; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -class IndicInputMethodImpl { - - protected char[] KBD_MAP; - - private static final char SUBSTITUTION_BASE = '\uff00'; - - // Indexed by map value - SUBSTITUTION_BASE - protected char[][] SUBSTITUTION_TABLE; - - // Invalid character. - private static final char INVALID_CHAR = '\uffff'; - - // Unmapped versions of some interesting characters. - private static final char KEY_SIGN_VIRAMA = '\u0064'; // or just 'd'?? - private static final char KEY_SIGN_NUKTA = '\u005d'; // or just ']'?? - - // Two succeeding viramas are replaced by one virama and one ZWNJ. - // Viram followed by Nukta is replaced by one VIRAMA and one ZWJ - private static final char ZWJ = '\u200d'; - private static final char ZWNJ = '\u200c'; - - // Backspace - private static final char BACKSPACE = '\u0008'; - - // Sorted list of characters which can be followed by Nukta - protected char[] JOIN_WITH_NUKTA; - - // Nukta form of the above characters - protected char[] NUKTA_FORM; - - private int log2; - private int power; - private int extra; - - // cached TextHitInfo. Only one type of TextHitInfo is required. - private static final TextHitInfo ZERO_TRAILING_HIT_INFO = TextHitInfo.trailing(0); - - /** - * Returns the index of the given character in the JOIN_WITH_NUKTA array. - * If character is not found, -1 is returned. - */ - private int nuktaIndex(char ch) { - - if (JOIN_WITH_NUKTA == null) { - return -1; - } - - int probe = power; - int index = 0; - - if (JOIN_WITH_NUKTA[extra] <= ch) { - index = extra; - } - - while (probe > (1 << 0)) { - probe >>= 1; - - if (JOIN_WITH_NUKTA[index + probe] <= ch) { - index += probe; - } - } - - if (JOIN_WITH_NUKTA[index] != ch) { - index = -1; - } - - return index; - } - - /** - * Returns the equivalent character for hindi locale. - * @param originalChar The original character. - */ - private char getMappedChar( char originalChar ) - { - if (originalChar <= KBD_MAP.length) { - return KBD_MAP[originalChar]; - } - - return originalChar; - }//getMappedChar() - - // Array used to hold the text to be sent. - // If the last character was not committed it is stored in text[0]. - // The variable totalChars give an indication of whether the last - // character was committed or not. If at any time ( but not within a - // a call to dispatchEvent ) totalChars is not equal to 0 ( it can - // only be 1 otherwise ) the last character was not committed. - private char [] text = new char[4]; - - // this is always 0 before and after call to dispatchEvent. This character assumes - // significance only within a call to dispatchEvent. - private int committedChars = 0;// number of committed characters - - // the total valid characters in variable text currently. - private int totalChars = 0;//number of total characters ( committed + composed ) - - private boolean lastCharWasVirama = false; - - private InputMethodContext context; - - // - // Finds the high bit by binary searching - // through the bits in n. - // - private static byte highBit(int n) - { - if (n <= 0) { - return -32; - } - - byte bit = 0; - - if (n >= 1 << 16) { - n >>= 16; - bit += 16; - } - - if (n >= 1 << 8) { - n >>= 8; - bit += 8; - } - - if (n >= 1 << 4) { - n >>= 4; - bit += 4; - } - - if (n >= 1 << 2) { - n >>= 2; - bit += 2; - } - - if (n >= 1 << 1) { - n >>= 1; - bit += 1; - } - - return bit; - } - - IndicInputMethodImpl(char[] keyboardMap, char[] joinWithNukta, char[] nuktaForm, - char[][] substitutionTable) { - KBD_MAP = keyboardMap; - JOIN_WITH_NUKTA = joinWithNukta; - NUKTA_FORM = nuktaForm; - SUBSTITUTION_TABLE = substitutionTable; - - if (JOIN_WITH_NUKTA != null) { - int log2 = highBit(JOIN_WITH_NUKTA.length); - - power = 1 << log2; - extra = JOIN_WITH_NUKTA.length - power; - } else { - power = extra = 0; - } - - } - - void setInputMethodContext(InputMethodContext context) { - - this.context = context; - } - - void handleKeyTyped(KeyEvent kevent) { - - char keyChar = kevent.getKeyChar(); - char currentChar = getMappedChar(keyChar); - - // The Explicit and Soft Halanta case. - if ( lastCharWasVirama ) { - switch (keyChar) { - case KEY_SIGN_NUKTA: - currentChar = ZWJ; - break; - case KEY_SIGN_VIRAMA: - currentChar = ZWNJ; - break; - default: - }//endSwitch - }//endif - - if (currentChar == INVALID_CHAR) { - kevent.consume(); - return; - } - - if (currentChar == BACKSPACE) { - lastCharWasVirama = false; - - if (totalChars > 0) { - totalChars = committedChars = 0; - } else { - return; - } - } - else if (keyChar == KEY_SIGN_NUKTA) { - int nuktaIndex = nuktaIndex(text[0]); - - if (nuktaIndex != -1) { - text[0] = NUKTA_FORM[nuktaIndex]; - } else { - // the last character was committed, commit just Nukta. - // Note : the lastChar must have been committed if it is not one of - // the characters which combine with nukta. - // the state must be totalChars = committedChars = 0; - text[totalChars++] = currentChar; - } - - committedChars += 1; - } - else { - int nuktaIndex = nuktaIndex(currentChar); - - if (nuktaIndex != -1) { - // Commit everything but currentChar - text[totalChars++] = currentChar; - committedChars = totalChars-1; - } else { - if (currentChar >= SUBSTITUTION_BASE) { - char[] sub = SUBSTITUTION_TABLE[currentChar - SUBSTITUTION_BASE]; - - System.arraycopy(sub, 0, text, totalChars, sub.length); - totalChars += sub.length; - } else { - text[totalChars++] = currentChar; - } - - committedChars = totalChars; - } - } - - ACIText aText = new ACIText( text, 0, totalChars, committedChars ); - int composedCharLength = totalChars - committedChars; - TextHitInfo caret=null,visiblePosition=null; - switch( composedCharLength ) { - case 0: - break; - case 1: - visiblePosition = caret = ZERO_TRAILING_HIT_INFO; - break; - default: - assert false : "The code should not reach here. There is no case where there can be more than one character pending."; - } - - context.dispatchInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, - aText, - committedChars, - caret, - visiblePosition); - - if (totalChars == 0) { - text[0] = INVALID_CHAR; - } else { - text[0] = text[totalChars - 1];// make text[0] hold the last character - } - - lastCharWasVirama = keyChar == KEY_SIGN_VIRAMA && !lastCharWasVirama; - - totalChars -= committedChars; - committedChars = 0; - // state now text[0] = last character - // totalChars = ( last character committed )? 0 : 1; - // committedChars = 0; - - kevent.consume();// prevent client from getting this event. - }//dispatchEvent() - - void endComposition() { - if( totalChars != 0 ) {// if some character is not committed. - ACIText aText = new ACIText( text, 0, totalChars, totalChars ); - context.dispatchInputMethodEvent( InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, - aText, totalChars, null, null ); - totalChars = committedChars = 0; - text[0] = INVALID_CHAR; - lastCharWasVirama = false; - }//end if - }//endComposition() - - // custom AttributedCharacterIterator -- much lightweight since currently there is no - // attribute defined on the text being generated by the input method. - private class ACIText implements AttributedCharacterIterator { - private char [] text = null; - private int committed = 0; - private int index = 0; - - ACIText( char [] chArray, int offset, int length, int committed ) { - this.text = new char[length]; - this.committed = committed; - System.arraycopy( chArray, offset, text, 0, length ); - }//c'tor - - // CharacterIterator methods. - public char first() { - return _setIndex( 0 ); - } - - public char last() { - if( text.length == 0 ) { - return _setIndex( text.length ); - } - return _setIndex( text.length - 1 ); - } - - public char current() { - if( index == text.length ) - return DONE; - return text[index]; - } - - public char next() { - if( index == text.length ) { - return DONE; - } - return _setIndex( index + 1 ); - } - - public char previous() { - if( index == 0 ) - return DONE; - return _setIndex( index - 1 ); - } - - public char setIndex(int position) { - if( position < 0 || position > text.length ) { - throw new IllegalArgumentException(); - } - return _setIndex( position ); - } - - public int getBeginIndex() { - return 0; - } - - public int getEndIndex() { - return text.length; - } - - public int getIndex() { - return index; - } - - public Object clone() { - try { - ACIText clone = (ACIText) super.clone(); - return clone; - } catch (CloneNotSupportedException e) { - throw new InternalError(); - } - } - - - // AttributedCharacterIterator methods. - public int getRunStart() { - return index >= committed ? committed : 0; - } - - public int getRunStart(AttributedCharacterIterator.Attribute attribute) { - return (index >= committed && - attribute == TextAttribute.INPUT_METHOD_UNDERLINE) ? committed : 0; - } - - public int getRunStart(Set attributes) { - return (index >= committed && - attributes.contains(TextAttribute.INPUT_METHOD_UNDERLINE)) ? committed : 0; - } - - public int getRunLimit() { - return index < committed ? committed : text.length; - } - - public int getRunLimit(AttributedCharacterIterator.Attribute attribute) { - return (index < committed && - attribute == TextAttribute.INPUT_METHOD_UNDERLINE) ? committed : text.length; - } - - public int getRunLimit(Set attributes) { - return (index < committed && - attributes.contains(TextAttribute.INPUT_METHOD_UNDERLINE)) ? committed : text.length; - } - - public Map getAttributes() { - Hashtable result = new Hashtable(); - if (index >= committed && committed < text.length) { - result.put(TextAttribute.INPUT_METHOD_UNDERLINE, - TextAttribute.UNDERLINE_LOW_ONE_PIXEL); - } - return result; - } - - public Object getAttribute(AttributedCharacterIterator.Attribute attribute) { - if (index >= committed && - committed < text.length && - attribute == TextAttribute.INPUT_METHOD_UNDERLINE) { - - return TextAttribute.UNDERLINE_LOW_ONE_PIXEL; - } - return null; - } - - public Set getAllAttributeKeys() { - HashSet result = new HashSet(); - if (committed < text.length) { - result.add(TextAttribute.INPUT_METHOD_UNDERLINE); - } - return result; - } - - // private methods - - /** - * This is always called with valid i ( 0 < i <= text.length ) - */ - private char _setIndex( int i ) { - index = i; - if( i == text.length ) { - return DONE; - } - return text[i]; - }//_setIndex() - - }//end of inner class -} diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/java.awt.im.spi.InputMethodDescriptor b/src/share/classes/com/sun/inputmethods/internal/indicim/java.awt.im.spi.InputMethodDescriptor deleted file mode 100644 index f06b18187..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/java.awt.im.spi.InputMethodDescriptor +++ /dev/null @@ -1 +0,0 @@ -com.sun.inputmethods.internal.indicim.DevanagariInputMethodDescriptor diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames.properties b/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames.properties deleted file mode 100644 index f0feb6395..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames.properties +++ /dev/null @@ -1,6 +0,0 @@ -# -# Default Input method display names for Indic input methods -# - -DisplayName.Devanagari = Devanagari Input Method - diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_de.properties b/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_de.properties deleted file mode 100644 index c460ffeb9..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_de.properties +++ /dev/null @@ -1,5 +0,0 @@ -# -# Default Input method display names for Indic input methods -# - -DisplayName.Devanagari = Devanagari Input Method diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_es.properties b/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_es.properties deleted file mode 100644 index c460ffeb9..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_es.properties +++ /dev/null @@ -1,5 +0,0 @@ -# -# Default Input method display names for Indic input methods -# - -DisplayName.Devanagari = Devanagari Input Method diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_fr.properties b/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_fr.properties deleted file mode 100644 index c460ffeb9..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_fr.properties +++ /dev/null @@ -1,5 +0,0 @@ -# -# Default Input method display names for Indic input methods -# - -DisplayName.Devanagari = Devanagari Input Method diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_it.properties b/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_it.properties deleted file mode 100644 index c460ffeb9..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_it.properties +++ /dev/null @@ -1,5 +0,0 @@ -# -# Default Input method display names for Indic input methods -# - -DisplayName.Devanagari = Devanagari Input Method diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_ja.properties b/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_ja.properties deleted file mode 100644 index e668c6e5c..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_ja.properties +++ /dev/null @@ -1,5 +0,0 @@ -# -# Default Input method display names for Indic input methods -# - -DisplayName.Devanagari = \u30c7\u30fc\u30f4\u30a1\u30ca\u30fc\u30ac\u30ea\u30fc\u30a4\u30f3\u30d7\u30c3\u30c8\u30e1\u30bd\u30c3\u30c9 diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_ko.properties b/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_ko.properties deleted file mode 100644 index 514b240ca..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_ko.properties +++ /dev/null @@ -1,5 +0,0 @@ -# -# Default Input method display names for Indic input methods -# - -DisplayName.Devanagari = Devanagari \uc785\ub825 \uba54\uc18c\ub4dc diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_sv.properties b/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_sv.properties deleted file mode 100644 index c460ffeb9..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_sv.properties +++ /dev/null @@ -1,5 +0,0 @@ -# -# Default Input method display names for Indic input methods -# - -DisplayName.Devanagari = Devanagari Input Method diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_zh_CN.properties b/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_zh_CN.properties deleted file mode 100644 index 895fd8f8e..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_zh_CN.properties +++ /dev/null @@ -1,5 +0,0 @@ -# -# Default Input method display names for Indic input methods -# - -DisplayName.Devanagari = Devanagari \u8f93\u5165\u6cd5 diff --git a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_zh_TW.properties b/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_zh_TW.properties deleted file mode 100644 index 6b228d84c..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/indicim/resources/DisplayNames_zh_TW.properties +++ /dev/null @@ -1,5 +0,0 @@ -# -# Default Input method display names for Indic input methods -# - -DisplayName.Devanagari = Devanagari \u8f38\u5165\u6cd5 diff --git a/src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiInputMethod.java b/src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiInputMethod.java deleted file mode 100644 index fb1509642..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiInputMethod.java +++ /dev/null @@ -1,437 +0,0 @@ -/* - * Portions Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -/* - * - * (C) Copyright IBM Corp. 2000 - All Rights Reserved - * - * The original version of this source code and documentation is - * copyrighted and owned by IBM. These materials are provided - * under terms of a License Agreement between IBM and Sun. - * This technology is protected by multiple US and International - * patents. This notice and attribution to IBM may not be removed. - * - */ - -package com.sun.inputmethods.internal.thaiim; - -import java.awt.im.spi.InputMethod; -import java.awt.im.spi.InputMethodContext; - -import java.awt.AWTEvent; -import java.awt.Rectangle; - -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; - -import java.lang.Character.Subset; - -import java.util.Locale; - -class ThaiInputMethod implements InputMethod { - - private ThaiInputMethodImpl impl; - private Locale locale; - - ThaiInputMethod(Locale theLocale, ThaiInputMethodImpl theImplementation) { - locale = theLocale; - impl = theImplementation; - } - - /** - * Sets the input method context, which is used to dispatch input method - * events to the client component and to request information from - * the client component. - *

      - * This method is called once immediately after instantiating this input - * method. - * - * @param context the input method context for this input method - * @exception NullPointerException if context is null - */ - public void setInputMethodContext(InputMethodContext context) { - - impl.setInputMethodContext(context); - } - - /** - * Attempts to set the input locale. If the input method supports the - * desired locale, it changes its behavior to support input for the locale - * and returns true. - * Otherwise, it returns false and does not change its behavior. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}, - *
      • when switching to this input method through the user interface if the user - * specified a locale or if the previously selected input method's - * {@link java.awt.im.spi.InputMethod#getLocale getLocale} method - * returns a non-null value. - *
      - * - * @param locale locale to input - * @return whether the specified locale is supported - * @exception NullPointerException if locale is null - */ - public boolean setLocale(Locale locale) { - - if (locale.getLanguage().equals(this.locale.getLanguage())) { - //System.out.println("returning true for locale " + locale); - return true; - } - else { - //System.out.println("returning false for locale " + locale); - return false; - } - } - - /** - * Returns the current input locale. Might return null in exceptional cases. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#getLocale InputContext.getLocale} and - *
      • when switching from this input method to a different one through the - * user interface. - *
      - * - * @return the current input locale, or null - */ - public Locale getLocale() { - - return locale; - } - - /** - * Sets the subsets of the Unicode character set that this input method - * is allowed to input. Null may be passed in to indicate that all - * characters are allowed. - *

      - * This method is called - *

        - *
      • immediately after instantiating this input method, - *
      • when switching to this input method from a different one, and - *
      • by {@link java.awt.im.InputContext#setCharacterSubsets InputContext.setCharacterSubsets}. - *
      - * - * @param subsets the subsets of the Unicode character set from which - * characters may be input - */ - public void setCharacterSubsets(Subset[] subsets) { - } - - /** - * Enables or disables this input method for composition, - * depending on the value of the parameter enable. - *

      - * An input method that is enabled for composition interprets incoming - * events for both composition and control purposes, while a - * disabled input method does not interpret events for composition. - * Note however that events are passed on to the input method regardless - * whether it is enabled or not, and that an input method that is disabled - * for composition may still interpret events for control purposes, - * including to enable or disable itself for composition. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#setCompositionEnabled InputContext.setCompositionEnabled}, - *
      • when switching to this input method from a different one using the - * user interface or - * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}, - * if the previously selected input method's - * {@link java.awt.im.spi.InputMethod#isCompositionEnabled isCompositionEnabled} - * method returns without throwing an exception. - *
      - * - * @param enable whether to enable the input method for composition - * @throws UnsupportedOperationException if this input method does not - * support the enabling/disabling operation - * @see #isCompositionEnabled - */ - public void setCompositionEnabled(boolean enable) { - - throw new UnsupportedOperationException(); - } - - /** - * Determines whether this input method is enabled. - * An input method that is enabled for composition interprets incoming - * events for both composition and control purposes, while a - * disabled input method does not interpret events for composition. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#isCompositionEnabled InputContext.isCompositionEnabled} and - *
      • when switching from this input method to a different one using the - * user interface or - * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}. - *
      - * - * @return true if this input method is enabled for - * composition; false otherwise. - * @throws UnsupportedOperationException if this input method does not - * support checking whether it is enabled for composition - * @see #setCompositionEnabled - */ - public boolean isCompositionEnabled() { - - return true; - } - - /** - * Starts the reconversion operation. The input method obtains the - * text to be reconverted from the current client component using the - * {@link java.awt.im.InputMethodRequests#getSelectedText InputMethodRequests.getSelectedText} - * method. It can use other InputMethodRequests - * methods to request additional information required for the - * reconversion operation. The composed and committed text - * produced by the operation is sent to the client component as a - * sequence of InputMethodEvents. If the given text - * cannot be reconverted, the same text should be sent to the - * client component as committed text. - *

      - * This method is called by - * {@link java.awt.im.InputContext#reconvert() InputContext.reconvert}. - * - * @throws UnsupportedOperationException if the input method does not - * support the reconversion operation. - */ - public void reconvert() { - - throw new UnsupportedOperationException("This input method does not reconvert."); - } - - /** - * Dispatches the event to the input method. If input method support is - * enabled for the focussed component, incoming events of certain types - * are dispatched to the current input method for this component before - * they are dispatched to the component's methods or event listeners. - * The input method decides whether it needs to handle the event. If it - * does, it also calls the event's consume method; this - * causes the event to not get dispatched to the component's event - * processing methods or event listeners. - *

      - * Events are dispatched if they are instances of InputEvent or its - * subclasses. - * This includes instances of the AWT classes KeyEvent and MouseEvent. - *

      - * This method is called by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}. - * - * @param event the event being dispatched to the input method - * @exception NullPointerException if event is null - */ - public void dispatchEvent(AWTEvent event) { - - if (event instanceof KeyEvent) { - - KeyEvent keyEvent = (KeyEvent) event; - if (event.getID() == KeyEvent.KEY_TYPED) { - //System.out.println("handled event " + event); - impl.handleKeyTyped(keyEvent); - } - } - else { - //System.out.println("did not handle event " + event); - } - } - - /** - * Notifies this input method of changes in the client window - * location or state. This method is called while this input - * method is the current input method of its input context and - * notifications for it are enabled (see {@link - * InputMethodContext#enableClientWindowNotification - * InputMethodContext.enableClientWindowNotification}). Calls - * to this method are temporarily suspended if the input context's - * {@link java.awt.im.InputContext#removeNotify removeNotify} - * method is called, and resume when the input method is activated - * for a new client component. It is called in the following - * situations: - *

        - *
      • - * when the window containing the current client component changes - * in location, size, visibility, iconification state, or when the - * window is closed.
      • - *
      • - * from enableClientWindowNotification(inputMethod, - * true) if the current client component exists,
      • - *
      • - * when activating the input method for the first time after it - * called - * enableClientWindowNotification(inputMethod, - * true) if during the call no current client component was - * available,
      • - *
      • - * when activating the input method for a new client component - * after the input context's removeNotify method has been - * called.
      • - *
      - * @param bounds client window's {@link - * java.awt.Component#getBounds bounds} on the screen; or null if - * the client window is iconified or invisible - */ - public void notifyClientWindowChange(Rectangle bounds) { - } - - /** - * Activates the input method for immediate input processing. - *

      - * If an input method provides its own windows, it should make sure - * at this point that all necessary windows are open and visible. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent} - * when a client component receives a FOCUS_GAINED event, - *
      • when switching to this input method from a different one using the - * user interface or - * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}. - *
      - * The method is only called when the input method is inactive. - * A newly instantiated input method is assumed to be inactive. - */ - public void activate() { - //System.out.println("activated"); - } - - /** - * Deactivates the input method. - * The isTemporary argument has the same meaning as in - * {@link java.awt.event.FocusEvent#isTemporary FocusEvent.isTemporary}. - *

      - * If an input method provides its own windows, only windows that relate - * to the current composition (such as a lookup choice window) should be - * closed at this point. - * It is possible that the input method will be immediately activated again - * for a different client component, and closing and reopening more - * persistent windows (such as a control panel) would create unnecessary - * screen flicker. - * Before an instance of a different input method class is activated, - * {@link #hideWindows} is called on the current input method. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent} - * when a client component receives a FOCUS_LOST event, - *
      • when switching from this input method to a different one using the - * user interface or - * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}, - *
      • before {@link #removeNotify removeNotify} if the current client component is - * removed. - *
      - * The method is only called when the input method is active. - * - * @param isTemporary whether the focus change is temporary - */ - public void deactivate(boolean isTemporary) { - //System.out.println("deactivated"); - } - - /** - * Closes or hides all windows opened by this input method instance or - * its class. - *

      - * This method is called - *

        - *
      • before calling {@link #activate activate} on an instance of a different input - * method class, - *
      • before calling {@link #dispose dispose} on this input method. - *
      - * The method is only called when the input method is inactive. - */ - public void hideWindows() { - } - - /** - * Notifies the input method that a client component has been - * removed from its containment hierarchy, or that input method - * support has been disabled for the component. - *

      - * This method is called by {@link java.awt.im.InputContext#removeNotify InputContext.removeNotify}. - *

      - * The method is only called when the input method is inactive. - */ - public void removeNotify() { - } - - /** - * Ends any input composition that may currently be going on in this - * context. Depending on the platform and possibly user preferences, - * this may commit or delete uncommitted text. Any changes to the text - * are communicated to the active component using an input method event. - * - *

      - * A text editing component may call this in a variety of situations, - * for example, when the user moves the insertion point within the text - * (but outside the composed text), or when the component's text is - * saved to a file or copied to the clipboard. - *

      - * This method is called - *

        - *
      • by {@link java.awt.im.InputContext#endComposition InputContext.endComposition}, - *
      • by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent} - * when switching to a different client component - *
      • when switching from this input method to a different one using the - * user interface or - * {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}. - *
      - */ - public void endComposition() { - - impl.endComposition(); - } - - /** - * Disposes of the input method and releases the resources used by it. - * In particular, the input method should dispose windows and close files that are no - * longer needed. - *

      - * This method is called by {@link java.awt.im.InputContext#dispose InputContext.dispose}. - *

      - * The method is only called when the input method is inactive. - * No method of this interface is called on this instance after dispose. - */ - public void dispose() { - } - - /** - * Returns a control object from this input method, or null. A - * control object provides methods that control the behavior of the - * input method or obtain information from the input method. The type - * of the object is an input method specific class. Clients have to - * compare the result against known input method control object - * classes and cast to the appropriate class to invoke the methods - * provided. - *

      - * This method is called by - * {@link java.awt.im.InputContext#getInputMethodControlObject InputContext.getInputMethodControlObject}. - * - * @return a control object from this input method, or null - */ - public Object getControlObject() { - - return null; - } -} diff --git a/src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiInputMethodDescriptor.java b/src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiInputMethodDescriptor.java deleted file mode 100644 index b8f172c3e..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiInputMethodDescriptor.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Portions Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -/* - * - * (C) Copyright IBM Corp. 2000 - All Rights Reserved - * - * The original version of this source code and documentation is - * copyrighted and owned by IBM. These materials are provided - * under terms of a License Agreement between IBM and Sun. - * This technology is protected by multiple US and International - * patents. This notice and attribution to IBM may not be removed. - * - */ - -package com.sun.inputmethods.internal.thaiim; - -import java.awt.Image; -import java.awt.im.spi.InputMethod; -import java.awt.im.spi.InputMethodDescriptor; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -public class ThaiInputMethodDescriptor implements InputMethodDescriptor { - - static final Locale THAI = new Locale("th"); - - public ThaiInputMethodDescriptor() { - } - - /** - * @see java.awt.im.spi.InputMethodDescriptor#getAvailableLocales - */ - public Locale[] getAvailableLocales() { - return new Locale[] { THAI }; - } - - /** - * @see java.awt.im.spi.InputMethodDescriptor#hasDynamicLocaleList - */ - public boolean hasDynamicLocaleList() { - return false; - } - - /** - * @see java.awt.im.spi.InputMethodDescriptor#getInputMethodDisplayName - */ - public synchronized String getInputMethodDisplayName(Locale inputLocale, Locale displayLanguage) { - try { - ResourceBundle resources = ResourceBundle.getBundle( - "com.sun.inputmethods.internal.thaiim.resources.DisplayNames", displayLanguage); - return resources.getString("DisplayName.Thai"); - } catch (MissingResourceException mre) { - return "Thai Input Method"; - } - } - - /** - * @see java.awt.im.spi.InputMethodDescriptor#getInputMethodIcon - */ - public Image getInputMethodIcon(Locale inputLocale) { - return null; - } - - /** - * @see java.awt.im.spi.InputMethodDescriptor#createInputMethod - */ - public InputMethod createInputMethod() throws Exception { - ThaiInputMethodImpl impl = new ThaiInputMethodImpl(); - return new ThaiInputMethod(THAI, impl); - } - - public String toString() { - return getClass().getName(); - } -} diff --git a/src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiInputMethodImpl.java b/src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiInputMethodImpl.java deleted file mode 100644 index dba664474..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiInputMethodImpl.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Portions Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -/* - * - * (C) Copyright IBM Corp. 2000 - All Rights Reserved - * - * The original version of this source code and documentation is - * copyrighted and owned by IBM. These materials are provided - * under terms of a License Agreement between IBM and Sun. - * This technology is protected by multiple US and International - * patents. This notice and attribution to IBM may not be removed. - * - */ - -package com.sun.inputmethods.internal.thaiim; - -import java.awt.im.InputMethodRequests; -import java.awt.im.spi.InputMethodContext; - -import java.awt.Toolkit; -import java.awt.event.KeyEvent; -import java.awt.event.InputMethodEvent; -import java.awt.font.TextAttribute; -import java.awt.font.TextHitInfo; - -import java.text.AttributedCharacterIterator; -import java.text.AttributedString; - -class ThaiInputMethodImpl { - - private static final char[] keyboardMap = { - /* 00 */ '\u0000', - /* 01 */ '\u0001', - /* 02 */ '\u0002', - /* 03 */ '\u0003', - /* 04 */ '\u0004', - /* 05 */ '\u0005', - /* 06 */ '\u0006', - /* 07 */ '\u0007', - /* 08 */ '\u0008', - /* 09 */ '\u0009', - /* 0A */ '\012', - /* 0B */ '\u000B', - /* 0C */ '\u000C', - /* 0D */ '\015', - /* 0E */ '\u000E', - /* 0F */ '\u000F', - /* 10 */ '\u0010', - /* 11 */ '\u0011', - /* 12 */ '\u0012', - /* 13 */ '\u0013', - /* 14 */ '\u0014', - /* 15 */ '\u0015', - /* 16 */ '\u0016', - /* 17 */ '\u0017', - /* 18 */ '\u0018', - /* 19 */ '\u0019', - /* 1A */ '\u001A', - /* 1B */ '\u001B', - /* 1C */ '\u001C', - /* 1D */ '\u001D', - /* 1E */ '\u001E', - /* 1F */ '\u001F', - /* 20 */ '\u0020', - /* 21 */ '\u0e45', // '!' - /* 22 */ '\u002e', // '"' - /* 23 */ '\u0e52', // '#' - /* 24 */ '\u0e53', // '$' - /* 25 */ '\u0e54', // '%' - /* 26 */ '\u0e4e', // '&' - /* 27 */ '\u0e07', // ''' - /* 28 */ '\u0e56', // '(' - /* 29 */ '\u0e57', // ')' - /* 2A */ '\u0e55', // '*' - /* 2B */ '\u0e59', // '+' - /* 2C */ '\u0e21', // ',' - /* 2D */ '\u0e02', // '-' - /* 2E */ '\u0e43', // '.' - /* 2F */ '\u0e1d', // '/' - /* 30 */ '\u0e08', // '0' - /* 31 */ '\u0e3f', // '1' - /* 32 */ '\u002f', // '2' - /* 33 */ '\u002d', // '3' - /* 34 */ '\u0e20', // '4' - /* 35 */ '\u0e16', // '5' - /* 36 */ '\u0e38', // '6' - /* 37 */ '\u0e36', // '7' - /* 38 */ '\u0e04', // '8' - /* 39 */ '\u0e15', // '9' - /* 3A */ '\u0e0b', // ':' - /* 3B */ '\u0e27', // ';' - /* 3C */ '\u0e12', // '<' - /* 3D */ '\u0e0a', // '=' - /* 3E */ '\u0e2c', // '>' - /* 3F */ '\u0e26', // '?' - /* 40 */ '\u0e51', // '@' - /* 41 */ '\u0e24', // 'A' - /* 42 */ '\u0e3a', // 'B' - /* 43 */ '\u0e09', // 'C' - /* 44 */ '\u0e0f', // 'D' - /* 45 */ '\u0e0e', // 'E' - /* 46 */ '\u0e42', // 'F' - /* 47 */ '\u0e0c', // 'G' - /* 48 */ '\u0e47', // 'H' - /* 49 */ '\u0e13', // 'I' - /* 4A */ '\u0e4b', // 'J' - /* 4B */ '\u0e29', // 'K' - /* 4C */ '\u0e28', // 'L' - /* 4D */ '\u003f', // 'M' - /* 4E */ '\u0e4c', // 'N' - /* 4F */ '\u0e2f', // 'O' - /* 50 */ '\u0e0d', // 'P' - /* 51 */ '\u0e50', // 'Q' - /* 52 */ '\u0e11', // 'R' - /* 53 */ '\u0e06', // 'S' - /* 54 */ '\u0e18', // 'T' - /* 55 */ '\u0e4a', // 'U' - /* 56 */ '\u0e2e', // 'V' - /* 57 */ '\u0022', // 'W' - /* 58 */ '\u0029', // 'X' - /* 59 */ '\u0e4d', // 'Y' - /* 5A */ '\u0028', // 'Z' - /* 5B */ '\u0e1a', // '[' - /* 5C */ '\u0e05', // '\' - /* 5D */ '\u0e25', // ']' - /* 5E */ '\u0e39', // '^' - /* 5F */ '\u0e58', // '_' - /* 60 */ '\u0e4f', // '`' - /* 61 */ '\u0e1f', // 'a' - /* 62 */ '\u0e34', // 'b' - /* 63 */ '\u0e41', // 'c' - /* 64 */ '\u0e01', // 'd' - /* 65 */ '\u0e33', // 'e' - /* 66 */ '\u0e14', // 'f' - /* 67 */ '\u0e40', // 'g' - /* 68 */ '\u0e49', // 'h' - /* 69 */ '\u0e23', // 'i' - /* 6A */ '\u0e48', // 'j' - /* 6B */ '\u0e32', // 'k' - /* 6C */ '\u0e2a', // 'l' - /* 6D */ '\u0e17', // 'm' - /* 6E */ '\u0e37', // 'n' - /* 6F */ '\u0e19', // 'o' - /* 70 */ '\u0e22', // 'p' - /* 71 */ '\u0e46', // 'q' - /* 72 */ '\u0e1e', // 'r' - /* 73 */ '\u0e2b', // 's' - /* 74 */ '\u0e30', // 't' - /* 75 */ '\u0e35', // 'u' - /* 76 */ '\u0e2d', // 'v' - /* 77 */ '\u0e44', // 'w' - /* 78 */ '\u0e1b', // 'x' - /* 79 */ '\u0e31', // 'y' - /* 7A */ '\u0e1c', // 'z' - /* 7B */ '\u0e10', // '{' - /* 7C */ '\u0e03', // '|' - /* 7D */ '\u002c', // '}' - /* 7E */ '\u0e5b', // '~' - /* 7F */ '\u007F' // - }; - - // cached TextHitInfo. Only one type of TextHitInfo is required. - private static final TextHitInfo ZERO_TRAILING_HIT_INFO = TextHitInfo.trailing(0); - - private ThaiRules rules; - - /** - * Returns the equivalent character for thai locale. - * @param originalChar The original character. - */ - private char getMappedChar( char originalChar ) - { - if (originalChar <= keyboardMap.length) { - return keyboardMap[originalChar]; - } - - return originalChar; - }//getMappedChar() - - private InputMethodContext context; - - void setInputMethodContext(InputMethodContext context) { - this.context = context; - rules = new ThaiRules((InputMethodRequests)context); - } - - void handleKeyTyped(KeyEvent kevent) { - char keyChar = kevent.getKeyChar(); - char currentChar = getMappedChar(keyChar); - if (!Character.UnicodeBlock.THAI.equals(Character.UnicodeBlock.of(currentChar))) { - // don't care - return; - } else if (rules.isInputValid(currentChar)) { - Character tmp = new Character(currentChar); - String tmp2 = tmp.toString(); - context.dispatchInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, - (new AttributedString(tmp2)).getIterator(), - 1, - ZERO_TRAILING_HIT_INFO, - ZERO_TRAILING_HIT_INFO); - } else { - // input sequence is not allowed - Toolkit.getDefaultToolkit().beep(); - } - - kevent.consume();// prevent client from getting this event. - return; - }//dispatchEvent() - - void endComposition() { - }//endComposition() -} diff --git a/src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiRules.java b/src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiRules.java deleted file mode 100644 index 5dc89b2b7..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/thaiim/ThaiRules.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -package com.sun.inputmethods.internal.thaiim; - -import java.awt.im.InputMethodRequests; - -public class ThaiRules { - - public static final char BASE = 0x0e00; - - public static final byte NON = 0; - public static final byte CONS = 1; - public static final byte LV = 2; - public static final byte FV1 = 3; - public static final byte FV2 = 4; - public static final byte FV3 = 5; - public static final byte FV4 = 6; - /* Note that FV4 is added. It is not in WTT. - * We need it for SARA AM since it has a - * weired characteristic to share the same - * cell with whatever consonant preceeds it. - */ - public static final byte BV1 = 7; - public static final byte BV2 = 8; - public static final byte BD = 9; - public static final byte TONE = 10; - public static final byte AD1 = 11; - public static final byte AD2 = 12; - public static final byte AD3 = 13; - public static final byte AV1 = 14; - public static final byte AV2 = 15; - public static final byte AV3 = 16; - - /** - * Constants for validity checking and auto correction - */ - public static final byte STRICT = 0; - public static final byte LOOSE = 1; - public static final byte NOREPLACE = 2; - - public static final byte[] CHARTYPE = { - /* 0e00 UNUSED */ NON, - /* THAI CHARACTER KO KAI */ CONS, - /* THAI CHARACTER KHO KHAI */ CONS, - /* THAI CHARACTER KHO KHUAT */ CONS, - /* THAI CHARACTER KHO KHWAI */ CONS, - /* THAI CHARACTER KHO KHON */ CONS, - /* THAI CHARACTER KHO RAKHANG */ CONS, - /* THAI CHARACTER NGO NGU */ CONS, - /* THAI CHARACTER CHO CHAN */ CONS, - /* THAI CHARACTER CHO CHING */ CONS, - /* THAI CHARACTER CHO CHANG */ CONS, - /* THAI CHARACTER SO SO */ CONS, - /* THAI CHARACTER CHO CHOE */ CONS, - /* THAI CHARACTER YO YING */ CONS, - /* THAI CHARACTER DO CHADA */ CONS, - /* THAI CHARACTER TO PATAK */ CONS, - /* THAI CHARACTER THO THAN */ CONS, - /* THAI CHARACTER THO NANGMONTHO */ CONS, - /* THAI CHARACTER THO PHUTHAO */ CONS, - /* THAI CHARACTER NO NEN */ CONS, - /* THAI CHARACTER DO DEK */ CONS, - /* THAI CHARACTER TO TAO */ CONS, - /* THAI CHARACTER THO THUNG */ CONS, - /* THAI CHARACTER THO THAHAN */ CONS, - /* THAI CHARACTER THO THONG */ CONS, - /* THAI CHARACTER NO NU */ CONS, - /* THAI CHARACTER BO BAIMAI */ CONS, - /* THAI CHARACTER PO PLA */ CONS, - /* THAI CHARACTER PHO PHUNG */ CONS, - /* THAI CHARACTER FO FA */ CONS, - /* THAI CHARACTER PHO PHAN */ CONS, - /* THAI CHARACTER FO FAN */ CONS, - /* THAI CHARACTER PHO SAMPHAO */ CONS, - /* THAI CHARACTER MO MA */ CONS, - /* THAI CHARACTER YO YAK */ CONS, - /* THAI CHARACTER RO RUA */ CONS, - /* THAI CHARACTER RU */ FV3, - /* THAI CHARACTER LO LING */ CONS, - /* THAI CHARACTER LU */ FV3, - /* THAI CHARACTER WO WAEN */ CONS, - /* THAI CHARACTER SO SALA */ CONS, - /* THAI CHARACTER SO RUSI */ CONS, - /* THAI CHARACTER SO SUA */ CONS, - /* THAI CHARACTER HO HIP */ CONS, - /* THAI CHARACTER LO CHULA */ CONS, - /* THAI CHARACTER O ANG */ CONS, - /* THAI CHARACTER HO NOKHUK */ CONS, - /* THAI CHARACTER PAIYANNOI */ NON, - /* THAI CHARACTER SARA A */ FV1, - /* THAI CHARACTER MAI HAN-AKAT */ AV2, - /* THAI CHARACTER SARA AA */ FV1, - /* THAI CHARACTER SARA AM */ FV4, - /* THAI CHARACTER SARA I */ AV1, - /* THAI CHARACTER SARA II */ AV3, - /* THAI CHARACTER SARA UE */ AV2, - /* THAI CHARACTER SARA UEE */ AV3, - /* THAI CHARACTER SARA U */ BV1, - /* THAI CHARACTER SARA UU */ BV2, - /* THAI CHARACTER PHINTHU */ BD, - /* 0e3b UNUSED */ NON, - /* 0e3c UNUSED */ NON, - /* 0e3d UNUSED */ NON, - /* 0e3e UNUSED */ NON, - /* THAI CURRENCY SYMBOL BAHT */ NON, - /* THAI CHARACTER SARA E */ LV, - /* THAI CHARACTER SARA AE */ LV, - /* THAI CHARACTER SARA O */ LV, - /* THAI CHARACTER SARA AI MAIMUAN */ LV, - /* THAI CHARACTER SARA AI MAIMALAI */ LV, - /* THAI CHARACTER LAKKHANGYAO */ FV2, - /* THAI CHARACTER MAIYAMOK */ NON, - /* THAI CHARACTER MAITAIKHU */ AD2, - /* THAI CHARACTER MAI EK */ TONE, - /* THAI CHARACTER MAI THO */ TONE, - /* THAI CHARACTER MAI TRI */ TONE, - /* THAI CHARACTER MAI CHATTAWA */ TONE, - /* THAI CHARACTER THANTHAKHAT */ AD1, - /* THAI CHARACTER NIKHAHIT */ AD3, - /* THAI CHARACTER YAMAKKAN */ AD3, - /* THAI CHARACTER FONGMAN */ NON, - /* THAI DIGIT ZERO */ NON, - /* THAI DIGIT ONE */ NON, - /* THAI DIGIT TWO */ NON, - /* THAI DIGIT THREE */ NON, - /* THAI DIGIT FOUR */ NON, - /* THAI DIGIT FIVE */ NON, - /* THAI DIGIT SIX */ NON, - /* THAI DIGIT SEVEN */ NON, - /* THAI DIGIT EIGHT */ NON, - /* THAI DIGIT NINE */ NON, - /* THAI CHARACTER ANGKHANKHU */ NON, - /* THAI CHARACTER KHOMUT */ NON - }; - - private InputMethodRequests requests; - - ThaiRules(InputMethodRequests requests) { - this.requests = requests; - } - - public static byte getCharType(char c) { - byte cType; - int ci = ((int) c) - (int) BASE; - if (ci < 0 || ci >= CHARTYPE.length) - cType = NON; - else - cType = CHARTYPE[ci]; - return cType; - } - - private static boolean isValid(char c1, char c2, int[] validityArray) { - return ((validityArray[getCharType(c1)] - & (1 << getCharType(c2))) != 0); - } - - /** - * VALIDITY is a bit matrix defining whether one - * character is allowed to be typed in after the - * previous one (array index). Determining the - * validity is done by bit-anding the 2nd char - * type's mask (obtained by 1 << chartype) with - * the array element indexed by the first char - * type. If the result is non-zero, the 2nd - * character is allowed to follow the first. - */ - - /* Please note that the bits in the comment below - * are displayed least significant bit first. - * The actual value reflexs this representation - * when the bits are swapped. - */ - - private static final int[] INPUTVALIDITY = { - /* NON 1110 010 0 0000 0000 0 */ 0x00027, - /* CONS 1111 111 1 1111 1111 1 */ 0x1ffff, - /* LV 0100 000 0 0000 0000 0 */ 0x00002, - /* FV1 1110 010 0 0000 0000 0 */ 0x00027, - /* FV2 1110 010 0 0000 0000 0 */ 0x00027, - /* FV3 1110 110 0 0000 0000 0 */ 0x00037, - /* FV4 1110 010 0 0000 0000 0 */ 0x00027, - /* BV1 1110 010 0 0011 0000 0 */ 0x00c27, - /* BV2 1110 010 0 0010 0000 0 */ 0x00427, - /* BD 1110 010 0 0000 0000 0 */ 0x00027, - /* TONE 1111 011 0 0000 0000 0 */ 0x0006f, - /* AD1 1110 010 0 0000 0000 0 */ 0x00027, - /* AD2 1110 010 0 0000 0000 0 */ 0x00027, - /* AD3 1110 010 0 0000 0000 0 */ 0x00027, - /* AV1 1110 010 0 0011 0000 0 */ 0x00c27, - /* AV2 1110 010 0 0010 0000 0 */ 0x00427, - /* AV3 1110 010 0 0010 0100 0 */ 0x02427 - }; - - private static final int[] COMPOSABLE = { - /* NON 0000 000 0 0000 0000 0 */ 0x00000, - /* CONS 0000 001 1 1111 1111 1 */ 0x1ffc0, - /* LV 0000 000 0 0000 0000 0 */ 0x00000, - /* FV1 0000 000 0 0000 0000 0 */ 0x00000, - /* FV2 0000 000 0 0000 0000 0 */ 0x00000, - /* FV3 0000 000 0 0000 0000 0 */ 0x00000, - /* FV4 0000 000 0 0000 0000 0 */ 0x00000, - /* BV1 0000 000 0 0011 0000 0 */ 0x00c00, - /* BV2 0000 000 0 0010 0000 0 */ 0x00400, - /* BD 0000 000 0 0000 0000 0 */ 0x00000, - /* TONE 0000 001 0 0000 0000 0 */ 0x00040, - /* AD1 0000 000 0 0000 0000 0 */ 0x00000, - /* AD2 0000 000 0 0000 0000 0 */ 0x00000, - /* AD3 0000 000 0 0000 0000 0 */ 0x00000, - /* AV1 0000 000 0 0011 0000 0 */ 0x00c00, - /* AV2 0000 000 0 0010 0000 0 */ 0x00400, - /* AV3 0000 000 0 0010 0100 0 */ 0x02400 - }; - - private static final int[] REPLACABLE = { - /* NON 0000 000 0 0000 0000 0 */ 0x00000, - /* CONS 0000 000 0 0000 0000 0 */ 0x00000, - /* LV 0000 000 0 0000 0000 0 */ 0x00000, - /* FV1 0000 000 0 0000 0000 0 */ 0x00000, - /* FV2 0000 000 0 0000 0000 0 */ 0x00000, - /* FV3 0000 000 0 0000 0000 0 */ 0x00000, - /* FV4 0000 001 1 1001 1111 1 */ 0x1f9c0, - /* BV1 0000 001 1 1100 1111 1 */ 0x1f3c0, - /* BV2 0000 001 1 1101 1111 1 */ 0x1fbc0, - /* BD 0000 001 1 1111 1111 1 */ 0x1ffc0, - /* TONE 0000 000 0 0111 1100 0 */ 0x03e00, - /* AD1 0000 001 0 1111 1101 1 */ 0x1bf40, - /* AD2 0000 001 1 1111 1111 1 */ 0x1ffc0, - /* AD3 0000 001 1 1111 1111 0 */ 0x0ffc0, - /* AV1 0000 001 1 1100 1111 1 */ 0x1f3c0, - /* AV2 0000 001 1 1101 1111 1 */ 0x1fbc0, - /* AV3 0000 001 1 1101 1011 1 */ 0x1dbc0 - }; - - private static final int[] SWAPPABLE = { - /* NON 0000 000 0 0000 0000 0 */ 0x00000, - /* CONS 0000 000 0 0000 0000 0 */ 0x00000, - /* LV 0000 000 0 0000 0000 0 */ 0x00000, - /* FV1 0000 000 0 0000 0000 0 */ 0x00000, - /* FV2 0000 000 0 0000 0000 0 */ 0x00000, - /* FV3 0000 000 0 0000 0000 0 */ 0x00000, - /* FV4 0000 000 0 0010 0000 0 */ 0x00400, - /* BV1 0000 000 0 0000 0000 0 */ 0x00000, - /* BV2 0000 000 0 0000 0000 0 */ 0x00000, - /* BD 0000 000 0 0000 0000 0 */ 0x00000, - /* TONE 0000 000 1 1000 0011 1 */ 0x1c180, - /* AD1 0000 000 1 0000 0010 0 */ 0x04080, - /* AD2 0000 000 0 0000 0000 0 */ 0x00000, - /* AD3 0000 000 0 0000 0000 1 */ 0x10000, - /* AV1 0000 000 0 0000 0000 0 */ 0x00000, - /* AV2 0000 000 0 0000 0000 0 */ 0x00000, - /* AV3 0000 000 0 0000 0000 0 */ 0x00000 - }; - - public static boolean isInputValid(char c1, char c2) { - return isValid(c1, c2, INPUTVALIDITY); - } - - public static boolean isComposable(char c1, char c2) { - return isValid(c1, c2, COMPOSABLE); - } - - public static boolean isSwappable(char c1, char c2) { - return isValid(c1, c2, SWAPPABLE); - } - - public static boolean isReplacable(char c1, char c2) { - return isValid(c1, c2, REPLACABLE); - } - - public static boolean isForward(char c) { - return (getCharType(c) < FV4); - } - - public static boolean isDead(char c) { - return (getCharType(c) > FV3); - } - - public boolean isInputValid(char current) { - int offset = requests.getInsertPositionOffset(); - if (offset == 0) { - byte charType = getCharType(current); - return ((charType < FV1) || (charType == FV3)); - } - else { - char prev = requests.getCommittedText(offset-1, offset, null).first(); - - if(isForward(current)) { - if (isInputValid(prev, current)) { - if (getCharType(prev) == TONE && - getCharType(current) == FV1) { - if (offset == 1) { - return true; - } else { - char pprev = - requests.getCommittedText(offset-2, offset-1, null).first(); - return isInputValid(pprev, current); - } - } else { - return true; - } - } else if (prev == '\u0e32' && // SARA AA - current == '\u0e30') { // SARA A - return true; - } else if (prev == '\u0e4d' && // NIKAHIT - current == '\u0e32') { // SARA AA - // Special compose to SARA AM - return true; - } else { - return false; - } - } else { - if(isInputValid(prev, current)) { - if (getCharType(prev) == TONE && - getCharType(current) == FV4) { - return (offset != 1); - } else { - return true; - } - } else { - return false; - } - } - } - } -} diff --git a/src/share/classes/com/sun/inputmethods/internal/thaiim/java.awt.im.spi.InputMethodDescriptor b/src/share/classes/com/sun/inputmethods/internal/thaiim/java.awt.im.spi.InputMethodDescriptor deleted file mode 100644 index 9f60bbe99..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/thaiim/java.awt.im.spi.InputMethodDescriptor +++ /dev/null @@ -1 +0,0 @@ -com.sun.inputmethods.internal.thaiim.ThaiInputMethodDescriptor diff --git a/src/share/classes/com/sun/inputmethods/internal/thaiim/resources/DisplayNames.properties b/src/share/classes/com/sun/inputmethods/internal/thaiim/resources/DisplayNames.properties deleted file mode 100644 index e4528a49a..000000000 --- a/src/share/classes/com/sun/inputmethods/internal/thaiim/resources/DisplayNames.properties +++ /dev/null @@ -1,6 +0,0 @@ -# -# Default Input method display names for Thai input methods -# - -DisplayName.Thai = Thai Input Method - -- cgit v1.2.3 From ccd7a2998aafa6dabdcf76ff1989ea524cf37201 Mon Sep 17 00:00:00 2001 From: mchung Date: Tue, 18 May 2010 13:12:46 -0700 Subject: 6951599: Rename package of security tools for modularization Summary: Move PolicyTool to sun.security.tools.policytool package Reviewed-by: weijun --HG-- rename : src/share/classes/sun/security/tools/PolicyTool.java => src/share/classes/sun/security/tools/policytool/PolicyTool.java --- .../classes/sun/security/tools/PolicyTool.java | 4261 -------------------- .../sun/security/tools/policytool/PolicyTool.java | 4261 ++++++++++++++++++++ 2 files changed, 4261 insertions(+), 4261 deletions(-) delete mode 100644 src/share/classes/sun/security/tools/PolicyTool.java create mode 100644 src/share/classes/sun/security/tools/policytool/PolicyTool.java (limited to 'src/share') diff --git a/src/share/classes/sun/security/tools/PolicyTool.java b/src/share/classes/sun/security/tools/PolicyTool.java deleted file mode 100644 index ce54ba61c..000000000 --- a/src/share/classes/sun/security/tools/PolicyTool.java +++ /dev/null @@ -1,4261 +0,0 @@ -/* - * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -package sun.security.tools; - -import java.io.*; -import java.util.LinkedList; -import java.util.ListIterator; -import java.util.Vector; -import java.util.Enumeration; -import java.net.URL; -import java.net.MalformedURLException; -import java.lang.reflect.*; -import java.text.Collator; -import java.text.MessageFormat; -import sun.security.util.PropertyExpander; -import sun.security.util.PropertyExpander.ExpandException; -import java.awt.*; -import java.awt.event.*; -import java.security.cert.Certificate; -import java.security.cert.CertificateException; -import java.security.*; -import sun.security.provider.*; -import sun.security.util.PolicyUtil; -import javax.security.auth.x500.X500Principal; - -/** - * PolicyTool may be used by users and administrators to configure the - * overall java security policy (currently stored in the policy file). - * Using PolicyTool administators may add and remove policies from - * the policy file.

      - * - * @see java.security.Policy - * @since 1.2 - */ - -public class PolicyTool { - - // for i18n - static final java.util.ResourceBundle rb = - java.util.ResourceBundle.getBundle("sun.security.util.Resources"); - static final Collator collator = Collator.getInstance(); - static { - // this is for case insensitive string comparisons - collator.setStrength(Collator.PRIMARY); - }; - - // anyone can add warnings - Vector warnings; - boolean newWarning = false; - - // set to true if policy modified. - // this way upon exit we know if to ask the user to save changes - boolean modified = false; - - private static final boolean testing = false; - private static final Class[] TWOPARAMS = { String.class, String.class }; - private static final Class[] ONEPARAMS = { String.class }; - private static final Class[] NOPARAMS = {}; - /* - * All of the policy entries are read in from the - * policy file and stored here. Updates to the policy entries - * using addEntry() and removeEntry() are made here. To ultimately save - * the policy entries back to the policy file, the SavePolicy button - * must be clicked. - **/ - private static String policyFileName = null; - private Vector policyEntries = null; - private PolicyParser parser = null; - - /* The public key alias information is stored here. */ - private KeyStore keyStore = null; - private String keyStoreName = " "; - private String keyStoreType = " "; - private String keyStoreProvider = " "; - private String keyStorePwdURL = " "; - - /* standard PKCS11 KeyStore type */ - private static final String P11KEYSTORE = "PKCS11"; - - /* reserved word for PKCS11 KeyStores */ - private static final String NONE = "NONE"; - - /** - * default constructor - */ - private PolicyTool() { - policyEntries = new Vector(); - parser = new PolicyParser(); - warnings = new Vector(); - } - - /** - * get the PolicyFileName - */ - String getPolicyFileName() { - return policyFileName; - } - - /** - * set the PolicyFileName - */ - void setPolicyFileName(String policyFileName) { - this.policyFileName = policyFileName; - } - - /** - * clear keyStore info - */ - void clearKeyStoreInfo() { - this.keyStoreName = null; - this.keyStoreType = null; - this.keyStoreProvider = null; - this.keyStorePwdURL = null; - - this.keyStore = null; - } - - /** - * get the keyStore URL name - */ - String getKeyStoreName() { - return keyStoreName; - } - - /** - * get the keyStore Type - */ - String getKeyStoreType() { - return keyStoreType; - } - - /** - * get the keyStore Provider - */ - String getKeyStoreProvider() { - return keyStoreProvider; - } - - /** - * get the keyStore password URL - */ - String getKeyStorePwdURL() { - return keyStorePwdURL; - } - - /** - * Open and read a policy file - */ - void openPolicy(String filename) throws FileNotFoundException, - PolicyParser.ParsingException, - KeyStoreException, - CertificateException, - InstantiationException, - MalformedURLException, - IOException, - NoSuchAlgorithmException, - IllegalAccessException, - NoSuchMethodException, - UnrecoverableKeyException, - NoSuchProviderException, - ClassNotFoundException, - PropertyExpander.ExpandException, - InvocationTargetException { - - newWarning = false; - - // start fresh - blow away the current state - policyEntries = new Vector(); - parser = new PolicyParser(); - warnings = new Vector(); - setPolicyFileName(null); - clearKeyStoreInfo(); - - // see if user is opening a NEW policy file - if (filename == null) { - modified = false; - return; - } - - // Read in the policy entries from the file and - // populate the parser vector table. The parser vector - // table only holds the entries as strings, so it only - // guarantees that the policies are syntactically - // correct. - setPolicyFileName(filename); - parser.read(new FileReader(filename)); - - // open the keystore - openKeyStore(parser.getKeyStoreUrl(), parser.getKeyStoreType(), - parser.getKeyStoreProvider(), parser.getStorePassURL()); - - // Update the local vector with the same policy entries. - // This guarantees that the policy entries are not only - // syntactically correct, but semantically valid as well. - Enumeration enum_ = parser.grantElements(); - while (enum_.hasMoreElements()) { - PolicyParser.GrantEntry ge = enum_.nextElement(); - - // see if all the signers have public keys - if (ge.signedBy != null) { - - String signers[] = parseSigners(ge.signedBy); - for (int i = 0; i < signers.length; i++) { - PublicKey pubKey = getPublicKeyAlias(signers[i]); - if (pubKey == null) { - newWarning = true; - MessageFormat form = new MessageFormat(rb.getString - ("Warning: A public key for alias " + - "'signers[i]' does not exist. " + - "Make sure a KeyStore is properly configured.")); - Object[] source = {signers[i]}; - warnings.addElement(form.format(source)); - } - } - } - - // check to see if the Principals are valid - ListIterator prinList = - ge.principals.listIterator(0); - while (prinList.hasNext()) { - PolicyParser.PrincipalEntry pe = prinList.next(); - try { - verifyPrincipal(pe.getPrincipalClass(), - pe.getPrincipalName()); - } catch (ClassNotFoundException fnfe) { - newWarning = true; - MessageFormat form = new MessageFormat(rb.getString - ("Warning: Class not found: class")); - Object[] source = {pe.getPrincipalClass()}; - warnings.addElement(form.format(source)); - } - } - - // check to see if the Permissions are valid - Enumeration perms = - ge.permissionElements(); - while (perms.hasMoreElements()) { - PolicyParser.PermissionEntry pe = perms.nextElement(); - try { - verifyPermission(pe.permission, pe.name, pe.action); - } catch (ClassNotFoundException fnfe) { - newWarning = true; - MessageFormat form = new MessageFormat(rb.getString - ("Warning: Class not found: class")); - Object[] source = {pe.permission}; - warnings.addElement(form.format(source)); - } catch (InvocationTargetException ite) { - newWarning = true; - MessageFormat form = new MessageFormat(rb.getString - ("Warning: Invalid argument(s) for constructor: arg")); - Object[] source = {pe.permission}; - warnings.addElement(form.format(source)); - } - - // see if all the permission signers have public keys - if (pe.signedBy != null) { - - String signers[] = parseSigners(pe.signedBy); - - for (int i = 0; i < signers.length; i++) { - PublicKey pubKey = getPublicKeyAlias(signers[i]); - if (pubKey == null) { - newWarning = true; - MessageFormat form = new MessageFormat(rb.getString - ("Warning: A public key for alias " + - "'signers[i]' does not exist. " + - "Make sure a KeyStore is properly configured.")); - Object[] source = {signers[i]}; - warnings.addElement(form.format(source)); - } - } - } - } - PolicyEntry pEntry = new PolicyEntry(this, ge); - policyEntries.addElement(pEntry); - } - - // just read in the policy -- nothing has been modified yet - modified = false; - } - - - /** - * Save a policy to a file - */ - void savePolicy(String filename) - throws FileNotFoundException, IOException { - // save the policy entries to a file - parser.setKeyStoreUrl(keyStoreName); - parser.setKeyStoreType(keyStoreType); - parser.setKeyStoreProvider(keyStoreProvider); - parser.setStorePassURL(keyStorePwdURL); - parser.write(new FileWriter(filename)); - modified = false; - } - - /** - * Open the KeyStore - */ - void openKeyStore(String name, - String type, - String provider, - String pwdURL) throws KeyStoreException, - NoSuchAlgorithmException, - UnrecoverableKeyException, - IOException, - CertificateException, - NoSuchProviderException, - ExpandException { - - if (name == null && type == null && - provider == null && pwdURL == null) { - - // policy did not specify a keystore during open - // or use wants to reset keystore values - - this.keyStoreName = null; - this.keyStoreType = null; - this.keyStoreProvider = null; - this.keyStorePwdURL = null; - - // caller will set (tool.modified = true) if appropriate - - return; - } - - URL policyURL = null; - if (policyFileName != null) { - File pfile = new File(policyFileName); - policyURL = new URL("file:" + pfile.getCanonicalPath()); - } - - // although PolicyUtil.getKeyStore may properly handle - // defaults and property expansion, we do it here so that - // if the call is successful, we can set the proper values - // (PolicyUtil.getKeyStore does not return expanded values) - - if (name != null && name.length() > 0) { - name = PropertyExpander.expand(name).replace - (File.separatorChar, '/'); - } - if (type == null || type.length() == 0) { - type = KeyStore.getDefaultType(); - } - if (pwdURL != null && pwdURL.length() > 0) { - pwdURL = PropertyExpander.expand(pwdURL).replace - (File.separatorChar, '/'); - } - - try { - this.keyStore = PolicyUtil.getKeyStore(policyURL, - name, - type, - provider, - pwdURL, - null); - } catch (IOException ioe) { - - // copied from sun.security.pkcs11.SunPKCS11 - String MSG = "no password provided, and no callback handler " + - "available for retrieving password"; - - Throwable cause = ioe.getCause(); - if (cause != null && - cause instanceof javax.security.auth.login.LoginException && - MSG.equals(cause.getMessage())) { - - // throw a more friendly exception message - throw new IOException(MSG); - } else { - throw ioe; - } - } - - this.keyStoreName = name; - this.keyStoreType = type; - this.keyStoreProvider = provider; - this.keyStorePwdURL = pwdURL; - - // caller will set (tool.modified = true) - } - - /** - * Add a Grant entry to the overall policy at the specified index. - * A policy entry consists of a CodeSource. - */ - boolean addEntry(PolicyEntry pe, int index) { - - if (index < 0) { - // new entry -- just add it to the end - policyEntries.addElement(pe); - parser.add(pe.getGrantEntry()); - } else { - // existing entry -- replace old one - PolicyEntry origPe = policyEntries.elementAt(index); - parser.replace(origPe.getGrantEntry(), pe.getGrantEntry()); - policyEntries.setElementAt(pe, index); - } - return true; - } - - /** - * Add a Principal entry to an existing PolicyEntry at the specified index. - * A Principal entry consists of a class, and name. - * - * If the principal already exists, it is not added again. - */ - boolean addPrinEntry(PolicyEntry pe, - PolicyParser.PrincipalEntry newPrin, - int index) { - - // first add the principal to the Policy Parser entry - PolicyParser.GrantEntry grantEntry = pe.getGrantEntry(); - if (grantEntry.contains(newPrin) == true) - return false; - - LinkedList prinList = - grantEntry.principals; - if (index != -1) - prinList.set(index, newPrin); - else - prinList.add(newPrin); - - modified = true; - return true; - } - - /** - * Add a Permission entry to an existing PolicyEntry at the specified index. - * A Permission entry consists of a permission, name, and actions. - * - * If the permission already exists, it is not added again. - */ - boolean addPermEntry(PolicyEntry pe, - PolicyParser.PermissionEntry newPerm, - int index) { - - // first add the permission to the Policy Parser Vector - PolicyParser.GrantEntry grantEntry = pe.getGrantEntry(); - if (grantEntry.contains(newPerm) == true) - return false; - - Vector permList = - grantEntry.permissionEntries; - if (index != -1) - permList.setElementAt(newPerm, index); - else - permList.addElement(newPerm); - - modified = true; - return true; - } - - /** - * Remove a Permission entry from an existing PolicyEntry. - */ - boolean removePermEntry(PolicyEntry pe, - PolicyParser.PermissionEntry perm) { - - // remove the Permission from the GrantEntry - PolicyParser.GrantEntry ppge = pe.getGrantEntry(); - modified = ppge.remove(perm); - return modified; - } - - /** - * remove an entry from the overall policy - */ - boolean removeEntry(PolicyEntry pe) { - - parser.remove(pe.getGrantEntry()); - modified = true; - return (policyEntries.removeElement(pe)); - } - - /** - * retrieve all Policy Entries - */ - PolicyEntry[] getEntry() { - - if (policyEntries.size() > 0) { - PolicyEntry entries[] = new PolicyEntry[policyEntries.size()]; - for (int i = 0; i < policyEntries.size(); i++) - entries[i] = policyEntries.elementAt(i); - return entries; - } - return null; - } - - /** - * Retrieve the public key mapped to a particular name. - * If the key has expired, a KeyException is thrown. - */ - PublicKey getPublicKeyAlias(String name) throws KeyStoreException { - if (keyStore == null) { - return null; - } - - Certificate cert = keyStore.getCertificate(name); - if (cert == null) { - return null; - } - PublicKey pubKey = cert.getPublicKey(); - return pubKey; - } - - /** - * Retrieve all the alias names stored in the certificate database - */ - String[] getPublicKeyAlias() throws KeyStoreException { - - int numAliases = 0; - String aliases[] = null; - - if (keyStore == null) { - return null; - } - Enumeration enum_ = keyStore.aliases(); - - // first count the number of elements - while (enum_.hasMoreElements()) { - enum_.nextElement(); - numAliases++; - } - - if (numAliases > 0) { - // now copy them into an array - aliases = new String[numAliases]; - numAliases = 0; - enum_ = keyStore.aliases(); - while (enum_.hasMoreElements()) { - aliases[numAliases] = new String(enum_.nextElement()); - numAliases++; - } - } - return aliases; - } - - /** - * This method parses a single string of signers separated by commas - * ("jordan, duke, pippen") into an array of individual strings. - */ - String[] parseSigners(String signedBy) { - - String signers[] = null; - int numSigners = 1; - int signedByIndex = 0; - int commaIndex = 0; - int signerNum = 0; - - // first pass thru "signedBy" counts the number of signers - while (commaIndex >= 0) { - commaIndex = signedBy.indexOf(',', signedByIndex); - if (commaIndex >= 0) { - numSigners++; - signedByIndex = commaIndex + 1; - } - } - signers = new String[numSigners]; - - // second pass thru "signedBy" transfers signers to array - commaIndex = 0; - signedByIndex = 0; - while (commaIndex >= 0) { - if ((commaIndex = signedBy.indexOf(',', signedByIndex)) >= 0) { - // transfer signer and ignore trailing part of the string - signers[signerNum] = - signedBy.substring(signedByIndex, commaIndex).trim(); - signerNum++; - signedByIndex = commaIndex + 1; - } else { - // we are at the end of the string -- transfer signer - signers[signerNum] = signedBy.substring(signedByIndex).trim(); - } - } - return signers; - } - - /** - * Check to see if the Principal contents are OK - */ - void verifyPrincipal(String type, String name) - throws ClassNotFoundException, - InstantiationException - { - if (type.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS) || - type.equals(PolicyParser.REPLACE_NAME)) { - return; - }; - Class PRIN = Class.forName("java.security.Principal"); - Class pc = Class.forName(type, true, - Thread.currentThread().getContextClassLoader()); - if (!PRIN.isAssignableFrom(pc)) { - MessageFormat form = new MessageFormat(rb.getString - ("Illegal Principal Type: type")); - Object[] source = {type}; - throw new InstantiationException(form.format(source)); - } - - if (ToolDialog.X500_PRIN_CLASS.equals(pc.getName())) { - // PolicyParser checks validity of X500Principal name - // - PolicyTool needs to as well so that it doesn't store - // an invalid name that can't be read in later - // - // this can throw an IllegalArgumentException - X500Principal newP = new X500Principal(name); - } - } - - /** - * Check to see if the Permission contents are OK - */ - void verifyPermission(String type, - String name, - String actions) - throws ClassNotFoundException, - InstantiationException, - IllegalAccessException, - NoSuchMethodException, - InvocationTargetException - { - - //XXX we might want to keep a hash of created factories... - Class pc = Class.forName(type, true, - Thread.currentThread().getContextClassLoader()); - Constructor c = null; - Vector objects = new Vector(2); - if (name != null) objects.add(name); - if (actions != null) objects.add(actions); - switch (objects.size()) { - case 0: - try { - c = pc.getConstructor(NOPARAMS); - break; - } catch (NoSuchMethodException ex) { - // proceed to the one-param constructor - objects.add(null); - } - case 1: - try { - c = pc.getConstructor(ONEPARAMS); - break; - } catch (NoSuchMethodException ex) { - // proceed to the two-param constructor - objects.add(null); - } - case 2: - c = pc.getConstructor(TWOPARAMS); - break; - } - Object parameters[] = objects.toArray(); - Permission p = (Permission)c.newInstance(parameters); - } - - /* - * Parse command line arguments. - */ - static void parseArgs(String args[]) { - /* parse flags */ - int n = 0; - - for (n=0; (n < args.length) && args[n].startsWith("-"); n++) { - - String flags = args[n]; - - if (collator.compare(flags, "-file") == 0) { - if (++n == args.length) usage(); - policyFileName = args[n]; - } else { - MessageFormat form = new MessageFormat(rb.getString - ("Illegal option: option")); - Object[] source = { flags }; - System.err.println(form.format(source)); - usage(); - } - } - } - - static void usage() { - System.out.println(rb.getString("Usage: policytool [options]")); - System.out.println(); - System.out.println(rb.getString - (" [-file ] policy file location")); - System.out.println(); - - System.exit(1); - } - - /** - * run the PolicyTool - */ - public static void main(String args[]) { - parseArgs(args); - ToolWindow tw = new ToolWindow(new PolicyTool()); - tw.displayToolWindow(args); - } - - // split instr to words according to capitalization, - // like, AWTControl -> A W T Control - // this method is for easy pronounciation - static String splitToWords(String instr) { - return instr.replaceAll("([A-Z])", " $1"); - } - -} - -/** - * Each entry in the policy configuration file is represented by a - * PolicyEntry object. - * - * A PolicyEntry is a (CodeSource,Permission) pair. The - * CodeSource contains the (URL, PublicKey) that together identify - * where the Java bytecodes come from and who (if anyone) signed - * them. The URL could refer to localhost. The URL could also be - * null, meaning that this policy entry is given to all comers, as - * long as they match the signer field. The signer could be null, - * meaning the code is not signed. - * - * The Permission contains the (Type, Name, Action) triplet. - * - */ -class PolicyEntry { - - private CodeSource codesource; - private PolicyTool tool; - private PolicyParser.GrantEntry grantEntry; - private boolean testing = false; - - /** - * Create a PolicyEntry object from the information read in - * from a policy file. - */ - PolicyEntry(PolicyTool tool, PolicyParser.GrantEntry ge) - throws MalformedURLException, NoSuchMethodException, - ClassNotFoundException, InstantiationException, IllegalAccessException, - InvocationTargetException, CertificateException, - IOException, NoSuchAlgorithmException, UnrecoverableKeyException { - - this.tool = tool; - - URL location = null; - - // construct the CodeSource - if (ge.codeBase != null) - location = new URL(ge.codeBase); - this.codesource = new CodeSource(location, - (java.security.cert.Certificate[]) null); - - if (testing) { - System.out.println("Adding Policy Entry:"); - System.out.println(" CodeBase = " + location); - System.out.println(" Signers = " + ge.signedBy); - System.out.println(" with " + ge.principals.size() + - " Principals"); - } - - this.grantEntry = ge; - } - - /** - * get the codesource associated with this PolicyEntry - */ - CodeSource getCodeSource() { - return codesource; - } - - /** - * get the GrantEntry associated with this PolicyEntry - */ - PolicyParser.GrantEntry getGrantEntry() { - return grantEntry; - } - - /** - * convert the header portion, i.e. codebase, signer, principals, of - * this policy entry into a string - */ - String headerToString() { - String pString = principalsToString(); - if (pString.length() == 0) { - return codebaseToString(); - } else { - return codebaseToString() + ", " + pString; - } - } - - /** - * convert the Codebase/signer portion of this policy entry into a string - */ - String codebaseToString() { - - String stringEntry = new String(); - - if (grantEntry.codeBase != null && - grantEntry.codeBase.equals("") == false) - stringEntry = stringEntry.concat - ("CodeBase \"" + - grantEntry.codeBase + - "\""); - - if (grantEntry.signedBy != null && - grantEntry.signedBy.equals("") == false) - stringEntry = ((stringEntry.length() > 0) ? - stringEntry.concat(", SignedBy \"" + - grantEntry.signedBy + - "\"") : - stringEntry.concat("SignedBy \"" + - grantEntry.signedBy + - "\"")); - - if (stringEntry.length() == 0) - return new String("CodeBase "); - return stringEntry; - } - - /** - * convert the Principals portion of this policy entry into a string - */ - String principalsToString() { - String result = ""; - if ((grantEntry.principals != null) && - (!grantEntry.principals.isEmpty())) { - StringBuffer buffer = new StringBuffer(200); - ListIterator list = - grantEntry.principals.listIterator(); - while (list.hasNext()) { - PolicyParser.PrincipalEntry pppe = list.next(); - buffer.append(" Principal " + pppe.getDisplayClass() + " " + - pppe.getDisplayName(true)); - if (list.hasNext()) buffer.append(", "); - } - result = buffer.toString(); - } - return result; - } - - /** - * convert this policy entry into a PolicyParser.PermissionEntry - */ - PolicyParser.PermissionEntry toPermissionEntry(Permission perm) { - - String actions = null; - - // get the actions - if (perm.getActions() != null && - perm.getActions().trim() != "") - actions = perm.getActions(); - - PolicyParser.PermissionEntry pe = new PolicyParser.PermissionEntry - (perm.getClass().getName(), - perm.getName(), - actions); - return pe; - } -} - -/** - * The main window for the PolicyTool - */ -class ToolWindow extends Frame { - // use serialVersionUID from JDK 1.2.2 for interoperability - private static final long serialVersionUID = 5682568601210376777L; - - /* external paddings */ - public static final Insets TOP_PADDING = new Insets(25,0,0,0); - public static final Insets BOTTOM_PADDING = new Insets(0,0,25,0); - public static final Insets LITE_BOTTOM_PADDING = new Insets(0,0,10,0); - public static final Insets LR_PADDING = new Insets(0,10,0,10); - public static final Insets TOP_BOTTOM_PADDING = new Insets(15, 0, 15, 0); - public static final Insets L_TOP_BOTTOM_PADDING = new Insets(5,10,15,0); - public static final Insets LR_BOTTOM_PADDING = new Insets(0,10,5,10); - public static final Insets L_BOTTOM_PADDING = new Insets(0,10,5,0); - public static final Insets R_BOTTOM_PADDING = new Insets(0,0,5,10); - - /* buttons and menus */ - public static final String NEW_POLICY_FILE = - PolicyTool.rb.getString("New"); - public static final String OPEN_POLICY_FILE = - PolicyTool.rb.getString("Open"); - public static final String SAVE_POLICY_FILE = - PolicyTool.rb.getString("Save"); - public static final String SAVE_AS_POLICY_FILE = - PolicyTool.rb.getString("Save As"); - public static final String VIEW_WARNINGS = - PolicyTool.rb.getString("View Warning Log"); - public static final String QUIT = - PolicyTool.rb.getString("Exit"); - public static final String ADD_POLICY_ENTRY = - PolicyTool.rb.getString("Add Policy Entry"); - public static final String EDIT_POLICY_ENTRY = - PolicyTool.rb.getString("Edit Policy Entry"); - public static final String REMOVE_POLICY_ENTRY = - PolicyTool.rb.getString("Remove Policy Entry"); - public static final String EDIT_KEYSTORE = - PolicyTool.rb.getString("Edit"); - public static final String ADD_PUBKEY_ALIAS = - PolicyTool.rb.getString("Add Public Key Alias"); - public static final String REMOVE_PUBKEY_ALIAS = - PolicyTool.rb.getString("Remove Public Key Alias"); - - /* gridbag index for components in the main window (MW) */ - public static final int MW_FILENAME_LABEL = 0; - public static final int MW_FILENAME_TEXTFIELD = 1; - public static final int MW_PANEL = 2; - public static final int MW_ADD_BUTTON = 0; - public static final int MW_EDIT_BUTTON = 1; - public static final int MW_REMOVE_BUTTON = 2; - public static final int MW_POLICY_LIST = 3; // follows MW_PANEL - - private PolicyTool tool; - - /** - * Constructor - */ - ToolWindow(PolicyTool tool) { - this.tool = tool; - } - - /** - * Initialize the PolicyTool window with the necessary components - */ - private void initWindow() { - - // create the top menu bar - MenuBar menuBar = new MenuBar(); - - // create a File menu - Menu menu = new Menu(PolicyTool.rb.getString("File")); - menu.add(NEW_POLICY_FILE); - menu.add(OPEN_POLICY_FILE); - menu.add(SAVE_POLICY_FILE); - menu.add(SAVE_AS_POLICY_FILE); - menu.add(VIEW_WARNINGS); - menu.add(QUIT); - menu.addActionListener(new FileMenuListener(tool, this)); - menuBar.add(menu); - setMenuBar(menuBar); - - // create a KeyStore menu - menu = new Menu(PolicyTool.rb.getString("KeyStore")); - menu.add(EDIT_KEYSTORE); - menu.addActionListener(new MainWindowListener(tool, this)); - menuBar.add(menu); - setMenuBar(menuBar); - - - // policy entry listing - Label label = new Label(PolicyTool.rb.getString("Policy File:")); - addNewComponent(this, label, MW_FILENAME_LABEL, - 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - TOP_BOTTOM_PADDING); - TextField tf = new TextField(50); - tf.getAccessibleContext().setAccessibleName( - PolicyTool.rb.getString("Policy File:")); - tf.setEditable(false); - addNewComponent(this, tf, MW_FILENAME_TEXTFIELD, - 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - TOP_BOTTOM_PADDING); - - - // add ADD/REMOVE/EDIT buttons in a new panel - Panel panel = new Panel(); - panel.setLayout(new GridBagLayout()); - - Button button = new Button(ADD_POLICY_ENTRY); - button.addActionListener(new MainWindowListener(tool, this)); - addNewComponent(panel, button, MW_ADD_BUTTON, - 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - LR_PADDING); - - button = new Button(EDIT_POLICY_ENTRY); - button.addActionListener(new MainWindowListener(tool, this)); - addNewComponent(panel, button, MW_EDIT_BUTTON, - 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - LR_PADDING); - - button = new Button(REMOVE_POLICY_ENTRY); - button.addActionListener(new MainWindowListener(tool, this)); - addNewComponent(panel, button, MW_REMOVE_BUTTON, - 2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - LR_PADDING); - - addNewComponent(this, panel, MW_PANEL, - 0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH, - BOTTOM_PADDING); - - - String policyFile = tool.getPolicyFileName(); - if (policyFile == null) { - String userHome; - userHome = java.security.AccessController.doPrivileged( - new sun.security.action.GetPropertyAction("user.home")); - policyFile = userHome + File.separatorChar + ".java.policy"; - } - - try { - // open the policy file - tool.openPolicy(policyFile); - - // display the policy entries via the policy list textarea - List list = new List(40, false); - list.addActionListener(new PolicyListListener(tool, this)); - PolicyEntry entries[] = tool.getEntry(); - if (entries != null) { - for (int i = 0; i < entries.length; i++) - list.add(entries[i].headerToString()); - } - TextField newFilename = (TextField) - getComponent(MW_FILENAME_TEXTFIELD); - newFilename.setText(policyFile); - initPolicyList(list); - - } catch (FileNotFoundException fnfe) { - // add blank policy listing - List list = new List(40, false); - list.addActionListener(new PolicyListListener(tool, this)); - initPolicyList(list); - tool.setPolicyFileName(null); - tool.modified = false; - setVisible(true); - - // just add warning - tool.warnings.addElement(fnfe.toString()); - - } catch (Exception e) { - // add blank policy listing - List list = new List(40, false); - list.addActionListener(new PolicyListListener(tool, this)); - initPolicyList(list); - tool.setPolicyFileName(null); - tool.modified = false; - setVisible(true); - - // display the error - MessageFormat form = new MessageFormat(PolicyTool.rb.getString - ("Could not open policy file: policyFile: e.toString()")); - Object[] source = {policyFile, e.toString()}; - displayErrorDialog(null, form.format(source)); - } - } - - - /** - * Add a component to the PolicyTool window - */ - void addNewComponent(Container container, Component component, - int index, int gridx, int gridy, int gridwidth, int gridheight, - double weightx, double weighty, int fill, Insets is) { - - // add the component at the specified gridbag index - container.add(component, index); - - // set the constraints - GridBagLayout gbl = (GridBagLayout)container.getLayout(); - GridBagConstraints gbc = new GridBagConstraints(); - gbc.gridx = gridx; - gbc.gridy = gridy; - gbc.gridwidth = gridwidth; - gbc.gridheight = gridheight; - gbc.weightx = weightx; - gbc.weighty = weighty; - gbc.fill = fill; - if (is != null) gbc.insets = is; - gbl.setConstraints(component, gbc); - } - - - /** - * Add a component to the PolicyTool window without external padding - */ - void addNewComponent(Container container, Component component, - int index, int gridx, int gridy, int gridwidth, int gridheight, - double weightx, double weighty, int fill) { - - // delegate with "null" external padding - addNewComponent(container, component, index, gridx, gridy, - gridwidth, gridheight, weightx, weighty, - fill, null); - } - - - /** - * Init the policy_entry_list TEXTAREA component in the - * PolicyTool window - */ - void initPolicyList(List policyList) { - - // add the policy list to the window - addNewComponent(this, policyList, MW_POLICY_LIST, - 0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.BOTH); - } - - /** - * Replace the policy_entry_list TEXTAREA component in the - * PolicyTool window with an updated one. - */ - void replacePolicyList(List policyList) { - - // remove the original list of Policy Entries - // and add the new list of entries - List list = (List)getComponent(MW_POLICY_LIST); - list.removeAll(); - String newItems[] = policyList.getItems(); - for (int i = 0; i < newItems.length; i++) - list.add(newItems[i]); - } - - /** - * display the main PolicyTool window - */ - void displayToolWindow(String args[]) { - - setTitle(PolicyTool.rb.getString("Policy Tool")); - setResizable(true); - addWindowListener(new ToolWindowListener(this)); - setBounds(135, 80, 500, 500); - setLayout(new GridBagLayout()); - - initWindow(); - - // display it - setVisible(true); - - if (tool.newWarning == true) { - displayStatusDialog(this, PolicyTool.rb.getString - ("Errors have occurred while opening the " + - "policy configuration. View the Warning Log " + - "for more information.")); - } - } - - /** - * displays a dialog box describing an error which occurred. - */ - void displayErrorDialog(Window w, String error) { - ToolDialog ed = new ToolDialog - (PolicyTool.rb.getString("Error"), tool, this, true); - - // find where the PolicyTool gui is - Point location = ((w == null) ? - getLocationOnScreen() : w.getLocationOnScreen()); - ed.setBounds(location.x + 50, location.y + 50, 600, 100); - ed.setLayout(new GridBagLayout()); - - Label label = new Label(error); - addNewComponent(ed, label, 0, - 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); - - Button okButton = new Button(PolicyTool.rb.getString("OK")); - okButton.addActionListener(new ErrorOKButtonListener(ed)); - addNewComponent(ed, okButton, 1, - 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); - - ed.pack(); - ed.setVisible(true); - } - - /** - * displays a dialog box describing an error which occurred. - */ - void displayErrorDialog(Window w, Throwable t) { - if (t instanceof NoDisplayException) { - return; - } - displayErrorDialog(w, t.toString()); - } - - /** - * displays a dialog box describing the status of an event - */ - void displayStatusDialog(Window w, String status) { - ToolDialog sd = new ToolDialog - (PolicyTool.rb.getString("Status"), tool, this, true); - - // find the location of the PolicyTool gui - Point location = ((w == null) ? - getLocationOnScreen() : w.getLocationOnScreen()); - sd.setBounds(location.x + 50, location.y + 50, 500, 100); - sd.setLayout(new GridBagLayout()); - - Label label = new Label(status); - addNewComponent(sd, label, 0, - 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); - - Button okButton = new Button(PolicyTool.rb.getString("OK")); - okButton.addActionListener(new StatusOKButtonListener(sd)); - addNewComponent(sd, okButton, 1, - 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); - sd.pack(); - sd.setVisible(true); - } - - /** - * display the warning log - */ - void displayWarningLog(Window w) { - - ToolDialog wd = new ToolDialog - (PolicyTool.rb.getString("Warning"), tool, this, true); - - // find the location of the PolicyTool gui - Point location = ((w == null) ? - getLocationOnScreen() : w.getLocationOnScreen()); - wd.setBounds(location.x + 50, location.y + 50, 500, 100); - wd.setLayout(new GridBagLayout()); - - TextArea ta = new TextArea(); - ta.setEditable(false); - for (int i = 0; i < tool.warnings.size(); i++) { - ta.append(tool.warnings.elementAt(i)); - ta.append(PolicyTool.rb.getString("\n")); - } - addNewComponent(wd, ta, 0, - 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - BOTTOM_PADDING); - ta.setFocusable(false); - - Button okButton = new Button(PolicyTool.rb.getString("OK")); - okButton.addActionListener(new CancelButtonListener(wd)); - addNewComponent(wd, okButton, 1, - 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, - LR_PADDING); - - wd.pack(); - wd.setVisible(true); - } - - char displayYesNoDialog(Window w, String title, String prompt, String yes, String no) { - - final ToolDialog tw = new ToolDialog - (title, tool, this, true); - Point location = ((w == null) ? - getLocationOnScreen() : w.getLocationOnScreen()); - tw.setBounds(location.x + 75, location.y + 100, 400, 150); - tw.setLayout(new GridBagLayout()); - - TextArea ta = new TextArea(prompt, 10, 50, TextArea.SCROLLBARS_VERTICAL_ONLY); - ta.setEditable(false); - addNewComponent(tw, ta, 0, - 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); - ta.setFocusable(false); - - Panel panel = new Panel(); - panel.setLayout(new GridBagLayout()); - - // StringBuffer to store button press. Must be final. - final StringBuffer chooseResult = new StringBuffer(); - - Button button = new Button(yes); - button.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - chooseResult.append('Y'); - tw.setVisible(false); - tw.dispose(); - } - }); - addNewComponent(panel, button, 0, - 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, - LR_PADDING); - - button = new Button(no); - button.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - chooseResult.append('N'); - tw.setVisible(false); - tw.dispose(); - } - }); - addNewComponent(panel, button, 1, - 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, - LR_PADDING); - - addNewComponent(tw, panel, 1, - 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); - - tw.pack(); - tw.setVisible(true); - if (chooseResult.length() > 0) { - return chooseResult.charAt(0); - } else { - // I did encounter this once, don't why. - return 'N'; - } - } - -} - -/** - * General dialog window - */ -class ToolDialog extends Dialog { - // use serialVersionUID from JDK 1.2.2 for interoperability - private static final long serialVersionUID = -372244357011301190L; - - /* necessary constants */ - public static final int NOACTION = 0; - public static final int QUIT = 1; - public static final int NEW = 2; - public static final int OPEN = 3; - - public static final String ALL_PERM_CLASS = - "java.security.AllPermission"; - public static final String FILE_PERM_CLASS = - "java.io.FilePermission"; - - public static final String X500_PRIN_CLASS = - "javax.security.auth.x500.X500Principal"; - - /* popup menus */ - public static final String PERM = - PolicyTool.rb.getString - ("Permission: "); - - public static final String PRIN_TYPE = - PolicyTool.rb.getString("Principal Type:"); - public static final String PRIN_NAME = - PolicyTool.rb.getString("Principal Name:"); - - /* more popu menus */ - public static final String PERM_NAME = - PolicyTool.rb.getString - ("Target Name: "); - - /* and more popup menus */ - public static final String PERM_ACTIONS = - PolicyTool.rb.getString - ("Actions: "); - - /* gridbag index for display OverWriteFile (OW) components */ - public static final int OW_LABEL = 0; - public static final int OW_OK_BUTTON = 1; - public static final int OW_CANCEL_BUTTON = 2; - - /* gridbag index for display PolicyEntry (PE) components */ - public static final int PE_CODEBASE_LABEL = 0; - public static final int PE_CODEBASE_TEXTFIELD = 1; - public static final int PE_SIGNEDBY_LABEL = 2; - public static final int PE_SIGNEDBY_TEXTFIELD = 3; - - public static final int PE_PANEL0 = 4; - public static final int PE_ADD_PRIN_BUTTON = 0; - public static final int PE_EDIT_PRIN_BUTTON = 1; - public static final int PE_REMOVE_PRIN_BUTTON = 2; - - public static final int PE_PRIN_LABEL = 5; - public static final int PE_PRIN_LIST = 6; - - public static final int PE_PANEL1 = 7; - public static final int PE_ADD_PERM_BUTTON = 0; - public static final int PE_EDIT_PERM_BUTTON = 1; - public static final int PE_REMOVE_PERM_BUTTON = 2; - - public static final int PE_PERM_LIST = 8; - - public static final int PE_PANEL2 = 9; - public static final int PE_CANCEL_BUTTON = 1; - public static final int PE_DONE_BUTTON = 0; - - /* the gridbag index for components in the Principal Dialog (PRD) */ - public static final int PRD_DESC_LABEL = 0; - public static final int PRD_PRIN_CHOICE = 1; - public static final int PRD_PRIN_TEXTFIELD = 2; - public static final int PRD_NAME_LABEL = 3; - public static final int PRD_NAME_TEXTFIELD = 4; - public static final int PRD_CANCEL_BUTTON = 6; - public static final int PRD_OK_BUTTON = 5; - - /* the gridbag index for components in the Permission Dialog (PD) */ - public static final int PD_DESC_LABEL = 0; - public static final int PD_PERM_CHOICE = 1; - public static final int PD_PERM_TEXTFIELD = 2; - public static final int PD_NAME_CHOICE = 3; - public static final int PD_NAME_TEXTFIELD = 4; - public static final int PD_ACTIONS_CHOICE = 5; - public static final int PD_ACTIONS_TEXTFIELD = 6; - public static final int PD_SIGNEDBY_LABEL = 7; - public static final int PD_SIGNEDBY_TEXTFIELD = 8; - public static final int PD_CANCEL_BUTTON = 10; - public static final int PD_OK_BUTTON = 9; - - /* modes for KeyStore */ - public static final int EDIT_KEYSTORE = 0; - - /* the gridbag index for components in the Change KeyStore Dialog (KSD) */ - public static final int KSD_NAME_LABEL = 0; - public static final int KSD_NAME_TEXTFIELD = 1; - public static final int KSD_TYPE_LABEL = 2; - public static final int KSD_TYPE_TEXTFIELD = 3; - public static final int KSD_PROVIDER_LABEL = 4; - public static final int KSD_PROVIDER_TEXTFIELD = 5; - public static final int KSD_PWD_URL_LABEL = 6; - public static final int KSD_PWD_URL_TEXTFIELD = 7; - public static final int KSD_CANCEL_BUTTON = 9; - public static final int KSD_OK_BUTTON = 8; - - /* the gridbag index for components in the User Save Changes Dialog (USC) */ - public static final int USC_LABEL = 0; - public static final int USC_PANEL = 1; - public static final int USC_YES_BUTTON = 0; - public static final int USC_NO_BUTTON = 1; - public static final int USC_CANCEL_BUTTON = 2; - - /* gridbag index for the ConfirmRemovePolicyEntryDialog (CRPE) */ - public static final int CRPE_LABEL1 = 0; - public static final int CRPE_LABEL2 = 1; - public static final int CRPE_PANEL = 2; - public static final int CRPE_PANEL_OK = 0; - public static final int CRPE_PANEL_CANCEL = 1; - - /* some private static finals */ - private static final int PERMISSION = 0; - private static final int PERMISSION_NAME = 1; - private static final int PERMISSION_ACTIONS = 2; - private static final int PERMISSION_SIGNEDBY = 3; - private static final int PRINCIPAL_TYPE = 4; - private static final int PRINCIPAL_NAME = 5; - - public static java.util.ArrayList PERM_ARRAY; - public static java.util.ArrayList PRIN_ARRAY; - PolicyTool tool; - ToolWindow tw; - - static { - - // set up permission objects - - PERM_ARRAY = new java.util.ArrayList(); - PERM_ARRAY.add(new AllPerm()); - PERM_ARRAY.add(new AudioPerm()); - PERM_ARRAY.add(new AuthPerm()); - PERM_ARRAY.add(new AWTPerm()); - PERM_ARRAY.add(new DelegationPerm()); - PERM_ARRAY.add(new FilePerm()); - PERM_ARRAY.add(new InqSecContextPerm()); - PERM_ARRAY.add(new LogPerm()); - PERM_ARRAY.add(new MgmtPerm()); - PERM_ARRAY.add(new MBeanPerm()); - PERM_ARRAY.add(new MBeanSvrPerm()); - PERM_ARRAY.add(new MBeanTrustPerm()); - PERM_ARRAY.add(new NetPerm()); - PERM_ARRAY.add(new PrivCredPerm()); - PERM_ARRAY.add(new PropPerm()); - PERM_ARRAY.add(new ReflectPerm()); - PERM_ARRAY.add(new RuntimePerm()); - PERM_ARRAY.add(new SecurityPerm()); - PERM_ARRAY.add(new SerialPerm()); - PERM_ARRAY.add(new ServicePerm()); - PERM_ARRAY.add(new SocketPerm()); - PERM_ARRAY.add(new SQLPerm()); - PERM_ARRAY.add(new SSLPerm()); - PERM_ARRAY.add(new SubjDelegPerm()); - - // set up principal objects - - PRIN_ARRAY = new java.util.ArrayList(); - PRIN_ARRAY.add(new KrbPrin()); - PRIN_ARRAY.add(new X500Prin()); - } - - ToolDialog(String title, PolicyTool tool, ToolWindow tw, boolean modal) { - super(tw, modal); - setTitle(title); - this.tool = tool; - this.tw = tw; - addWindowListener(new ChildWindowListener(this)); - } - - /** - * get the Perm instance based on either the (shortened) class name - * or the fully qualified class name - */ - static Perm getPerm(String clazz, boolean fullClassName) { - for (int i = 0; i < PERM_ARRAY.size(); i++) { - Perm next = PERM_ARRAY.get(i); - if (fullClassName) { - if (next.FULL_CLASS.equals(clazz)) { - return next; - } - } else { - if (next.CLASS.equals(clazz)) { - return next; - } - } - } - return null; - } - - /** - * get the Prin instance based on either the (shortened) class name - * or the fully qualified class name - */ - static Prin getPrin(String clazz, boolean fullClassName) { - for (int i = 0; i < PRIN_ARRAY.size(); i++) { - Prin next = PRIN_ARRAY.get(i); - if (fullClassName) { - if (next.FULL_CLASS.equals(clazz)) { - return next; - } - } else { - if (next.CLASS.equals(clazz)) { - return next; - } - } - } - return null; - } - - /** - * ask user if they want to overwrite an existing file - */ - void displayOverWriteFileDialog(String filename, int nextEvent) { - - // find where the PolicyTool gui is - Point location = tw.getLocationOnScreen(); - setBounds(location.x + 75, location.y + 100, 400, 150); - setLayout(new GridBagLayout()); - - // ask the user if they want to over write the existing file - MessageFormat form = new MessageFormat(PolicyTool.rb.getString - ("OK to overwrite existing file filename?")); - Object[] source = {filename}; - Label label = new Label(form.format(source)); - tw.addNewComponent(this, label, OW_LABEL, - 0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.TOP_PADDING); - - // OK button - Button button = new Button(PolicyTool.rb.getString("OK")); - button.addActionListener(new OverWriteFileOKButtonListener - (tool, tw, this, filename, nextEvent)); - tw.addNewComponent(this, button, OW_OK_BUTTON, - 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, - tw.TOP_PADDING); - - // Cancel button - // -- if the user hits cancel, do NOT go on to the next event - button = new Button(PolicyTool.rb.getString("Cancel")); - button.addActionListener(new CancelButtonListener(this)); - tw.addNewComponent(this, button, OW_CANCEL_BUTTON, - 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, - tw.TOP_PADDING); - - setVisible(true); - } - - /** - * pop up a dialog so the user can enter info to add a new PolicyEntry - * - if edit is TRUE, then the user is editing an existing entry - * and we should display the original info as well. - * - * - the other reason we need the 'edit' boolean is we need to know - * when we are adding a NEW policy entry. in this case, we can - * not simply update the existing entry, because it doesn't exist. - * we ONLY update the GUI listing/info, and then when the user - * finally clicks 'OK' or 'DONE', then we can collect that info - * and add it to the policy. - */ - void displayPolicyEntryDialog(boolean edit) { - - int listIndex = 0; - PolicyEntry entries[] = null; - TaggedList prinList = new TaggedList(3, false); - prinList.getAccessibleContext().setAccessibleName( - PolicyTool.rb.getString("Principal List")); - prinList.addActionListener - (new EditPrinButtonListener(tool, tw, this, edit)); - TaggedList permList = new TaggedList(10, false); - permList.getAccessibleContext().setAccessibleName( - PolicyTool.rb.getString("Permission List")); - permList.addActionListener - (new EditPermButtonListener(tool, tw, this, edit)); - - // find where the PolicyTool gui is - Point location = tw.getLocationOnScreen(); - setBounds(location.x + 75, location.y + 200, 650, 500); - setLayout(new GridBagLayout()); - setResizable(true); - - if (edit) { - // get the selected item - entries = tool.getEntry(); - List policyList = (List)tw.getComponent(tw.MW_POLICY_LIST); - listIndex = policyList.getSelectedIndex(); - - // get principal list - LinkedList principals = - entries[listIndex].getGrantEntry().principals; - for (int i = 0; i < principals.size(); i++) { - String prinString = null; - PolicyParser.PrincipalEntry nextPrin = - (PolicyParser.PrincipalEntry)principals.get(i); - prinList.addTaggedItem(PrincipalEntryToUserFriendlyString(nextPrin), nextPrin); - } - - // get permission list - Vector permissions = - entries[listIndex].getGrantEntry().permissionEntries; - for (int i = 0; i < permissions.size(); i++) { - String permString = null; - PolicyParser.PermissionEntry nextPerm = - permissions.elementAt(i); - permList.addTaggedItem(ToolDialog.PermissionEntryToUserFriendlyString(nextPerm), nextPerm); - } - } - - // codebase label and textfield - Label label = new Label(PolicyTool.rb.getString("CodeBase:")); - tw.addNewComponent(this, label, PE_CODEBASE_LABEL, - 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); - TextField tf; - tf = (edit ? - new TextField(entries[listIndex].getGrantEntry().codeBase, 60) : - new TextField(60)); - tf.getAccessibleContext().setAccessibleName( - PolicyTool.rb.getString("Code Base")); - tw.addNewComponent(this, tf, PE_CODEBASE_TEXTFIELD, - 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); - - // signedby label and textfield - label = new Label(PolicyTool.rb.getString("SignedBy:")); - tw.addNewComponent(this, label, PE_SIGNEDBY_LABEL, - 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); - tf = (edit ? - new TextField(entries[listIndex].getGrantEntry().signedBy, 60) : - new TextField(60)); - tf.getAccessibleContext().setAccessibleName( - PolicyTool.rb.getString("Signed By:")); - tw.addNewComponent(this, tf, PE_SIGNEDBY_TEXTFIELD, - 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); - - // panel for principal buttons - Panel panel = new Panel(); - panel.setLayout(new GridBagLayout()); - - Button button = new Button(PolicyTool.rb.getString("Add Principal")); - button.addActionListener - (new AddPrinButtonListener(tool, tw, this, edit)); - tw.addNewComponent(panel, button, PE_ADD_PRIN_BUTTON, - 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); - - button = new Button(PolicyTool.rb.getString("Edit Principal")); - button.addActionListener(new EditPrinButtonListener - (tool, tw, this, edit)); - tw.addNewComponent(panel, button, PE_EDIT_PRIN_BUTTON, - 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); - - button = new Button(PolicyTool.rb.getString("Remove Principal")); - button.addActionListener(new RemovePrinButtonListener - (tool, tw, this, edit)); - tw.addNewComponent(panel, button, PE_REMOVE_PRIN_BUTTON, - 2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); - - tw.addNewComponent(this, panel, PE_PANEL0, - 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL); - - // principal label and list - label = new Label(PolicyTool.rb.getString("Principals:")); - tw.addNewComponent(this, label, PE_PRIN_LABEL, - 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.BOTTOM_PADDING); - tw.addNewComponent(this, prinList, PE_PRIN_LIST, - 1, 3, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.BOTTOM_PADDING); - - // panel for permission buttons - panel = new Panel(); - panel.setLayout(new GridBagLayout()); - - button = new Button(PolicyTool.rb.getString(" Add Permission")); - button.addActionListener(new AddPermButtonListener - (tool, tw, this, edit)); - tw.addNewComponent(panel, button, PE_ADD_PERM_BUTTON, - 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); - - button = new Button(PolicyTool.rb.getString(" Edit Permission")); - button.addActionListener(new EditPermButtonListener - (tool, tw, this, edit)); - tw.addNewComponent(panel, button, PE_EDIT_PERM_BUTTON, - 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); - - - button = new Button(PolicyTool.rb.getString("Remove Permission")); - button.addActionListener(new RemovePermButtonListener - (tool, tw, this, edit)); - tw.addNewComponent(panel, button, PE_REMOVE_PERM_BUTTON, - 2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); - - tw.addNewComponent(this, panel, PE_PANEL1, - 0, 4, 2, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL, - tw.LITE_BOTTOM_PADDING); - - // permission list - tw.addNewComponent(this, permList, PE_PERM_LIST, - 0, 5, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.BOTTOM_PADDING); - - - // panel for Done and Cancel buttons - panel = new Panel(); - panel.setLayout(new GridBagLayout()); - - // Done Button - button = new Button(PolicyTool.rb.getString("Done")); - button.addActionListener - (new AddEntryDoneButtonListener(tool, tw, this, edit)); - tw.addNewComponent(panel, button, PE_DONE_BUTTON, - 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, - tw.LR_PADDING); - - // Cancel Button - button = new Button(PolicyTool.rb.getString("Cancel")); - button.addActionListener(new CancelButtonListener(this)); - tw.addNewComponent(panel, button, PE_CANCEL_BUTTON, - 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, - tw.LR_PADDING); - - // add the panel - tw.addNewComponent(this, panel, PE_PANEL2, - 0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); - - setVisible(true); - } - - /** - * Read all the Policy information data in the dialog box - * and construct a PolicyEntry object with it. - */ - PolicyEntry getPolicyEntryFromDialog() - throws InvalidParameterException, MalformedURLException, - NoSuchMethodException, ClassNotFoundException, InstantiationException, - IllegalAccessException, InvocationTargetException, - CertificateException, IOException, Exception { - - // get the Codebase - TextField tf = (TextField)getComponent(PE_CODEBASE_TEXTFIELD); - String codebase = null; - if (tf.getText().trim().equals("") == false) - codebase = new String(tf.getText().trim()); - - // get the SignedBy - tf = (TextField)getComponent(PE_SIGNEDBY_TEXTFIELD); - String signedby = null; - if (tf.getText().trim().equals("") == false) - signedby = new String(tf.getText().trim()); - - // construct a new GrantEntry - PolicyParser.GrantEntry ge = - new PolicyParser.GrantEntry(signedby, codebase); - - // get the new Principals - LinkedList prins = - new LinkedList(); - TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST); - for (int i = 0; i < prinList.getItemCount(); i++) { - prins.add((PolicyParser.PrincipalEntry)prinList.getObject(i)); - } - ge.principals = prins; - - // get the new Permissions - Vector perms = - new Vector(); - TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST); - for (int i = 0; i < permList.getItemCount(); i++) { - perms.addElement((PolicyParser.PermissionEntry)permList.getObject(i)); - } - ge.permissionEntries = perms; - - // construct a new PolicyEntry object - PolicyEntry entry = new PolicyEntry(tool, ge); - - return entry; - } - - /** - * display a dialog box for the user to enter KeyStore information - */ - void keyStoreDialog(int mode) { - - // find where the PolicyTool gui is - Point location = tw.getLocationOnScreen(); - setBounds(location.x + 25, location.y + 100, 500, 300); - setLayout(new GridBagLayout()); - - if (mode == EDIT_KEYSTORE) { - - // KeyStore label and textfield - Label label = new Label - (PolicyTool.rb.getString("KeyStore URL:")); - tw.addNewComponent(this, label, KSD_NAME_LABEL, - 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.BOTTOM_PADDING); - TextField tf = new TextField(tool.getKeyStoreName(), 30); - - // URL to U R L, so that accessibility reader will pronounce well - tf.getAccessibleContext().setAccessibleName( - PolicyTool.rb.getString("KeyStore U R L:")); - tw.addNewComponent(this, tf, KSD_NAME_TEXTFIELD, - 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.BOTTOM_PADDING); - - // KeyStore type and textfield - label = new Label(PolicyTool.rb.getString("KeyStore Type:")); - tw.addNewComponent(this, label, KSD_TYPE_LABEL, - 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.BOTTOM_PADDING); - tf = new TextField(tool.getKeyStoreType(), 30); - tf.getAccessibleContext().setAccessibleName( - PolicyTool.rb.getString("KeyStore Type:")); - tw.addNewComponent(this, tf, KSD_TYPE_TEXTFIELD, - 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.BOTTOM_PADDING); - - // KeyStore provider and textfield - label = new Label(PolicyTool.rb.getString - ("KeyStore Provider:")); - tw.addNewComponent(this, label, KSD_PROVIDER_LABEL, - 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.BOTTOM_PADDING); - tf = new TextField(tool.getKeyStoreProvider(), 30); - tf.getAccessibleContext().setAccessibleName( - PolicyTool.rb.getString("KeyStore Provider:")); - tw.addNewComponent(this, tf, KSD_PROVIDER_TEXTFIELD, - 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.BOTTOM_PADDING); - - // KeyStore password URL and textfield - label = new Label(PolicyTool.rb.getString - ("KeyStore Password URL:")); - tw.addNewComponent(this, label, KSD_PWD_URL_LABEL, - 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.BOTTOM_PADDING); - tf = new TextField(tool.getKeyStorePwdURL(), 30); - tf.getAccessibleContext().setAccessibleName( - PolicyTool.rb.getString("KeyStore Password U R L:")); - tw.addNewComponent(this, tf, KSD_PWD_URL_TEXTFIELD, - 1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.BOTTOM_PADDING); - - // OK button - Button okButton = new Button(PolicyTool.rb.getString("OK")); - okButton.addActionListener - (new ChangeKeyStoreOKButtonListener(tool, tw, this)); - tw.addNewComponent(this, okButton, KSD_OK_BUTTON, - 0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); - - // cancel button - Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); - cancelButton.addActionListener(new CancelButtonListener(this)); - tw.addNewComponent(this, cancelButton, KSD_CANCEL_BUTTON, - 1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); - - } - setVisible(true); - } - - /** - * display a dialog box for the user to input Principal info - * - * if editPolicyEntry is false, then we are adding Principals to - * a new PolicyEntry, and we only update the GUI listing - * with the new Principal. - * - * if edit is true, then we are editing an existing Policy entry. - */ - void displayPrincipalDialog(boolean editPolicyEntry, boolean edit) { - - PolicyParser.PrincipalEntry editMe = null; - - // get the Principal selected from the Principal List - TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST); - int prinIndex = prinList.getSelectedIndex(); - - if (edit) { - editMe = (PolicyParser.PrincipalEntry)prinList.getObject(prinIndex); - } - - ToolDialog newTD = new ToolDialog - (PolicyTool.rb.getString("Principals"), tool, tw, true); - newTD.addWindowListener(new ChildWindowListener(newTD)); - - // find where the PolicyTool gui is - Point location = getLocationOnScreen(); - newTD.setBounds(location.x + 50, location.y + 100, 650, 190); - newTD.setLayout(new GridBagLayout()); - newTD.setResizable(true); - - // description label - Label label = (edit ? - new Label(PolicyTool.rb.getString(" Edit Principal:")) : - new Label(PolicyTool.rb.getString(" Add New Principal:"))); - tw.addNewComponent(newTD, label, PRD_DESC_LABEL, - 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.TOP_BOTTOM_PADDING); - - // principal choice - Choice choice = new Choice(); - choice.add(PRIN_TYPE); - choice.getAccessibleContext().setAccessibleName(PRIN_TYPE); - for (int i = 0; i < PRIN_ARRAY.size(); i++) { - Prin next = PRIN_ARRAY.get(i); - choice.add(next.CLASS); - } - - choice.addItemListener(new PrincipalTypeMenuListener(newTD)); - if (edit) { - if (PolicyParser.PrincipalEntry.WILDCARD_CLASS.equals - (editMe.getPrincipalClass())) { - choice.select(PRIN_TYPE); - } else { - Prin inputPrin = getPrin(editMe.getPrincipalClass(), true); - if (inputPrin != null) { - choice.select(inputPrin.CLASS); - } - } - } - - tw.addNewComponent(newTD, choice, PRD_PRIN_CHOICE, - 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.LR_PADDING); - - // principal textfield - TextField tf; - tf = (edit ? - new TextField(editMe.getDisplayClass(), 30) : - new TextField(30)); - tf.getAccessibleContext().setAccessibleName(PRIN_TYPE); - tw.addNewComponent(newTD, tf, PRD_PRIN_TEXTFIELD, - 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.LR_PADDING); - - // name label and textfield - label = new Label(PRIN_NAME); - tf = (edit ? - new TextField(editMe.getDisplayName(), 40) : - new TextField(40)); - tf.getAccessibleContext().setAccessibleName(PRIN_NAME); - - tw.addNewComponent(newTD, label, PRD_NAME_LABEL, - 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.LR_PADDING); - tw.addNewComponent(newTD, tf, PRD_NAME_TEXTFIELD, - 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.LR_PADDING); - - // OK button - Button okButton = new Button(PolicyTool.rb.getString("OK")); - okButton.addActionListener( - new NewPolicyPrinOKButtonListener - (tool, tw, this, newTD, edit)); - tw.addNewComponent(newTD, okButton, PRD_OK_BUTTON, - 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, - tw.TOP_BOTTOM_PADDING); - // cancel button - Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); - cancelButton.addActionListener(new CancelButtonListener(newTD)); - tw.addNewComponent(newTD, cancelButton, PRD_CANCEL_BUTTON, - 1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, - tw.TOP_BOTTOM_PADDING); - - newTD.setVisible(true); - } - - /** - * display a dialog box for the user to input Permission info - * - * if editPolicyEntry is false, then we are adding Permissions to - * a new PolicyEntry, and we only update the GUI listing - * with the new Permission. - * - * if edit is true, then we are editing an existing Permission entry. - */ - void displayPermissionDialog(boolean editPolicyEntry, boolean edit) { - - PolicyParser.PermissionEntry editMe = null; - - // get the Permission selected from the Permission List - TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST); - int permIndex = permList.getSelectedIndex(); - - if (edit) { - editMe = (PolicyParser.PermissionEntry)permList.getObject(permIndex); - } - - ToolDialog newTD = new ToolDialog - (PolicyTool.rb.getString("Permissions"), tool, tw, true); - newTD.addWindowListener(new ChildWindowListener(newTD)); - - // find where the PolicyTool gui is - Point location = getLocationOnScreen(); - newTD.setBounds(location.x + 50, location.y + 100, 700, 250); - newTD.setLayout(new GridBagLayout()); - newTD.setResizable(true); - - // description label - Label label = (edit ? - new Label(PolicyTool.rb.getString(" Edit Permission:")) : - new Label(PolicyTool.rb.getString(" Add New Permission:"))); - tw.addNewComponent(newTD, label, PD_DESC_LABEL, - 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.TOP_BOTTOM_PADDING); - - // permission choice (added in alphabetical order) - Choice choice = new Choice(); - choice.add(PERM); - choice.getAccessibleContext().setAccessibleName(PERM); - for (int i = 0; i < PERM_ARRAY.size(); i++) { - Perm next = PERM_ARRAY.get(i); - choice.add(next.CLASS); - } - choice.addItemListener(new PermissionMenuListener(newTD)); - tw.addNewComponent(newTD, choice, PD_PERM_CHOICE, - 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.LR_PADDING); - - // permission textfield - TextField tf; - tf = (edit ? new TextField(editMe.permission, 30) : new TextField(30)); - tf.getAccessibleContext().setAccessibleName(PERM); - if (edit) { - Perm inputPerm = getPerm(editMe.permission, true); - if (inputPerm != null) { - choice.select(inputPerm.CLASS); - } - } - tw.addNewComponent(newTD, tf, PD_PERM_TEXTFIELD, - 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.LR_PADDING); - - // name label and textfield - choice = new Choice(); - choice.add(PERM_NAME); - choice.getAccessibleContext().setAccessibleName(PERM_NAME); - choice.addItemListener(new PermissionNameMenuListener(newTD)); - tf = (edit ? new TextField(editMe.name, 40) : new TextField(40)); - tf.getAccessibleContext().setAccessibleName(PERM_NAME); - if (edit) { - setPermissionNames(getPerm(editMe.permission, true), choice, tf); - } - tw.addNewComponent(newTD, choice, PD_NAME_CHOICE, - 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.LR_PADDING); - tw.addNewComponent(newTD, tf, PD_NAME_TEXTFIELD, - 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.LR_PADDING); - - // actions label and textfield - choice = new Choice(); - choice.add(PERM_ACTIONS); - choice.getAccessibleContext().setAccessibleName(PERM_ACTIONS); - choice.addItemListener(new PermissionActionsMenuListener(newTD)); - tf = (edit ? new TextField(editMe.action, 40) : new TextField(40)); - tf.getAccessibleContext().setAccessibleName(PERM_ACTIONS); - if (edit) { - setPermissionActions(getPerm(editMe.permission, true), choice, tf); - } - tw.addNewComponent(newTD, choice, PD_ACTIONS_CHOICE, - 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.LR_PADDING); - tw.addNewComponent(newTD, tf, PD_ACTIONS_TEXTFIELD, - 1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.LR_PADDING); - - // signedby label and textfield - label = new Label(PolicyTool.rb.getString("Signed By:")); - tw.addNewComponent(newTD, label, PD_SIGNEDBY_LABEL, - 0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.LR_PADDING); - tf = (edit ? new TextField(editMe.signedBy, 40) : new TextField(40)); - tf.getAccessibleContext().setAccessibleName( - PolicyTool.rb.getString("Signed By:")); - tw.addNewComponent(newTD, tf, PD_SIGNEDBY_TEXTFIELD, - 1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.LR_PADDING); - - // OK button - Button okButton = new Button(PolicyTool.rb.getString("OK")); - okButton.addActionListener( - new NewPolicyPermOKButtonListener - (tool, tw, this, newTD, edit)); - tw.addNewComponent(newTD, okButton, PD_OK_BUTTON, - 0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, - tw.TOP_BOTTOM_PADDING); - - // cancel button - Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); - cancelButton.addActionListener(new CancelButtonListener(newTD)); - tw.addNewComponent(newTD, cancelButton, PD_CANCEL_BUTTON, - 1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, - tw.TOP_BOTTOM_PADDING); - - newTD.setVisible(true); - } - - /** - * construct a Principal object from the Principal Info Dialog Box - */ - PolicyParser.PrincipalEntry getPrinFromDialog() throws Exception { - - TextField tf = (TextField)getComponent(PRD_PRIN_TEXTFIELD); - String pclass = new String(tf.getText().trim()); - tf = (TextField)getComponent(PRD_NAME_TEXTFIELD); - String pname = new String(tf.getText().trim()); - if (pclass.equals("*")) { - pclass = PolicyParser.PrincipalEntry.WILDCARD_CLASS; - } - if (pname.equals("*")) { - pname = PolicyParser.PrincipalEntry.WILDCARD_NAME; - } - - PolicyParser.PrincipalEntry pppe = null; - - if ((pclass.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS)) && - (!pname.equals(PolicyParser.PrincipalEntry.WILDCARD_NAME))) { - throw new Exception - (PolicyTool.rb.getString("Cannot Specify Principal " + - "with a Wildcard Class without a Wildcard Name")); - } else if (pname.equals("")) { - throw new Exception - (PolicyTool.rb.getString("Cannot Specify Principal " + - "without a Name")); - } else if (pclass.equals("")) { - // make this consistent with what PolicyParser does - // when it sees an empty principal class - pclass = PolicyParser.REPLACE_NAME; - tool.warnings.addElement( - "Warning: Principal name '" + pname + - "' specified without a Principal class.\n" + - "\t'" + pname + "' will be interpreted " + - "as a key store alias.\n" + - "\tThe final principal class will be " + - ToolDialog.X500_PRIN_CLASS + ".\n" + - "\tThe final principal name will be " + - "determined by the following:\n" + - "\n" + - "\tIf the key store entry identified by '" - + pname + "'\n" + - "\tis a key entry, then the principal name will be\n" + - "\tthe subject distinguished name from the first\n" + - "\tcertificate in the entry's certificate chain.\n" + - "\n" + - "\tIf the key store entry identified by '" + - pname + "'\n" + - "\tis a trusted certificate entry, then the\n" + - "\tprincipal name will be the subject distinguished\n" + - "\tname from the trusted public key certificate."); - tw.displayStatusDialog(this, - "'" + pname + "' will be interpreted as a key " + - "store alias. View Warning Log for details."); - } - return new PolicyParser.PrincipalEntry(pclass, pname); - } - - - /** - * construct a Permission object from the Permission Info Dialog Box - */ - PolicyParser.PermissionEntry getPermFromDialog() { - - TextField tf = (TextField)getComponent(PD_PERM_TEXTFIELD); - String permission = new String(tf.getText().trim()); - tf = (TextField)getComponent(PD_NAME_TEXTFIELD); - String name = null; - if (tf.getText().trim().equals("") == false) - name = new String(tf.getText().trim()); - if (permission.equals("") || - (!permission.equals(ALL_PERM_CLASS) && name == null)) { - throw new InvalidParameterException(PolicyTool.rb.getString - ("Permission and Target Name must have a value")); - } - - // When the permission is FilePermission, we need to check the name - // to make sure it's not escaped. We believe -- - // - // String name.lastIndexOf("\\\\") - // ---------------- ------------------------ - // c:\foo\bar -1, legal - // c:\\foo\\bar 2, illegal - // \\server\share 0, legal - // \\\\server\share 2, illegal - - if (permission.equals(FILE_PERM_CLASS) && name.lastIndexOf("\\\\") > 0) { - char result = tw.displayYesNoDialog(this, - PolicyTool.rb.getString("Warning"), - PolicyTool.rb.getString( - "Warning: File name may include escaped backslash characters. " + - "It is not necessary to escape backslash characters " + - "(the tool escapes characters as necessary when writing " + - "the policy contents to the persistent store).\n\n" + - "Click on Retain to retain the entered name, or click on " + - "Edit to edit the name."), - PolicyTool.rb.getString("Retain"), - PolicyTool.rb.getString("Edit") - ); - if (result != 'Y') { - // an invisible exception - throw new NoDisplayException(); - } - } - // get the Actions - tf = (TextField)getComponent(PD_ACTIONS_TEXTFIELD); - String actions = null; - if (tf.getText().trim().equals("") == false) - actions = new String(tf.getText().trim()); - - // get the Signed By - tf = (TextField)getComponent(PD_SIGNEDBY_TEXTFIELD); - String signedBy = null; - if (tf.getText().trim().equals("") == false) - signedBy = new String(tf.getText().trim()); - - PolicyParser.PermissionEntry pppe = new PolicyParser.PermissionEntry - (permission, name, actions); - pppe.signedBy = signedBy; - - // see if the signers have public keys - if (signedBy != null) { - String signers[] = tool.parseSigners(pppe.signedBy); - for (int i = 0; i < signers.length; i++) { - try { - PublicKey pubKey = tool.getPublicKeyAlias(signers[i]); - if (pubKey == null) { - MessageFormat form = new MessageFormat - (PolicyTool.rb.getString - ("Warning: A public key for alias " + - "'signers[i]' does not exist. " + - "Make sure a KeyStore is properly configured.")); - Object[] source = {signers[i]}; - tool.warnings.addElement(form.format(source)); - tw.displayStatusDialog(this, form.format(source)); - } - } catch (Exception e) { - tw.displayErrorDialog(this, e); - } - } - } - return pppe; - } - - /** - * confirm that the user REALLY wants to remove the Policy Entry - */ - void displayConfirmRemovePolicyEntry() { - - // find the entry to be removed - List list = (List)tw.getComponent(tw.MW_POLICY_LIST); - int index = list.getSelectedIndex(); - PolicyEntry entries[] = tool.getEntry(); - - // find where the PolicyTool gui is - Point location = tw.getLocationOnScreen(); - setBounds(location.x + 25, location.y + 100, 600, 400); - setLayout(new GridBagLayout()); - - // ask the user do they really want to do this? - Label label = new Label - (PolicyTool.rb.getString("Remove this Policy Entry?")); - tw.addNewComponent(this, label, CRPE_LABEL1, - 0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.BOTTOM_PADDING); - - // display the policy entry - label = new Label(entries[index].codebaseToString()); - tw.addNewComponent(this, label, CRPE_LABEL2, - 0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH); - label = new Label(entries[index].principalsToString().trim()); - tw.addNewComponent(this, label, CRPE_LABEL2+1, - 0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH); - Vector perms = - entries[index].getGrantEntry().permissionEntries; - for (int i = 0; i < perms.size(); i++) { - PolicyParser.PermissionEntry nextPerm = perms.elementAt(i); - String permString = ToolDialog.PermissionEntryToUserFriendlyString(nextPerm); - label = new Label(" " + permString); - if (i == (perms.size()-1)) { - tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i, - 1, 3 + i, 1, 1, 0.0, 0.0, - GridBagConstraints.BOTH, tw.BOTTOM_PADDING); - } else { - tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i, - 1, 3 + i, 1, 1, 0.0, 0.0, - GridBagConstraints.BOTH); - } - } - - - // add OK/CANCEL buttons in a new panel - Panel panel = new Panel(); - panel.setLayout(new GridBagLayout()); - - // OK button - Button okButton = new Button(PolicyTool.rb.getString("OK")); - okButton.addActionListener - (new ConfirmRemovePolicyEntryOKButtonListener(tool, tw, this)); - tw.addNewComponent(panel, okButton, CRPE_PANEL_OK, - 0, 0, 1, 1, 0.0, 0.0, - GridBagConstraints.VERTICAL, tw.LR_PADDING); - - // cancel button - Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); - cancelButton.addActionListener(new CancelButtonListener(this)); - tw.addNewComponent(panel, cancelButton, CRPE_PANEL_CANCEL, - 1, 0, 1, 1, 0.0, 0.0, - GridBagConstraints.VERTICAL, tw.LR_PADDING); - - tw.addNewComponent(this, panel, CRPE_LABEL2 + 2 + perms.size(), - 0, 3 + perms.size(), 2, 1, 0.0, 0.0, - GridBagConstraints.VERTICAL, tw.TOP_BOTTOM_PADDING); - - pack(); - setVisible(true); - } - - /** - * perform SAVE AS - */ - void displaySaveAsDialog(int nextEvent) { - - // pop up a dialog box for the user to enter a filename. - FileDialog fd = new FileDialog - (tw, PolicyTool.rb.getString("Save As"), FileDialog.SAVE); - fd.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - e.getWindow().setVisible(false); - } - }); - fd.setVisible(true); - - // see if the user hit cancel - if (fd.getFile() == null || - fd.getFile().equals("")) - return; - - // get the entered filename - String filename = new String(fd.getDirectory() + fd.getFile()); - fd.dispose(); - - // see if the file already exists - File saveAsFile = new File(filename); - if (saveAsFile.exists()) { - // display a dialog box for the user to enter policy info - ToolDialog td = new ToolDialog - (PolicyTool.rb.getString("Overwrite File"), tool, tw, true); - td.displayOverWriteFileDialog(filename, nextEvent); - } else { - try { - // save the policy entries to a file - tool.savePolicy(filename); - - // display status - MessageFormat form = new MessageFormat(PolicyTool.rb.getString - ("Policy successfully written to filename")); - Object[] source = {filename}; - tw.displayStatusDialog(null, form.format(source)); - - // display the new policy filename - TextField newFilename = (TextField)tw.getComponent - (tw.MW_FILENAME_TEXTFIELD); - newFilename.setText(filename); - tw.setVisible(true); - - // now continue with the originally requested command - // (QUIT, NEW, or OPEN) - userSaveContinue(tool, tw, this, nextEvent); - - } catch (FileNotFoundException fnfe) { - if (filename == null || filename.equals("")) { - tw.displayErrorDialog(null, new FileNotFoundException - (PolicyTool.rb.getString("null filename"))); - } else { - tw.displayErrorDialog(null, fnfe); - } - } catch (Exception ee) { - tw.displayErrorDialog(null, ee); - } - } - } - - /** - * ask user if they want to save changes - */ - void displayUserSave(int select) { - - if (tool.modified == true) { - - // find where the PolicyTool gui is - Point location = tw.getLocationOnScreen(); - setBounds(location.x + 75, location.y + 100, 400, 150); - setLayout(new GridBagLayout()); - - Label label = new Label - (PolicyTool.rb.getString("Save changes?")); - tw.addNewComponent(this, label, USC_LABEL, - 0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH, - tw.L_TOP_BOTTOM_PADDING); - - Panel panel = new Panel(); - panel.setLayout(new GridBagLayout()); - - Button yesButton = new Button(PolicyTool.rb.getString("Yes")); - yesButton.addActionListener - (new UserSaveYesButtonListener(this, tool, tw, select)); - tw.addNewComponent(panel, yesButton, USC_YES_BUTTON, - 0, 0, 1, 1, 0.0, 0.0, - GridBagConstraints.VERTICAL, - tw.LR_BOTTOM_PADDING); - Button noButton = new Button(PolicyTool.rb.getString("No")); - noButton.addActionListener - (new UserSaveNoButtonListener(this, tool, tw, select)); - tw.addNewComponent(panel, noButton, USC_NO_BUTTON, - 1, 0, 1, 1, 0.0, 0.0, - GridBagConstraints.VERTICAL, - tw.LR_BOTTOM_PADDING); - Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); - cancelButton.addActionListener - (new UserSaveCancelButtonListener(this)); - tw.addNewComponent(panel, cancelButton, USC_CANCEL_BUTTON, - 2, 0, 1, 1, 0.0, 0.0, - GridBagConstraints.VERTICAL, - tw.LR_BOTTOM_PADDING); - - tw.addNewComponent(this, panel, USC_PANEL, - 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); - - pack(); - setVisible(true); - } else { - // just do the original request (QUIT, NEW, or OPEN) - userSaveContinue(tool, tw, this, select); - } - } - - /** - * when the user sees the 'YES', 'NO', 'CANCEL' buttons on the - * displayUserSave dialog, and the click on one of them, - * we need to continue the originally requested action - * (either QUITting, opening NEW policy file, or OPENing an existing - * policy file. do that now. - */ - void userSaveContinue(PolicyTool tool, ToolWindow tw, - ToolDialog us, int select) { - - // now either QUIT, open a NEW policy file, or OPEN an existing policy - switch(select) { - case ToolDialog.QUIT: - - tw.setVisible(false); - tw.dispose(); - System.exit(0); - - case ToolDialog.NEW: - - try { - tool.openPolicy(null); - } catch (Exception ee) { - tool.modified = false; - tw.displayErrorDialog(null, ee); - } - - // display the policy entries via the policy list textarea - List list = new List(40, false); - list.addActionListener(new PolicyListListener(tool, tw)); - tw.replacePolicyList(list); - - // display null policy filename and keystore - TextField newFilename = (TextField) - tw.getComponent(tw.MW_FILENAME_TEXTFIELD); - newFilename.setText(""); - tw.setVisible(true); - break; - - case ToolDialog.OPEN: - - // pop up a dialog box for the user to enter a filename. - FileDialog fd = new FileDialog - (tw, PolicyTool.rb.getString("Open"), FileDialog.LOAD); - fd.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - e.getWindow().setVisible(false); - } - }); - fd.setVisible(true); - - // see if the user hit 'cancel' - if (fd.getFile() == null || - fd.getFile().equals("")) - return; - - // get the entered filename - String policyFile = new String(fd.getDirectory() + fd.getFile()); - - try { - // open the policy file - tool.openPolicy(policyFile); - - // display the policy entries via the policy list textarea - list = new List(40, false); - list.addActionListener(new PolicyListListener(tool, tw)); - PolicyEntry entries[] = tool.getEntry(); - if (entries != null) { - for (int i = 0; i < entries.length; i++) - list.add(entries[i].headerToString()); - } - tw.replacePolicyList(list); - tool.modified = false; - - // display the new policy filename - newFilename = (TextField) - tw.getComponent(tw.MW_FILENAME_TEXTFIELD); - newFilename.setText(policyFile); - tw.setVisible(true); - - // inform user of warnings - if (tool.newWarning == true) { - tw.displayStatusDialog(null, PolicyTool.rb.getString - ("Errors have occurred while opening the " + - "policy configuration. View the Warning Log " + - "for more information.")); - } - - } catch (Exception e) { - // add blank policy listing - list = new List(40, false); - list.addActionListener(new PolicyListListener(tool, tw)); - tw.replacePolicyList(list); - tool.setPolicyFileName(null); - tool.modified = false; - - // display a null policy filename - newFilename = (TextField) - tw.getComponent(tw.MW_FILENAME_TEXTFIELD); - newFilename.setText(""); - tw.setVisible(true); - - // display the error - MessageFormat form = new MessageFormat(PolicyTool.rb.getString - ("Could not open policy file: policyFile: e.toString()")); - Object[] source = {policyFile, e.toString()}; - tw.displayErrorDialog(null, form.format(source)); - } - break; - } - } - - /** - * Return a Menu list of names for a given permission - * - * If inputPerm's TARGETS are null, then this means TARGETS are - * not allowed to be entered (and the TextField is set to be - * non-editable). - * - * If TARGETS are valid but there are no standard ones - * (user must enter them by hand) then the TARGETS array may be empty - * (and of course non-null). - */ - void setPermissionNames(Perm inputPerm, Choice names, TextField field) { - names.removeAll(); - names.add(PERM_NAME); - - if (inputPerm == null) { - // custom permission - field.setEditable(true); - } else if (inputPerm.TARGETS == null) { - // standard permission with no targets - field.setEditable(false); - } else { - // standard permission with standard targets - field.setEditable(true); - for (int i = 0; i < inputPerm.TARGETS.length; i++) { - names.add(inputPerm.TARGETS[i]); - } - } - } - - /** - * Return a Menu list of actions for a given permission - * - * If inputPerm's ACTIONS are null, then this means ACTIONS are - * not allowed to be entered (and the TextField is set to be - * non-editable). This is typically true for BasicPermissions. - * - * If ACTIONS are valid but there are no standard ones - * (user must enter them by hand) then the ACTIONS array may be empty - * (and of course non-null). - */ - void setPermissionActions(Perm inputPerm, Choice actions, TextField field) { - actions.removeAll(); - actions.add(PERM_ACTIONS); - - if (inputPerm == null) { - // custom permission - field.setEditable(true); - } else if (inputPerm.ACTIONS == null) { - // standard permission with no actions - field.setEditable(false); - } else { - // standard permission with standard actions - field.setEditable(true); - for (int i = 0; i < inputPerm.ACTIONS.length; i++) { - actions.add(inputPerm.ACTIONS[i]); - } - } - } - - static String PermissionEntryToUserFriendlyString(PolicyParser.PermissionEntry pppe) { - String result = pppe.permission; - if (pppe.name != null) { - result += " " + pppe.name; - } - if (pppe.action != null) { - result += ", \"" + pppe.action + "\""; - } - if (pppe.signedBy != null) { - result += ", signedBy " + pppe.signedBy; - } - return result; - } - - static String PrincipalEntryToUserFriendlyString(PolicyParser.PrincipalEntry pppe) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - pppe.write(pw); - return sw.toString(); - } -} - -/** - * Event handler for the PolicyTool window - */ -class ToolWindowListener implements WindowListener { - - private ToolWindow tw; - - ToolWindowListener(ToolWindow tw) { - this.tw = tw; - } - - public void windowOpened(WindowEvent we) { - } - - public void windowClosing(WindowEvent we) { - - // XXX - // should we ask user if they want to save changes? - // (we do if they choose the Menu->Exit) - // seems that if they kill the application by hand, - // we don't have to ask. - - tw.setVisible(false); - tw.dispose(); - System.exit(0); - } - - public void windowClosed(WindowEvent we) { - System.exit(0); - } - - public void windowIconified(WindowEvent we) { - } - - public void windowDeiconified(WindowEvent we) { - } - - public void windowActivated(WindowEvent we) { - } - - public void windowDeactivated(WindowEvent we) { - } -} - -/** - * Event handler for the Policy List - */ -class PolicyListListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - - PolicyListListener(PolicyTool tool, ToolWindow tw) { - this.tool = tool; - this.tw = tw; - - } - - public void actionPerformed(ActionEvent e) { - - // display the permission list for a policy entry - ToolDialog td = new ToolDialog - (PolicyTool.rb.getString("Policy Entry"), tool, tw, true); - td.displayPolicyEntryDialog(true); - } -} - -/** - * Event handler for the File Menu - */ -class FileMenuListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - - FileMenuListener(PolicyTool tool, ToolWindow tw) { - this.tool = tool; - this.tw = tw; - } - - public void actionPerformed(ActionEvent e) { - - if (PolicyTool.collator.compare(e.getActionCommand(), tw.QUIT) == 0) { - - // ask user if they want to save changes - ToolDialog td = new ToolDialog - (PolicyTool.rb.getString("Save Changes"), tool, tw, true); - td.displayUserSave(td.QUIT); - - // the above method will perform the QUIT as long as the - // user does not CANCEL the request - - } else if (PolicyTool.collator.compare(e.getActionCommand(), - tw.NEW_POLICY_FILE) == 0) { - - // ask user if they want to save changes - ToolDialog td = new ToolDialog - (PolicyTool.rb.getString("Save Changes"), tool, tw, true); - td.displayUserSave(td.NEW); - - // the above method will perform the NEW as long as the - // user does not CANCEL the request - - } else if (PolicyTool.collator.compare(e.getActionCommand(), - tw.OPEN_POLICY_FILE) == 0) { - - // ask user if they want to save changes - ToolDialog td = new ToolDialog - (PolicyTool.rb.getString("Save Changes"), tool, tw, true); - td.displayUserSave(td.OPEN); - - // the above method will perform the OPEN as long as the - // user does not CANCEL the request - - } else if (PolicyTool.collator.compare(e.getActionCommand(), - tw.SAVE_POLICY_FILE) == 0) { - - // get the previously entered filename - String filename = ((TextField) - tw.getComponent(tw.MW_FILENAME_TEXTFIELD)).getText(); - - // if there is no filename, do a SAVE_AS - if (filename == null || filename.length() == 0) { - // user wants to SAVE AS - ToolDialog td = new ToolDialog - (PolicyTool.rb.getString("Save As"), tool, tw, true); - td.displaySaveAsDialog(td.NOACTION); - } else { - try { - // save the policy entries to a file - tool.savePolicy(filename); - - // display status - MessageFormat form = new MessageFormat - (PolicyTool.rb.getString - ("Policy successfully written to filename")); - Object[] source = {filename}; - tw.displayStatusDialog(null, form.format(source)); - } catch (FileNotFoundException fnfe) { - if (filename == null || filename.equals("")) { - tw.displayErrorDialog(null, new FileNotFoundException - (PolicyTool.rb.getString("null filename"))); - } else { - tw.displayErrorDialog(null, fnfe); - } - } catch (Exception ee) { - tw.displayErrorDialog(null, ee); - } - } - } else if (PolicyTool.collator.compare(e.getActionCommand(), - tw.SAVE_AS_POLICY_FILE) == 0) { - - // user wants to SAVE AS - ToolDialog td = new ToolDialog - (PolicyTool.rb.getString("Save As"), tool, tw, true); - td.displaySaveAsDialog(td.NOACTION); - - } else if (PolicyTool.collator.compare(e.getActionCommand(), - tw.VIEW_WARNINGS) == 0) { - tw.displayWarningLog(null); - } - } -} - -/** - * Event handler for the main window buttons and Edit Menu - */ -class MainWindowListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - - MainWindowListener(PolicyTool tool, ToolWindow tw) { - this.tool = tool; - this.tw = tw; - } - - public void actionPerformed(ActionEvent e) { - - if (PolicyTool.collator.compare(e.getActionCommand(), - tw.ADD_POLICY_ENTRY) == 0) { - - // display a dialog box for the user to enter policy info - ToolDialog td = new ToolDialog - (PolicyTool.rb.getString("Policy Entry"), tool, tw, true); - td.displayPolicyEntryDialog(false); - - } else if (PolicyTool.collator.compare(e.getActionCommand(), - tw.REMOVE_POLICY_ENTRY) == 0) { - - // get the selected entry - List list = (List)tw.getComponent(tw.MW_POLICY_LIST); - int index = list.getSelectedIndex(); - if (index < 0) { - tw.displayErrorDialog(null, new Exception - (PolicyTool.rb.getString("No Policy Entry selected"))); - return; - } - - // ask the user if they really want to remove the policy entry - ToolDialog td = new ToolDialog(PolicyTool.rb.getString - ("Remove Policy Entry"), tool, tw, true); - td.displayConfirmRemovePolicyEntry(); - - } else if (PolicyTool.collator.compare(e.getActionCommand(), - tw.EDIT_POLICY_ENTRY) == 0) { - - // get the selected entry - List list = (List)tw.getComponent(tw.MW_POLICY_LIST); - int index = list.getSelectedIndex(); - if (index < 0) { - tw.displayErrorDialog(null, new Exception - (PolicyTool.rb.getString("No Policy Entry selected"))); - return; - } - - // display the permission list for a policy entry - ToolDialog td = new ToolDialog - (PolicyTool.rb.getString("Policy Entry"), tool, tw, true); - td.displayPolicyEntryDialog(true); - - } else if (PolicyTool.collator.compare(e.getActionCommand(), - tw.EDIT_KEYSTORE) == 0) { - - // display a dialog box for the user to enter keystore info - ToolDialog td = new ToolDialog - (PolicyTool.rb.getString("KeyStore"), tool, tw, true); - td.keyStoreDialog(td.EDIT_KEYSTORE); - } - } -} - -/** - * Event handler for OverWriteFileOKButton button - */ -class OverWriteFileOKButtonListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - private ToolDialog td; - private String filename; - private int nextEvent; - - OverWriteFileOKButtonListener(PolicyTool tool, ToolWindow tw, - ToolDialog td, String filename, int nextEvent) { - this.tool = tool; - this.tw = tw; - this.td = td; - this.filename = filename; - this.nextEvent = nextEvent; - } - - public void actionPerformed(ActionEvent e) { - try { - // save the policy entries to a file - tool.savePolicy(filename); - - // display status - MessageFormat form = new MessageFormat - (PolicyTool.rb.getString - ("Policy successfully written to filename")); - Object[] source = {filename}; - tw.displayStatusDialog(null, form.format(source)); - - // display the new policy filename - TextField newFilename = (TextField)tw.getComponent - (tw.MW_FILENAME_TEXTFIELD); - newFilename.setText(filename); - tw.setVisible(true); - - // now continue with the originally requested command - // (QUIT, NEW, or OPEN) - td.setVisible(false); - td.dispose(); - td.userSaveContinue(tool, tw, td, nextEvent); - - } catch (FileNotFoundException fnfe) { - if (filename == null || filename.equals("")) { - tw.displayErrorDialog(null, new FileNotFoundException - (PolicyTool.rb.getString("null filename"))); - } else { - tw.displayErrorDialog(null, fnfe); - } - td.setVisible(false); - td.dispose(); - } catch (Exception ee) { - tw.displayErrorDialog(null, ee); - td.setVisible(false); - td.dispose(); - } - } -} - -/** - * Event handler for AddEntryDoneButton button - * - * -- if edit is TRUE, then we are EDITing an existing PolicyEntry - * and we need to update both the policy and the GUI listing. - * if edit is FALSE, then we are ADDing a new PolicyEntry, - * so we only need to update the GUI listing. - */ -class AddEntryDoneButtonListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - private ToolDialog td; - private boolean edit; - - AddEntryDoneButtonListener(PolicyTool tool, ToolWindow tw, - ToolDialog td, boolean edit) { - this.tool = tool; - this.tw = tw; - this.td = td; - this.edit = edit; - } - - public void actionPerformed(ActionEvent e) { - - try { - // get a PolicyEntry object from the dialog policy info - PolicyEntry newEntry = td.getPolicyEntryFromDialog(); - PolicyParser.GrantEntry newGe = newEntry.getGrantEntry(); - - // see if all the signers have public keys - if (newGe.signedBy != null) { - String signers[] = tool.parseSigners(newGe.signedBy); - for (int i = 0; i < signers.length; i++) { - PublicKey pubKey = tool.getPublicKeyAlias(signers[i]); - if (pubKey == null) { - MessageFormat form = new MessageFormat - (PolicyTool.rb.getString - ("Warning: A public key for alias " + - "'signers[i]' does not exist. " + - "Make sure a KeyStore is properly configured.")); - Object[] source = {signers[i]}; - tool.warnings.addElement(form.format(source)); - tw.displayStatusDialog(td, form.format(source)); - } - } - } - - // add the entry - List policyList = (List)tw.getComponent(tw.MW_POLICY_LIST); - if (edit) { - int listIndex = policyList.getSelectedIndex(); - tool.addEntry(newEntry, listIndex); - String newCodeBaseStr = newEntry.headerToString(); - if (PolicyTool.collator.compare - (newCodeBaseStr, policyList.getItem(listIndex)) != 0) - tool.modified = true; - policyList.replaceItem(newCodeBaseStr, listIndex); - } else { - tool.addEntry(newEntry, -1); - policyList.add(newEntry.headerToString()); - tool.modified = true; - } - td.setVisible(false); - td.dispose(); - - } catch (Exception eee) { - tw.displayErrorDialog(td, eee); - } - } -} - -/** - * Event handler for ChangeKeyStoreOKButton button - */ -class ChangeKeyStoreOKButtonListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - private ToolDialog td; - - ChangeKeyStoreOKButtonListener(PolicyTool tool, ToolWindow tw, - ToolDialog td) { - this.tool = tool; - this.tw = tw; - this.td = td; - } - - public void actionPerformed(ActionEvent e) { - - String URLString = ((TextField) - td.getComponent(td.KSD_NAME_TEXTFIELD)).getText().trim(); - String type = ((TextField) - td.getComponent(td.KSD_TYPE_TEXTFIELD)).getText().trim(); - String provider = ((TextField) - td.getComponent(td.KSD_PROVIDER_TEXTFIELD)).getText().trim(); - String pwdURL = ((TextField) - td.getComponent(td.KSD_PWD_URL_TEXTFIELD)).getText().trim(); - - try { - tool.openKeyStore - ((URLString.length() == 0 ? null : URLString), - (type.length() == 0 ? null : type), - (provider.length() == 0 ? null : provider), - (pwdURL.length() == 0 ? null : pwdURL)); - tool.modified = true; - } catch (Exception ex) { - MessageFormat form = new MessageFormat(PolicyTool.rb.getString - ("Unable to open KeyStore: ex.toString()")); - Object[] source = {ex.toString()}; - tw.displayErrorDialog(td, form.format(source)); - return; - } - - td.dispose(); - } -} - -/** - * Event handler for AddPrinButton button - */ -class AddPrinButtonListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - private ToolDialog td; - private boolean editPolicyEntry; - - AddPrinButtonListener(PolicyTool tool, ToolWindow tw, - ToolDialog td, boolean editPolicyEntry) { - this.tool = tool; - this.tw = tw; - this.td = td; - this.editPolicyEntry = editPolicyEntry; - } - - public void actionPerformed(ActionEvent e) { - - // display a dialog box for the user to enter principal info - td.displayPrincipalDialog(editPolicyEntry, false); - } -} - -/** - * Event handler for AddPermButton button - */ -class AddPermButtonListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - private ToolDialog td; - private boolean editPolicyEntry; - - AddPermButtonListener(PolicyTool tool, ToolWindow tw, - ToolDialog td, boolean editPolicyEntry) { - this.tool = tool; - this.tw = tw; - this.td = td; - this.editPolicyEntry = editPolicyEntry; - } - - public void actionPerformed(ActionEvent e) { - - // display a dialog box for the user to enter permission info - td.displayPermissionDialog(editPolicyEntry, false); - } -} - -/** - * Event handler for AddPrinOKButton button - */ -class NewPolicyPrinOKButtonListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - private ToolDialog listDialog; - private ToolDialog infoDialog; - private boolean edit; - - NewPolicyPrinOKButtonListener(PolicyTool tool, - ToolWindow tw, - ToolDialog listDialog, - ToolDialog infoDialog, - boolean edit) { - this.tool = tool; - this.tw = tw; - this.listDialog = listDialog; - this.infoDialog = infoDialog; - this.edit = edit; - } - - public void actionPerformed(ActionEvent e) { - - try { - // read in the new principal info from Dialog Box - PolicyParser.PrincipalEntry pppe = - infoDialog.getPrinFromDialog(); - if (pppe != null) { - try { - tool.verifyPrincipal(pppe.getPrincipalClass(), - pppe.getPrincipalName()); - } catch (ClassNotFoundException cnfe) { - MessageFormat form = new MessageFormat - (PolicyTool.rb.getString - ("Warning: Class not found: class")); - Object[] source = {pppe.getPrincipalClass()}; - tool.warnings.addElement(form.format(source)); - tw.displayStatusDialog(infoDialog, form.format(source)); - } - - // add the principal to the GUI principal list - TaggedList prinList = - (TaggedList)listDialog.getComponent(listDialog.PE_PRIN_LIST); - - String prinString = ToolDialog.PrincipalEntryToUserFriendlyString(pppe); - if (edit) { - // if editing, replace the original principal - int index = prinList.getSelectedIndex(); - prinList.replaceTaggedItem(prinString, pppe, index); - } else { - // if adding, just add it to the end - prinList.addTaggedItem(prinString, pppe); - } - } - infoDialog.dispose(); - } catch (Exception ee) { - tw.displayErrorDialog(infoDialog, ee); - } - } -} - -/** - * Event handler for AddPermOKButton button - */ -class NewPolicyPermOKButtonListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - private ToolDialog listDialog; - private ToolDialog infoDialog; - private boolean edit; - - NewPolicyPermOKButtonListener(PolicyTool tool, - ToolWindow tw, - ToolDialog listDialog, - ToolDialog infoDialog, - boolean edit) { - this.tool = tool; - this.tw = tw; - this.listDialog = listDialog; - this.infoDialog = infoDialog; - this.edit = edit; - } - - public void actionPerformed(ActionEvent e) { - - try { - // read in the new permission info from Dialog Box - PolicyParser.PermissionEntry pppe = - infoDialog.getPermFromDialog(); - - try { - tool.verifyPermission(pppe.permission, pppe.name, pppe.action); - } catch (ClassNotFoundException cnfe) { - MessageFormat form = new MessageFormat(PolicyTool.rb.getString - ("Warning: Class not found: class")); - Object[] source = {pppe.permission}; - tool.warnings.addElement(form.format(source)); - tw.displayStatusDialog(infoDialog, form.format(source)); - } - - // add the permission to the GUI permission list - TaggedList permList = - (TaggedList)listDialog.getComponent(listDialog.PE_PERM_LIST); - - String permString = ToolDialog.PermissionEntryToUserFriendlyString(pppe); - if (edit) { - // if editing, replace the original permission - int which = permList.getSelectedIndex(); - permList.replaceTaggedItem(permString, pppe, which); - } else { - // if adding, just add it to the end - permList.addTaggedItem(permString, pppe); - } - infoDialog.dispose(); - - } catch (InvocationTargetException ite) { - tw.displayErrorDialog(infoDialog, ite.getTargetException()); - } catch (Exception ee) { - tw.displayErrorDialog(infoDialog, ee); - } - } -} - -/** - * Event handler for RemovePrinButton button - */ -class RemovePrinButtonListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - private ToolDialog td; - private boolean edit; - - RemovePrinButtonListener(PolicyTool tool, ToolWindow tw, - ToolDialog td, boolean edit) { - this.tool = tool; - this.tw = tw; - this.td = td; - this.edit = edit; - } - - public void actionPerformed(ActionEvent e) { - - // get the Principal selected from the Principal List - TaggedList prinList = (TaggedList)td.getComponent(td.PE_PRIN_LIST); - int prinIndex = prinList.getSelectedIndex(); - - if (prinIndex < 0) { - tw.displayErrorDialog(td, new Exception - (PolicyTool.rb.getString("No principal selected"))); - return; - } - // remove the principal from the display - prinList.removeTaggedItem(prinIndex); - } -} - -/** - * Event handler for RemovePermButton button - */ -class RemovePermButtonListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - private ToolDialog td; - private boolean edit; - - RemovePermButtonListener(PolicyTool tool, ToolWindow tw, - ToolDialog td, boolean edit) { - this.tool = tool; - this.tw = tw; - this.td = td; - this.edit = edit; - } - - public void actionPerformed(ActionEvent e) { - - // get the Permission selected from the Permission List - TaggedList permList = (TaggedList)td.getComponent(td.PE_PERM_LIST); - int permIndex = permList.getSelectedIndex(); - - if (permIndex < 0) { - tw.displayErrorDialog(td, new Exception - (PolicyTool.rb.getString("No permission selected"))); - return; - } - // remove the permission from the display - permList.removeTaggedItem(permIndex); - - } -} - -/** - * Event handler for Edit Principal button - * - * We need the editPolicyEntry boolean to tell us if the user is - * adding a new PolicyEntry at this time, or editing an existing entry. - * If the user is adding a new PolicyEntry, we ONLY update the - * GUI listing. If the user is editing an existing PolicyEntry, we - * update both the GUI listing and the actual PolicyEntry. - */ -class EditPrinButtonListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - private ToolDialog td; - private boolean editPolicyEntry; - - EditPrinButtonListener(PolicyTool tool, ToolWindow tw, - ToolDialog td, boolean editPolicyEntry) { - this.tool = tool; - this.tw = tw; - this.td = td; - this.editPolicyEntry = editPolicyEntry; - } - - public void actionPerformed(ActionEvent e) { - - // get the Principal selected from the Principal List - TaggedList list = (TaggedList)td.getComponent(td.PE_PRIN_LIST); - int prinIndex = list.getSelectedIndex(); - - if (prinIndex < 0) { - tw.displayErrorDialog(td, new Exception - (PolicyTool.rb.getString("No principal selected"))); - return; - } - td.displayPrincipalDialog(editPolicyEntry, true); - } -} - -/** - * Event handler for Edit Permission button - * - * We need the editPolicyEntry boolean to tell us if the user is - * adding a new PolicyEntry at this time, or editing an existing entry. - * If the user is adding a new PolicyEntry, we ONLY update the - * GUI listing. If the user is editing an existing PolicyEntry, we - * update both the GUI listing and the actual PolicyEntry. - */ -class EditPermButtonListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - private ToolDialog td; - private boolean editPolicyEntry; - - EditPermButtonListener(PolicyTool tool, ToolWindow tw, - ToolDialog td, boolean editPolicyEntry) { - this.tool = tool; - this.tw = tw; - this.td = td; - this.editPolicyEntry = editPolicyEntry; - } - - public void actionPerformed(ActionEvent e) { - - // get the Permission selected from the Permission List - List list = (List)td.getComponent(td.PE_PERM_LIST); - int permIndex = list.getSelectedIndex(); - - if (permIndex < 0) { - tw.displayErrorDialog(td, new Exception - (PolicyTool.rb.getString("No permission selected"))); - return; - } - td.displayPermissionDialog(editPolicyEntry, true); - } -} - -/** - * Event handler for Principal Popup Menu - */ -class PrincipalTypeMenuListener implements ItemListener { - - private ToolDialog td; - - PrincipalTypeMenuListener(ToolDialog td) { - this.td = td; - } - - public void itemStateChanged(ItemEvent e) { - - Choice prin = (Choice)td.getComponent(td.PRD_PRIN_CHOICE); - TextField prinField = - (TextField)td.getComponent(td.PRD_PRIN_TEXTFIELD); - TextField nameField = - (TextField)td.getComponent(td.PRD_NAME_TEXTFIELD); - - prin.getAccessibleContext().setAccessibleName( - PolicyTool.splitToWords((String)e.getItem())); - if (((String)e.getItem()).equals(td.PRIN_TYPE)) { - // ignore if they choose "Principal Type:" item - if (prinField.getText() != null && - prinField.getText().length() > 0) { - Prin inputPrin = td.getPrin(prinField.getText(), true); - prin.select(inputPrin.CLASS); - } - return; - } - - // if you change the principal, clear the name - if (prinField.getText().indexOf((String)e.getItem()) == -1) { - nameField.setText(""); - } - - // set the text in the textfield and also modify the - // pull-down choice menus to reflect the correct possible - // set of names and actions - Prin inputPrin = td.getPrin((String)e.getItem(), false); - if (inputPrin != null) { - prinField.setText(inputPrin.FULL_CLASS); - } - } -} - -/** - * Event handler for Permission Popup Menu - */ -class PermissionMenuListener implements ItemListener { - - private ToolDialog td; - - PermissionMenuListener(ToolDialog td) { - this.td = td; - } - - public void itemStateChanged(ItemEvent e) { - - Choice perms = (Choice)td.getComponent(td.PD_PERM_CHOICE); - Choice names = (Choice)td.getComponent(td.PD_NAME_CHOICE); - Choice actions = (Choice)td.getComponent(td.PD_ACTIONS_CHOICE); - TextField nameField = - (TextField)td.getComponent(td.PD_NAME_TEXTFIELD); - TextField actionsField = - (TextField)td.getComponent(td.PD_ACTIONS_TEXTFIELD); - TextField permField = (TextField)td.getComponent(td.PD_PERM_TEXTFIELD); - TextField signedbyField = - (TextField)td.getComponent(td.PD_SIGNEDBY_TEXTFIELD); - - perms.getAccessibleContext().setAccessibleName( - PolicyTool.splitToWords((String)e.getItem())); - - // ignore if they choose the 'Permission:' item - if (PolicyTool.collator.compare((String)e.getItem(), td.PERM) == 0) { - if (permField.getText() != null && - permField.getText().length() > 0) { - - Perm inputPerm = td.getPerm(permField.getText(), true); - if (inputPerm != null) { - perms.select(inputPerm.CLASS); - } - } - return; - } - - // if you change the permission, clear the name, actions, and signedBy - if (permField.getText().indexOf((String)e.getItem()) == -1) { - nameField.setText(""); - actionsField.setText(""); - signedbyField.setText(""); - } - - // set the text in the textfield and also modify the - // pull-down choice menus to reflect the correct possible - // set of names and actions - - Perm inputPerm = td.getPerm((String)e.getItem(), false); - if (inputPerm == null) { - permField.setText(""); - } else { - permField.setText(inputPerm.FULL_CLASS); - } - td.setPermissionNames(inputPerm, names, nameField); - td.setPermissionActions(inputPerm, actions, actionsField); - } -} - -/** - * Event handler for Permission Name Popup Menu - */ -class PermissionNameMenuListener implements ItemListener { - - private ToolDialog td; - - PermissionNameMenuListener(ToolDialog td) { - this.td = td; - } - - public void itemStateChanged(ItemEvent e) { - - Choice names = (Choice)td.getComponent(td.PD_NAME_CHOICE); - names.getAccessibleContext().setAccessibleName( - PolicyTool.splitToWords((String)e.getItem())); - - if (((String)e.getItem()).indexOf(td.PERM_NAME) != -1) - return; - - TextField tf = (TextField)td.getComponent(td.PD_NAME_TEXTFIELD); - tf.setText((String)e.getItem()); - } -} - -/** - * Event handler for Permission Actions Popup Menu - */ -class PermissionActionsMenuListener implements ItemListener { - - private ToolDialog td; - - PermissionActionsMenuListener(ToolDialog td) { - this.td = td; - } - - public void itemStateChanged(ItemEvent e) { - - Choice actions = (Choice)td.getComponent(td.PD_ACTIONS_CHOICE); - actions.getAccessibleContext().setAccessibleName((String)e.getItem()); - - if (((String)e.getItem()).indexOf(td.PERM_ACTIONS) != -1) - return; - - TextField tf = (TextField)td.getComponent(td.PD_ACTIONS_TEXTFIELD); - if (tf.getText() == null || tf.getText().equals("")) { - tf.setText((String)e.getItem()); - } else { - if (tf.getText().indexOf((String)e.getItem()) == -1) - tf.setText(tf.getText() + ", " + (String)e.getItem()); - } - } -} - -/** - * Event handler for all the children dialogs/windows - */ -class ChildWindowListener implements WindowListener { - - private ToolDialog td; - - ChildWindowListener(ToolDialog td) { - this.td = td; - } - - public void windowOpened(WindowEvent we) { - } - - public void windowClosing(WindowEvent we) { - // same as pressing the "cancel" button - td.setVisible(false); - td.dispose(); - } - - public void windowClosed(WindowEvent we) { - } - - public void windowIconified(WindowEvent we) { - } - - public void windowDeiconified(WindowEvent we) { - } - - public void windowActivated(WindowEvent we) { - } - - public void windowDeactivated(WindowEvent we) { - } -} - -/** - * Event handler for CancelButton button - */ -class CancelButtonListener implements ActionListener { - - private ToolDialog td; - - CancelButtonListener(ToolDialog td) { - this.td = td; - } - - public void actionPerformed(ActionEvent e) { - td.setVisible(false); - td.dispose(); - } -} - -/** - * Event handler for ErrorOKButton button - */ -class ErrorOKButtonListener implements ActionListener { - - private ToolDialog ed; - - ErrorOKButtonListener(ToolDialog ed) { - this.ed = ed; - } - - public void actionPerformed(ActionEvent e) { - ed.setVisible(false); - ed.dispose(); - } -} - -/** - * Event handler for StatusOKButton button - */ -class StatusOKButtonListener implements ActionListener { - - private ToolDialog sd; - - StatusOKButtonListener(ToolDialog sd) { - this.sd = sd; - } - - public void actionPerformed(ActionEvent e) { - sd.setVisible(false); - sd.dispose(); - } -} - -/** - * Event handler for UserSaveYes button - */ -class UserSaveYesButtonListener implements ActionListener { - - private ToolDialog us; - private PolicyTool tool; - private ToolWindow tw; - private int select; - - UserSaveYesButtonListener(ToolDialog us, PolicyTool tool, - ToolWindow tw, int select) { - this.us = us; - this.tool = tool; - this.tw = tw; - this.select = select; - } - - public void actionPerformed(ActionEvent e) { - - // first get rid of the window - us.setVisible(false); - us.dispose(); - - try { - String filename = ((TextField) - tw.getComponent(tw.MW_FILENAME_TEXTFIELD)).getText(); - if (filename == null || filename.equals("")) { - us.displaySaveAsDialog(select); - - // the above dialog will continue with the originally - // requested command if necessary - } else { - // save the policy entries to a file - tool.savePolicy(filename); - - // display status - MessageFormat form = new MessageFormat - (PolicyTool.rb.getString - ("Policy successfully written to filename")); - Object[] source = {filename}; - tw.displayStatusDialog(null, form.format(source)); - - // now continue with the originally requested command - // (QUIT, NEW, or OPEN) - us.userSaveContinue(tool, tw, us, select); - } - } catch (Exception ee) { - // error -- just report it and bail - tw.displayErrorDialog(null, ee); - } - } -} - -/** - * Event handler for UserSaveNoButton - */ -class UserSaveNoButtonListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - private ToolDialog us; - private int select; - - UserSaveNoButtonListener(ToolDialog us, PolicyTool tool, - ToolWindow tw, int select) { - this.us = us; - this.tool = tool; - this.tw = tw; - this.select = select; - } - - public void actionPerformed(ActionEvent e) { - us.setVisible(false); - us.dispose(); - - // now continue with the originally requested command - // (QUIT, NEW, or OPEN) - us.userSaveContinue(tool, tw, us, select); - } -} - -/** - * Event handler for UserSaveCancelButton - */ -class UserSaveCancelButtonListener implements ActionListener { - - private ToolDialog us; - - UserSaveCancelButtonListener(ToolDialog us) { - this.us = us; - } - - public void actionPerformed(ActionEvent e) { - us.setVisible(false); - us.dispose(); - - // do NOT continue with the originally requested command - // (QUIT, NEW, or OPEN) - } -} - -/** - * Event handler for ConfirmRemovePolicyEntryOKButtonListener - */ -class ConfirmRemovePolicyEntryOKButtonListener implements ActionListener { - - private PolicyTool tool; - private ToolWindow tw; - private ToolDialog us; - - ConfirmRemovePolicyEntryOKButtonListener(PolicyTool tool, - ToolWindow tw, ToolDialog us) { - this.tool = tool; - this.tw = tw; - this.us = us; - } - - public void actionPerformed(ActionEvent e) { - // remove the entry - List list = (List)tw.getComponent(tw.MW_POLICY_LIST); - int index = list.getSelectedIndex(); - PolicyEntry entries[] = tool.getEntry(); - tool.removeEntry(entries[index]); - - // redraw the window listing - list = new List(40, false); - list.addActionListener(new PolicyListListener(tool, tw)); - entries = tool.getEntry(); - if (entries != null) { - for (int i = 0; i < entries.length; i++) - list.add(entries[i].headerToString()); - } - tw.replacePolicyList(list); - us.setVisible(false); - us.dispose(); - } -} - -/** - * Just a special name, so that the codes dealing with this exception knows - * it's special, and does not pop out a warning box. - */ -class NoDisplayException extends RuntimeException { - -} - -/** - * This is a java.awt.List that bind an Object to each String it holds. - */ -class TaggedList extends List { - private java.util.List data = new LinkedList(); - public TaggedList(int i, boolean b) { - super(i, b); - } - - public Object getObject(int index) { - return data.get(index); - } - - @Override @Deprecated public void add(String string) { - throw new AssertionError("should not call add in TaggedList"); - } - public void addTaggedItem(String string, Object object) { - super.add(string); - data.add(object); - } - - @Override @Deprecated public void replaceItem(String string, int index) { - throw new AssertionError("should not call replaceItem in TaggedList"); - } - public void replaceTaggedItem(String string, Object object, int index) { - super.replaceItem(string, index); - data.set(index, object); - } - - @Override @Deprecated public void remove(int index) { - // Cannot throw AssertionError, because replaceItem() call remove() internally - super.remove(index); - } - public void removeTaggedItem(int index) { - super.remove(index); - data.remove(index); - } -} - -/** - * Convenience Principal Classes - */ - -class Prin { - public final String CLASS; - public final String FULL_CLASS; - - public Prin(String clazz, String fullClass) { - this.CLASS = clazz; - this.FULL_CLASS = fullClass; - } -} - -class KrbPrin extends Prin { - public KrbPrin() { - super("KerberosPrincipal", - "javax.security.auth.kerberos.KerberosPrincipal"); - } -} - -class X500Prin extends Prin { - public X500Prin() { - super("X500Principal", - "javax.security.auth.x500.X500Principal"); - } -} - -/** - * Convenience Permission Classes - */ - -class Perm { - public final String CLASS; - public final String FULL_CLASS; - public final String[] TARGETS; - public final String[] ACTIONS; - - public Perm(String clazz, String fullClass, - String[] targets, String[] actions) { - - this.CLASS = clazz; - this.FULL_CLASS = fullClass; - this.TARGETS = targets; - this.ACTIONS = actions; - } -} - -class AllPerm extends Perm { - public AllPerm() { - super("AllPermission", "java.security.AllPermission", null, null); - } -} - -class AudioPerm extends Perm { - public AudioPerm() { - super("AudioPermission", - "javax.sound.sampled.AudioPermission", - new String[] { - "play", - "record" - }, - null); - } -} - -class AuthPerm extends Perm { - public AuthPerm() { - super("AuthPermission", - "javax.security.auth.AuthPermission", - new String[] { - "doAs", - "doAsPrivileged", - "getSubject", - "getSubjectFromDomainCombiner", - "setReadOnly", - "modifyPrincipals", - "modifyPublicCredentials", - "modifyPrivateCredentials", - "refreshCredential", - "destroyCredential", - "createLoginContext.<" + PolicyTool.rb.getString("name") + ">", - "getLoginConfiguration", - "setLoginConfiguration", - "createLoginConfiguration.<" + - PolicyTool.rb.getString("configuration type") + ">", - "refreshLoginConfiguration" - }, - null); - } -} - -class AWTPerm extends Perm { - public AWTPerm() { - super("AWTPermission", - "java.awt.AWTPermission", - new String[] { - "accessClipboard", - "accessEventQueue", - "accessSystemTray", - "createRobot", - "fullScreenExclusive", - "listenToAllAWTEvents", - "readDisplayPixels", - "replaceKeyboardFocusManager", - "setAppletStub", - "setWindowAlwaysOnTop", - "showWindowWithoutWarningBanner", - "toolkitModality", - "watchMousePointer" - }, - null); - } -} - -class DelegationPerm extends Perm { - public DelegationPerm() { - super("DelegationPermission", - "javax.security.auth.kerberos.DelegationPermission", - new String[] { - // allow user input - }, - null); - } -} - -class FilePerm extends Perm { - public FilePerm() { - super("FilePermission", - "java.io.FilePermission", - new String[] { - "<>" - }, - new String[] { - "read", - "write", - "delete", - "execute" - }); - } -} - -class InqSecContextPerm extends Perm { - public InqSecContextPerm() { - super("InquireSecContextPermission", - "com.sun.security.jgss.InquireSecContextPermission", - new String[] { - "KRB5_GET_SESSION_KEY", - "KRB5_GET_TKT_FLAGS", - "KRB5_GET_AUTHZ_DATA", - "KRB5_GET_AUTHTIME" - }, - null); - } -} - -class LogPerm extends Perm { - public LogPerm() { - super("LoggingPermission", - "java.util.logging.LoggingPermission", - new String[] { - "control" - }, - null); - } -} - -class MgmtPerm extends Perm { - public MgmtPerm() { - super("ManagementPermission", - "java.lang.management.ManagementPermission", - new String[] { - "control", - "monitor" - }, - null); - } -} - -class MBeanPerm extends Perm { - public MBeanPerm() { - super("MBeanPermission", - "javax.management.MBeanPermission", - new String[] { - // allow user input - }, - new String[] { - "addNotificationListener", - "getAttribute", - "getClassLoader", - "getClassLoaderFor", - "getClassLoaderRepository", - "getDomains", - "getMBeanInfo", - "getObjectInstance", - "instantiate", - "invoke", - "isInstanceOf", - "queryMBeans", - "queryNames", - "registerMBean", - "removeNotificationListener", - "setAttribute", - "unregisterMBean" - }); - } -} - -class MBeanSvrPerm extends Perm { - public MBeanSvrPerm() { - super("MBeanServerPermission", - "javax.management.MBeanServerPermission", - new String[] { - "createMBeanServer", - "findMBeanServer", - "newMBeanServer", - "releaseMBeanServer" - }, - null); - } -} - -class MBeanTrustPerm extends Perm { - public MBeanTrustPerm() { - super("MBeanTrustPermission", - "javax.management.MBeanTrustPermission", - new String[] { - "register" - }, - null); - } -} - -class NetPerm extends Perm { - public NetPerm() { - super("NetPermission", - "java.net.NetPermission", - new String[] { - "setDefaultAuthenticator", - "requestPasswordAuthentication", - "specifyStreamHandler", - "setProxySelector", - "getProxySelector", - "setCookieHandler", - "getCookieHandler", - "setResponseCache", - "getResponseCache" - }, - null); - } -} - -class PrivCredPerm extends Perm { - public PrivCredPerm() { - super("PrivateCredentialPermission", - "javax.security.auth.PrivateCredentialPermission", - new String[] { - // allow user input - }, - new String[] { - "read" - }); - } -} - -class PropPerm extends Perm { - public PropPerm() { - super("PropertyPermission", - "java.util.PropertyPermission", - new String[] { - // allow user input - }, - new String[] { - "read", - "write" - }); - } -} - -class ReflectPerm extends Perm { - public ReflectPerm() { - super("ReflectPermission", - "java.lang.reflect.ReflectPermission", - new String[] { - "suppressAccessChecks" - }, - null); - } -} - -class RuntimePerm extends Perm { - public RuntimePerm() { - super("RuntimePermission", - "java.lang.RuntimePermission", - new String[] { - "createClassLoader", - "getClassLoader", - "setContextClassLoader", - "enableContextClassLoaderOverride", - "setSecurityManager", - "createSecurityManager", - "getenv.<" + - PolicyTool.rb.getString("environment variable name") + ">", - "exitVM", - "shutdownHooks", - "setFactory", - "setIO", - "modifyThread", - "stopThread", - "modifyThreadGroup", - "getProtectionDomain", - "readFileDescriptor", - "writeFileDescriptor", - "loadLibrary.<" + - PolicyTool.rb.getString("library name") + ">", - "accessClassInPackage.<" + - PolicyTool.rb.getString("package name")+">", - "defineClassInPackage.<" + - PolicyTool.rb.getString("package name")+">", - "accessDeclaredMembers", - "queuePrintJob", - "getStackTrace", - "setDefaultUncaughtExceptionHandler", - "preferences", - "usePolicy", - // "inheritedChannel" - }, - null); - } -} - -class SecurityPerm extends Perm { - public SecurityPerm() { - super("SecurityPermission", - "java.security.SecurityPermission", - new String[] { - "createAccessControlContext", - "getDomainCombiner", - "getPolicy", - "setPolicy", - "createPolicy.<" + - PolicyTool.rb.getString("policy type") + ">", - "getProperty.<" + - PolicyTool.rb.getString("property name") + ">", - "setProperty.<" + - PolicyTool.rb.getString("property name") + ">", - "insertProvider.<" + - PolicyTool.rb.getString("provider name") + ">", - "removeProvider.<" + - PolicyTool.rb.getString("provider name") + ">", - //"setSystemScope", - //"setIdentityPublicKey", - //"setIdentityInfo", - //"addIdentityCertificate", - //"removeIdentityCertificate", - //"printIdentity", - "clearProviderProperties.<" + - PolicyTool.rb.getString("provider name") + ">", - "putProviderProperty.<" + - PolicyTool.rb.getString("provider name") + ">", - "removeProviderProperty.<" + - PolicyTool.rb.getString("provider name") + ">", - //"getSignerPrivateKey", - //"setSignerKeyPair" - }, - null); - } -} - -class SerialPerm extends Perm { - public SerialPerm() { - super("SerializablePermission", - "java.io.SerializablePermission", - new String[] { - "enableSubclassImplementation", - "enableSubstitution" - }, - null); - } -} - -class ServicePerm extends Perm { - public ServicePerm() { - super("ServicePermission", - "javax.security.auth.kerberos.ServicePermission", - new String[] { - // allow user input - }, - new String[] { - "initiate", - "accept" - }); - } -} - -class SocketPerm extends Perm { - public SocketPerm() { - super("SocketPermission", - "java.net.SocketPermission", - new String[] { - // allow user input - }, - new String[] { - "accept", - "connect", - "listen", - "resolve" - }); - } -} - -class SQLPerm extends Perm { - public SQLPerm() { - super("SQLPermission", - "java.sql.SQLPermission", - new String[] { - "setLog" - }, - null); - } -} - -class SSLPerm extends Perm { - public SSLPerm() { - super("SSLPermission", - "javax.net.ssl.SSLPermission", - new String[] { - "setHostnameVerifier", - "getSSLSessionContext" - }, - null); - } -} - -class SubjDelegPerm extends Perm { - public SubjDelegPerm() { - super("SubjectDelegationPermission", - "javax.management.remote.SubjectDelegationPermission", - new String[] { - // allow user input - }, - null); - } -} diff --git a/src/share/classes/sun/security/tools/policytool/PolicyTool.java b/src/share/classes/sun/security/tools/policytool/PolicyTool.java new file mode 100644 index 000000000..bf9f485e3 --- /dev/null +++ b/src/share/classes/sun/security/tools/policytool/PolicyTool.java @@ -0,0 +1,4261 @@ +/* + * Copyright 1997-2010 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package sun.security.tools.policytool; + +import java.io.*; +import java.util.LinkedList; +import java.util.ListIterator; +import java.util.Vector; +import java.util.Enumeration; +import java.net.URL; +import java.net.MalformedURLException; +import java.lang.reflect.*; +import java.text.Collator; +import java.text.MessageFormat; +import sun.security.util.PropertyExpander; +import sun.security.util.PropertyExpander.ExpandException; +import java.awt.*; +import java.awt.event.*; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.*; +import sun.security.provider.*; +import sun.security.util.PolicyUtil; +import javax.security.auth.x500.X500Principal; + +/** + * PolicyTool may be used by users and administrators to configure the + * overall java security policy (currently stored in the policy file). + * Using PolicyTool administators may add and remove policies from + * the policy file.

      + * + * @see java.security.Policy + * @since 1.2 + */ + +public class PolicyTool { + + // for i18n + static final java.util.ResourceBundle rb = + java.util.ResourceBundle.getBundle("sun.security.util.Resources"); + static final Collator collator = Collator.getInstance(); + static { + // this is for case insensitive string comparisons + collator.setStrength(Collator.PRIMARY); + }; + + // anyone can add warnings + Vector warnings; + boolean newWarning = false; + + // set to true if policy modified. + // this way upon exit we know if to ask the user to save changes + boolean modified = false; + + private static final boolean testing = false; + private static final Class[] TWOPARAMS = { String.class, String.class }; + private static final Class[] ONEPARAMS = { String.class }; + private static final Class[] NOPARAMS = {}; + /* + * All of the policy entries are read in from the + * policy file and stored here. Updates to the policy entries + * using addEntry() and removeEntry() are made here. To ultimately save + * the policy entries back to the policy file, the SavePolicy button + * must be clicked. + **/ + private static String policyFileName = null; + private Vector policyEntries = null; + private PolicyParser parser = null; + + /* The public key alias information is stored here. */ + private KeyStore keyStore = null; + private String keyStoreName = " "; + private String keyStoreType = " "; + private String keyStoreProvider = " "; + private String keyStorePwdURL = " "; + + /* standard PKCS11 KeyStore type */ + private static final String P11KEYSTORE = "PKCS11"; + + /* reserved word for PKCS11 KeyStores */ + private static final String NONE = "NONE"; + + /** + * default constructor + */ + private PolicyTool() { + policyEntries = new Vector(); + parser = new PolicyParser(); + warnings = new Vector(); + } + + /** + * get the PolicyFileName + */ + String getPolicyFileName() { + return policyFileName; + } + + /** + * set the PolicyFileName + */ + void setPolicyFileName(String policyFileName) { + this.policyFileName = policyFileName; + } + + /** + * clear keyStore info + */ + void clearKeyStoreInfo() { + this.keyStoreName = null; + this.keyStoreType = null; + this.keyStoreProvider = null; + this.keyStorePwdURL = null; + + this.keyStore = null; + } + + /** + * get the keyStore URL name + */ + String getKeyStoreName() { + return keyStoreName; + } + + /** + * get the keyStore Type + */ + String getKeyStoreType() { + return keyStoreType; + } + + /** + * get the keyStore Provider + */ + String getKeyStoreProvider() { + return keyStoreProvider; + } + + /** + * get the keyStore password URL + */ + String getKeyStorePwdURL() { + return keyStorePwdURL; + } + + /** + * Open and read a policy file + */ + void openPolicy(String filename) throws FileNotFoundException, + PolicyParser.ParsingException, + KeyStoreException, + CertificateException, + InstantiationException, + MalformedURLException, + IOException, + NoSuchAlgorithmException, + IllegalAccessException, + NoSuchMethodException, + UnrecoverableKeyException, + NoSuchProviderException, + ClassNotFoundException, + PropertyExpander.ExpandException, + InvocationTargetException { + + newWarning = false; + + // start fresh - blow away the current state + policyEntries = new Vector(); + parser = new PolicyParser(); + warnings = new Vector(); + setPolicyFileName(null); + clearKeyStoreInfo(); + + // see if user is opening a NEW policy file + if (filename == null) { + modified = false; + return; + } + + // Read in the policy entries from the file and + // populate the parser vector table. The parser vector + // table only holds the entries as strings, so it only + // guarantees that the policies are syntactically + // correct. + setPolicyFileName(filename); + parser.read(new FileReader(filename)); + + // open the keystore + openKeyStore(parser.getKeyStoreUrl(), parser.getKeyStoreType(), + parser.getKeyStoreProvider(), parser.getStorePassURL()); + + // Update the local vector with the same policy entries. + // This guarantees that the policy entries are not only + // syntactically correct, but semantically valid as well. + Enumeration enum_ = parser.grantElements(); + while (enum_.hasMoreElements()) { + PolicyParser.GrantEntry ge = enum_.nextElement(); + + // see if all the signers have public keys + if (ge.signedBy != null) { + + String signers[] = parseSigners(ge.signedBy); + for (int i = 0; i < signers.length; i++) { + PublicKey pubKey = getPublicKeyAlias(signers[i]); + if (pubKey == null) { + newWarning = true; + MessageFormat form = new MessageFormat(rb.getString + ("Warning: A public key for alias " + + "'signers[i]' does not exist. " + + "Make sure a KeyStore is properly configured.")); + Object[] source = {signers[i]}; + warnings.addElement(form.format(source)); + } + } + } + + // check to see if the Principals are valid + ListIterator prinList = + ge.principals.listIterator(0); + while (prinList.hasNext()) { + PolicyParser.PrincipalEntry pe = prinList.next(); + try { + verifyPrincipal(pe.getPrincipalClass(), + pe.getPrincipalName()); + } catch (ClassNotFoundException fnfe) { + newWarning = true; + MessageFormat form = new MessageFormat(rb.getString + ("Warning: Class not found: class")); + Object[] source = {pe.getPrincipalClass()}; + warnings.addElement(form.format(source)); + } + } + + // check to see if the Permissions are valid + Enumeration perms = + ge.permissionElements(); + while (perms.hasMoreElements()) { + PolicyParser.PermissionEntry pe = perms.nextElement(); + try { + verifyPermission(pe.permission, pe.name, pe.action); + } catch (ClassNotFoundException fnfe) { + newWarning = true; + MessageFormat form = new MessageFormat(rb.getString + ("Warning: Class not found: class")); + Object[] source = {pe.permission}; + warnings.addElement(form.format(source)); + } catch (InvocationTargetException ite) { + newWarning = true; + MessageFormat form = new MessageFormat(rb.getString + ("Warning: Invalid argument(s) for constructor: arg")); + Object[] source = {pe.permission}; + warnings.addElement(form.format(source)); + } + + // see if all the permission signers have public keys + if (pe.signedBy != null) { + + String signers[] = parseSigners(pe.signedBy); + + for (int i = 0; i < signers.length; i++) { + PublicKey pubKey = getPublicKeyAlias(signers[i]); + if (pubKey == null) { + newWarning = true; + MessageFormat form = new MessageFormat(rb.getString + ("Warning: A public key for alias " + + "'signers[i]' does not exist. " + + "Make sure a KeyStore is properly configured.")); + Object[] source = {signers[i]}; + warnings.addElement(form.format(source)); + } + } + } + } + PolicyEntry pEntry = new PolicyEntry(this, ge); + policyEntries.addElement(pEntry); + } + + // just read in the policy -- nothing has been modified yet + modified = false; + } + + + /** + * Save a policy to a file + */ + void savePolicy(String filename) + throws FileNotFoundException, IOException { + // save the policy entries to a file + parser.setKeyStoreUrl(keyStoreName); + parser.setKeyStoreType(keyStoreType); + parser.setKeyStoreProvider(keyStoreProvider); + parser.setStorePassURL(keyStorePwdURL); + parser.write(new FileWriter(filename)); + modified = false; + } + + /** + * Open the KeyStore + */ + void openKeyStore(String name, + String type, + String provider, + String pwdURL) throws KeyStoreException, + NoSuchAlgorithmException, + UnrecoverableKeyException, + IOException, + CertificateException, + NoSuchProviderException, + ExpandException { + + if (name == null && type == null && + provider == null && pwdURL == null) { + + // policy did not specify a keystore during open + // or use wants to reset keystore values + + this.keyStoreName = null; + this.keyStoreType = null; + this.keyStoreProvider = null; + this.keyStorePwdURL = null; + + // caller will set (tool.modified = true) if appropriate + + return; + } + + URL policyURL = null; + if (policyFileName != null) { + File pfile = new File(policyFileName); + policyURL = new URL("file:" + pfile.getCanonicalPath()); + } + + // although PolicyUtil.getKeyStore may properly handle + // defaults and property expansion, we do it here so that + // if the call is successful, we can set the proper values + // (PolicyUtil.getKeyStore does not return expanded values) + + if (name != null && name.length() > 0) { + name = PropertyExpander.expand(name).replace + (File.separatorChar, '/'); + } + if (type == null || type.length() == 0) { + type = KeyStore.getDefaultType(); + } + if (pwdURL != null && pwdURL.length() > 0) { + pwdURL = PropertyExpander.expand(pwdURL).replace + (File.separatorChar, '/'); + } + + try { + this.keyStore = PolicyUtil.getKeyStore(policyURL, + name, + type, + provider, + pwdURL, + null); + } catch (IOException ioe) { + + // copied from sun.security.pkcs11.SunPKCS11 + String MSG = "no password provided, and no callback handler " + + "available for retrieving password"; + + Throwable cause = ioe.getCause(); + if (cause != null && + cause instanceof javax.security.auth.login.LoginException && + MSG.equals(cause.getMessage())) { + + // throw a more friendly exception message + throw new IOException(MSG); + } else { + throw ioe; + } + } + + this.keyStoreName = name; + this.keyStoreType = type; + this.keyStoreProvider = provider; + this.keyStorePwdURL = pwdURL; + + // caller will set (tool.modified = true) + } + + /** + * Add a Grant entry to the overall policy at the specified index. + * A policy entry consists of a CodeSource. + */ + boolean addEntry(PolicyEntry pe, int index) { + + if (index < 0) { + // new entry -- just add it to the end + policyEntries.addElement(pe); + parser.add(pe.getGrantEntry()); + } else { + // existing entry -- replace old one + PolicyEntry origPe = policyEntries.elementAt(index); + parser.replace(origPe.getGrantEntry(), pe.getGrantEntry()); + policyEntries.setElementAt(pe, index); + } + return true; + } + + /** + * Add a Principal entry to an existing PolicyEntry at the specified index. + * A Principal entry consists of a class, and name. + * + * If the principal already exists, it is not added again. + */ + boolean addPrinEntry(PolicyEntry pe, + PolicyParser.PrincipalEntry newPrin, + int index) { + + // first add the principal to the Policy Parser entry + PolicyParser.GrantEntry grantEntry = pe.getGrantEntry(); + if (grantEntry.contains(newPrin) == true) + return false; + + LinkedList prinList = + grantEntry.principals; + if (index != -1) + prinList.set(index, newPrin); + else + prinList.add(newPrin); + + modified = true; + return true; + } + + /** + * Add a Permission entry to an existing PolicyEntry at the specified index. + * A Permission entry consists of a permission, name, and actions. + * + * If the permission already exists, it is not added again. + */ + boolean addPermEntry(PolicyEntry pe, + PolicyParser.PermissionEntry newPerm, + int index) { + + // first add the permission to the Policy Parser Vector + PolicyParser.GrantEntry grantEntry = pe.getGrantEntry(); + if (grantEntry.contains(newPerm) == true) + return false; + + Vector permList = + grantEntry.permissionEntries; + if (index != -1) + permList.setElementAt(newPerm, index); + else + permList.addElement(newPerm); + + modified = true; + return true; + } + + /** + * Remove a Permission entry from an existing PolicyEntry. + */ + boolean removePermEntry(PolicyEntry pe, + PolicyParser.PermissionEntry perm) { + + // remove the Permission from the GrantEntry + PolicyParser.GrantEntry ppge = pe.getGrantEntry(); + modified = ppge.remove(perm); + return modified; + } + + /** + * remove an entry from the overall policy + */ + boolean removeEntry(PolicyEntry pe) { + + parser.remove(pe.getGrantEntry()); + modified = true; + return (policyEntries.removeElement(pe)); + } + + /** + * retrieve all Policy Entries + */ + PolicyEntry[] getEntry() { + + if (policyEntries.size() > 0) { + PolicyEntry entries[] = new PolicyEntry[policyEntries.size()]; + for (int i = 0; i < policyEntries.size(); i++) + entries[i] = policyEntries.elementAt(i); + return entries; + } + return null; + } + + /** + * Retrieve the public key mapped to a particular name. + * If the key has expired, a KeyException is thrown. + */ + PublicKey getPublicKeyAlias(String name) throws KeyStoreException { + if (keyStore == null) { + return null; + } + + Certificate cert = keyStore.getCertificate(name); + if (cert == null) { + return null; + } + PublicKey pubKey = cert.getPublicKey(); + return pubKey; + } + + /** + * Retrieve all the alias names stored in the certificate database + */ + String[] getPublicKeyAlias() throws KeyStoreException { + + int numAliases = 0; + String aliases[] = null; + + if (keyStore == null) { + return null; + } + Enumeration enum_ = keyStore.aliases(); + + // first count the number of elements + while (enum_.hasMoreElements()) { + enum_.nextElement(); + numAliases++; + } + + if (numAliases > 0) { + // now copy them into an array + aliases = new String[numAliases]; + numAliases = 0; + enum_ = keyStore.aliases(); + while (enum_.hasMoreElements()) { + aliases[numAliases] = new String(enum_.nextElement()); + numAliases++; + } + } + return aliases; + } + + /** + * This method parses a single string of signers separated by commas + * ("jordan, duke, pippen") into an array of individual strings. + */ + String[] parseSigners(String signedBy) { + + String signers[] = null; + int numSigners = 1; + int signedByIndex = 0; + int commaIndex = 0; + int signerNum = 0; + + // first pass thru "signedBy" counts the number of signers + while (commaIndex >= 0) { + commaIndex = signedBy.indexOf(',', signedByIndex); + if (commaIndex >= 0) { + numSigners++; + signedByIndex = commaIndex + 1; + } + } + signers = new String[numSigners]; + + // second pass thru "signedBy" transfers signers to array + commaIndex = 0; + signedByIndex = 0; + while (commaIndex >= 0) { + if ((commaIndex = signedBy.indexOf(',', signedByIndex)) >= 0) { + // transfer signer and ignore trailing part of the string + signers[signerNum] = + signedBy.substring(signedByIndex, commaIndex).trim(); + signerNum++; + signedByIndex = commaIndex + 1; + } else { + // we are at the end of the string -- transfer signer + signers[signerNum] = signedBy.substring(signedByIndex).trim(); + } + } + return signers; + } + + /** + * Check to see if the Principal contents are OK + */ + void verifyPrincipal(String type, String name) + throws ClassNotFoundException, + InstantiationException + { + if (type.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS) || + type.equals(PolicyParser.REPLACE_NAME)) { + return; + }; + Class PRIN = Class.forName("java.security.Principal"); + Class pc = Class.forName(type, true, + Thread.currentThread().getContextClassLoader()); + if (!PRIN.isAssignableFrom(pc)) { + MessageFormat form = new MessageFormat(rb.getString + ("Illegal Principal Type: type")); + Object[] source = {type}; + throw new InstantiationException(form.format(source)); + } + + if (ToolDialog.X500_PRIN_CLASS.equals(pc.getName())) { + // PolicyParser checks validity of X500Principal name + // - PolicyTool needs to as well so that it doesn't store + // an invalid name that can't be read in later + // + // this can throw an IllegalArgumentException + X500Principal newP = new X500Principal(name); + } + } + + /** + * Check to see if the Permission contents are OK + */ + void verifyPermission(String type, + String name, + String actions) + throws ClassNotFoundException, + InstantiationException, + IllegalAccessException, + NoSuchMethodException, + InvocationTargetException + { + + //XXX we might want to keep a hash of created factories... + Class pc = Class.forName(type, true, + Thread.currentThread().getContextClassLoader()); + Constructor c = null; + Vector objects = new Vector(2); + if (name != null) objects.add(name); + if (actions != null) objects.add(actions); + switch (objects.size()) { + case 0: + try { + c = pc.getConstructor(NOPARAMS); + break; + } catch (NoSuchMethodException ex) { + // proceed to the one-param constructor + objects.add(null); + } + case 1: + try { + c = pc.getConstructor(ONEPARAMS); + break; + } catch (NoSuchMethodException ex) { + // proceed to the two-param constructor + objects.add(null); + } + case 2: + c = pc.getConstructor(TWOPARAMS); + break; + } + Object parameters[] = objects.toArray(); + Permission p = (Permission)c.newInstance(parameters); + } + + /* + * Parse command line arguments. + */ + static void parseArgs(String args[]) { + /* parse flags */ + int n = 0; + + for (n=0; (n < args.length) && args[n].startsWith("-"); n++) { + + String flags = args[n]; + + if (collator.compare(flags, "-file") == 0) { + if (++n == args.length) usage(); + policyFileName = args[n]; + } else { + MessageFormat form = new MessageFormat(rb.getString + ("Illegal option: option")); + Object[] source = { flags }; + System.err.println(form.format(source)); + usage(); + } + } + } + + static void usage() { + System.out.println(rb.getString("Usage: policytool [options]")); + System.out.println(); + System.out.println(rb.getString + (" [-file ] policy file location")); + System.out.println(); + + System.exit(1); + } + + /** + * run the PolicyTool + */ + public static void main(String args[]) { + parseArgs(args); + ToolWindow tw = new ToolWindow(new PolicyTool()); + tw.displayToolWindow(args); + } + + // split instr to words according to capitalization, + // like, AWTControl -> A W T Control + // this method is for easy pronounciation + static String splitToWords(String instr) { + return instr.replaceAll("([A-Z])", " $1"); + } + +} + +/** + * Each entry in the policy configuration file is represented by a + * PolicyEntry object. + * + * A PolicyEntry is a (CodeSource,Permission) pair. The + * CodeSource contains the (URL, PublicKey) that together identify + * where the Java bytecodes come from and who (if anyone) signed + * them. The URL could refer to localhost. The URL could also be + * null, meaning that this policy entry is given to all comers, as + * long as they match the signer field. The signer could be null, + * meaning the code is not signed. + * + * The Permission contains the (Type, Name, Action) triplet. + * + */ +class PolicyEntry { + + private CodeSource codesource; + private PolicyTool tool; + private PolicyParser.GrantEntry grantEntry; + private boolean testing = false; + + /** + * Create a PolicyEntry object from the information read in + * from a policy file. + */ + PolicyEntry(PolicyTool tool, PolicyParser.GrantEntry ge) + throws MalformedURLException, NoSuchMethodException, + ClassNotFoundException, InstantiationException, IllegalAccessException, + InvocationTargetException, CertificateException, + IOException, NoSuchAlgorithmException, UnrecoverableKeyException { + + this.tool = tool; + + URL location = null; + + // construct the CodeSource + if (ge.codeBase != null) + location = new URL(ge.codeBase); + this.codesource = new CodeSource(location, + (java.security.cert.Certificate[]) null); + + if (testing) { + System.out.println("Adding Policy Entry:"); + System.out.println(" CodeBase = " + location); + System.out.println(" Signers = " + ge.signedBy); + System.out.println(" with " + ge.principals.size() + + " Principals"); + } + + this.grantEntry = ge; + } + + /** + * get the codesource associated with this PolicyEntry + */ + CodeSource getCodeSource() { + return codesource; + } + + /** + * get the GrantEntry associated with this PolicyEntry + */ + PolicyParser.GrantEntry getGrantEntry() { + return grantEntry; + } + + /** + * convert the header portion, i.e. codebase, signer, principals, of + * this policy entry into a string + */ + String headerToString() { + String pString = principalsToString(); + if (pString.length() == 0) { + return codebaseToString(); + } else { + return codebaseToString() + ", " + pString; + } + } + + /** + * convert the Codebase/signer portion of this policy entry into a string + */ + String codebaseToString() { + + String stringEntry = new String(); + + if (grantEntry.codeBase != null && + grantEntry.codeBase.equals("") == false) + stringEntry = stringEntry.concat + ("CodeBase \"" + + grantEntry.codeBase + + "\""); + + if (grantEntry.signedBy != null && + grantEntry.signedBy.equals("") == false) + stringEntry = ((stringEntry.length() > 0) ? + stringEntry.concat(", SignedBy \"" + + grantEntry.signedBy + + "\"") : + stringEntry.concat("SignedBy \"" + + grantEntry.signedBy + + "\"")); + + if (stringEntry.length() == 0) + return new String("CodeBase "); + return stringEntry; + } + + /** + * convert the Principals portion of this policy entry into a string + */ + String principalsToString() { + String result = ""; + if ((grantEntry.principals != null) && + (!grantEntry.principals.isEmpty())) { + StringBuffer buffer = new StringBuffer(200); + ListIterator list = + grantEntry.principals.listIterator(); + while (list.hasNext()) { + PolicyParser.PrincipalEntry pppe = list.next(); + buffer.append(" Principal " + pppe.getDisplayClass() + " " + + pppe.getDisplayName(true)); + if (list.hasNext()) buffer.append(", "); + } + result = buffer.toString(); + } + return result; + } + + /** + * convert this policy entry into a PolicyParser.PermissionEntry + */ + PolicyParser.PermissionEntry toPermissionEntry(Permission perm) { + + String actions = null; + + // get the actions + if (perm.getActions() != null && + perm.getActions().trim() != "") + actions = perm.getActions(); + + PolicyParser.PermissionEntry pe = new PolicyParser.PermissionEntry + (perm.getClass().getName(), + perm.getName(), + actions); + return pe; + } +} + +/** + * The main window for the PolicyTool + */ +class ToolWindow extends Frame { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 5682568601210376777L; + + /* external paddings */ + public static final Insets TOP_PADDING = new Insets(25,0,0,0); + public static final Insets BOTTOM_PADDING = new Insets(0,0,25,0); + public static final Insets LITE_BOTTOM_PADDING = new Insets(0,0,10,0); + public static final Insets LR_PADDING = new Insets(0,10,0,10); + public static final Insets TOP_BOTTOM_PADDING = new Insets(15, 0, 15, 0); + public static final Insets L_TOP_BOTTOM_PADDING = new Insets(5,10,15,0); + public static final Insets LR_BOTTOM_PADDING = new Insets(0,10,5,10); + public static final Insets L_BOTTOM_PADDING = new Insets(0,10,5,0); + public static final Insets R_BOTTOM_PADDING = new Insets(0,0,5,10); + + /* buttons and menus */ + public static final String NEW_POLICY_FILE = + PolicyTool.rb.getString("New"); + public static final String OPEN_POLICY_FILE = + PolicyTool.rb.getString("Open"); + public static final String SAVE_POLICY_FILE = + PolicyTool.rb.getString("Save"); + public static final String SAVE_AS_POLICY_FILE = + PolicyTool.rb.getString("Save As"); + public static final String VIEW_WARNINGS = + PolicyTool.rb.getString("View Warning Log"); + public static final String QUIT = + PolicyTool.rb.getString("Exit"); + public static final String ADD_POLICY_ENTRY = + PolicyTool.rb.getString("Add Policy Entry"); + public static final String EDIT_POLICY_ENTRY = + PolicyTool.rb.getString("Edit Policy Entry"); + public static final String REMOVE_POLICY_ENTRY = + PolicyTool.rb.getString("Remove Policy Entry"); + public static final String EDIT_KEYSTORE = + PolicyTool.rb.getString("Edit"); + public static final String ADD_PUBKEY_ALIAS = + PolicyTool.rb.getString("Add Public Key Alias"); + public static final String REMOVE_PUBKEY_ALIAS = + PolicyTool.rb.getString("Remove Public Key Alias"); + + /* gridbag index for components in the main window (MW) */ + public static final int MW_FILENAME_LABEL = 0; + public static final int MW_FILENAME_TEXTFIELD = 1; + public static final int MW_PANEL = 2; + public static final int MW_ADD_BUTTON = 0; + public static final int MW_EDIT_BUTTON = 1; + public static final int MW_REMOVE_BUTTON = 2; + public static final int MW_POLICY_LIST = 3; // follows MW_PANEL + + private PolicyTool tool; + + /** + * Constructor + */ + ToolWindow(PolicyTool tool) { + this.tool = tool; + } + + /** + * Initialize the PolicyTool window with the necessary components + */ + private void initWindow() { + + // create the top menu bar + MenuBar menuBar = new MenuBar(); + + // create a File menu + Menu menu = new Menu(PolicyTool.rb.getString("File")); + menu.add(NEW_POLICY_FILE); + menu.add(OPEN_POLICY_FILE); + menu.add(SAVE_POLICY_FILE); + menu.add(SAVE_AS_POLICY_FILE); + menu.add(VIEW_WARNINGS); + menu.add(QUIT); + menu.addActionListener(new FileMenuListener(tool, this)); + menuBar.add(menu); + setMenuBar(menuBar); + + // create a KeyStore menu + menu = new Menu(PolicyTool.rb.getString("KeyStore")); + menu.add(EDIT_KEYSTORE); + menu.addActionListener(new MainWindowListener(tool, this)); + menuBar.add(menu); + setMenuBar(menuBar); + + + // policy entry listing + Label label = new Label(PolicyTool.rb.getString("Policy File:")); + addNewComponent(this, label, MW_FILENAME_LABEL, + 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + TOP_BOTTOM_PADDING); + TextField tf = new TextField(50); + tf.getAccessibleContext().setAccessibleName( + PolicyTool.rb.getString("Policy File:")); + tf.setEditable(false); + addNewComponent(this, tf, MW_FILENAME_TEXTFIELD, + 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + TOP_BOTTOM_PADDING); + + + // add ADD/REMOVE/EDIT buttons in a new panel + Panel panel = new Panel(); + panel.setLayout(new GridBagLayout()); + + Button button = new Button(ADD_POLICY_ENTRY); + button.addActionListener(new MainWindowListener(tool, this)); + addNewComponent(panel, button, MW_ADD_BUTTON, + 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + LR_PADDING); + + button = new Button(EDIT_POLICY_ENTRY); + button.addActionListener(new MainWindowListener(tool, this)); + addNewComponent(panel, button, MW_EDIT_BUTTON, + 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + LR_PADDING); + + button = new Button(REMOVE_POLICY_ENTRY); + button.addActionListener(new MainWindowListener(tool, this)); + addNewComponent(panel, button, MW_REMOVE_BUTTON, + 2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + LR_PADDING); + + addNewComponent(this, panel, MW_PANEL, + 0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH, + BOTTOM_PADDING); + + + String policyFile = tool.getPolicyFileName(); + if (policyFile == null) { + String userHome; + userHome = java.security.AccessController.doPrivileged( + new sun.security.action.GetPropertyAction("user.home")); + policyFile = userHome + File.separatorChar + ".java.policy"; + } + + try { + // open the policy file + tool.openPolicy(policyFile); + + // display the policy entries via the policy list textarea + List list = new List(40, false); + list.addActionListener(new PolicyListListener(tool, this)); + PolicyEntry entries[] = tool.getEntry(); + if (entries != null) { + for (int i = 0; i < entries.length; i++) + list.add(entries[i].headerToString()); + } + TextField newFilename = (TextField) + getComponent(MW_FILENAME_TEXTFIELD); + newFilename.setText(policyFile); + initPolicyList(list); + + } catch (FileNotFoundException fnfe) { + // add blank policy listing + List list = new List(40, false); + list.addActionListener(new PolicyListListener(tool, this)); + initPolicyList(list); + tool.setPolicyFileName(null); + tool.modified = false; + setVisible(true); + + // just add warning + tool.warnings.addElement(fnfe.toString()); + + } catch (Exception e) { + // add blank policy listing + List list = new List(40, false); + list.addActionListener(new PolicyListListener(tool, this)); + initPolicyList(list); + tool.setPolicyFileName(null); + tool.modified = false; + setVisible(true); + + // display the error + MessageFormat form = new MessageFormat(PolicyTool.rb.getString + ("Could not open policy file: policyFile: e.toString()")); + Object[] source = {policyFile, e.toString()}; + displayErrorDialog(null, form.format(source)); + } + } + + + /** + * Add a component to the PolicyTool window + */ + void addNewComponent(Container container, Component component, + int index, int gridx, int gridy, int gridwidth, int gridheight, + double weightx, double weighty, int fill, Insets is) { + + // add the component at the specified gridbag index + container.add(component, index); + + // set the constraints + GridBagLayout gbl = (GridBagLayout)container.getLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridx = gridx; + gbc.gridy = gridy; + gbc.gridwidth = gridwidth; + gbc.gridheight = gridheight; + gbc.weightx = weightx; + gbc.weighty = weighty; + gbc.fill = fill; + if (is != null) gbc.insets = is; + gbl.setConstraints(component, gbc); + } + + + /** + * Add a component to the PolicyTool window without external padding + */ + void addNewComponent(Container container, Component component, + int index, int gridx, int gridy, int gridwidth, int gridheight, + double weightx, double weighty, int fill) { + + // delegate with "null" external padding + addNewComponent(container, component, index, gridx, gridy, + gridwidth, gridheight, weightx, weighty, + fill, null); + } + + + /** + * Init the policy_entry_list TEXTAREA component in the + * PolicyTool window + */ + void initPolicyList(List policyList) { + + // add the policy list to the window + addNewComponent(this, policyList, MW_POLICY_LIST, + 0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.BOTH); + } + + /** + * Replace the policy_entry_list TEXTAREA component in the + * PolicyTool window with an updated one. + */ + void replacePolicyList(List policyList) { + + // remove the original list of Policy Entries + // and add the new list of entries + List list = (List)getComponent(MW_POLICY_LIST); + list.removeAll(); + String newItems[] = policyList.getItems(); + for (int i = 0; i < newItems.length; i++) + list.add(newItems[i]); + } + + /** + * display the main PolicyTool window + */ + void displayToolWindow(String args[]) { + + setTitle(PolicyTool.rb.getString("Policy Tool")); + setResizable(true); + addWindowListener(new ToolWindowListener(this)); + setBounds(135, 80, 500, 500); + setLayout(new GridBagLayout()); + + initWindow(); + + // display it + setVisible(true); + + if (tool.newWarning == true) { + displayStatusDialog(this, PolicyTool.rb.getString + ("Errors have occurred while opening the " + + "policy configuration. View the Warning Log " + + "for more information.")); + } + } + + /** + * displays a dialog box describing an error which occurred. + */ + void displayErrorDialog(Window w, String error) { + ToolDialog ed = new ToolDialog + (PolicyTool.rb.getString("Error"), tool, this, true); + + // find where the PolicyTool gui is + Point location = ((w == null) ? + getLocationOnScreen() : w.getLocationOnScreen()); + ed.setBounds(location.x + 50, location.y + 50, 600, 100); + ed.setLayout(new GridBagLayout()); + + Label label = new Label(error); + addNewComponent(ed, label, 0, + 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); + + Button okButton = new Button(PolicyTool.rb.getString("OK")); + okButton.addActionListener(new ErrorOKButtonListener(ed)); + addNewComponent(ed, okButton, 1, + 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); + + ed.pack(); + ed.setVisible(true); + } + + /** + * displays a dialog box describing an error which occurred. + */ + void displayErrorDialog(Window w, Throwable t) { + if (t instanceof NoDisplayException) { + return; + } + displayErrorDialog(w, t.toString()); + } + + /** + * displays a dialog box describing the status of an event + */ + void displayStatusDialog(Window w, String status) { + ToolDialog sd = new ToolDialog + (PolicyTool.rb.getString("Status"), tool, this, true); + + // find the location of the PolicyTool gui + Point location = ((w == null) ? + getLocationOnScreen() : w.getLocationOnScreen()); + sd.setBounds(location.x + 50, location.y + 50, 500, 100); + sd.setLayout(new GridBagLayout()); + + Label label = new Label(status); + addNewComponent(sd, label, 0, + 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); + + Button okButton = new Button(PolicyTool.rb.getString("OK")); + okButton.addActionListener(new StatusOKButtonListener(sd)); + addNewComponent(sd, okButton, 1, + 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); + sd.pack(); + sd.setVisible(true); + } + + /** + * display the warning log + */ + void displayWarningLog(Window w) { + + ToolDialog wd = new ToolDialog + (PolicyTool.rb.getString("Warning"), tool, this, true); + + // find the location of the PolicyTool gui + Point location = ((w == null) ? + getLocationOnScreen() : w.getLocationOnScreen()); + wd.setBounds(location.x + 50, location.y + 50, 500, 100); + wd.setLayout(new GridBagLayout()); + + TextArea ta = new TextArea(); + ta.setEditable(false); + for (int i = 0; i < tool.warnings.size(); i++) { + ta.append(tool.warnings.elementAt(i)); + ta.append(PolicyTool.rb.getString("\n")); + } + addNewComponent(wd, ta, 0, + 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + BOTTOM_PADDING); + ta.setFocusable(false); + + Button okButton = new Button(PolicyTool.rb.getString("OK")); + okButton.addActionListener(new CancelButtonListener(wd)); + addNewComponent(wd, okButton, 1, + 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, + LR_PADDING); + + wd.pack(); + wd.setVisible(true); + } + + char displayYesNoDialog(Window w, String title, String prompt, String yes, String no) { + + final ToolDialog tw = new ToolDialog + (title, tool, this, true); + Point location = ((w == null) ? + getLocationOnScreen() : w.getLocationOnScreen()); + tw.setBounds(location.x + 75, location.y + 100, 400, 150); + tw.setLayout(new GridBagLayout()); + + TextArea ta = new TextArea(prompt, 10, 50, TextArea.SCROLLBARS_VERTICAL_ONLY); + ta.setEditable(false); + addNewComponent(tw, ta, 0, + 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); + ta.setFocusable(false); + + Panel panel = new Panel(); + panel.setLayout(new GridBagLayout()); + + // StringBuffer to store button press. Must be final. + final StringBuffer chooseResult = new StringBuffer(); + + Button button = new Button(yes); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + chooseResult.append('Y'); + tw.setVisible(false); + tw.dispose(); + } + }); + addNewComponent(panel, button, 0, + 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, + LR_PADDING); + + button = new Button(no); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + chooseResult.append('N'); + tw.setVisible(false); + tw.dispose(); + } + }); + addNewComponent(panel, button, 1, + 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, + LR_PADDING); + + addNewComponent(tw, panel, 1, + 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); + + tw.pack(); + tw.setVisible(true); + if (chooseResult.length() > 0) { + return chooseResult.charAt(0); + } else { + // I did encounter this once, don't why. + return 'N'; + } + } + +} + +/** + * General dialog window + */ +class ToolDialog extends Dialog { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = -372244357011301190L; + + /* necessary constants */ + public static final int NOACTION = 0; + public static final int QUIT = 1; + public static final int NEW = 2; + public static final int OPEN = 3; + + public static final String ALL_PERM_CLASS = + "java.security.AllPermission"; + public static final String FILE_PERM_CLASS = + "java.io.FilePermission"; + + public static final String X500_PRIN_CLASS = + "javax.security.auth.x500.X500Principal"; + + /* popup menus */ + public static final String PERM = + PolicyTool.rb.getString + ("Permission: "); + + public static final String PRIN_TYPE = + PolicyTool.rb.getString("Principal Type:"); + public static final String PRIN_NAME = + PolicyTool.rb.getString("Principal Name:"); + + /* more popu menus */ + public static final String PERM_NAME = + PolicyTool.rb.getString + ("Target Name: "); + + /* and more popup menus */ + public static final String PERM_ACTIONS = + PolicyTool.rb.getString + ("Actions: "); + + /* gridbag index for display OverWriteFile (OW) components */ + public static final int OW_LABEL = 0; + public static final int OW_OK_BUTTON = 1; + public static final int OW_CANCEL_BUTTON = 2; + + /* gridbag index for display PolicyEntry (PE) components */ + public static final int PE_CODEBASE_LABEL = 0; + public static final int PE_CODEBASE_TEXTFIELD = 1; + public static final int PE_SIGNEDBY_LABEL = 2; + public static final int PE_SIGNEDBY_TEXTFIELD = 3; + + public static final int PE_PANEL0 = 4; + public static final int PE_ADD_PRIN_BUTTON = 0; + public static final int PE_EDIT_PRIN_BUTTON = 1; + public static final int PE_REMOVE_PRIN_BUTTON = 2; + + public static final int PE_PRIN_LABEL = 5; + public static final int PE_PRIN_LIST = 6; + + public static final int PE_PANEL1 = 7; + public static final int PE_ADD_PERM_BUTTON = 0; + public static final int PE_EDIT_PERM_BUTTON = 1; + public static final int PE_REMOVE_PERM_BUTTON = 2; + + public static final int PE_PERM_LIST = 8; + + public static final int PE_PANEL2 = 9; + public static final int PE_CANCEL_BUTTON = 1; + public static final int PE_DONE_BUTTON = 0; + + /* the gridbag index for components in the Principal Dialog (PRD) */ + public static final int PRD_DESC_LABEL = 0; + public static final int PRD_PRIN_CHOICE = 1; + public static final int PRD_PRIN_TEXTFIELD = 2; + public static final int PRD_NAME_LABEL = 3; + public static final int PRD_NAME_TEXTFIELD = 4; + public static final int PRD_CANCEL_BUTTON = 6; + public static final int PRD_OK_BUTTON = 5; + + /* the gridbag index for components in the Permission Dialog (PD) */ + public static final int PD_DESC_LABEL = 0; + public static final int PD_PERM_CHOICE = 1; + public static final int PD_PERM_TEXTFIELD = 2; + public static final int PD_NAME_CHOICE = 3; + public static final int PD_NAME_TEXTFIELD = 4; + public static final int PD_ACTIONS_CHOICE = 5; + public static final int PD_ACTIONS_TEXTFIELD = 6; + public static final int PD_SIGNEDBY_LABEL = 7; + public static final int PD_SIGNEDBY_TEXTFIELD = 8; + public static final int PD_CANCEL_BUTTON = 10; + public static final int PD_OK_BUTTON = 9; + + /* modes for KeyStore */ + public static final int EDIT_KEYSTORE = 0; + + /* the gridbag index for components in the Change KeyStore Dialog (KSD) */ + public static final int KSD_NAME_LABEL = 0; + public static final int KSD_NAME_TEXTFIELD = 1; + public static final int KSD_TYPE_LABEL = 2; + public static final int KSD_TYPE_TEXTFIELD = 3; + public static final int KSD_PROVIDER_LABEL = 4; + public static final int KSD_PROVIDER_TEXTFIELD = 5; + public static final int KSD_PWD_URL_LABEL = 6; + public static final int KSD_PWD_URL_TEXTFIELD = 7; + public static final int KSD_CANCEL_BUTTON = 9; + public static final int KSD_OK_BUTTON = 8; + + /* the gridbag index for components in the User Save Changes Dialog (USC) */ + public static final int USC_LABEL = 0; + public static final int USC_PANEL = 1; + public static final int USC_YES_BUTTON = 0; + public static final int USC_NO_BUTTON = 1; + public static final int USC_CANCEL_BUTTON = 2; + + /* gridbag index for the ConfirmRemovePolicyEntryDialog (CRPE) */ + public static final int CRPE_LABEL1 = 0; + public static final int CRPE_LABEL2 = 1; + public static final int CRPE_PANEL = 2; + public static final int CRPE_PANEL_OK = 0; + public static final int CRPE_PANEL_CANCEL = 1; + + /* some private static finals */ + private static final int PERMISSION = 0; + private static final int PERMISSION_NAME = 1; + private static final int PERMISSION_ACTIONS = 2; + private static final int PERMISSION_SIGNEDBY = 3; + private static final int PRINCIPAL_TYPE = 4; + private static final int PRINCIPAL_NAME = 5; + + public static java.util.ArrayList PERM_ARRAY; + public static java.util.ArrayList PRIN_ARRAY; + PolicyTool tool; + ToolWindow tw; + + static { + + // set up permission objects + + PERM_ARRAY = new java.util.ArrayList(); + PERM_ARRAY.add(new AllPerm()); + PERM_ARRAY.add(new AudioPerm()); + PERM_ARRAY.add(new AuthPerm()); + PERM_ARRAY.add(new AWTPerm()); + PERM_ARRAY.add(new DelegationPerm()); + PERM_ARRAY.add(new FilePerm()); + PERM_ARRAY.add(new InqSecContextPerm()); + PERM_ARRAY.add(new LogPerm()); + PERM_ARRAY.add(new MgmtPerm()); + PERM_ARRAY.add(new MBeanPerm()); + PERM_ARRAY.add(new MBeanSvrPerm()); + PERM_ARRAY.add(new MBeanTrustPerm()); + PERM_ARRAY.add(new NetPerm()); + PERM_ARRAY.add(new PrivCredPerm()); + PERM_ARRAY.add(new PropPerm()); + PERM_ARRAY.add(new ReflectPerm()); + PERM_ARRAY.add(new RuntimePerm()); + PERM_ARRAY.add(new SecurityPerm()); + PERM_ARRAY.add(new SerialPerm()); + PERM_ARRAY.add(new ServicePerm()); + PERM_ARRAY.add(new SocketPerm()); + PERM_ARRAY.add(new SQLPerm()); + PERM_ARRAY.add(new SSLPerm()); + PERM_ARRAY.add(new SubjDelegPerm()); + + // set up principal objects + + PRIN_ARRAY = new java.util.ArrayList(); + PRIN_ARRAY.add(new KrbPrin()); + PRIN_ARRAY.add(new X500Prin()); + } + + ToolDialog(String title, PolicyTool tool, ToolWindow tw, boolean modal) { + super(tw, modal); + setTitle(title); + this.tool = tool; + this.tw = tw; + addWindowListener(new ChildWindowListener(this)); + } + + /** + * get the Perm instance based on either the (shortened) class name + * or the fully qualified class name + */ + static Perm getPerm(String clazz, boolean fullClassName) { + for (int i = 0; i < PERM_ARRAY.size(); i++) { + Perm next = PERM_ARRAY.get(i); + if (fullClassName) { + if (next.FULL_CLASS.equals(clazz)) { + return next; + } + } else { + if (next.CLASS.equals(clazz)) { + return next; + } + } + } + return null; + } + + /** + * get the Prin instance based on either the (shortened) class name + * or the fully qualified class name + */ + static Prin getPrin(String clazz, boolean fullClassName) { + for (int i = 0; i < PRIN_ARRAY.size(); i++) { + Prin next = PRIN_ARRAY.get(i); + if (fullClassName) { + if (next.FULL_CLASS.equals(clazz)) { + return next; + } + } else { + if (next.CLASS.equals(clazz)) { + return next; + } + } + } + return null; + } + + /** + * ask user if they want to overwrite an existing file + */ + void displayOverWriteFileDialog(String filename, int nextEvent) { + + // find where the PolicyTool gui is + Point location = tw.getLocationOnScreen(); + setBounds(location.x + 75, location.y + 100, 400, 150); + setLayout(new GridBagLayout()); + + // ask the user if they want to over write the existing file + MessageFormat form = new MessageFormat(PolicyTool.rb.getString + ("OK to overwrite existing file filename?")); + Object[] source = {filename}; + Label label = new Label(form.format(source)); + tw.addNewComponent(this, label, OW_LABEL, + 0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.TOP_PADDING); + + // OK button + Button button = new Button(PolicyTool.rb.getString("OK")); + button.addActionListener(new OverWriteFileOKButtonListener + (tool, tw, this, filename, nextEvent)); + tw.addNewComponent(this, button, OW_OK_BUTTON, + 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, + tw.TOP_PADDING); + + // Cancel button + // -- if the user hits cancel, do NOT go on to the next event + button = new Button(PolicyTool.rb.getString("Cancel")); + button.addActionListener(new CancelButtonListener(this)); + tw.addNewComponent(this, button, OW_CANCEL_BUTTON, + 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, + tw.TOP_PADDING); + + setVisible(true); + } + + /** + * pop up a dialog so the user can enter info to add a new PolicyEntry + * - if edit is TRUE, then the user is editing an existing entry + * and we should display the original info as well. + * + * - the other reason we need the 'edit' boolean is we need to know + * when we are adding a NEW policy entry. in this case, we can + * not simply update the existing entry, because it doesn't exist. + * we ONLY update the GUI listing/info, and then when the user + * finally clicks 'OK' or 'DONE', then we can collect that info + * and add it to the policy. + */ + void displayPolicyEntryDialog(boolean edit) { + + int listIndex = 0; + PolicyEntry entries[] = null; + TaggedList prinList = new TaggedList(3, false); + prinList.getAccessibleContext().setAccessibleName( + PolicyTool.rb.getString("Principal List")); + prinList.addActionListener + (new EditPrinButtonListener(tool, tw, this, edit)); + TaggedList permList = new TaggedList(10, false); + permList.getAccessibleContext().setAccessibleName( + PolicyTool.rb.getString("Permission List")); + permList.addActionListener + (new EditPermButtonListener(tool, tw, this, edit)); + + // find where the PolicyTool gui is + Point location = tw.getLocationOnScreen(); + setBounds(location.x + 75, location.y + 200, 650, 500); + setLayout(new GridBagLayout()); + setResizable(true); + + if (edit) { + // get the selected item + entries = tool.getEntry(); + List policyList = (List)tw.getComponent(tw.MW_POLICY_LIST); + listIndex = policyList.getSelectedIndex(); + + // get principal list + LinkedList principals = + entries[listIndex].getGrantEntry().principals; + for (int i = 0; i < principals.size(); i++) { + String prinString = null; + PolicyParser.PrincipalEntry nextPrin = + (PolicyParser.PrincipalEntry)principals.get(i); + prinList.addTaggedItem(PrincipalEntryToUserFriendlyString(nextPrin), nextPrin); + } + + // get permission list + Vector permissions = + entries[listIndex].getGrantEntry().permissionEntries; + for (int i = 0; i < permissions.size(); i++) { + String permString = null; + PolicyParser.PermissionEntry nextPerm = + permissions.elementAt(i); + permList.addTaggedItem(ToolDialog.PermissionEntryToUserFriendlyString(nextPerm), nextPerm); + } + } + + // codebase label and textfield + Label label = new Label(PolicyTool.rb.getString("CodeBase:")); + tw.addNewComponent(this, label, PE_CODEBASE_LABEL, + 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); + TextField tf; + tf = (edit ? + new TextField(entries[listIndex].getGrantEntry().codeBase, 60) : + new TextField(60)); + tf.getAccessibleContext().setAccessibleName( + PolicyTool.rb.getString("Code Base")); + tw.addNewComponent(this, tf, PE_CODEBASE_TEXTFIELD, + 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); + + // signedby label and textfield + label = new Label(PolicyTool.rb.getString("SignedBy:")); + tw.addNewComponent(this, label, PE_SIGNEDBY_LABEL, + 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); + tf = (edit ? + new TextField(entries[listIndex].getGrantEntry().signedBy, 60) : + new TextField(60)); + tf.getAccessibleContext().setAccessibleName( + PolicyTool.rb.getString("Signed By:")); + tw.addNewComponent(this, tf, PE_SIGNEDBY_TEXTFIELD, + 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); + + // panel for principal buttons + Panel panel = new Panel(); + panel.setLayout(new GridBagLayout()); + + Button button = new Button(PolicyTool.rb.getString("Add Principal")); + button.addActionListener + (new AddPrinButtonListener(tool, tw, this, edit)); + tw.addNewComponent(panel, button, PE_ADD_PRIN_BUTTON, + 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); + + button = new Button(PolicyTool.rb.getString("Edit Principal")); + button.addActionListener(new EditPrinButtonListener + (tool, tw, this, edit)); + tw.addNewComponent(panel, button, PE_EDIT_PRIN_BUTTON, + 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); + + button = new Button(PolicyTool.rb.getString("Remove Principal")); + button.addActionListener(new RemovePrinButtonListener + (tool, tw, this, edit)); + tw.addNewComponent(panel, button, PE_REMOVE_PRIN_BUTTON, + 2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); + + tw.addNewComponent(this, panel, PE_PANEL0, + 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL); + + // principal label and list + label = new Label(PolicyTool.rb.getString("Principals:")); + tw.addNewComponent(this, label, PE_PRIN_LABEL, + 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.BOTTOM_PADDING); + tw.addNewComponent(this, prinList, PE_PRIN_LIST, + 1, 3, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.BOTTOM_PADDING); + + // panel for permission buttons + panel = new Panel(); + panel.setLayout(new GridBagLayout()); + + button = new Button(PolicyTool.rb.getString(" Add Permission")); + button.addActionListener(new AddPermButtonListener + (tool, tw, this, edit)); + tw.addNewComponent(panel, button, PE_ADD_PERM_BUTTON, + 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); + + button = new Button(PolicyTool.rb.getString(" Edit Permission")); + button.addActionListener(new EditPermButtonListener + (tool, tw, this, edit)); + tw.addNewComponent(panel, button, PE_EDIT_PERM_BUTTON, + 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); + + + button = new Button(PolicyTool.rb.getString("Remove Permission")); + button.addActionListener(new RemovePermButtonListener + (tool, tw, this, edit)); + tw.addNewComponent(panel, button, PE_REMOVE_PERM_BUTTON, + 2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); + + tw.addNewComponent(this, panel, PE_PANEL1, + 0, 4, 2, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL, + tw.LITE_BOTTOM_PADDING); + + // permission list + tw.addNewComponent(this, permList, PE_PERM_LIST, + 0, 5, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.BOTTOM_PADDING); + + + // panel for Done and Cancel buttons + panel = new Panel(); + panel.setLayout(new GridBagLayout()); + + // Done Button + button = new Button(PolicyTool.rb.getString("Done")); + button.addActionListener + (new AddEntryDoneButtonListener(tool, tw, this, edit)); + tw.addNewComponent(panel, button, PE_DONE_BUTTON, + 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, + tw.LR_PADDING); + + // Cancel Button + button = new Button(PolicyTool.rb.getString("Cancel")); + button.addActionListener(new CancelButtonListener(this)); + tw.addNewComponent(panel, button, PE_CANCEL_BUTTON, + 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, + tw.LR_PADDING); + + // add the panel + tw.addNewComponent(this, panel, PE_PANEL2, + 0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); + + setVisible(true); + } + + /** + * Read all the Policy information data in the dialog box + * and construct a PolicyEntry object with it. + */ + PolicyEntry getPolicyEntryFromDialog() + throws InvalidParameterException, MalformedURLException, + NoSuchMethodException, ClassNotFoundException, InstantiationException, + IllegalAccessException, InvocationTargetException, + CertificateException, IOException, Exception { + + // get the Codebase + TextField tf = (TextField)getComponent(PE_CODEBASE_TEXTFIELD); + String codebase = null; + if (tf.getText().trim().equals("") == false) + codebase = new String(tf.getText().trim()); + + // get the SignedBy + tf = (TextField)getComponent(PE_SIGNEDBY_TEXTFIELD); + String signedby = null; + if (tf.getText().trim().equals("") == false) + signedby = new String(tf.getText().trim()); + + // construct a new GrantEntry + PolicyParser.GrantEntry ge = + new PolicyParser.GrantEntry(signedby, codebase); + + // get the new Principals + LinkedList prins = + new LinkedList(); + TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST); + for (int i = 0; i < prinList.getItemCount(); i++) { + prins.add((PolicyParser.PrincipalEntry)prinList.getObject(i)); + } + ge.principals = prins; + + // get the new Permissions + Vector perms = + new Vector(); + TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST); + for (int i = 0; i < permList.getItemCount(); i++) { + perms.addElement((PolicyParser.PermissionEntry)permList.getObject(i)); + } + ge.permissionEntries = perms; + + // construct a new PolicyEntry object + PolicyEntry entry = new PolicyEntry(tool, ge); + + return entry; + } + + /** + * display a dialog box for the user to enter KeyStore information + */ + void keyStoreDialog(int mode) { + + // find where the PolicyTool gui is + Point location = tw.getLocationOnScreen(); + setBounds(location.x + 25, location.y + 100, 500, 300); + setLayout(new GridBagLayout()); + + if (mode == EDIT_KEYSTORE) { + + // KeyStore label and textfield + Label label = new Label + (PolicyTool.rb.getString("KeyStore URL:")); + tw.addNewComponent(this, label, KSD_NAME_LABEL, + 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.BOTTOM_PADDING); + TextField tf = new TextField(tool.getKeyStoreName(), 30); + + // URL to U R L, so that accessibility reader will pronounce well + tf.getAccessibleContext().setAccessibleName( + PolicyTool.rb.getString("KeyStore U R L:")); + tw.addNewComponent(this, tf, KSD_NAME_TEXTFIELD, + 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.BOTTOM_PADDING); + + // KeyStore type and textfield + label = new Label(PolicyTool.rb.getString("KeyStore Type:")); + tw.addNewComponent(this, label, KSD_TYPE_LABEL, + 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.BOTTOM_PADDING); + tf = new TextField(tool.getKeyStoreType(), 30); + tf.getAccessibleContext().setAccessibleName( + PolicyTool.rb.getString("KeyStore Type:")); + tw.addNewComponent(this, tf, KSD_TYPE_TEXTFIELD, + 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.BOTTOM_PADDING); + + // KeyStore provider and textfield + label = new Label(PolicyTool.rb.getString + ("KeyStore Provider:")); + tw.addNewComponent(this, label, KSD_PROVIDER_LABEL, + 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.BOTTOM_PADDING); + tf = new TextField(tool.getKeyStoreProvider(), 30); + tf.getAccessibleContext().setAccessibleName( + PolicyTool.rb.getString("KeyStore Provider:")); + tw.addNewComponent(this, tf, KSD_PROVIDER_TEXTFIELD, + 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.BOTTOM_PADDING); + + // KeyStore password URL and textfield + label = new Label(PolicyTool.rb.getString + ("KeyStore Password URL:")); + tw.addNewComponent(this, label, KSD_PWD_URL_LABEL, + 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.BOTTOM_PADDING); + tf = new TextField(tool.getKeyStorePwdURL(), 30); + tf.getAccessibleContext().setAccessibleName( + PolicyTool.rb.getString("KeyStore Password U R L:")); + tw.addNewComponent(this, tf, KSD_PWD_URL_TEXTFIELD, + 1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.BOTTOM_PADDING); + + // OK button + Button okButton = new Button(PolicyTool.rb.getString("OK")); + okButton.addActionListener + (new ChangeKeyStoreOKButtonListener(tool, tw, this)); + tw.addNewComponent(this, okButton, KSD_OK_BUTTON, + 0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); + + // cancel button + Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); + cancelButton.addActionListener(new CancelButtonListener(this)); + tw.addNewComponent(this, cancelButton, KSD_CANCEL_BUTTON, + 1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); + + } + setVisible(true); + } + + /** + * display a dialog box for the user to input Principal info + * + * if editPolicyEntry is false, then we are adding Principals to + * a new PolicyEntry, and we only update the GUI listing + * with the new Principal. + * + * if edit is true, then we are editing an existing Policy entry. + */ + void displayPrincipalDialog(boolean editPolicyEntry, boolean edit) { + + PolicyParser.PrincipalEntry editMe = null; + + // get the Principal selected from the Principal List + TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST); + int prinIndex = prinList.getSelectedIndex(); + + if (edit) { + editMe = (PolicyParser.PrincipalEntry)prinList.getObject(prinIndex); + } + + ToolDialog newTD = new ToolDialog + (PolicyTool.rb.getString("Principals"), tool, tw, true); + newTD.addWindowListener(new ChildWindowListener(newTD)); + + // find where the PolicyTool gui is + Point location = getLocationOnScreen(); + newTD.setBounds(location.x + 50, location.y + 100, 650, 190); + newTD.setLayout(new GridBagLayout()); + newTD.setResizable(true); + + // description label + Label label = (edit ? + new Label(PolicyTool.rb.getString(" Edit Principal:")) : + new Label(PolicyTool.rb.getString(" Add New Principal:"))); + tw.addNewComponent(newTD, label, PRD_DESC_LABEL, + 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.TOP_BOTTOM_PADDING); + + // principal choice + Choice choice = new Choice(); + choice.add(PRIN_TYPE); + choice.getAccessibleContext().setAccessibleName(PRIN_TYPE); + for (int i = 0; i < PRIN_ARRAY.size(); i++) { + Prin next = PRIN_ARRAY.get(i); + choice.add(next.CLASS); + } + + choice.addItemListener(new PrincipalTypeMenuListener(newTD)); + if (edit) { + if (PolicyParser.PrincipalEntry.WILDCARD_CLASS.equals + (editMe.getPrincipalClass())) { + choice.select(PRIN_TYPE); + } else { + Prin inputPrin = getPrin(editMe.getPrincipalClass(), true); + if (inputPrin != null) { + choice.select(inputPrin.CLASS); + } + } + } + + tw.addNewComponent(newTD, choice, PRD_PRIN_CHOICE, + 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.LR_PADDING); + + // principal textfield + TextField tf; + tf = (edit ? + new TextField(editMe.getDisplayClass(), 30) : + new TextField(30)); + tf.getAccessibleContext().setAccessibleName(PRIN_TYPE); + tw.addNewComponent(newTD, tf, PRD_PRIN_TEXTFIELD, + 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.LR_PADDING); + + // name label and textfield + label = new Label(PRIN_NAME); + tf = (edit ? + new TextField(editMe.getDisplayName(), 40) : + new TextField(40)); + tf.getAccessibleContext().setAccessibleName(PRIN_NAME); + + tw.addNewComponent(newTD, label, PRD_NAME_LABEL, + 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.LR_PADDING); + tw.addNewComponent(newTD, tf, PRD_NAME_TEXTFIELD, + 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.LR_PADDING); + + // OK button + Button okButton = new Button(PolicyTool.rb.getString("OK")); + okButton.addActionListener( + new NewPolicyPrinOKButtonListener + (tool, tw, this, newTD, edit)); + tw.addNewComponent(newTD, okButton, PRD_OK_BUTTON, + 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, + tw.TOP_BOTTOM_PADDING); + // cancel button + Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); + cancelButton.addActionListener(new CancelButtonListener(newTD)); + tw.addNewComponent(newTD, cancelButton, PRD_CANCEL_BUTTON, + 1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, + tw.TOP_BOTTOM_PADDING); + + newTD.setVisible(true); + } + + /** + * display a dialog box for the user to input Permission info + * + * if editPolicyEntry is false, then we are adding Permissions to + * a new PolicyEntry, and we only update the GUI listing + * with the new Permission. + * + * if edit is true, then we are editing an existing Permission entry. + */ + void displayPermissionDialog(boolean editPolicyEntry, boolean edit) { + + PolicyParser.PermissionEntry editMe = null; + + // get the Permission selected from the Permission List + TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST); + int permIndex = permList.getSelectedIndex(); + + if (edit) { + editMe = (PolicyParser.PermissionEntry)permList.getObject(permIndex); + } + + ToolDialog newTD = new ToolDialog + (PolicyTool.rb.getString("Permissions"), tool, tw, true); + newTD.addWindowListener(new ChildWindowListener(newTD)); + + // find where the PolicyTool gui is + Point location = getLocationOnScreen(); + newTD.setBounds(location.x + 50, location.y + 100, 700, 250); + newTD.setLayout(new GridBagLayout()); + newTD.setResizable(true); + + // description label + Label label = (edit ? + new Label(PolicyTool.rb.getString(" Edit Permission:")) : + new Label(PolicyTool.rb.getString(" Add New Permission:"))); + tw.addNewComponent(newTD, label, PD_DESC_LABEL, + 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.TOP_BOTTOM_PADDING); + + // permission choice (added in alphabetical order) + Choice choice = new Choice(); + choice.add(PERM); + choice.getAccessibleContext().setAccessibleName(PERM); + for (int i = 0; i < PERM_ARRAY.size(); i++) { + Perm next = PERM_ARRAY.get(i); + choice.add(next.CLASS); + } + choice.addItemListener(new PermissionMenuListener(newTD)); + tw.addNewComponent(newTD, choice, PD_PERM_CHOICE, + 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.LR_PADDING); + + // permission textfield + TextField tf; + tf = (edit ? new TextField(editMe.permission, 30) : new TextField(30)); + tf.getAccessibleContext().setAccessibleName(PERM); + if (edit) { + Perm inputPerm = getPerm(editMe.permission, true); + if (inputPerm != null) { + choice.select(inputPerm.CLASS); + } + } + tw.addNewComponent(newTD, tf, PD_PERM_TEXTFIELD, + 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.LR_PADDING); + + // name label and textfield + choice = new Choice(); + choice.add(PERM_NAME); + choice.getAccessibleContext().setAccessibleName(PERM_NAME); + choice.addItemListener(new PermissionNameMenuListener(newTD)); + tf = (edit ? new TextField(editMe.name, 40) : new TextField(40)); + tf.getAccessibleContext().setAccessibleName(PERM_NAME); + if (edit) { + setPermissionNames(getPerm(editMe.permission, true), choice, tf); + } + tw.addNewComponent(newTD, choice, PD_NAME_CHOICE, + 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.LR_PADDING); + tw.addNewComponent(newTD, tf, PD_NAME_TEXTFIELD, + 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.LR_PADDING); + + // actions label and textfield + choice = new Choice(); + choice.add(PERM_ACTIONS); + choice.getAccessibleContext().setAccessibleName(PERM_ACTIONS); + choice.addItemListener(new PermissionActionsMenuListener(newTD)); + tf = (edit ? new TextField(editMe.action, 40) : new TextField(40)); + tf.getAccessibleContext().setAccessibleName(PERM_ACTIONS); + if (edit) { + setPermissionActions(getPerm(editMe.permission, true), choice, tf); + } + tw.addNewComponent(newTD, choice, PD_ACTIONS_CHOICE, + 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.LR_PADDING); + tw.addNewComponent(newTD, tf, PD_ACTIONS_TEXTFIELD, + 1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.LR_PADDING); + + // signedby label and textfield + label = new Label(PolicyTool.rb.getString("Signed By:")); + tw.addNewComponent(newTD, label, PD_SIGNEDBY_LABEL, + 0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.LR_PADDING); + tf = (edit ? new TextField(editMe.signedBy, 40) : new TextField(40)); + tf.getAccessibleContext().setAccessibleName( + PolicyTool.rb.getString("Signed By:")); + tw.addNewComponent(newTD, tf, PD_SIGNEDBY_TEXTFIELD, + 1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.LR_PADDING); + + // OK button + Button okButton = new Button(PolicyTool.rb.getString("OK")); + okButton.addActionListener( + new NewPolicyPermOKButtonListener + (tool, tw, this, newTD, edit)); + tw.addNewComponent(newTD, okButton, PD_OK_BUTTON, + 0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, + tw.TOP_BOTTOM_PADDING); + + // cancel button + Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); + cancelButton.addActionListener(new CancelButtonListener(newTD)); + tw.addNewComponent(newTD, cancelButton, PD_CANCEL_BUTTON, + 1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, + tw.TOP_BOTTOM_PADDING); + + newTD.setVisible(true); + } + + /** + * construct a Principal object from the Principal Info Dialog Box + */ + PolicyParser.PrincipalEntry getPrinFromDialog() throws Exception { + + TextField tf = (TextField)getComponent(PRD_PRIN_TEXTFIELD); + String pclass = new String(tf.getText().trim()); + tf = (TextField)getComponent(PRD_NAME_TEXTFIELD); + String pname = new String(tf.getText().trim()); + if (pclass.equals("*")) { + pclass = PolicyParser.PrincipalEntry.WILDCARD_CLASS; + } + if (pname.equals("*")) { + pname = PolicyParser.PrincipalEntry.WILDCARD_NAME; + } + + PolicyParser.PrincipalEntry pppe = null; + + if ((pclass.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS)) && + (!pname.equals(PolicyParser.PrincipalEntry.WILDCARD_NAME))) { + throw new Exception + (PolicyTool.rb.getString("Cannot Specify Principal " + + "with a Wildcard Class without a Wildcard Name")); + } else if (pname.equals("")) { + throw new Exception + (PolicyTool.rb.getString("Cannot Specify Principal " + + "without a Name")); + } else if (pclass.equals("")) { + // make this consistent with what PolicyParser does + // when it sees an empty principal class + pclass = PolicyParser.REPLACE_NAME; + tool.warnings.addElement( + "Warning: Principal name '" + pname + + "' specified without a Principal class.\n" + + "\t'" + pname + "' will be interpreted " + + "as a key store alias.\n" + + "\tThe final principal class will be " + + ToolDialog.X500_PRIN_CLASS + ".\n" + + "\tThe final principal name will be " + + "determined by the following:\n" + + "\n" + + "\tIf the key store entry identified by '" + + pname + "'\n" + + "\tis a key entry, then the principal name will be\n" + + "\tthe subject distinguished name from the first\n" + + "\tcertificate in the entry's certificate chain.\n" + + "\n" + + "\tIf the key store entry identified by '" + + pname + "'\n" + + "\tis a trusted certificate entry, then the\n" + + "\tprincipal name will be the subject distinguished\n" + + "\tname from the trusted public key certificate."); + tw.displayStatusDialog(this, + "'" + pname + "' will be interpreted as a key " + + "store alias. View Warning Log for details."); + } + return new PolicyParser.PrincipalEntry(pclass, pname); + } + + + /** + * construct a Permission object from the Permission Info Dialog Box + */ + PolicyParser.PermissionEntry getPermFromDialog() { + + TextField tf = (TextField)getComponent(PD_PERM_TEXTFIELD); + String permission = new String(tf.getText().trim()); + tf = (TextField)getComponent(PD_NAME_TEXTFIELD); + String name = null; + if (tf.getText().trim().equals("") == false) + name = new String(tf.getText().trim()); + if (permission.equals("") || + (!permission.equals(ALL_PERM_CLASS) && name == null)) { + throw new InvalidParameterException(PolicyTool.rb.getString + ("Permission and Target Name must have a value")); + } + + // When the permission is FilePermission, we need to check the name + // to make sure it's not escaped. We believe -- + // + // String name.lastIndexOf("\\\\") + // ---------------- ------------------------ + // c:\foo\bar -1, legal + // c:\\foo\\bar 2, illegal + // \\server\share 0, legal + // \\\\server\share 2, illegal + + if (permission.equals(FILE_PERM_CLASS) && name.lastIndexOf("\\\\") > 0) { + char result = tw.displayYesNoDialog(this, + PolicyTool.rb.getString("Warning"), + PolicyTool.rb.getString( + "Warning: File name may include escaped backslash characters. " + + "It is not necessary to escape backslash characters " + + "(the tool escapes characters as necessary when writing " + + "the policy contents to the persistent store).\n\n" + + "Click on Retain to retain the entered name, or click on " + + "Edit to edit the name."), + PolicyTool.rb.getString("Retain"), + PolicyTool.rb.getString("Edit") + ); + if (result != 'Y') { + // an invisible exception + throw new NoDisplayException(); + } + } + // get the Actions + tf = (TextField)getComponent(PD_ACTIONS_TEXTFIELD); + String actions = null; + if (tf.getText().trim().equals("") == false) + actions = new String(tf.getText().trim()); + + // get the Signed By + tf = (TextField)getComponent(PD_SIGNEDBY_TEXTFIELD); + String signedBy = null; + if (tf.getText().trim().equals("") == false) + signedBy = new String(tf.getText().trim()); + + PolicyParser.PermissionEntry pppe = new PolicyParser.PermissionEntry + (permission, name, actions); + pppe.signedBy = signedBy; + + // see if the signers have public keys + if (signedBy != null) { + String signers[] = tool.parseSigners(pppe.signedBy); + for (int i = 0; i < signers.length; i++) { + try { + PublicKey pubKey = tool.getPublicKeyAlias(signers[i]); + if (pubKey == null) { + MessageFormat form = new MessageFormat + (PolicyTool.rb.getString + ("Warning: A public key for alias " + + "'signers[i]' does not exist. " + + "Make sure a KeyStore is properly configured.")); + Object[] source = {signers[i]}; + tool.warnings.addElement(form.format(source)); + tw.displayStatusDialog(this, form.format(source)); + } + } catch (Exception e) { + tw.displayErrorDialog(this, e); + } + } + } + return pppe; + } + + /** + * confirm that the user REALLY wants to remove the Policy Entry + */ + void displayConfirmRemovePolicyEntry() { + + // find the entry to be removed + List list = (List)tw.getComponent(tw.MW_POLICY_LIST); + int index = list.getSelectedIndex(); + PolicyEntry entries[] = tool.getEntry(); + + // find where the PolicyTool gui is + Point location = tw.getLocationOnScreen(); + setBounds(location.x + 25, location.y + 100, 600, 400); + setLayout(new GridBagLayout()); + + // ask the user do they really want to do this? + Label label = new Label + (PolicyTool.rb.getString("Remove this Policy Entry?")); + tw.addNewComponent(this, label, CRPE_LABEL1, + 0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.BOTTOM_PADDING); + + // display the policy entry + label = new Label(entries[index].codebaseToString()); + tw.addNewComponent(this, label, CRPE_LABEL2, + 0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH); + label = new Label(entries[index].principalsToString().trim()); + tw.addNewComponent(this, label, CRPE_LABEL2+1, + 0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH); + Vector perms = + entries[index].getGrantEntry().permissionEntries; + for (int i = 0; i < perms.size(); i++) { + PolicyParser.PermissionEntry nextPerm = perms.elementAt(i); + String permString = ToolDialog.PermissionEntryToUserFriendlyString(nextPerm); + label = new Label(" " + permString); + if (i == (perms.size()-1)) { + tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i, + 1, 3 + i, 1, 1, 0.0, 0.0, + GridBagConstraints.BOTH, tw.BOTTOM_PADDING); + } else { + tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i, + 1, 3 + i, 1, 1, 0.0, 0.0, + GridBagConstraints.BOTH); + } + } + + + // add OK/CANCEL buttons in a new panel + Panel panel = new Panel(); + panel.setLayout(new GridBagLayout()); + + // OK button + Button okButton = new Button(PolicyTool.rb.getString("OK")); + okButton.addActionListener + (new ConfirmRemovePolicyEntryOKButtonListener(tool, tw, this)); + tw.addNewComponent(panel, okButton, CRPE_PANEL_OK, + 0, 0, 1, 1, 0.0, 0.0, + GridBagConstraints.VERTICAL, tw.LR_PADDING); + + // cancel button + Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); + cancelButton.addActionListener(new CancelButtonListener(this)); + tw.addNewComponent(panel, cancelButton, CRPE_PANEL_CANCEL, + 1, 0, 1, 1, 0.0, 0.0, + GridBagConstraints.VERTICAL, tw.LR_PADDING); + + tw.addNewComponent(this, panel, CRPE_LABEL2 + 2 + perms.size(), + 0, 3 + perms.size(), 2, 1, 0.0, 0.0, + GridBagConstraints.VERTICAL, tw.TOP_BOTTOM_PADDING); + + pack(); + setVisible(true); + } + + /** + * perform SAVE AS + */ + void displaySaveAsDialog(int nextEvent) { + + // pop up a dialog box for the user to enter a filename. + FileDialog fd = new FileDialog + (tw, PolicyTool.rb.getString("Save As"), FileDialog.SAVE); + fd.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + e.getWindow().setVisible(false); + } + }); + fd.setVisible(true); + + // see if the user hit cancel + if (fd.getFile() == null || + fd.getFile().equals("")) + return; + + // get the entered filename + String filename = new String(fd.getDirectory() + fd.getFile()); + fd.dispose(); + + // see if the file already exists + File saveAsFile = new File(filename); + if (saveAsFile.exists()) { + // display a dialog box for the user to enter policy info + ToolDialog td = new ToolDialog + (PolicyTool.rb.getString("Overwrite File"), tool, tw, true); + td.displayOverWriteFileDialog(filename, nextEvent); + } else { + try { + // save the policy entries to a file + tool.savePolicy(filename); + + // display status + MessageFormat form = new MessageFormat(PolicyTool.rb.getString + ("Policy successfully written to filename")); + Object[] source = {filename}; + tw.displayStatusDialog(null, form.format(source)); + + // display the new policy filename + TextField newFilename = (TextField)tw.getComponent + (tw.MW_FILENAME_TEXTFIELD); + newFilename.setText(filename); + tw.setVisible(true); + + // now continue with the originally requested command + // (QUIT, NEW, or OPEN) + userSaveContinue(tool, tw, this, nextEvent); + + } catch (FileNotFoundException fnfe) { + if (filename == null || filename.equals("")) { + tw.displayErrorDialog(null, new FileNotFoundException + (PolicyTool.rb.getString("null filename"))); + } else { + tw.displayErrorDialog(null, fnfe); + } + } catch (Exception ee) { + tw.displayErrorDialog(null, ee); + } + } + } + + /** + * ask user if they want to save changes + */ + void displayUserSave(int select) { + + if (tool.modified == true) { + + // find where the PolicyTool gui is + Point location = tw.getLocationOnScreen(); + setBounds(location.x + 75, location.y + 100, 400, 150); + setLayout(new GridBagLayout()); + + Label label = new Label + (PolicyTool.rb.getString("Save changes?")); + tw.addNewComponent(this, label, USC_LABEL, + 0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH, + tw.L_TOP_BOTTOM_PADDING); + + Panel panel = new Panel(); + panel.setLayout(new GridBagLayout()); + + Button yesButton = new Button(PolicyTool.rb.getString("Yes")); + yesButton.addActionListener + (new UserSaveYesButtonListener(this, tool, tw, select)); + tw.addNewComponent(panel, yesButton, USC_YES_BUTTON, + 0, 0, 1, 1, 0.0, 0.0, + GridBagConstraints.VERTICAL, + tw.LR_BOTTOM_PADDING); + Button noButton = new Button(PolicyTool.rb.getString("No")); + noButton.addActionListener + (new UserSaveNoButtonListener(this, tool, tw, select)); + tw.addNewComponent(panel, noButton, USC_NO_BUTTON, + 1, 0, 1, 1, 0.0, 0.0, + GridBagConstraints.VERTICAL, + tw.LR_BOTTOM_PADDING); + Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); + cancelButton.addActionListener + (new UserSaveCancelButtonListener(this)); + tw.addNewComponent(panel, cancelButton, USC_CANCEL_BUTTON, + 2, 0, 1, 1, 0.0, 0.0, + GridBagConstraints.VERTICAL, + tw.LR_BOTTOM_PADDING); + + tw.addNewComponent(this, panel, USC_PANEL, + 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); + + pack(); + setVisible(true); + } else { + // just do the original request (QUIT, NEW, or OPEN) + userSaveContinue(tool, tw, this, select); + } + } + + /** + * when the user sees the 'YES', 'NO', 'CANCEL' buttons on the + * displayUserSave dialog, and the click on one of them, + * we need to continue the originally requested action + * (either QUITting, opening NEW policy file, or OPENing an existing + * policy file. do that now. + */ + void userSaveContinue(PolicyTool tool, ToolWindow tw, + ToolDialog us, int select) { + + // now either QUIT, open a NEW policy file, or OPEN an existing policy + switch(select) { + case ToolDialog.QUIT: + + tw.setVisible(false); + tw.dispose(); + System.exit(0); + + case ToolDialog.NEW: + + try { + tool.openPolicy(null); + } catch (Exception ee) { + tool.modified = false; + tw.displayErrorDialog(null, ee); + } + + // display the policy entries via the policy list textarea + List list = new List(40, false); + list.addActionListener(new PolicyListListener(tool, tw)); + tw.replacePolicyList(list); + + // display null policy filename and keystore + TextField newFilename = (TextField) + tw.getComponent(tw.MW_FILENAME_TEXTFIELD); + newFilename.setText(""); + tw.setVisible(true); + break; + + case ToolDialog.OPEN: + + // pop up a dialog box for the user to enter a filename. + FileDialog fd = new FileDialog + (tw, PolicyTool.rb.getString("Open"), FileDialog.LOAD); + fd.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + e.getWindow().setVisible(false); + } + }); + fd.setVisible(true); + + // see if the user hit 'cancel' + if (fd.getFile() == null || + fd.getFile().equals("")) + return; + + // get the entered filename + String policyFile = new String(fd.getDirectory() + fd.getFile()); + + try { + // open the policy file + tool.openPolicy(policyFile); + + // display the policy entries via the policy list textarea + list = new List(40, false); + list.addActionListener(new PolicyListListener(tool, tw)); + PolicyEntry entries[] = tool.getEntry(); + if (entries != null) { + for (int i = 0; i < entries.length; i++) + list.add(entries[i].headerToString()); + } + tw.replacePolicyList(list); + tool.modified = false; + + // display the new policy filename + newFilename = (TextField) + tw.getComponent(tw.MW_FILENAME_TEXTFIELD); + newFilename.setText(policyFile); + tw.setVisible(true); + + // inform user of warnings + if (tool.newWarning == true) { + tw.displayStatusDialog(null, PolicyTool.rb.getString + ("Errors have occurred while opening the " + + "policy configuration. View the Warning Log " + + "for more information.")); + } + + } catch (Exception e) { + // add blank policy listing + list = new List(40, false); + list.addActionListener(new PolicyListListener(tool, tw)); + tw.replacePolicyList(list); + tool.setPolicyFileName(null); + tool.modified = false; + + // display a null policy filename + newFilename = (TextField) + tw.getComponent(tw.MW_FILENAME_TEXTFIELD); + newFilename.setText(""); + tw.setVisible(true); + + // display the error + MessageFormat form = new MessageFormat(PolicyTool.rb.getString + ("Could not open policy file: policyFile: e.toString()")); + Object[] source = {policyFile, e.toString()}; + tw.displayErrorDialog(null, form.format(source)); + } + break; + } + } + + /** + * Return a Menu list of names for a given permission + * + * If inputPerm's TARGETS are null, then this means TARGETS are + * not allowed to be entered (and the TextField is set to be + * non-editable). + * + * If TARGETS are valid but there are no standard ones + * (user must enter them by hand) then the TARGETS array may be empty + * (and of course non-null). + */ + void setPermissionNames(Perm inputPerm, Choice names, TextField field) { + names.removeAll(); + names.add(PERM_NAME); + + if (inputPerm == null) { + // custom permission + field.setEditable(true); + } else if (inputPerm.TARGETS == null) { + // standard permission with no targets + field.setEditable(false); + } else { + // standard permission with standard targets + field.setEditable(true); + for (int i = 0; i < inputPerm.TARGETS.length; i++) { + names.add(inputPerm.TARGETS[i]); + } + } + } + + /** + * Return a Menu list of actions for a given permission + * + * If inputPerm's ACTIONS are null, then this means ACTIONS are + * not allowed to be entered (and the TextField is set to be + * non-editable). This is typically true for BasicPermissions. + * + * If ACTIONS are valid but there are no standard ones + * (user must enter them by hand) then the ACTIONS array may be empty + * (and of course non-null). + */ + void setPermissionActions(Perm inputPerm, Choice actions, TextField field) { + actions.removeAll(); + actions.add(PERM_ACTIONS); + + if (inputPerm == null) { + // custom permission + field.setEditable(true); + } else if (inputPerm.ACTIONS == null) { + // standard permission with no actions + field.setEditable(false); + } else { + // standard permission with standard actions + field.setEditable(true); + for (int i = 0; i < inputPerm.ACTIONS.length; i++) { + actions.add(inputPerm.ACTIONS[i]); + } + } + } + + static String PermissionEntryToUserFriendlyString(PolicyParser.PermissionEntry pppe) { + String result = pppe.permission; + if (pppe.name != null) { + result += " " + pppe.name; + } + if (pppe.action != null) { + result += ", \"" + pppe.action + "\""; + } + if (pppe.signedBy != null) { + result += ", signedBy " + pppe.signedBy; + } + return result; + } + + static String PrincipalEntryToUserFriendlyString(PolicyParser.PrincipalEntry pppe) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + pppe.write(pw); + return sw.toString(); + } +} + +/** + * Event handler for the PolicyTool window + */ +class ToolWindowListener implements WindowListener { + + private ToolWindow tw; + + ToolWindowListener(ToolWindow tw) { + this.tw = tw; + } + + public void windowOpened(WindowEvent we) { + } + + public void windowClosing(WindowEvent we) { + + // XXX + // should we ask user if they want to save changes? + // (we do if they choose the Menu->Exit) + // seems that if they kill the application by hand, + // we don't have to ask. + + tw.setVisible(false); + tw.dispose(); + System.exit(0); + } + + public void windowClosed(WindowEvent we) { + System.exit(0); + } + + public void windowIconified(WindowEvent we) { + } + + public void windowDeiconified(WindowEvent we) { + } + + public void windowActivated(WindowEvent we) { + } + + public void windowDeactivated(WindowEvent we) { + } +} + +/** + * Event handler for the Policy List + */ +class PolicyListListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + + PolicyListListener(PolicyTool tool, ToolWindow tw) { + this.tool = tool; + this.tw = tw; + + } + + public void actionPerformed(ActionEvent e) { + + // display the permission list for a policy entry + ToolDialog td = new ToolDialog + (PolicyTool.rb.getString("Policy Entry"), tool, tw, true); + td.displayPolicyEntryDialog(true); + } +} + +/** + * Event handler for the File Menu + */ +class FileMenuListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + + FileMenuListener(PolicyTool tool, ToolWindow tw) { + this.tool = tool; + this.tw = tw; + } + + public void actionPerformed(ActionEvent e) { + + if (PolicyTool.collator.compare(e.getActionCommand(), tw.QUIT) == 0) { + + // ask user if they want to save changes + ToolDialog td = new ToolDialog + (PolicyTool.rb.getString("Save Changes"), tool, tw, true); + td.displayUserSave(td.QUIT); + + // the above method will perform the QUIT as long as the + // user does not CANCEL the request + + } else if (PolicyTool.collator.compare(e.getActionCommand(), + tw.NEW_POLICY_FILE) == 0) { + + // ask user if they want to save changes + ToolDialog td = new ToolDialog + (PolicyTool.rb.getString("Save Changes"), tool, tw, true); + td.displayUserSave(td.NEW); + + // the above method will perform the NEW as long as the + // user does not CANCEL the request + + } else if (PolicyTool.collator.compare(e.getActionCommand(), + tw.OPEN_POLICY_FILE) == 0) { + + // ask user if they want to save changes + ToolDialog td = new ToolDialog + (PolicyTool.rb.getString("Save Changes"), tool, tw, true); + td.displayUserSave(td.OPEN); + + // the above method will perform the OPEN as long as the + // user does not CANCEL the request + + } else if (PolicyTool.collator.compare(e.getActionCommand(), + tw.SAVE_POLICY_FILE) == 0) { + + // get the previously entered filename + String filename = ((TextField) + tw.getComponent(tw.MW_FILENAME_TEXTFIELD)).getText(); + + // if there is no filename, do a SAVE_AS + if (filename == null || filename.length() == 0) { + // user wants to SAVE AS + ToolDialog td = new ToolDialog + (PolicyTool.rb.getString("Save As"), tool, tw, true); + td.displaySaveAsDialog(td.NOACTION); + } else { + try { + // save the policy entries to a file + tool.savePolicy(filename); + + // display status + MessageFormat form = new MessageFormat + (PolicyTool.rb.getString + ("Policy successfully written to filename")); + Object[] source = {filename}; + tw.displayStatusDialog(null, form.format(source)); + } catch (FileNotFoundException fnfe) { + if (filename == null || filename.equals("")) { + tw.displayErrorDialog(null, new FileNotFoundException + (PolicyTool.rb.getString("null filename"))); + } else { + tw.displayErrorDialog(null, fnfe); + } + } catch (Exception ee) { + tw.displayErrorDialog(null, ee); + } + } + } else if (PolicyTool.collator.compare(e.getActionCommand(), + tw.SAVE_AS_POLICY_FILE) == 0) { + + // user wants to SAVE AS + ToolDialog td = new ToolDialog + (PolicyTool.rb.getString("Save As"), tool, tw, true); + td.displaySaveAsDialog(td.NOACTION); + + } else if (PolicyTool.collator.compare(e.getActionCommand(), + tw.VIEW_WARNINGS) == 0) { + tw.displayWarningLog(null); + } + } +} + +/** + * Event handler for the main window buttons and Edit Menu + */ +class MainWindowListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + + MainWindowListener(PolicyTool tool, ToolWindow tw) { + this.tool = tool; + this.tw = tw; + } + + public void actionPerformed(ActionEvent e) { + + if (PolicyTool.collator.compare(e.getActionCommand(), + tw.ADD_POLICY_ENTRY) == 0) { + + // display a dialog box for the user to enter policy info + ToolDialog td = new ToolDialog + (PolicyTool.rb.getString("Policy Entry"), tool, tw, true); + td.displayPolicyEntryDialog(false); + + } else if (PolicyTool.collator.compare(e.getActionCommand(), + tw.REMOVE_POLICY_ENTRY) == 0) { + + // get the selected entry + List list = (List)tw.getComponent(tw.MW_POLICY_LIST); + int index = list.getSelectedIndex(); + if (index < 0) { + tw.displayErrorDialog(null, new Exception + (PolicyTool.rb.getString("No Policy Entry selected"))); + return; + } + + // ask the user if they really want to remove the policy entry + ToolDialog td = new ToolDialog(PolicyTool.rb.getString + ("Remove Policy Entry"), tool, tw, true); + td.displayConfirmRemovePolicyEntry(); + + } else if (PolicyTool.collator.compare(e.getActionCommand(), + tw.EDIT_POLICY_ENTRY) == 0) { + + // get the selected entry + List list = (List)tw.getComponent(tw.MW_POLICY_LIST); + int index = list.getSelectedIndex(); + if (index < 0) { + tw.displayErrorDialog(null, new Exception + (PolicyTool.rb.getString("No Policy Entry selected"))); + return; + } + + // display the permission list for a policy entry + ToolDialog td = new ToolDialog + (PolicyTool.rb.getString("Policy Entry"), tool, tw, true); + td.displayPolicyEntryDialog(true); + + } else if (PolicyTool.collator.compare(e.getActionCommand(), + tw.EDIT_KEYSTORE) == 0) { + + // display a dialog box for the user to enter keystore info + ToolDialog td = new ToolDialog + (PolicyTool.rb.getString("KeyStore"), tool, tw, true); + td.keyStoreDialog(td.EDIT_KEYSTORE); + } + } +} + +/** + * Event handler for OverWriteFileOKButton button + */ +class OverWriteFileOKButtonListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + private ToolDialog td; + private String filename; + private int nextEvent; + + OverWriteFileOKButtonListener(PolicyTool tool, ToolWindow tw, + ToolDialog td, String filename, int nextEvent) { + this.tool = tool; + this.tw = tw; + this.td = td; + this.filename = filename; + this.nextEvent = nextEvent; + } + + public void actionPerformed(ActionEvent e) { + try { + // save the policy entries to a file + tool.savePolicy(filename); + + // display status + MessageFormat form = new MessageFormat + (PolicyTool.rb.getString + ("Policy successfully written to filename")); + Object[] source = {filename}; + tw.displayStatusDialog(null, form.format(source)); + + // display the new policy filename + TextField newFilename = (TextField)tw.getComponent + (tw.MW_FILENAME_TEXTFIELD); + newFilename.setText(filename); + tw.setVisible(true); + + // now continue with the originally requested command + // (QUIT, NEW, or OPEN) + td.setVisible(false); + td.dispose(); + td.userSaveContinue(tool, tw, td, nextEvent); + + } catch (FileNotFoundException fnfe) { + if (filename == null || filename.equals("")) { + tw.displayErrorDialog(null, new FileNotFoundException + (PolicyTool.rb.getString("null filename"))); + } else { + tw.displayErrorDialog(null, fnfe); + } + td.setVisible(false); + td.dispose(); + } catch (Exception ee) { + tw.displayErrorDialog(null, ee); + td.setVisible(false); + td.dispose(); + } + } +} + +/** + * Event handler for AddEntryDoneButton button + * + * -- if edit is TRUE, then we are EDITing an existing PolicyEntry + * and we need to update both the policy and the GUI listing. + * if edit is FALSE, then we are ADDing a new PolicyEntry, + * so we only need to update the GUI listing. + */ +class AddEntryDoneButtonListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + private ToolDialog td; + private boolean edit; + + AddEntryDoneButtonListener(PolicyTool tool, ToolWindow tw, + ToolDialog td, boolean edit) { + this.tool = tool; + this.tw = tw; + this.td = td; + this.edit = edit; + } + + public void actionPerformed(ActionEvent e) { + + try { + // get a PolicyEntry object from the dialog policy info + PolicyEntry newEntry = td.getPolicyEntryFromDialog(); + PolicyParser.GrantEntry newGe = newEntry.getGrantEntry(); + + // see if all the signers have public keys + if (newGe.signedBy != null) { + String signers[] = tool.parseSigners(newGe.signedBy); + for (int i = 0; i < signers.length; i++) { + PublicKey pubKey = tool.getPublicKeyAlias(signers[i]); + if (pubKey == null) { + MessageFormat form = new MessageFormat + (PolicyTool.rb.getString + ("Warning: A public key for alias " + + "'signers[i]' does not exist. " + + "Make sure a KeyStore is properly configured.")); + Object[] source = {signers[i]}; + tool.warnings.addElement(form.format(source)); + tw.displayStatusDialog(td, form.format(source)); + } + } + } + + // add the entry + List policyList = (List)tw.getComponent(tw.MW_POLICY_LIST); + if (edit) { + int listIndex = policyList.getSelectedIndex(); + tool.addEntry(newEntry, listIndex); + String newCodeBaseStr = newEntry.headerToString(); + if (PolicyTool.collator.compare + (newCodeBaseStr, policyList.getItem(listIndex)) != 0) + tool.modified = true; + policyList.replaceItem(newCodeBaseStr, listIndex); + } else { + tool.addEntry(newEntry, -1); + policyList.add(newEntry.headerToString()); + tool.modified = true; + } + td.setVisible(false); + td.dispose(); + + } catch (Exception eee) { + tw.displayErrorDialog(td, eee); + } + } +} + +/** + * Event handler for ChangeKeyStoreOKButton button + */ +class ChangeKeyStoreOKButtonListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + private ToolDialog td; + + ChangeKeyStoreOKButtonListener(PolicyTool tool, ToolWindow tw, + ToolDialog td) { + this.tool = tool; + this.tw = tw; + this.td = td; + } + + public void actionPerformed(ActionEvent e) { + + String URLString = ((TextField) + td.getComponent(td.KSD_NAME_TEXTFIELD)).getText().trim(); + String type = ((TextField) + td.getComponent(td.KSD_TYPE_TEXTFIELD)).getText().trim(); + String provider = ((TextField) + td.getComponent(td.KSD_PROVIDER_TEXTFIELD)).getText().trim(); + String pwdURL = ((TextField) + td.getComponent(td.KSD_PWD_URL_TEXTFIELD)).getText().trim(); + + try { + tool.openKeyStore + ((URLString.length() == 0 ? null : URLString), + (type.length() == 0 ? null : type), + (provider.length() == 0 ? null : provider), + (pwdURL.length() == 0 ? null : pwdURL)); + tool.modified = true; + } catch (Exception ex) { + MessageFormat form = new MessageFormat(PolicyTool.rb.getString + ("Unable to open KeyStore: ex.toString()")); + Object[] source = {ex.toString()}; + tw.displayErrorDialog(td, form.format(source)); + return; + } + + td.dispose(); + } +} + +/** + * Event handler for AddPrinButton button + */ +class AddPrinButtonListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + private ToolDialog td; + private boolean editPolicyEntry; + + AddPrinButtonListener(PolicyTool tool, ToolWindow tw, + ToolDialog td, boolean editPolicyEntry) { + this.tool = tool; + this.tw = tw; + this.td = td; + this.editPolicyEntry = editPolicyEntry; + } + + public void actionPerformed(ActionEvent e) { + + // display a dialog box for the user to enter principal info + td.displayPrincipalDialog(editPolicyEntry, false); + } +} + +/** + * Event handler for AddPermButton button + */ +class AddPermButtonListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + private ToolDialog td; + private boolean editPolicyEntry; + + AddPermButtonListener(PolicyTool tool, ToolWindow tw, + ToolDialog td, boolean editPolicyEntry) { + this.tool = tool; + this.tw = tw; + this.td = td; + this.editPolicyEntry = editPolicyEntry; + } + + public void actionPerformed(ActionEvent e) { + + // display a dialog box for the user to enter permission info + td.displayPermissionDialog(editPolicyEntry, false); + } +} + +/** + * Event handler for AddPrinOKButton button + */ +class NewPolicyPrinOKButtonListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + private ToolDialog listDialog; + private ToolDialog infoDialog; + private boolean edit; + + NewPolicyPrinOKButtonListener(PolicyTool tool, + ToolWindow tw, + ToolDialog listDialog, + ToolDialog infoDialog, + boolean edit) { + this.tool = tool; + this.tw = tw; + this.listDialog = listDialog; + this.infoDialog = infoDialog; + this.edit = edit; + } + + public void actionPerformed(ActionEvent e) { + + try { + // read in the new principal info from Dialog Box + PolicyParser.PrincipalEntry pppe = + infoDialog.getPrinFromDialog(); + if (pppe != null) { + try { + tool.verifyPrincipal(pppe.getPrincipalClass(), + pppe.getPrincipalName()); + } catch (ClassNotFoundException cnfe) { + MessageFormat form = new MessageFormat + (PolicyTool.rb.getString + ("Warning: Class not found: class")); + Object[] source = {pppe.getPrincipalClass()}; + tool.warnings.addElement(form.format(source)); + tw.displayStatusDialog(infoDialog, form.format(source)); + } + + // add the principal to the GUI principal list + TaggedList prinList = + (TaggedList)listDialog.getComponent(listDialog.PE_PRIN_LIST); + + String prinString = ToolDialog.PrincipalEntryToUserFriendlyString(pppe); + if (edit) { + // if editing, replace the original principal + int index = prinList.getSelectedIndex(); + prinList.replaceTaggedItem(prinString, pppe, index); + } else { + // if adding, just add it to the end + prinList.addTaggedItem(prinString, pppe); + } + } + infoDialog.dispose(); + } catch (Exception ee) { + tw.displayErrorDialog(infoDialog, ee); + } + } +} + +/** + * Event handler for AddPermOKButton button + */ +class NewPolicyPermOKButtonListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + private ToolDialog listDialog; + private ToolDialog infoDialog; + private boolean edit; + + NewPolicyPermOKButtonListener(PolicyTool tool, + ToolWindow tw, + ToolDialog listDialog, + ToolDialog infoDialog, + boolean edit) { + this.tool = tool; + this.tw = tw; + this.listDialog = listDialog; + this.infoDialog = infoDialog; + this.edit = edit; + } + + public void actionPerformed(ActionEvent e) { + + try { + // read in the new permission info from Dialog Box + PolicyParser.PermissionEntry pppe = + infoDialog.getPermFromDialog(); + + try { + tool.verifyPermission(pppe.permission, pppe.name, pppe.action); + } catch (ClassNotFoundException cnfe) { + MessageFormat form = new MessageFormat(PolicyTool.rb.getString + ("Warning: Class not found: class")); + Object[] source = {pppe.permission}; + tool.warnings.addElement(form.format(source)); + tw.displayStatusDialog(infoDialog, form.format(source)); + } + + // add the permission to the GUI permission list + TaggedList permList = + (TaggedList)listDialog.getComponent(listDialog.PE_PERM_LIST); + + String permString = ToolDialog.PermissionEntryToUserFriendlyString(pppe); + if (edit) { + // if editing, replace the original permission + int which = permList.getSelectedIndex(); + permList.replaceTaggedItem(permString, pppe, which); + } else { + // if adding, just add it to the end + permList.addTaggedItem(permString, pppe); + } + infoDialog.dispose(); + + } catch (InvocationTargetException ite) { + tw.displayErrorDialog(infoDialog, ite.getTargetException()); + } catch (Exception ee) { + tw.displayErrorDialog(infoDialog, ee); + } + } +} + +/** + * Event handler for RemovePrinButton button + */ +class RemovePrinButtonListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + private ToolDialog td; + private boolean edit; + + RemovePrinButtonListener(PolicyTool tool, ToolWindow tw, + ToolDialog td, boolean edit) { + this.tool = tool; + this.tw = tw; + this.td = td; + this.edit = edit; + } + + public void actionPerformed(ActionEvent e) { + + // get the Principal selected from the Principal List + TaggedList prinList = (TaggedList)td.getComponent(td.PE_PRIN_LIST); + int prinIndex = prinList.getSelectedIndex(); + + if (prinIndex < 0) { + tw.displayErrorDialog(td, new Exception + (PolicyTool.rb.getString("No principal selected"))); + return; + } + // remove the principal from the display + prinList.removeTaggedItem(prinIndex); + } +} + +/** + * Event handler for RemovePermButton button + */ +class RemovePermButtonListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + private ToolDialog td; + private boolean edit; + + RemovePermButtonListener(PolicyTool tool, ToolWindow tw, + ToolDialog td, boolean edit) { + this.tool = tool; + this.tw = tw; + this.td = td; + this.edit = edit; + } + + public void actionPerformed(ActionEvent e) { + + // get the Permission selected from the Permission List + TaggedList permList = (TaggedList)td.getComponent(td.PE_PERM_LIST); + int permIndex = permList.getSelectedIndex(); + + if (permIndex < 0) { + tw.displayErrorDialog(td, new Exception + (PolicyTool.rb.getString("No permission selected"))); + return; + } + // remove the permission from the display + permList.removeTaggedItem(permIndex); + + } +} + +/** + * Event handler for Edit Principal button + * + * We need the editPolicyEntry boolean to tell us if the user is + * adding a new PolicyEntry at this time, or editing an existing entry. + * If the user is adding a new PolicyEntry, we ONLY update the + * GUI listing. If the user is editing an existing PolicyEntry, we + * update both the GUI listing and the actual PolicyEntry. + */ +class EditPrinButtonListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + private ToolDialog td; + private boolean editPolicyEntry; + + EditPrinButtonListener(PolicyTool tool, ToolWindow tw, + ToolDialog td, boolean editPolicyEntry) { + this.tool = tool; + this.tw = tw; + this.td = td; + this.editPolicyEntry = editPolicyEntry; + } + + public void actionPerformed(ActionEvent e) { + + // get the Principal selected from the Principal List + TaggedList list = (TaggedList)td.getComponent(td.PE_PRIN_LIST); + int prinIndex = list.getSelectedIndex(); + + if (prinIndex < 0) { + tw.displayErrorDialog(td, new Exception + (PolicyTool.rb.getString("No principal selected"))); + return; + } + td.displayPrincipalDialog(editPolicyEntry, true); + } +} + +/** + * Event handler for Edit Permission button + * + * We need the editPolicyEntry boolean to tell us if the user is + * adding a new PolicyEntry at this time, or editing an existing entry. + * If the user is adding a new PolicyEntry, we ONLY update the + * GUI listing. If the user is editing an existing PolicyEntry, we + * update both the GUI listing and the actual PolicyEntry. + */ +class EditPermButtonListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + private ToolDialog td; + private boolean editPolicyEntry; + + EditPermButtonListener(PolicyTool tool, ToolWindow tw, + ToolDialog td, boolean editPolicyEntry) { + this.tool = tool; + this.tw = tw; + this.td = td; + this.editPolicyEntry = editPolicyEntry; + } + + public void actionPerformed(ActionEvent e) { + + // get the Permission selected from the Permission List + List list = (List)td.getComponent(td.PE_PERM_LIST); + int permIndex = list.getSelectedIndex(); + + if (permIndex < 0) { + tw.displayErrorDialog(td, new Exception + (PolicyTool.rb.getString("No permission selected"))); + return; + } + td.displayPermissionDialog(editPolicyEntry, true); + } +} + +/** + * Event handler for Principal Popup Menu + */ +class PrincipalTypeMenuListener implements ItemListener { + + private ToolDialog td; + + PrincipalTypeMenuListener(ToolDialog td) { + this.td = td; + } + + public void itemStateChanged(ItemEvent e) { + + Choice prin = (Choice)td.getComponent(td.PRD_PRIN_CHOICE); + TextField prinField = + (TextField)td.getComponent(td.PRD_PRIN_TEXTFIELD); + TextField nameField = + (TextField)td.getComponent(td.PRD_NAME_TEXTFIELD); + + prin.getAccessibleContext().setAccessibleName( + PolicyTool.splitToWords((String)e.getItem())); + if (((String)e.getItem()).equals(td.PRIN_TYPE)) { + // ignore if they choose "Principal Type:" item + if (prinField.getText() != null && + prinField.getText().length() > 0) { + Prin inputPrin = td.getPrin(prinField.getText(), true); + prin.select(inputPrin.CLASS); + } + return; + } + + // if you change the principal, clear the name + if (prinField.getText().indexOf((String)e.getItem()) == -1) { + nameField.setText(""); + } + + // set the text in the textfield and also modify the + // pull-down choice menus to reflect the correct possible + // set of names and actions + Prin inputPrin = td.getPrin((String)e.getItem(), false); + if (inputPrin != null) { + prinField.setText(inputPrin.FULL_CLASS); + } + } +} + +/** + * Event handler for Permission Popup Menu + */ +class PermissionMenuListener implements ItemListener { + + private ToolDialog td; + + PermissionMenuListener(ToolDialog td) { + this.td = td; + } + + public void itemStateChanged(ItemEvent e) { + + Choice perms = (Choice)td.getComponent(td.PD_PERM_CHOICE); + Choice names = (Choice)td.getComponent(td.PD_NAME_CHOICE); + Choice actions = (Choice)td.getComponent(td.PD_ACTIONS_CHOICE); + TextField nameField = + (TextField)td.getComponent(td.PD_NAME_TEXTFIELD); + TextField actionsField = + (TextField)td.getComponent(td.PD_ACTIONS_TEXTFIELD); + TextField permField = (TextField)td.getComponent(td.PD_PERM_TEXTFIELD); + TextField signedbyField = + (TextField)td.getComponent(td.PD_SIGNEDBY_TEXTFIELD); + + perms.getAccessibleContext().setAccessibleName( + PolicyTool.splitToWords((String)e.getItem())); + + // ignore if they choose the 'Permission:' item + if (PolicyTool.collator.compare((String)e.getItem(), td.PERM) == 0) { + if (permField.getText() != null && + permField.getText().length() > 0) { + + Perm inputPerm = td.getPerm(permField.getText(), true); + if (inputPerm != null) { + perms.select(inputPerm.CLASS); + } + } + return; + } + + // if you change the permission, clear the name, actions, and signedBy + if (permField.getText().indexOf((String)e.getItem()) == -1) { + nameField.setText(""); + actionsField.setText(""); + signedbyField.setText(""); + } + + // set the text in the textfield and also modify the + // pull-down choice menus to reflect the correct possible + // set of names and actions + + Perm inputPerm = td.getPerm((String)e.getItem(), false); + if (inputPerm == null) { + permField.setText(""); + } else { + permField.setText(inputPerm.FULL_CLASS); + } + td.setPermissionNames(inputPerm, names, nameField); + td.setPermissionActions(inputPerm, actions, actionsField); + } +} + +/** + * Event handler for Permission Name Popup Menu + */ +class PermissionNameMenuListener implements ItemListener { + + private ToolDialog td; + + PermissionNameMenuListener(ToolDialog td) { + this.td = td; + } + + public void itemStateChanged(ItemEvent e) { + + Choice names = (Choice)td.getComponent(td.PD_NAME_CHOICE); + names.getAccessibleContext().setAccessibleName( + PolicyTool.splitToWords((String)e.getItem())); + + if (((String)e.getItem()).indexOf(td.PERM_NAME) != -1) + return; + + TextField tf = (TextField)td.getComponent(td.PD_NAME_TEXTFIELD); + tf.setText((String)e.getItem()); + } +} + +/** + * Event handler for Permission Actions Popup Menu + */ +class PermissionActionsMenuListener implements ItemListener { + + private ToolDialog td; + + PermissionActionsMenuListener(ToolDialog td) { + this.td = td; + } + + public void itemStateChanged(ItemEvent e) { + + Choice actions = (Choice)td.getComponent(td.PD_ACTIONS_CHOICE); + actions.getAccessibleContext().setAccessibleName((String)e.getItem()); + + if (((String)e.getItem()).indexOf(td.PERM_ACTIONS) != -1) + return; + + TextField tf = (TextField)td.getComponent(td.PD_ACTIONS_TEXTFIELD); + if (tf.getText() == null || tf.getText().equals("")) { + tf.setText((String)e.getItem()); + } else { + if (tf.getText().indexOf((String)e.getItem()) == -1) + tf.setText(tf.getText() + ", " + (String)e.getItem()); + } + } +} + +/** + * Event handler for all the children dialogs/windows + */ +class ChildWindowListener implements WindowListener { + + private ToolDialog td; + + ChildWindowListener(ToolDialog td) { + this.td = td; + } + + public void windowOpened(WindowEvent we) { + } + + public void windowClosing(WindowEvent we) { + // same as pressing the "cancel" button + td.setVisible(false); + td.dispose(); + } + + public void windowClosed(WindowEvent we) { + } + + public void windowIconified(WindowEvent we) { + } + + public void windowDeiconified(WindowEvent we) { + } + + public void windowActivated(WindowEvent we) { + } + + public void windowDeactivated(WindowEvent we) { + } +} + +/** + * Event handler for CancelButton button + */ +class CancelButtonListener implements ActionListener { + + private ToolDialog td; + + CancelButtonListener(ToolDialog td) { + this.td = td; + } + + public void actionPerformed(ActionEvent e) { + td.setVisible(false); + td.dispose(); + } +} + +/** + * Event handler for ErrorOKButton button + */ +class ErrorOKButtonListener implements ActionListener { + + private ToolDialog ed; + + ErrorOKButtonListener(ToolDialog ed) { + this.ed = ed; + } + + public void actionPerformed(ActionEvent e) { + ed.setVisible(false); + ed.dispose(); + } +} + +/** + * Event handler for StatusOKButton button + */ +class StatusOKButtonListener implements ActionListener { + + private ToolDialog sd; + + StatusOKButtonListener(ToolDialog sd) { + this.sd = sd; + } + + public void actionPerformed(ActionEvent e) { + sd.setVisible(false); + sd.dispose(); + } +} + +/** + * Event handler for UserSaveYes button + */ +class UserSaveYesButtonListener implements ActionListener { + + private ToolDialog us; + private PolicyTool tool; + private ToolWindow tw; + private int select; + + UserSaveYesButtonListener(ToolDialog us, PolicyTool tool, + ToolWindow tw, int select) { + this.us = us; + this.tool = tool; + this.tw = tw; + this.select = select; + } + + public void actionPerformed(ActionEvent e) { + + // first get rid of the window + us.setVisible(false); + us.dispose(); + + try { + String filename = ((TextField) + tw.getComponent(tw.MW_FILENAME_TEXTFIELD)).getText(); + if (filename == null || filename.equals("")) { + us.displaySaveAsDialog(select); + + // the above dialog will continue with the originally + // requested command if necessary + } else { + // save the policy entries to a file + tool.savePolicy(filename); + + // display status + MessageFormat form = new MessageFormat + (PolicyTool.rb.getString + ("Policy successfully written to filename")); + Object[] source = {filename}; + tw.displayStatusDialog(null, form.format(source)); + + // now continue with the originally requested command + // (QUIT, NEW, or OPEN) + us.userSaveContinue(tool, tw, us, select); + } + } catch (Exception ee) { + // error -- just report it and bail + tw.displayErrorDialog(null, ee); + } + } +} + +/** + * Event handler for UserSaveNoButton + */ +class UserSaveNoButtonListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + private ToolDialog us; + private int select; + + UserSaveNoButtonListener(ToolDialog us, PolicyTool tool, + ToolWindow tw, int select) { + this.us = us; + this.tool = tool; + this.tw = tw; + this.select = select; + } + + public void actionPerformed(ActionEvent e) { + us.setVisible(false); + us.dispose(); + + // now continue with the originally requested command + // (QUIT, NEW, or OPEN) + us.userSaveContinue(tool, tw, us, select); + } +} + +/** + * Event handler for UserSaveCancelButton + */ +class UserSaveCancelButtonListener implements ActionListener { + + private ToolDialog us; + + UserSaveCancelButtonListener(ToolDialog us) { + this.us = us; + } + + public void actionPerformed(ActionEvent e) { + us.setVisible(false); + us.dispose(); + + // do NOT continue with the originally requested command + // (QUIT, NEW, or OPEN) + } +} + +/** + * Event handler for ConfirmRemovePolicyEntryOKButtonListener + */ +class ConfirmRemovePolicyEntryOKButtonListener implements ActionListener { + + private PolicyTool tool; + private ToolWindow tw; + private ToolDialog us; + + ConfirmRemovePolicyEntryOKButtonListener(PolicyTool tool, + ToolWindow tw, ToolDialog us) { + this.tool = tool; + this.tw = tw; + this.us = us; + } + + public void actionPerformed(ActionEvent e) { + // remove the entry + List list = (List)tw.getComponent(tw.MW_POLICY_LIST); + int index = list.getSelectedIndex(); + PolicyEntry entries[] = tool.getEntry(); + tool.removeEntry(entries[index]); + + // redraw the window listing + list = new List(40, false); + list.addActionListener(new PolicyListListener(tool, tw)); + entries = tool.getEntry(); + if (entries != null) { + for (int i = 0; i < entries.length; i++) + list.add(entries[i].headerToString()); + } + tw.replacePolicyList(list); + us.setVisible(false); + us.dispose(); + } +} + +/** + * Just a special name, so that the codes dealing with this exception knows + * it's special, and does not pop out a warning box. + */ +class NoDisplayException extends RuntimeException { + +} + +/** + * This is a java.awt.List that bind an Object to each String it holds. + */ +class TaggedList extends List { + private java.util.List data = new LinkedList(); + public TaggedList(int i, boolean b) { + super(i, b); + } + + public Object getObject(int index) { + return data.get(index); + } + + @Override @Deprecated public void add(String string) { + throw new AssertionError("should not call add in TaggedList"); + } + public void addTaggedItem(String string, Object object) { + super.add(string); + data.add(object); + } + + @Override @Deprecated public void replaceItem(String string, int index) { + throw new AssertionError("should not call replaceItem in TaggedList"); + } + public void replaceTaggedItem(String string, Object object, int index) { + super.replaceItem(string, index); + data.set(index, object); + } + + @Override @Deprecated public void remove(int index) { + // Cannot throw AssertionError, because replaceItem() call remove() internally + super.remove(index); + } + public void removeTaggedItem(int index) { + super.remove(index); + data.remove(index); + } +} + +/** + * Convenience Principal Classes + */ + +class Prin { + public final String CLASS; + public final String FULL_CLASS; + + public Prin(String clazz, String fullClass) { + this.CLASS = clazz; + this.FULL_CLASS = fullClass; + } +} + +class KrbPrin extends Prin { + public KrbPrin() { + super("KerberosPrincipal", + "javax.security.auth.kerberos.KerberosPrincipal"); + } +} + +class X500Prin extends Prin { + public X500Prin() { + super("X500Principal", + "javax.security.auth.x500.X500Principal"); + } +} + +/** + * Convenience Permission Classes + */ + +class Perm { + public final String CLASS; + public final String FULL_CLASS; + public final String[] TARGETS; + public final String[] ACTIONS; + + public Perm(String clazz, String fullClass, + String[] targets, String[] actions) { + + this.CLASS = clazz; + this.FULL_CLASS = fullClass; + this.TARGETS = targets; + this.ACTIONS = actions; + } +} + +class AllPerm extends Perm { + public AllPerm() { + super("AllPermission", "java.security.AllPermission", null, null); + } +} + +class AudioPerm extends Perm { + public AudioPerm() { + super("AudioPermission", + "javax.sound.sampled.AudioPermission", + new String[] { + "play", + "record" + }, + null); + } +} + +class AuthPerm extends Perm { + public AuthPerm() { + super("AuthPermission", + "javax.security.auth.AuthPermission", + new String[] { + "doAs", + "doAsPrivileged", + "getSubject", + "getSubjectFromDomainCombiner", + "setReadOnly", + "modifyPrincipals", + "modifyPublicCredentials", + "modifyPrivateCredentials", + "refreshCredential", + "destroyCredential", + "createLoginContext.<" + PolicyTool.rb.getString("name") + ">", + "getLoginConfiguration", + "setLoginConfiguration", + "createLoginConfiguration.<" + + PolicyTool.rb.getString("configuration type") + ">", + "refreshLoginConfiguration" + }, + null); + } +} + +class AWTPerm extends Perm { + public AWTPerm() { + super("AWTPermission", + "java.awt.AWTPermission", + new String[] { + "accessClipboard", + "accessEventQueue", + "accessSystemTray", + "createRobot", + "fullScreenExclusive", + "listenToAllAWTEvents", + "readDisplayPixels", + "replaceKeyboardFocusManager", + "setAppletStub", + "setWindowAlwaysOnTop", + "showWindowWithoutWarningBanner", + "toolkitModality", + "watchMousePointer" + }, + null); + } +} + +class DelegationPerm extends Perm { + public DelegationPerm() { + super("DelegationPermission", + "javax.security.auth.kerberos.DelegationPermission", + new String[] { + // allow user input + }, + null); + } +} + +class FilePerm extends Perm { + public FilePerm() { + super("FilePermission", + "java.io.FilePermission", + new String[] { + "<>" + }, + new String[] { + "read", + "write", + "delete", + "execute" + }); + } +} + +class InqSecContextPerm extends Perm { + public InqSecContextPerm() { + super("InquireSecContextPermission", + "com.sun.security.jgss.InquireSecContextPermission", + new String[] { + "KRB5_GET_SESSION_KEY", + "KRB5_GET_TKT_FLAGS", + "KRB5_GET_AUTHZ_DATA", + "KRB5_GET_AUTHTIME" + }, + null); + } +} + +class LogPerm extends Perm { + public LogPerm() { + super("LoggingPermission", + "java.util.logging.LoggingPermission", + new String[] { + "control" + }, + null); + } +} + +class MgmtPerm extends Perm { + public MgmtPerm() { + super("ManagementPermission", + "java.lang.management.ManagementPermission", + new String[] { + "control", + "monitor" + }, + null); + } +} + +class MBeanPerm extends Perm { + public MBeanPerm() { + super("MBeanPermission", + "javax.management.MBeanPermission", + new String[] { + // allow user input + }, + new String[] { + "addNotificationListener", + "getAttribute", + "getClassLoader", + "getClassLoaderFor", + "getClassLoaderRepository", + "getDomains", + "getMBeanInfo", + "getObjectInstance", + "instantiate", + "invoke", + "isInstanceOf", + "queryMBeans", + "queryNames", + "registerMBean", + "removeNotificationListener", + "setAttribute", + "unregisterMBean" + }); + } +} + +class MBeanSvrPerm extends Perm { + public MBeanSvrPerm() { + super("MBeanServerPermission", + "javax.management.MBeanServerPermission", + new String[] { + "createMBeanServer", + "findMBeanServer", + "newMBeanServer", + "releaseMBeanServer" + }, + null); + } +} + +class MBeanTrustPerm extends Perm { + public MBeanTrustPerm() { + super("MBeanTrustPermission", + "javax.management.MBeanTrustPermission", + new String[] { + "register" + }, + null); + } +} + +class NetPerm extends Perm { + public NetPerm() { + super("NetPermission", + "java.net.NetPermission", + new String[] { + "setDefaultAuthenticator", + "requestPasswordAuthentication", + "specifyStreamHandler", + "setProxySelector", + "getProxySelector", + "setCookieHandler", + "getCookieHandler", + "setResponseCache", + "getResponseCache" + }, + null); + } +} + +class PrivCredPerm extends Perm { + public PrivCredPerm() { + super("PrivateCredentialPermission", + "javax.security.auth.PrivateCredentialPermission", + new String[] { + // allow user input + }, + new String[] { + "read" + }); + } +} + +class PropPerm extends Perm { + public PropPerm() { + super("PropertyPermission", + "java.util.PropertyPermission", + new String[] { + // allow user input + }, + new String[] { + "read", + "write" + }); + } +} + +class ReflectPerm extends Perm { + public ReflectPerm() { + super("ReflectPermission", + "java.lang.reflect.ReflectPermission", + new String[] { + "suppressAccessChecks" + }, + null); + } +} + +class RuntimePerm extends Perm { + public RuntimePerm() { + super("RuntimePermission", + "java.lang.RuntimePermission", + new String[] { + "createClassLoader", + "getClassLoader", + "setContextClassLoader", + "enableContextClassLoaderOverride", + "setSecurityManager", + "createSecurityManager", + "getenv.<" + + PolicyTool.rb.getString("environment variable name") + ">", + "exitVM", + "shutdownHooks", + "setFactory", + "setIO", + "modifyThread", + "stopThread", + "modifyThreadGroup", + "getProtectionDomain", + "readFileDescriptor", + "writeFileDescriptor", + "loadLibrary.<" + + PolicyTool.rb.getString("library name") + ">", + "accessClassInPackage.<" + + PolicyTool.rb.getString("package name")+">", + "defineClassInPackage.<" + + PolicyTool.rb.getString("package name")+">", + "accessDeclaredMembers", + "queuePrintJob", + "getStackTrace", + "setDefaultUncaughtExceptionHandler", + "preferences", + "usePolicy", + // "inheritedChannel" + }, + null); + } +} + +class SecurityPerm extends Perm { + public SecurityPerm() { + super("SecurityPermission", + "java.security.SecurityPermission", + new String[] { + "createAccessControlContext", + "getDomainCombiner", + "getPolicy", + "setPolicy", + "createPolicy.<" + + PolicyTool.rb.getString("policy type") + ">", + "getProperty.<" + + PolicyTool.rb.getString("property name") + ">", + "setProperty.<" + + PolicyTool.rb.getString("property name") + ">", + "insertProvider.<" + + PolicyTool.rb.getString("provider name") + ">", + "removeProvider.<" + + PolicyTool.rb.getString("provider name") + ">", + //"setSystemScope", + //"setIdentityPublicKey", + //"setIdentityInfo", + //"addIdentityCertificate", + //"removeIdentityCertificate", + //"printIdentity", + "clearProviderProperties.<" + + PolicyTool.rb.getString("provider name") + ">", + "putProviderProperty.<" + + PolicyTool.rb.getString("provider name") + ">", + "removeProviderProperty.<" + + PolicyTool.rb.getString("provider name") + ">", + //"getSignerPrivateKey", + //"setSignerKeyPair" + }, + null); + } +} + +class SerialPerm extends Perm { + public SerialPerm() { + super("SerializablePermission", + "java.io.SerializablePermission", + new String[] { + "enableSubclassImplementation", + "enableSubstitution" + }, + null); + } +} + +class ServicePerm extends Perm { + public ServicePerm() { + super("ServicePermission", + "javax.security.auth.kerberos.ServicePermission", + new String[] { + // allow user input + }, + new String[] { + "initiate", + "accept" + }); + } +} + +class SocketPerm extends Perm { + public SocketPerm() { + super("SocketPermission", + "java.net.SocketPermission", + new String[] { + // allow user input + }, + new String[] { + "accept", + "connect", + "listen", + "resolve" + }); + } +} + +class SQLPerm extends Perm { + public SQLPerm() { + super("SQLPermission", + "java.sql.SQLPermission", + new String[] { + "setLog" + }, + null); + } +} + +class SSLPerm extends Perm { + public SSLPerm() { + super("SSLPermission", + "javax.net.ssl.SSLPermission", + new String[] { + "setHostnameVerifier", + "getSSLSessionContext" + }, + null); + } +} + +class SubjDelegPerm extends Perm { + public SubjDelegPerm() { + super("SubjectDelegationPermission", + "javax.management.remote.SubjectDelegationPermission", + new String[] { + // allow user input + }, + null); + } +} -- cgit v1.2.3 From 43926c8c6ca5ba5ef1318b84719d54a2fa628914 Mon Sep 17 00:00:00 2001 From: sherman Date: Tue, 18 May 2010 15:36:47 -0700 Subject: 6945564: Unicode script support in Character class 6948903: Make Unicode scripts available for use in regular expressions Summary: added Unicode script suport Reviewed-by: martin --- src/share/classes/java/lang/Character.java | 1283 ++++++++++++++++++++++++ src/share/classes/java/lang/CharacterName.java | 106 ++ src/share/classes/java/util/regex/Pattern.java | 101 +- 3 files changed, 1473 insertions(+), 17 deletions(-) create mode 100644 src/share/classes/java/lang/CharacterName.java (limited to 'src/share') diff --git a/src/share/classes/java/lang/Character.java b/src/share/classes/java/lang/Character.java index 8f106a473..265882c50 100644 --- a/src/share/classes/java/lang/Character.java +++ b/src/share/classes/java/lang/Character.java @@ -24,6 +24,7 @@ */ package java.lang; +import java.util.Arrays; import java.util.Map; import java.util.HashMap; import java.util.Locale; @@ -2546,6 +2547,1241 @@ class Character extends Object implements java.io.Serializable, Comparable + * Unicode Standard Annex #24: Script Names. Every Unicode + * character is assigned to a single Unicode script, either a specific + * script, such as {@link Character.UnicodeScript#LATIN Latin}, or + * one of the following three special values, + * {@link Character.UnicodeScript#INHERITED Inherited}, + * {@link Character.UnicodeScript#COMMON Common} or + * {@link Character.UnicodeScript#UNKNOWN Unknown}. + * + * @since 1.7 + */ + public static enum UnicodeScript { + /** + * Unicode script "Common". + */ + COMMON, + + /** + * Unicode script "Latin". + */ + LATIN, + + /** + * Unicode script "Greek". + */ + GREEK, + + /** + * Unicode script "Cyrillic". + */ + CYRILLIC, + + /** + * Unicode script "Armenian". + */ + ARMENIAN, + + /** + * Unicode script "Hebrew". + */ + HEBREW, + + /** + * Unicode script "Arabic". + */ + ARABIC, + + /** + * Unicode script "Syriac". + */ + SYRIAC, + + /** + * Unicode script "Thaana". + */ + THAANA, + + /** + * Unicode script "Devanagari". + */ + DEVANAGARI, + + /** + * Unicode script "Bengali". + */ + BENGALI, + + /** + * Unicode script "Gurmukhi". + */ + GURMUKHI, + + /** + * Unicode script "Gujarati". + */ + GUJARATI, + + /** + * Unicode script "Oriya". + */ + ORIYA, + + /** + * Unicode script "Tamil". + */ + TAMIL, + + /** + * Unicode script "Telugu". + */ + TELUGU, + + /** + * Unicode script "Kannada". + */ + KANNADA, + + /** + * Unicode script "Malayalam". + */ + MALAYALAM, + + /** + * Unicode script "Sinhala". + */ + SINHALA, + + /** + * Unicode script "Thai". + */ + THAI, + + /** + * Unicode script "Lao". + */ + LAO, + + /** + * Unicode script "Tibetan". + */ + TIBETAN, + + /** + * Unicode script "Myanmar". + */ + MYANMAR, + + /** + * Unicode script "Georgian". + */ + GEORGIAN, + + /** + * Unicode script "Hangul". + */ + HANGUL, + + /** + * Unicode script "Ethiopic". + */ + ETHIOPIC, + + /** + * Unicode script "Cherokee". + */ + CHEROKEE, + + /** + * Unicode script "Canadian_Aboriginal". + */ + CANADIAN_ABORIGINAL, + + /** + * Unicode script "Ogham". + */ + OGHAM, + + /** + * Unicode script "Runic". + */ + RUNIC, + + /** + * Unicode script "Khmer". + */ + KHMER, + + /** + * Unicode script "Mongolian". + */ + MONGOLIAN, + + /** + * Unicode script "Hiragana". + */ + HIRAGANA, + + /** + * Unicode script "Katakana". + */ + KATAKANA, + + /** + * Unicode script "Bopomofo". + */ + BOPOMOFO, + + /** + * Unicode script "Han". + */ + HAN, + + /** + * Unicode script "Yi". + */ + YI, + + /** + * Unicode script "Old_Italic". + */ + OLD_ITALIC, + + /** + * Unicode script "Gothic". + */ + GOTHIC, + + /** + * Unicode script "Deseret". + */ + DESERET, + + /** + * Unicode script "Inherited". + */ + INHERITED, + + /** + * Unicode script "Tagalog". + */ + TAGALOG, + + /** + * Unicode script "Hanunoo". + */ + HANUNOO, + + /** + * Unicode script "Buhid". + */ + BUHID, + + /** + * Unicode script "Tagbanwa". + */ + TAGBANWA, + + /** + * Unicode script "Limbu". + */ + LIMBU, + + /** + * Unicode script "Tai_Le". + */ + TAI_LE, + + /** + * Unicode script "Linear_B". + */ + LINEAR_B, + + /** + * Unicode script "Ugaritic". + */ + UGARITIC, + + /** + * Unicode script "Shavian". + */ + SHAVIAN, + + /** + * Unicode script "Osmanya". + */ + OSMANYA, + + /** + * Unicode script "Cypriot". + */ + CYPRIOT, + + /** + * Unicode script "Braille". + */ + BRAILLE, + + /** + * Unicode script "Buginese". + */ + BUGINESE, + + /** + * Unicode script "Coptic". + */ + COPTIC, + + /** + * Unicode script "New_Tai_Lue". + */ + NEW_TAI_LUE, + + /** + * Unicode script "Glagolitic". + */ + GLAGOLITIC, + + /** + * Unicode script "Tifinagh". + */ + TIFINAGH, + + /** + * Unicode script "Syloti_Nagri". + */ + SYLOTI_NAGRI, + + /** + * Unicode script "Old_Persian". + */ + OLD_PERSIAN, + + /** + * Unicode script "Kharoshthi". + */ + KHAROSHTHI, + + /** + * Unicode script "Balinese". + */ + BALINESE, + + /** + * Unicode script "Cuneiform". + */ + CUNEIFORM, + + /** + * Unicode script "Phoenician". + */ + PHOENICIAN, + + /** + * Unicode script "Phags_Pa". + */ + PHAGS_PA, + + /** + * Unicode script "Nko". + */ + NKO, + + /** + * Unicode script "Sundanese". + */ + SUNDANESE, + + /** + * Unicode script "Lepcha". + */ + LEPCHA, + + /** + * Unicode script "Ol_Chiki". + */ + OL_CHIKI, + + /** + * Unicode script "Vai". + */ + VAI, + + /** + * Unicode script "Saurashtra". + */ + SAURASHTRA, + + /** + * Unicode script "Kayah_Li". + */ + KAYAH_LI, + + /** + * Unicode script "Rejang". + */ + REJANG, + + /** + * Unicode script "Lycian". + */ + LYCIAN, + + /** + * Unicode script "Carian". + */ + CARIAN, + + /** + * Unicode script "Lydian". + */ + LYDIAN, + + /** + * Unicode script "Cham". + */ + CHAM, + + /** + * Unicode script "Tai_Tham". + */ + TAI_THAM, + + /** + * Unicode script "Tai_Viet". + */ + TAI_VIET, + + /** + * Unicode script "Avestan". + */ + AVESTAN, + + /** + * Unicode script "Egyptian_Hieroglyphs". + */ + EGYPTIAN_HIEROGLYPHS, + + /** + * Unicode script "Samaritan". + */ + SAMARITAN, + + /** + * Unicode script "Lisu". + */ + LISU, + + /** + * Unicode script "Bamum". + */ + BAMUM, + + /** + * Unicode script "Javanese". + */ + JAVANESE, + + /** + * Unicode script "Meetei_Mayek". + */ + MEETEI_MAYEK, + + /** + * Unicode script "Imperial_Aramaic". + */ + IMPERIAL_ARAMAIC, + + /** + * Unicode script "Old_South_Arabian". + */ + OLD_SOUTH_ARABIAN, + + /** + * Unicode script "Inscriptional_Parthian". + */ + INSCRIPTIONAL_PARTHIAN, + + /** + * Unicode script "Inscriptional_Pahlavi". + */ + INSCRIPTIONAL_PAHLAVI, + + /** + * Unicode script "Old_Turkic". + */ + OLD_TURKIC, + + /** + * Unicode script "Kaithi". + */ + KAITHI, + + /** + * Unicode script "Unknown". + */ + UNKNOWN; + + private static final int[] scriptStarts = { + 0x0000, // 0000..0040; COMMON + 0x0041, // 0041..005A; LATIN + 0x005B, // 005B..0060; COMMON + 0x0061, // 0061..007A; LATIN + 0x007B, // 007B..00A9; COMMON + 0x00AA, // 00AA..00AA; LATIN + 0x00AB, // 00AB..00B9; COMMON + 0x00BA, // 00BA..00BA; LATIN + 0x00BB, // 00BB..00BF; COMMON + 0x00C0, // 00C0..00D6; LATIN + 0x00D7, // 00D7..00D7; COMMON + 0x00D8, // 00D8..00F6; LATIN + 0x00F7, // 00F7..00F7; COMMON + 0x00F8, // 00F8..02B8; LATIN + 0x02B9, // 02B9..02DF; COMMON + 0x02E0, // 02E0..02E4; LATIN + 0x02E5, // 02E5..02FF; COMMON + 0x0300, // 0300..036F; INHERITED + 0x0370, // 0370..0373; GREEK + 0x0374, // 0374..0374; COMMON + 0x0375, // 0375..037D; GREEK + 0x037E, // 037E..0383; COMMON + 0x0384, // 0384..0384; GREEK + 0x0385, // 0385..0385; COMMON + 0x0386, // 0386..0386; GREEK + 0x0387, // 0387..0387; COMMON + 0x0388, // 0388..03E1; GREEK + 0x03E2, // 03E2..03EF; COPTIC + 0x03F0, // 03F0..03FF; GREEK + 0x0400, // 0400..0484; CYRILLIC + 0x0485, // 0485..0486; INHERITED + 0x0487, // 0487..0530; CYRILLIC + 0x0531, // 0531..0588; ARMENIAN + 0x0589, // 0589..0589; COMMON + 0x058A, // 058A..0590; ARMENIAN + 0x0591, // 0591..05FF; HEBREW + 0x0600, // 0600..0605; COMMON + 0x0606, // 0606..060B; ARABIC + 0x060C, // 060C..060C; COMMON + 0x060D, // 060D..061A; ARABIC + 0x061B, // 061B..061D; COMMON + 0x061E, // 061E..061E; ARABIC + 0x061F, // 061F..0620; COMMON + 0x0621, // 0621..063F; ARABIC + 0x0640, // 0640..0640; COMMON + 0x0641, // 0641..064A; ARABIC + 0x064B, // 064B..0655; INHERITED + 0x0656, // 0656..065F; ARABIC + 0x0660, // 0660..0669; COMMON + 0x066A, // 066A..066F; ARABIC + 0x0670, // 0670..0670; INHERITED + 0x0671, // 0671..06DC; ARABIC + 0x06DD, // 06DD..06DD; COMMON + 0x06DE, // 06DE..06FF; ARABIC + 0x0700, // 0700..074F; SYRIAC + 0x0750, // 0750..077F; ARABIC + 0x0780, // 0780..07BF; THAANA + 0x07C0, // 07C0..07FF; NKO + 0x0800, // 0800..08FF; SAMARITAN + 0x0900, // 0900..0950; DEVANAGARI + 0x0951, // 0951..0952; INHERITED + 0x0953, // 0953..0963; DEVANAGARI + 0x0964, // 0964..0965; COMMON + 0x0966, // 0966..096F; DEVANAGARI + 0x0970, // 0970..0970; COMMON + 0x0971, // 0971..0980; DEVANAGARI + 0x0981, // 0981..0A00; BENGALI + 0x0A01, // 0A01..0A80; GURMUKHI + 0x0A81, // 0A81..0B00; GUJARATI + 0x0B01, // 0B01..0B81; ORIYA + 0x0B82, // 0B82..0C00; TAMIL + 0x0C01, // 0C01..0C81; TELUGU + 0x0C82, // 0C82..0CF0; KANNADA + 0x0CF1, // 0CF1..0D01; COMMON + 0x0D02, // 0D02..0D81; MALAYALAM + 0x0D82, // 0D82..0E00; SINHALA + 0x0E01, // 0E01..0E3E; THAI + 0x0E3F, // 0E3F..0E3F; COMMON + 0x0E40, // 0E40..0E80; THAI + 0x0E81, // 0E81..0EFF; LAO + 0x0F00, // 0F00..0FD4; TIBETAN + 0x0FD5, // 0FD5..0FFF; COMMON + 0x1000, // 1000..109F; MYANMAR + 0x10A0, // 10A0..10FA; GEORGIAN + 0x10FB, // 10FB..10FB; COMMON + 0x10FC, // 10FC..10FF; GEORGIAN + 0x1100, // 1100..11FF; HANGUL + 0x1200, // 1200..139F; ETHIOPIC + 0x13A0, // 13A0..13FF; CHEROKEE + 0x1400, // 1400..167F; CANADIAN_ABORIGINAL + 0x1680, // 1680..169F; OGHAM + 0x16A0, // 16A0..16EA; RUNIC + 0x16EB, // 16EB..16ED; COMMON + 0x16EE, // 16EE..16FF; RUNIC + 0x1700, // 1700..171F; TAGALOG + 0x1720, // 1720..1734; HANUNOO + 0x1735, // 1735..173F; COMMON + 0x1740, // 1740..175F; BUHID + 0x1760, // 1760..177F; TAGBANWA + 0x1780, // 1780..17FF; KHMER + 0x1800, // 1800..1801; MONGOLIAN + 0x1802, // 1802..1803; COMMON + 0x1804, // 1804..1804; MONGOLIAN + 0x1805, // 1805..1805; COMMON + 0x1806, // 1806..18AF; MONGOLIAN + 0x18B0, // 18B0..18FF; CANADIAN_ABORIGINAL + 0x1900, // 1900..194F; LIMBU + 0x1950, // 1950..197F; TAI_LE + 0x1980, // 1980..19DF; NEW_TAI_LUE + 0x19E0, // 19E0..19FF; KHMER + 0x1A00, // 1A00..1A1F; BUGINESE + 0x1A20, // 1A20..1AFF; TAI_THAM + 0x1B00, // 1B00..1B7F; BALINESE + 0x1B80, // 1B80..1BFF; SUNDANESE + 0x1C00, // 1C00..1C4F; LEPCHA + 0x1C50, // 1C50..1CCF; OL_CHIKI + 0x1CD0, // 1CD0..1CD2; INHERITED + 0x1CD3, // 1CD3..1CD3; COMMON + 0x1CD4, // 1CD4..1CE0; INHERITED + 0x1CE1, // 1CE1..1CE1; COMMON + 0x1CE2, // 1CE2..1CE8; INHERITED + 0x1CE9, // 1CE9..1CEC; COMMON + 0x1CED, // 1CED..1CED; INHERITED + 0x1CEE, // 1CEE..1CFF; COMMON + 0x1D00, // 1D00..1D25; LATIN + 0x1D26, // 1D26..1D2A; GREEK + 0x1D2B, // 1D2B..1D2B; CYRILLIC + 0x1D2C, // 1D2C..1D5C; LATIN + 0x1D5D, // 1D5D..1D61; GREEK + 0x1D62, // 1D62..1D65; LATIN + 0x1D66, // 1D66..1D6A; GREEK + 0x1D6B, // 1D6B..1D77; LATIN + 0x1D78, // 1D78..1D78; CYRILLIC + 0x1D79, // 1D79..1DBE; LATIN + 0x1DBF, // 1DBF..1DBF; GREEK + 0x1DC0, // 1DC0..1DFF; INHERITED + 0x1E00, // 1E00..1EFF; LATIN + 0x1F00, // 1F00..1FFF; GREEK + 0x2000, // 2000..200B; COMMON + 0x200C, // 200C..200D; INHERITED + 0x200E, // 200E..2070; COMMON + 0x2071, // 2071..2073; LATIN + 0x2074, // 2074..207E; COMMON + 0x207F, // 207F..207F; LATIN + 0x2080, // 2080..208F; COMMON + 0x2090, // 2090..209F; LATIN + 0x20A0, // 20A0..20CF; COMMON + 0x20D0, // 20D0..20FF; INHERITED + 0x2100, // 2100..2125; COMMON + 0x2126, // 2126..2126; GREEK + 0x2127, // 2127..2129; COMMON + 0x212A, // 212A..212B; LATIN + 0x212C, // 212C..2131; COMMON + 0x2132, // 2132..2132; LATIN + 0x2133, // 2133..214D; COMMON + 0x214E, // 214E..214E; LATIN + 0x214F, // 214F..215F; COMMON + 0x2160, // 2160..2188; LATIN + 0x2189, // 2189..27FF; COMMON + 0x2800, // 2800..28FF; BRAILLE + 0x2900, // 2900..2BFF; COMMON + 0x2C00, // 2C00..2C5F; GLAGOLITIC + 0x2C60, // 2C60..2C7F; LATIN + 0x2C80, // 2C80..2CFF; COPTIC + 0x2D00, // 2D00..2D2F; GEORGIAN + 0x2D30, // 2D30..2D7F; TIFINAGH + 0x2D80, // 2D80..2DDF; ETHIOPIC + 0x2DE0, // 2DE0..2DFF; CYRILLIC + 0x2E00, // 2E00..2E7F; COMMON + 0x2E80, // 2E80..2FEF; HAN + 0x2FF0, // 2FF0..3004; COMMON + 0x3005, // 3005..3005; HAN + 0x3006, // 3006..3006; COMMON + 0x3007, // 3007..3007; HAN + 0x3008, // 3008..3020; COMMON + 0x3021, // 3021..3029; HAN + 0x302A, // 302A..302F; INHERITED + 0x3030, // 3030..3037; COMMON + 0x3038, // 3038..303B; HAN + 0x303C, // 303C..3040; COMMON + 0x3041, // 3041..3098; HIRAGANA + 0x3099, // 3099..309A; INHERITED + 0x309B, // 309B..309C; COMMON + 0x309D, // 309D..309F; HIRAGANA + 0x30A0, // 30A0..30A0; COMMON + 0x30A1, // 30A1..30FA; KATAKANA + 0x30FB, // 30FB..30FC; COMMON + 0x30FD, // 30FD..3104; KATAKANA + 0x3105, // 3105..3130; BOPOMOFO + 0x3131, // 3131..318F; HANGUL + 0x3190, // 3190..319F; COMMON + 0x31A0, // 31A0..31BF; BOPOMOFO + 0x31C0, // 31C0..31EF; COMMON + 0x31F0, // 31F0..31FF; KATAKANA + 0x3200, // 3200..321F; HANGUL + 0x3220, // 3220..325F; COMMON + 0x3260, // 3260..327E; HANGUL + 0x327F, // 327F..32CF; COMMON + 0x32D0, // 32D0..3357; KATAKANA + 0x3358, // 3358..33FF; COMMON + 0x3400, // 3400..4DBF; HAN + 0x4DC0, // 4DC0..4DFF; COMMON + 0x4E00, // 4E00..9FFF; HAN + 0xA000, // A000..A4CF; YI + 0xA4D0, // A4D0..A4FF; LISU + 0xA500, // A500..A63F; VAI + 0xA640, // A640..A69F; CYRILLIC + 0xA6A0, // A6A0..A6FF; BAMUM + 0xA700, // A700..A721; COMMON + 0xA722, // A722..A787; LATIN + 0xA788, // A788..A78A; COMMON + 0xA78B, // A78B..A7FF; LATIN + 0xA800, // A800..A82F; SYLOTI_NAGRI + 0xA830, // A830..A83F; COMMON + 0xA840, // A840..A87F; PHAGS_PA + 0xA880, // A880..A8DF; SAURASHTRA + 0xA8E0, // A8E0..A8FF; DEVANAGARI + 0xA900, // A900..A92F; KAYAH_LI + 0xA930, // A930..A95F; REJANG + 0xA960, // A960..A97F; HANGUL + 0xA980, // A980..A9FF; JAVANESE + 0xAA00, // AA00..AA5F; CHAM + 0xAA60, // AA60..AA7F; MYANMAR + 0xAA80, // AA80..ABBF; TAI_VIET + 0xABC0, // ABC0..ABFF; MEETEI_MAYEK + 0xAC00, // AC00..D7FB; HANGUL + 0xD7FC, // D7FC..F8FF; UNKNOWN + 0xF900, // F900..FAFF; HAN + 0xFB00, // FB00..FB12; LATIN + 0xFB13, // FB13..FB1C; ARMENIAN + 0xFB1D, // FB1D..FB4F; HEBREW + 0xFB50, // FB50..FD3D; ARABIC + 0xFD3E, // FD3E..FD4F; COMMON + 0xFD50, // FD50..FDFC; ARABIC + 0xFDFD, // FDFD..FDFF; COMMON + 0xFE00, // FE00..FE0F; INHERITED + 0xFE10, // FE10..FE1F; COMMON + 0xFE20, // FE20..FE2F; INHERITED + 0xFE30, // FE30..FE6F; COMMON + 0xFE70, // FE70..FEFE; ARABIC + 0xFEFF, // FEFF..FF20; COMMON + 0xFF21, // FF21..FF3A; LATIN + 0xFF3B, // FF3B..FF40; COMMON + 0xFF41, // FF41..FF5A; LATIN + 0xFF5B, // FF5B..FF65; COMMON + 0xFF66, // FF66..FF6F; KATAKANA + 0xFF70, // FF70..FF70; COMMON + 0xFF71, // FF71..FF9D; KATAKANA + 0xFF9E, // FF9E..FF9F; COMMON + 0xFFA0, // FFA0..FFDF; HANGUL + 0xFFE0, // FFE0..FFFF; COMMON + 0x10000, // 10000..100FF; LINEAR_B + 0x10100, // 10100..1013F; COMMON + 0x10140, // 10140..1018F; GREEK + 0x10190, // 10190..101FC; COMMON + 0x101FD, // 101FD..1027F; INHERITED + 0x10280, // 10280..1029F; LYCIAN + 0x102A0, // 102A0..102FF; CARIAN + 0x10300, // 10300..1032F; OLD_ITALIC + 0x10330, // 10330..1037F; GOTHIC + 0x10380, // 10380..1039F; UGARITIC + 0x103A0, // 103A0..103FF; OLD_PERSIAN + 0x10400, // 10400..1044F; DESERET + 0x10450, // 10450..1047F; SHAVIAN + 0x10480, // 10480..107FF; OSMANYA + 0x10800, // 10800..1083F; CYPRIOT + 0x10840, // 10840..108FF; IMPERIAL_ARAMAIC + 0x10900, // 10900..1091F; PHOENICIAN + 0x10920, // 10920..109FF; LYDIAN + 0x10A00, // 10A00..10A5F; KHAROSHTHI + 0x10A60, // 10A60..10AFF; OLD_SOUTH_ARABIAN + 0x10B00, // 10B00..10B3F; AVESTAN + 0x10B40, // 10B40..10B5F; INSCRIPTIONAL_PARTHIAN + 0x10B60, // 10B60..10BFF; INSCRIPTIONAL_PAHLAVI + 0x10C00, // 10C00..10E5F; OLD_TURKIC + 0x10E60, // 10E60..1107F; ARABIC + 0x11080, // 11080..11FFF; KAITHI + 0x12000, // 12000..12FFF; CUNEIFORM + 0x13000, // 13000..1CFFF; EGYPTIAN_HIEROGLYPHS + 0x1D000, // 1D000..1D166; COMMON + 0x1D167, // 1D167..1D169; INHERITED + 0x1D16A, // 1D16A..1D17A; COMMON + 0x1D17B, // 1D17B..1D182; INHERITED + 0x1D183, // 1D183..1D184; COMMON + 0x1D185, // 1D185..1D18B; INHERITED + 0x1D18C, // 1D18C..1D1A9; COMMON + 0x1D1AA, // 1D1AA..1D1AD; INHERITED + 0x1D1AE, // 1D1AE..1D1FF; COMMON + 0x1D200, // 1D200..1D2FF; GREEK + 0x1D300, // 1D300..1F1FF; COMMON + 0x1F200, // 1F200..1F20F; HIRAGANA + 0x1F210, // 1F210..1FFFF; COMMON + 0x20000, // 20000..E0000; HAN + 0xE0001, // E0001..E00FF; COMMON + 0xE0100, // E0100..E01EF; INHERITED + 0xE01F0 // E01F0..10FFFF; UNKNOWN + + }; + + private static final UnicodeScript[] scripts = { + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + INHERITED, + GREEK, + COMMON, + GREEK, + COMMON, + GREEK, + COMMON, + GREEK, + COMMON, + GREEK, + COPTIC, + GREEK, + CYRILLIC, + INHERITED, + CYRILLIC, + ARMENIAN, + COMMON, + ARMENIAN, + HEBREW, + COMMON, + ARABIC, + COMMON, + ARABIC, + COMMON, + ARABIC, + COMMON, + ARABIC, + COMMON, + ARABIC, + INHERITED, + ARABIC, + COMMON, + ARABIC, + INHERITED, + ARABIC, + COMMON, + ARABIC, + SYRIAC, + ARABIC, + THAANA, + NKO, + SAMARITAN, + DEVANAGARI, + INHERITED, + DEVANAGARI, + COMMON, + DEVANAGARI, + COMMON, + DEVANAGARI, + BENGALI, + GURMUKHI, + GUJARATI, + ORIYA, + TAMIL, + TELUGU, + KANNADA, + COMMON, + MALAYALAM, + SINHALA, + THAI, + COMMON, + THAI, + LAO, + TIBETAN, + COMMON, + MYANMAR, + GEORGIAN, + COMMON, + GEORGIAN, + HANGUL, + ETHIOPIC, + CHEROKEE, + CANADIAN_ABORIGINAL, + OGHAM, + RUNIC, + COMMON, + RUNIC, + TAGALOG, + HANUNOO, + COMMON, + BUHID, + TAGBANWA, + KHMER, + MONGOLIAN, + COMMON, + MONGOLIAN, + COMMON, + MONGOLIAN, + CANADIAN_ABORIGINAL, + LIMBU, + TAI_LE, + NEW_TAI_LUE, + KHMER, + BUGINESE, + TAI_THAM, + BALINESE, + SUNDANESE, + LEPCHA, + OL_CHIKI, + INHERITED, + COMMON, + INHERITED, + COMMON, + INHERITED, + COMMON, + INHERITED, + COMMON, + LATIN, + GREEK, + CYRILLIC, + LATIN, + GREEK, + LATIN, + GREEK, + LATIN, + CYRILLIC, + LATIN, + GREEK, + INHERITED, + LATIN, + GREEK, + COMMON, + INHERITED, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + INHERITED, + COMMON, + GREEK, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + BRAILLE, + COMMON, + GLAGOLITIC, + LATIN, + COPTIC, + GEORGIAN, + TIFINAGH, + ETHIOPIC, + CYRILLIC, + COMMON, + HAN, + COMMON, + HAN, + COMMON, + HAN, + COMMON, + HAN, + INHERITED, + COMMON, + HAN, + COMMON, + HIRAGANA, + INHERITED, + COMMON, + HIRAGANA, + COMMON, + KATAKANA, + COMMON, + KATAKANA, + BOPOMOFO, + HANGUL, + COMMON, + BOPOMOFO, + COMMON, + KATAKANA, + HANGUL, + COMMON, + HANGUL, + COMMON, + KATAKANA, + COMMON, + HAN, + COMMON, + HAN, + YI, + LISU, + VAI, + CYRILLIC, + BAMUM, + COMMON, + LATIN, + COMMON, + LATIN, + SYLOTI_NAGRI, + COMMON, + PHAGS_PA, + SAURASHTRA, + DEVANAGARI, + KAYAH_LI, + REJANG, + HANGUL, + JAVANESE, + CHAM, + MYANMAR, + TAI_VIET, + MEETEI_MAYEK, + HANGUL, + UNKNOWN, + HAN, + LATIN, + ARMENIAN, + HEBREW, + ARABIC, + COMMON, + ARABIC, + COMMON, + INHERITED, + COMMON, + INHERITED, + COMMON, + ARABIC, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + KATAKANA, + COMMON, + KATAKANA, + COMMON, + HANGUL, + COMMON, + LINEAR_B, + COMMON, + GREEK, + COMMON, + INHERITED, + LYCIAN, + CARIAN, + OLD_ITALIC, + GOTHIC, + UGARITIC, + OLD_PERSIAN, + DESERET, + SHAVIAN, + OSMANYA, + CYPRIOT, + IMPERIAL_ARAMAIC, + PHOENICIAN, + LYDIAN, + KHAROSHTHI, + OLD_SOUTH_ARABIAN, + AVESTAN, + INSCRIPTIONAL_PARTHIAN, + INSCRIPTIONAL_PAHLAVI, + OLD_TURKIC, + ARABIC, + KAITHI, + CUNEIFORM, + EGYPTIAN_HIEROGLYPHS, + COMMON, + INHERITED, + COMMON, + INHERITED, + COMMON, + INHERITED, + COMMON, + INHERITED, + COMMON, + GREEK, + COMMON, + HIRAGANA, + COMMON, + HAN, + COMMON, + INHERITED, + UNKNOWN + }; + + private static HashMap aliases; + static { + aliases = new HashMap(); + aliases.put("ARAB", ARABIC); + aliases.put("ARMI", IMPERIAL_ARAMAIC); + aliases.put("ARMN", ARMENIAN); + aliases.put("AVST", AVESTAN); + aliases.put("BALI", BALINESE); + aliases.put("BAMU", BAMUM); + aliases.put("BENG", BENGALI); + aliases.put("BOPO", BOPOMOFO); + aliases.put("BRAI", BRAILLE); + aliases.put("BUGI", BUGINESE); + aliases.put("BUHD", BUHID); + aliases.put("CANS", CANADIAN_ABORIGINAL); + aliases.put("CARI", CARIAN); + aliases.put("CHAM", CHAM); + aliases.put("CHER", CHEROKEE); + aliases.put("COPT", COPTIC); + aliases.put("CPRT", CYPRIOT); + aliases.put("CYRL", CYRILLIC); + aliases.put("DEVA", DEVANAGARI); + aliases.put("DSRT", DESERET); + aliases.put("EGYP", EGYPTIAN_HIEROGLYPHS); + aliases.put("ETHI", ETHIOPIC); + aliases.put("GEOR", GEORGIAN); + aliases.put("GLAG", GLAGOLITIC); + aliases.put("GOTH", GOTHIC); + aliases.put("GREK", GREEK); + aliases.put("GUJR", GUJARATI); + aliases.put("GURU", GURMUKHI); + aliases.put("HANG", HANGUL); + aliases.put("HANI", HAN); + aliases.put("HANO", HANUNOO); + aliases.put("HEBR", HEBREW); + aliases.put("HIRA", HIRAGANA); + // it appears we don't have the KATAKANA_OR_HIRAGANA + //aliases.put("HRKT", KATAKANA_OR_HIRAGANA); + aliases.put("ITAL", OLD_ITALIC); + aliases.put("JAVA", JAVANESE); + aliases.put("KALI", KAYAH_LI); + aliases.put("KANA", KATAKANA); + aliases.put("KHAR", KHAROSHTHI); + aliases.put("KHMR", KHMER); + aliases.put("KNDA", KANNADA); + aliases.put("KTHI", KAITHI); + aliases.put("LANA", TAI_THAM); + aliases.put("LAOO", LAO); + aliases.put("LATN", LATIN); + aliases.put("LEPC", LEPCHA); + aliases.put("LIMB", LIMBU); + aliases.put("LINB", LINEAR_B); + aliases.put("LISU", LISU); + aliases.put("LYCI", LYCIAN); + aliases.put("LYDI", LYDIAN); + aliases.put("MLYM", MALAYALAM); + aliases.put("MONG", MONGOLIAN); + aliases.put("MTEI", MEETEI_MAYEK); + aliases.put("MYMR", MYANMAR); + aliases.put("NKOO", NKO); + aliases.put("OGAM", OGHAM); + aliases.put("OLCK", OL_CHIKI); + aliases.put("ORKH", OLD_TURKIC); + aliases.put("ORYA", ORIYA); + aliases.put("OSMA", OSMANYA); + aliases.put("PHAG", PHAGS_PA); + aliases.put("PHLI", INSCRIPTIONAL_PAHLAVI); + aliases.put("PHNX", PHOENICIAN); + aliases.put("PRTI", INSCRIPTIONAL_PARTHIAN); + aliases.put("RJNG", REJANG); + aliases.put("RUNR", RUNIC); + aliases.put("SAMR", SAMARITAN); + aliases.put("SARB", OLD_SOUTH_ARABIAN); + aliases.put("SAUR", SAURASHTRA); + aliases.put("SHAW", SHAVIAN); + aliases.put("SINH", SINHALA); + aliases.put("SUND", SUNDANESE); + aliases.put("SYLO", SYLOTI_NAGRI); + aliases.put("SYRC", SYRIAC); + aliases.put("TAGB", TAGBANWA); + aliases.put("TALE", TAI_LE); + aliases.put("TALU", NEW_TAI_LUE); + aliases.put("TAML", TAMIL); + aliases.put("TAVT", TAI_VIET); + aliases.put("TELU", TELUGU); + aliases.put("TFNG", TIFINAGH); + aliases.put("TGLG", TAGALOG); + aliases.put("THAA", THAANA); + aliases.put("THAI", THAI); + aliases.put("TIBT", TIBETAN); + aliases.put("UGAR", UGARITIC); + aliases.put("VAII", VAI); + aliases.put("XPEO", OLD_PERSIAN); + aliases.put("XSUX", CUNEIFORM); + aliases.put("YIII", YI); + aliases.put("ZINH", INHERITED); + aliases.put("ZYYY", COMMON); + aliases.put("ZZZZ", UNKNOWN); + } + + /** + * Returns the enum constant representing the Unicode script of which + * the given character (Unicode code point) is assigned to. + * + * @param codePoint the character (Unicode code point) in question. + * @return The UnicodeScript constant representing the + * Unicode script of which this character is assigned to. + * + * @exception IllegalArgumentException if the specified + * codePoint is an invalid Unicode code point. + * @see Character#isValidCodePoint(int) + * + */ + public static UnicodeScript of(int codePoint) { + if (!isValidCodePoint(codePoint)) + throw new IllegalArgumentException(); + int type = getType(codePoint); + // leave SURROGATE and PRIVATE_USE for table lookup + if (type == UNASSIGNED) + return UNKNOWN; + int index = Arrays.binarySearch(scriptStarts, codePoint); + if (index < 0) + index = -index - 2; + return scripts[index]; + } + + /** + * Returns the UnicodeScript constant with the given Unicode script + * name or the script name alias. Script names and their aliases are + * determined by The Unicode Standard. The files Scripts<version>.txt + * and PropertyValueAliases<version>.txt define script names + * and the script name aliases for a particular version of the + * standard. The {@link Character} class specifies the version of + * the standard that it supports. + *

      + * Character case is ignored for all of the valid script names. + * The en_US locale's case mapping rules are used to provide + * case-insensitive string comparisons for script name validation. + *

      + * + * @param scriptName A UnicodeScript name. + * @return The UnicodeScript constant identified + * by scriptName + * @throws IllegalArgumentException if scriptName is an + * invalid name + * @throws NullPointerException if scriptName is null + */ + public static final UnicodeScript forName(String scriptName) { + scriptName = scriptName.toUpperCase(Locale.ENGLISH); + //.replace(' ', '_')); + UnicodeScript sc = aliases.get(scriptName); + if (sc != null) + return sc; + return valueOf(scriptName); + } + } + /** * The value of the Character. * @@ -5042,4 +6278,51 @@ class Character extends Object implements java.io.Serializable, Comparable> 8) | (ch << 8)); } + + /** + * Returns the Unicode name of the specified character + * codePoint, or null if the code point is + * {@link #UNASSIGNED unassigned}. + *

      + * Note: if the specified character is not assigned a name by + * the UnicodeData file (part of the Unicode Character + * Database maintained by the Unicode Consortium), the returned + * name is the same as the result of expression + * + *

      + * Character.UnicodeBlock.of(codePoint) + * .toString() + * .replace('_', ' ') + * + " " + * + Integer.toHexString(codePoint).toUpperCase(Locale.ENGLISH); + * + *
      + * + * @param codePoint the character (Unicode code point) + * + * @return the Unicode name of the specified character, or null if + * the code point is unassigned. + * + * @exception IllegalArgumentException if the specified + * codePoint is not a valid Unicode + * code point. + * + * @since 1.7 + */ + public static String getName(int codePoint) { + if (!isValidCodePoint(codePoint)) { + throw new IllegalArgumentException(); + } + String name = CharacterName.get(codePoint); + if (name != null) + return name; + if (getType(codePoint) == UNASSIGNED) + return null; + UnicodeBlock block = UnicodeBlock.of(codePoint); + if (block != null) + return block.toString().replace('_', ' ') + " " + + Integer.toHexString(codePoint).toUpperCase(Locale.ENGLISH); + // should never come here + return Integer.toHexString(codePoint).toUpperCase(Locale.ENGLISH); + } } diff --git a/src/share/classes/java/lang/CharacterName.java b/src/share/classes/java/lang/CharacterName.java new file mode 100644 index 000000000..d09734087 --- /dev/null +++ b/src/share/classes/java/lang/CharacterName.java @@ -0,0 +1,106 @@ +/* + * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package java.lang; + +import java.io.DataInputStream; +import java.io.InputStream; +import java.lang.ref.SoftReference; +import java.util.Arrays; +import java.util.zip.InflaterInputStream; +import java.security.AccessController; +import java.security.PrivilegedAction; + +class CharacterName { + + private static SoftReference refStrPool; + private static int[][] lookup; + + private static synchronized byte[] initNamePool() { + byte[] strPool = null; + if (refStrPool != null && (strPool = refStrPool.get()) != null) + return strPool; + DataInputStream dis = null; + try { + dis = new DataInputStream(new InflaterInputStream( + AccessController.doPrivileged(new PrivilegedAction() + { + public InputStream run() { + return getClass().getResourceAsStream("uniName.dat"); + } + }))); + + lookup = new int[(Character.MAX_CODE_POINT + 1) >> 8][]; + int total = dis.readInt(); + int cpEnd = dis.readInt(); + byte ba[] = new byte[cpEnd]; + dis.readFully(ba); + + int nameOff = 0; + int cpOff = 0; + int cp = 0; + do { + int len = ba[cpOff++] & 0xff; + if (len == 0) { + len = ba[cpOff++] & 0xff; + // always big-endian + cp = ((ba[cpOff++] & 0xff) << 16) | + ((ba[cpOff++] & 0xff) << 8) | + ((ba[cpOff++] & 0xff)); + } else { + cp++; + } + int hi = cp >> 8; + if (lookup[hi] == null) { + lookup[hi] = new int[0x100]; + } + lookup[hi][cp&0xff] = (nameOff << 8) | len; + nameOff += len; + } while (cpOff < cpEnd); + strPool = new byte[total - cpEnd]; + dis.readFully(strPool); + refStrPool = new SoftReference(strPool); + } catch (Exception x) { + throw new InternalError(x.getMessage()); + } finally { + try { + if (dis != null) + dis.close(); + } catch (Exception xx) {} + } + return strPool; + } + + public static String get(int cp) { + byte[] strPool = null; + if (refStrPool == null || (strPool = refStrPool.get()) == null) + strPool = initNamePool(); + int off = 0; + if (lookup[cp>>8] == null || + (off = lookup[cp>>8][cp&0xff]) == 0) + return null; + return new String(strPool, 0, off >>> 8, off & 0xff); // ASCII + } +} diff --git a/src/share/classes/java/util/regex/Pattern.java b/src/share/classes/java/util/regex/Pattern.java index 7bf6a1d78..e95c715cf 100644 --- a/src/share/classes/java/util/regex/Pattern.java +++ b/src/share/classes/java/util/regex/Pattern.java @@ -29,6 +29,7 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.text.CharacterIterator; import java.text.Normalizer; +import java.util.Locale; import java.util.Map; import java.util.ArrayList; import java.util.HashMap; @@ -200,8 +201,9 @@ import java.util.Arrays; * Equivalent to java.lang.Character.isMirrored() * *   - * Classes for Unicode blocks and categories - * + * Classes for Unicode scripts, blocks and categories + * * \p{IsLatin} + * A Latin script character (simple script) * \p{InGreek} * A character in the Greek block (simple block) * \p{Lu} @@ -527,25 +529,40 @@ import java.util.Arrays; * while not equal, compile into the same pattern, which matches the character * with hexadecimal value 0x2014. * - *

      Unicode blocks and categories are written with the - * \p and \P constructs as in - * Perl. \p{prop} matches if the input has the - * property prop, while \P{prop} does not match if - * the input has that property. Blocks are specified with the prefix - * In, as in InMongolian. Categories may be specified with - * the optional prefix Is: Both \p{L} and \p{IsL} - * denote the category of Unicode letters. Blocks and categories can be used - * both inside and outside of a character class. - * + * + *

      Unicode scripts, blocks and categories are written with the \p and + * \P constructs as in Perl. \p{prop} matches if + * the input has the property prop, while \P{prop} + * does not match if the input has that property. + *

      + * Scripts are specified either with the prefix {@code Is}, as in + * {@code IsHiragana}, or by using the {@code script} keyword (or its short + * form {@code sc})as in {@code script=Hiragana} or {@code sc=Hiragana}. + *

      + * Blocks are specified with the prefix {@code In}, as in + * {@code InMongolian}, or by using the keyword {@code block} (or its short + * form {@code blk}) as in {@code block=Mongolian} or {@code blk=Mongolian}. + *

      + * Categories may be specified with the optional prefix {@code Is}: + * Both {@code \p{L}} and {@code \p{IsL}} denote the category of Unicode + * letters. Same as scripts and blocks, categories can also be specified + * by using the keyword {@code general_category} (or its short form + * {@code gc}) as in {@code general_category=Lu} or {@code gc=Lu}. + *

      + * Scripts, blocks and categories can be used both inside and outside of a + * character class. *

      The supported categories are those of * * The Unicode Standard in the version specified by the * {@link java.lang.Character Character} class. The category names are those * defined in the Standard, both normative and informative. + * The script names supported by Pattern are the valid script names + * accepted and defined by + * {@link java.lang.Character.UnicodeScript#forName(String) UnicodeScript.forName}. * The block names supported by Pattern are the valid block names * accepted and defined by * {@link java.lang.Character.UnicodeBlock#forName(String) UnicodeBlock.forName}. - * + *

      *

      Categories that behave like the java.lang.Character * boolean ismethodname methods (except for the deprecated ones) are * available through the same \p{prop} syntax where @@ -2488,12 +2505,34 @@ loop: for(int x=0, offset=0; x, " + + "value=<" + value + ">}"); + } } else { - if (name.startsWith("Is")) + if (name.startsWith("In")) { + // \p{inBlockName} + node = unicodeBlockPropertyFor(name.substring(2)); + } else if (name.startsWith("Is")) { + // \p{isGeneralCategory} and \p{isScriptName} name = name.substring(2); - node = charPropertyNodeFor(name); + node = CharPropertyNames.charPropertyFor(name); + if (node == null) + node = unicodeScriptPropertyFor(name); + } else { + node = charPropertyNodeFor(name); + } } if (maybeComplement) { if (node instanceof Category || node instanceof Block) @@ -2503,6 +2542,21 @@ loop: for(int x=0, offset=0; x Date: Thu, 20 May 2010 18:44:51 +0400 Subject: 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type Reviewed-by: rupashka --- .../java/beans/DefaultPersistenceDelegate.java | 19 +++++ src/share/classes/java/beans/MetaData.java | 98 ---------------------- src/share/classes/java/beans/XMLEncoder.java | 25 +++++- 3 files changed, 40 insertions(+), 102 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/java/beans/DefaultPersistenceDelegate.java b/src/share/classes/java/beans/DefaultPersistenceDelegate.java index 915290981..2dc9a9d3d 100644 --- a/src/share/classes/java/beans/DefaultPersistenceDelegate.java +++ b/src/share/classes/java/beans/DefaultPersistenceDelegate.java @@ -222,6 +222,25 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate { // Write out the properties of this instance. private void initBean(Class type, Object oldInstance, Object newInstance, Encoder out) { + for (Field field : type.getFields()) { + int mod = field.getModifiers(); + if (Modifier.isFinal(mod) || Modifier.isStatic(mod) || Modifier.isTransient(mod)) { + continue; + } + try { + Expression oldGetExp = new Expression(field, "get", new Object[] { oldInstance }); + Expression newGetExp = new Expression(field, "get", new Object[] { newInstance }); + Object oldValue = oldGetExp.getValue(); + Object newValue = newGetExp.getValue(); + out.writeExpression(oldGetExp); + if (!equals(newValue, out.get(oldValue))) { + out.writeStatement(new Statement(field, "set", new Object[] { oldInstance, oldValue })); + } + } + catch (Exception exception) { + out.getExceptionListener().exceptionThrown(exception); + } + } BeanInfo info; try { info = Introspector.getBeanInfo(type); diff --git a/src/share/classes/java/beans/MetaData.java b/src/share/classes/java/beans/MetaData.java index 4827d785b..9d3a1053d 100644 --- a/src/share/classes/java/beans/MetaData.java +++ b/src/share/classes/java/beans/MetaData.java @@ -700,56 +700,6 @@ class java_beans_beancontext_BeanContextSupport_PersistenceDelegate extends java // AWT -/** - * The persistence delegate for {@link Dimension}. - * It is impossible to use {@link DefaultPersistenceDelegate} - * because all getters have return types that differ from parameter types - * of the constructor {@link Dimension#Dimension(int, int)}. - * - * @author Sergey A. Malenkov - */ -final class java_awt_Dimension_PersistenceDelegate extends PersistenceDelegate { - protected boolean mutatesTo(Object oldInstance, Object newInstance) { - return oldInstance.equals(newInstance); - } - - protected Expression instantiate(Object oldInstance, Encoder out) { - Dimension dimension = (Dimension) oldInstance; - Object[] args = new Object[] { - dimension.width, - dimension.height, - }; - return new Expression(dimension, dimension.getClass(), "new", args); - } -} - -/** - * The persistence delegate for {@link GridBagConstraints}. - * It is impossible to use {@link DefaultPersistenceDelegate} - * because this class does not have any properties. - * - * @author Sergey A. Malenkov - */ -final class java_awt_GridBagConstraints_PersistenceDelegate extends PersistenceDelegate { - protected Expression instantiate(Object oldInstance, Encoder out) { - GridBagConstraints gbc = (GridBagConstraints) oldInstance; - Object[] args = new Object[] { - gbc.gridx, - gbc.gridy, - gbc.gridwidth, - gbc.gridheight, - gbc.weightx, - gbc.weighty, - gbc.anchor, - gbc.fill, - gbc.insets, - gbc.ipadx, - gbc.ipady, - }; - return new Expression(gbc, gbc.getClass(), "new", args); - } -} - /** * The persistence delegate for {@link Insets}. * It is impossible to use {@link DefaultPersistenceDelegate} @@ -774,54 +724,6 @@ final class java_awt_Insets_PersistenceDelegate extends PersistenceDelegate { } } -/** - * The persistence delegate for {@link Point}. - * It is impossible to use {@link DefaultPersistenceDelegate} - * because all getters have return types that differ from parameter types - * of the constructor {@link Point#Point(int, int)}. - * - * @author Sergey A. Malenkov - */ -final class java_awt_Point_PersistenceDelegate extends PersistenceDelegate { - protected boolean mutatesTo(Object oldInstance, Object newInstance) { - return oldInstance.equals(newInstance); - } - - protected Expression instantiate(Object oldInstance, Encoder out) { - Point point = (Point) oldInstance; - Object[] args = new Object[] { - point.x, - point.y, - }; - return new Expression(point, point.getClass(), "new", args); - } -} - -/** - * The persistence delegate for {@link Rectangle}. - * It is impossible to use {@link DefaultPersistenceDelegate} - * because all getters have return types that differ from parameter types - * of the constructor {@link Rectangle#Rectangle(int, int, int, int)}. - * - * @author Sergey A. Malenkov - */ -final class java_awt_Rectangle_PersistenceDelegate extends PersistenceDelegate { - protected boolean mutatesTo(Object oldInstance, Object newInstance) { - return oldInstance.equals(newInstance); - } - - protected Expression instantiate(Object oldInstance, Encoder out) { - Rectangle rectangle = (Rectangle) oldInstance; - Object[] args = new Object[] { - rectangle.x, - rectangle.y, - rectangle.width, - rectangle.height, - }; - return new Expression(rectangle, rectangle.getClass(), "new", args); - } -} - /** * The persistence delegate for {@link Font}. * It is impossible to use {@link DefaultPersistenceDelegate} diff --git a/src/share/classes/java/beans/XMLEncoder.java b/src/share/classes/java/beans/XMLEncoder.java index e13c8262c..e07286592 100644 --- a/src/share/classes/java/beans/XMLEncoder.java +++ b/src/share/classes/java/beans/XMLEncoder.java @@ -407,7 +407,20 @@ public class XMLEncoder extends Encoder { os.writeObject(this); */ mark(oldStm); - statementList(oldStm.getTarget()).add(oldStm); + Object target = oldStm.getTarget(); + if (target instanceof Field) { + String method = oldStm.getMethodName(); + Object[] args = oldStm.getArguments(); + if ((method == null) || (args == null)) { + } + else if (method.equals("get") && (args.length == 1)) { + target = args[0]; + } + else if (method.equals("set") && (args.length == 2)) { + target = args[0]; + } + } + statementList(target).add(oldStm); } catch (Exception e) { getExceptionListener().exceptionThrown(new Exception("XMLEncoder: discarding statement " + oldStm, e)); @@ -703,7 +716,9 @@ public class XMLEncoder extends Encoder { statements.add(exp); } outputValue(target, outer, false); - outputValue(value, outer, isArgument); + if (expression) { + outputValue(value, outer, isArgument); + } return; } if (expression && (d.refs > 1)) { @@ -722,8 +737,10 @@ public class XMLEncoder extends Encoder { } else if ((!expression && methodName.startsWith("set") && args.length == 1) || (expression && methodName.startsWith("get") && args.length == 0)) { - attributes = attributes + " property=" + - quote(Introspector.decapitalize(methodName.substring(3))); + if (3 < methodName.length()) { + attributes = attributes + " property=" + + quote(Introspector.decapitalize(methodName.substring(3))); + } } else if (!methodName.equals("new") && !methodName.equals("newInstance")) { attributes = attributes + " method=" + quote(methodName); -- cgit v1.2.3 From 0d286fe7d011536930260553349123da9da57f67 Mon Sep 17 00:00:00 2001 From: malenkov Date: Thu, 20 May 2010 20:42:56 +0400 Subject: 6910490: MatteBorder JScrollpane interaction Reviewed-by: alexp --- .../classes/javax/swing/border/MatteBorder.java | 67 ++++++---------------- 1 file changed, 16 insertions(+), 51 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/javax/swing/border/MatteBorder.java b/src/share/classes/javax/swing/border/MatteBorder.java index 5cc89da65..511986d8a 100644 --- a/src/share/classes/javax/swing/border/MatteBorder.java +++ b/src/share/classes/javax/swing/border/MatteBorder.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2010 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,7 +26,6 @@ package javax.swing.border; import java.awt.Graphics; import java.awt.Insets; -import java.awt.Rectangle; import java.awt.Component; import java.awt.Color; @@ -133,63 +132,29 @@ public class MatteBorder extends EmptyBorder g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom); } else if (tileIcon != null) { - int tileW = tileIcon.getIconWidth(); int tileH = tileIcon.getIconHeight(); - int xpos, ypos, startx, starty; - Graphics cg; - - // Paint top matte edge - cg = g.create(); - cg.setClip(0, 0, width, insets.top); - for (ypos = 0; insets.top - ypos > 0; ypos += tileH) { - for (xpos = 0; width - xpos > 0; xpos += tileW) { - tileIcon.paintIcon(c, cg, xpos, ypos); - } - } - cg.dispose(); - - // Paint left matte edge - cg = g.create(); - cg.setClip(0, insets.top, insets.left, height - insets.top); - starty = insets.top - (insets.top%tileH); - startx = 0; - for (ypos = starty; height - ypos > 0; ypos += tileH) { - for (xpos = startx; insets.left - xpos > 0; xpos += tileW) { - tileIcon.paintIcon(c, cg, xpos, ypos); - } - } - cg.dispose(); - - // Paint bottom matte edge - cg = g.create(); - cg.setClip(insets.left, height - insets.bottom, width - insets.left, insets.bottom); - starty = (height - insets.bottom) - ((height - insets.bottom)%tileH); - startx = insets.left - (insets.left%tileW); - for (ypos = starty; height - ypos > 0; ypos += tileH) { - for (xpos = startx; width - xpos > 0; xpos += tileW) { - tileIcon.paintIcon(c, cg, xpos, ypos); - } - } - cg.dispose(); - - // Paint right matte edge - cg = g.create(); - cg.setClip(width - insets.right, insets.top, insets.right, height - insets.top - insets.bottom); - starty = insets.top - (insets.top%tileH); - startx = width - insets.right - ((width - insets.right)%tileW); - for (ypos = starty; height - ypos > 0; ypos += tileH) { - for (xpos = startx; width - xpos > 0; xpos += tileW) { - tileIcon.paintIcon(c, cg, xpos, ypos); - } - } - cg.dispose(); + paintEdge(c, g, 0, 0, width - insets.right, insets.top, tileW, tileH); + paintEdge(c, g, 0, insets.top, insets.left, height - insets.top, tileW, tileH); + paintEdge(c, g, insets.left, height - insets.bottom, width - insets.left, insets.bottom, tileW, tileH); + paintEdge(c, g, width - insets.right, 0, insets.right, height - insets.bottom, tileW, tileH); } g.translate(-x, -y); g.setColor(oldColor); } + private void paintEdge(Component c, Graphics g, int x, int y, int width, int height, int tileW, int tileH) { + g = g.create(x, y, width, height); + int sY = -(y % tileH); + for (x = -(x % tileW); x < width; x += tileW) { + for (y = sY; y < height; y += tileH) { + this.tileIcon.paintIcon(c, g, x, y); + } + } + g.dispose(); + } + /** * Reinitialize the insets parameter with this Border's current Insets. * @param c the component for which this border insets value applies -- cgit v1.2.3 From 8e4b3083151ae9e6e649efd5fc2089ba3149e57f Mon Sep 17 00:00:00 2001 From: michaelm Date: Fri, 21 May 2010 07:29:48 +0100 Subject: 6773270: java.net.URI fails to escape \u0000 Summary: check for \u0000 Reviewed-by: alanb --- src/share/classes/java/net/URI.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/share') diff --git a/src/share/classes/java/net/URI.java b/src/share/classes/java/net/URI.java index 879b2b75e..f8417c59b 100644 --- a/src/share/classes/java/net/URI.java +++ b/src/share/classes/java/net/URI.java @@ -2491,6 +2491,8 @@ public final class URI // Tell whether the given character is permitted by the given mask pair private static boolean match(char c, long lowMask, long highMask) { + if (c == 0) // 0 doesn't have a slot in the mask. So, it never matches. + return false; if (c < 64) return ((1L << c) & lowMask) != 0; if (c < 128) -- cgit v1.2.3 From 735f927819cf1defaf8ac3f13e6d32a0a67ec49c Mon Sep 17 00:00:00 2001 From: alexp Date: Fri, 21 May 2010 22:04:35 +0400 Subject: 6953396: javax.swing.plaf.basic.BasicViewportUI.uninstallDefaults() is not called when UI is uninstalled Reviewed-by: rupashka --- src/share/classes/javax/swing/plaf/basic/BasicViewportUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/share') diff --git a/src/share/classes/javax/swing/plaf/basic/BasicViewportUI.java b/src/share/classes/javax/swing/plaf/basic/BasicViewportUI.java index 4e4cfab3d..90e2de4a0 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicViewportUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicViewportUI.java @@ -56,8 +56,8 @@ public class BasicViewportUI extends ViewportUI { } public void uninstallUI(JComponent c) { + uninstallDefaults(c); super.uninstallUI(c); - } protected void installDefaults(JComponent c) { -- cgit v1.2.3 From 41a6a3c4a2a50bff14b5e49894da506685763940 Mon Sep 17 00:00:00 2001 From: weijun Date: Mon, 24 May 2010 09:28:06 +0800 Subject: 6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature Reviewed-by: xuelei, mullan --- src/share/classes/sun/security/validator/PKIXValidator.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/sun/security/validator/PKIXValidator.java b/src/share/classes/sun/security/validator/PKIXValidator.java index eb12ef220..543a71e3d 100644 --- a/src/share/classes/sun/security/validator/PKIXValidator.java +++ b/src/share/classes/sun/security/validator/PKIXValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2002-2010 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -155,12 +155,15 @@ public final class PKIXValidator extends Validator { X500Principal prevIssuer = null; for (int i = 0; i < chain.length; i++) { X509Certificate cert = chain[i]; + X500Principal dn = cert.getSubjectX500Principal(); if (i != 0 && - !cert.getSubjectX500Principal().equals(prevIssuer)) { + !dn.equals(prevIssuer)) { // chain is not ordered correctly, call builder instead return doBuild(chain, otherCerts); } - if (trustedCerts.contains(cert)) { + if (trustedSubjects.containsKey(dn) + && trustedSubjects.get(dn).getPublicKey() + .equals(cert.getPublicKey())) { if (i == 0) { return new X509Certificate[] {chain[0]}; } -- cgit v1.2.3 From 476d970297243143cae8f0f47a4f9586325791a4 Mon Sep 17 00:00:00 2001 From: weijun Date: Mon, 24 May 2010 09:28:25 +0800 Subject: 6954621: small error in 6948909 Reviewed-by: xuelei --- src/share/classes/sun/security/tools/JarSigner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/share') diff --git a/src/share/classes/sun/security/tools/JarSigner.java b/src/share/classes/sun/security/tools/JarSigner.java index f45a2c931..a3d74834f 100644 --- a/src/share/classes/sun/security/tools/JarSigner.java +++ b/src/share/classes/sun/security/tools/JarSigner.java @@ -1486,7 +1486,7 @@ public class JarSigner { for (int i=0; i Date: Mon, 24 May 2010 09:37:02 +0800 Subject: 6882687: KerberosTime too imprecise Reviewed-by: valeriep --- .../sun/security/krb5/internal/KerberosTime.java | 47 +++++++++++++++------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/sun/security/krb5/internal/KerberosTime.java b/src/share/classes/sun/security/krb5/internal/KerberosTime.java index 5288d5863..d524a2d19 100644 --- a/src/share/classes/sun/security/krb5/internal/KerberosTime.java +++ b/src/share/classes/sun/security/krb5/internal/KerberosTime.java @@ -57,11 +57,20 @@ import java.io.IOException; * specification available at * * http://www.ietf.org/rfc/rfc4120.txt. + * + * The implementation also includes the microseconds info so that the + * same class can be used as a precise timestamp in Authenticator etc. */ public class KerberosTime implements Cloneable { private long kerberosTime; // milliseconds since epoch, a Date.getTime() value + private int microSeconds; // the last three digits of the microsecond value + + // The time when this class is loaded. Used in setNow() + private static final long initMilli = System.currentTimeMillis(); + private static final long initMicro = System.nanoTime() / 1000; + private static long syncTime; private static boolean DEBUG = Krb5.DEBUG; @@ -77,9 +86,13 @@ public class KerberosTime implements Cloneable { kerberosTime = time; } + private KerberosTime(long time, int micro) { + kerberosTime = time; + microSeconds = micro; + } public Object clone() { - return new KerberosTime(kerberosTime); + return new KerberosTime(kerberosTime, microSeconds); } // This constructor is used in the native code @@ -109,8 +122,8 @@ public class KerberosTime implements Cloneable { // | | | | | | | // 0 4 6 8 | | | // 10 | | - // 12 | - // 14 + // 12 | + // 14 if (time.length() != 15) throw new Asn1Exception(Krb5.ASN1_BAD_TIMEFORMAT); @@ -148,11 +161,8 @@ public class KerberosTime implements Cloneable { public KerberosTime(boolean initToNow) { if (initToNow) { - Date temp = new Date(); - setTime(temp); + setNow(); } - else - kerberosTime = 0; } /** @@ -192,10 +202,12 @@ public class KerberosTime implements Cloneable { public void setTime(Date time) { kerberosTime = time.getTime(); // (time.getTimezoneOffset() * 60000L); + microSeconds = 0; } public void setTime(long time) { kerberosTime = time; + microSeconds = 0; } public Date toDate() { @@ -205,16 +217,18 @@ public class KerberosTime implements Cloneable { } public void setNow() { - Date temp = new Date(); - setTime(temp); + long microElapsed = System.nanoTime() / 1000 - initMicro; + setTime(initMilli + microElapsed/1000); + microSeconds = (int)(microElapsed % 1000); } public int getMicroSeconds() { Long temp_long = new Long((kerberosTime % 1000L) * 1000L); - return temp_long.intValue(); + return temp_long.intValue() + microSeconds; } public void setMicroSeconds(int usec) { + microSeconds = usec % 1000; Integer temp_int = new Integer(usec); long temp_long = temp_int.longValue() / 1000L; kerberosTime = kerberosTime - (kerberosTime % 1000L) + temp_long; @@ -222,6 +236,7 @@ public class KerberosTime implements Cloneable { public void setMicroSeconds(Integer usec) { if (usec != null) { + microSeconds = usec.intValue() % 1000; long temp_long = usec.longValue() / 1000L; kerberosTime = kerberosTime - (kerberosTime % 1000L) + temp_long; } @@ -262,7 +277,9 @@ public class KerberosTime implements Cloneable { } public boolean greaterThan(KerberosTime time) { - return kerberosTime > time.kerberosTime; + return kerberosTime > time.kerberosTime || + kerberosTime == time.kerberosTime && + microSeconds > time.microSeconds; } public boolean equals(Object obj) { @@ -274,15 +291,17 @@ public class KerberosTime implements Cloneable { return false; } - return kerberosTime == ((KerberosTime)obj).kerberosTime; + return kerberosTime == ((KerberosTime)obj).kerberosTime && + microSeconds == ((KerberosTime)obj).microSeconds; } public int hashCode() { - return 37 * 17 + (int)(kerberosTime ^ (kerberosTime >>> 32)); + int result = 37 * 17 + (int)(kerberosTime ^ (kerberosTime >>> 32)); + return result * 17 + microSeconds; } public boolean isZero() { - return kerberosTime == 0; + return kerberosTime == 0 && microSeconds == 0; } public int getSeconds() { -- cgit v1.2.3 From 578bcf265ed0589e78ff845577a90db9ace288b0 Mon Sep 17 00:00:00 2001 From: weijun Date: Mon, 24 May 2010 09:37:16 +0800 Subject: 6948781: CertificateFactory.generateCertificate doesn't throw CertificateException for malformed certificate Reviewed-by: mullan --- .../classes/sun/security/provider/X509Factory.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/share') diff --git a/src/share/classes/sun/security/provider/X509Factory.java b/src/share/classes/sun/security/provider/X509Factory.java index ceaf3c970..aca13d76a 100644 --- a/src/share/classes/sun/security/provider/X509Factory.java +++ b/src/share/classes/sun/security/provider/X509Factory.java @@ -518,6 +518,7 @@ public class X509Factory extends CertificateFactorySpi { // Step 2: Read the rest of header, determine the line end int end; + StringBuffer header = new StringBuffer("-----"); while (true) { int next = is.read(); if (next == -1) { @@ -540,6 +541,7 @@ public class X509Factory extends CertificateFactorySpi { } break; } + header.append((char)next); } // Step 3: Read the data @@ -559,6 +561,7 @@ public class X509Factory extends CertificateFactorySpi { } // Step 4: Consume the footer + StringBuffer footer = new StringBuffer("-"); while (true) { int next = is.read(); // Add next == '\n' for maximum safety, in case endline @@ -566,13 +569,34 @@ public class X509Factory extends CertificateFactorySpi { if (next == -1 || next == end || next == '\n') { break; } + if (next != '\r') footer.append((char)next); } + checkHeaderFooter(header.toString(), footer.toString()); + BASE64Decoder decoder = new BASE64Decoder(); return decoder.decodeBuffer(new String(data, 0, pos)); } } + private static void checkHeaderFooter(String header, + String footer) throws IOException { + if (header.length() < 16 || !header.startsWith("-----BEGIN ") || + !header.endsWith("-----")) { + throw new IOException("Illegal header: " + header); + } + if (footer.length() < 14 || !footer.startsWith("-----END ") || + !footer.endsWith("-----")) { + throw new IOException("Illegal footer: " + footer); + } + String headerType = header.substring(11, header.length()-5); + String footerType = footer.substring(9, footer.length()-5); + if (!headerType.equals(footerType)) { + throw new IOException("Header and footer do not match: " + + header + " " + footer); + } + } + /** * Read one BER data block. This method is aware of indefinite-length BER * encoding and will read all of the sub-sections in a recursive way -- cgit v1.2.3 From 876e877704a3a7e1026d6b625531545035cc1adc Mon Sep 17 00:00:00 2001 From: weijun Date: Mon, 24 May 2010 10:05:04 +0800 Subject: 6932525: Incorrect encryption types of KDC_REQ_BODY of AS-REQ with pre-authentication Reviewed-by: valeriep --- src/share/classes/sun/security/krb5/KrbAsReq.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/sun/security/krb5/KrbAsReq.java b/src/share/classes/sun/security/krb5/KrbAsReq.java index fec6998ce..ca2330e3a 100644 --- a/src/share/classes/sun/security/krb5/KrbAsReq.java +++ b/src/share/classes/sun/security/krb5/KrbAsReq.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2000-2010 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -344,16 +344,13 @@ public class KrbAsReq extends KrbKdcReq { princName = cname; EncryptionKey key = null; - int[] tktETypes = null; + int[] tktETypes = EType.getDefaults("default_tkt_enctypes"); if (pa_exists && pa_etype != EncryptedData.ETYPE_NULL) { if (DEBUG) { System.out.println("Pre-Authenticaton: find key for etype = " + pa_etype); } key = EncryptionKey.findKey(pa_etype, keys); - tktETypes = new int[1]; - tktETypes[0] = pa_etype; } else { - tktETypes = EType.getDefaults("default_tkt_enctypes", keys); key = EncryptionKey.findKey(tktETypes[0], keys); } -- cgit v1.2.3 From 4b899a81f9f2ba4bc5de21aadb52a69a2a06ef46 Mon Sep 17 00:00:00 2001 From: sherman Date: Mon, 24 May 2010 00:39:57 -0400 Subject: 4691425: GZIPInputStream fails to read concatenated .gz files Summary: to support concatenated .gz streams Reviewed-by: martin --- .../classes/java/util/zip/GZIPInputStream.java | 67 ++++++++++++++++------ 1 file changed, 49 insertions(+), 18 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/java/util/zip/GZIPInputStream.java b/src/share/classes/java/util/zip/GZIPInputStream.java index 389bc6e4d..2016373ad 100644 --- a/src/share/classes/java/util/zip/GZIPInputStream.java +++ b/src/share/classes/java/util/zip/GZIPInputStream.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1996-2010 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -75,8 +75,7 @@ class GZIPInputStream extends InflaterInputStream { public GZIPInputStream(InputStream in, int size) throws IOException { super(in, new Inflater(true), size); usesDefaultInflater = true; - readHeader(); - crc.reset(); + readHeader(in); } /** @@ -114,14 +113,16 @@ class GZIPInputStream extends InflaterInputStream { if (eos) { return -1; } - len = super.read(buf, off, len); - if (len == -1) { - readTrailer(); - eos = true; + int n = super.read(buf, off, len); + if (n == -1) { + if (readTrailer()) + eos = true; + else + return this.read(buf, off, len); } else { - crc.update(buf, off, len); + crc.update(buf, off, n); } - return len; + return n; } /** @@ -152,10 +153,11 @@ class GZIPInputStream extends InflaterInputStream { private final static int FCOMMENT = 16; // File comment /* - * Reads GZIP member header. + * Reads GZIP member header and returns the total byte number + * of this member header. */ - private void readHeader() throws IOException { - CheckedInputStream in = new CheckedInputStream(this.in, crc); + private int readHeader(InputStream this_in) throws IOException { + CheckedInputStream in = new CheckedInputStream(this_in, crc); crc.reset(); // Check header magic if (readUShort(in) != GZIP_MAGIC) { @@ -169,17 +171,24 @@ class GZIPInputStream extends InflaterInputStream { int flg = readUByte(in); // Skip MTIME, XFL, and OS fields skipBytes(in, 6); + int n = 2 + 2 + 6; // Skip optional extra field if ((flg & FEXTRA) == FEXTRA) { - skipBytes(in, readUShort(in)); + int m = readUShort(in); + skipBytes(in, m); + n += m + 2; } // Skip optional file name if ((flg & FNAME) == FNAME) { - while (readUByte(in) != 0) ; + do { + n++; + } while (readUByte(in) != 0); } // Skip optional file comment if ((flg & FCOMMENT) == FCOMMENT) { - while (readUByte(in) != 0) ; + do { + n++; + } while (readUByte(in) != 0); } // Check optional header CRC if ((flg & FHCRC) == FHCRC) { @@ -187,13 +196,18 @@ class GZIPInputStream extends InflaterInputStream { if (readUShort(in) != v) { throw new ZipException("Corrupt GZIP header"); } + n += 2; } + crc.reset(); + return n; } /* - * Reads GZIP member trailer. + * Reads GZIP member trailer and returns true if the eos + * reached, false if there are more (concatenated gzip + * data set) */ - private void readTrailer() throws IOException { + private boolean readTrailer() throws IOException { InputStream in = this.in; int n = inf.getRemaining(); if (n > 0) { @@ -205,6 +219,24 @@ class GZIPInputStream extends InflaterInputStream { // rfc1952; ISIZE is the input size modulo 2^32 (readUInt(in) != (inf.getBytesWritten() & 0xffffffffL))) throw new ZipException("Corrupt GZIP trailer"); + + // If there are more bytes available in "in" or + // the leftover in the "inf" is > 26 bytes: + // this.trailer(8) + next.header.min(10) + next.trailer(8) + // try concatenated case + if (this.in.available() > 0 || n > 26) { + int m = 8; // this.trailer + try { + m += readHeader(in); // next.header + } catch (IOException ze) { + return true; // ignore any malformed, do nothing + } + inf.reset(); + if (n > m) + inf.setInput(buf, len - n + m, n - m); + return false; + } + return true; } /* @@ -239,7 +271,6 @@ class GZIPInputStream extends InflaterInputStream { return b; } - private byte[] tmpbuf = new byte[128]; /* -- cgit v1.2.3 From 1d8246c104dbd013b957180db80f36dd0300912f Mon Sep 17 00:00:00 2001 From: sherman Date: Mon, 24 May 2010 15:20:23 -0400 Subject: 4690407: JAR tool: option -i can't be combined with other options Summary: -i can't combined with cxut, do sanity check on options Reviewed-by: martin --- src/share/classes/sun/tools/jar/Main.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/sun/tools/jar/Main.java b/src/share/classes/sun/tools/jar/Main.java index 404d5cded..db269fd52 100644 --- a/src/share/classes/sun/tools/jar/Main.java +++ b/src/share/classes/sun/tools/jar/Main.java @@ -306,28 +306,28 @@ class Main { for (int i = 0; i < flags.length(); i++) { switch (flags.charAt(i)) { case 'c': - if (xflag || tflag || uflag) { + if (xflag || tflag || uflag || iflag) { usageError(); return false; } cflag = true; break; case 'u': - if (cflag || xflag || tflag) { + if (cflag || xflag || tflag || iflag) { usageError(); return false; } uflag = true; break; case 'x': - if (cflag || uflag || tflag) { + if (cflag || uflag || tflag || iflag) { usageError(); return false; } xflag = true; break; case 't': - if (cflag || uflag || xflag) { + if (cflag || uflag || xflag || iflag) { usageError(); return false; } @@ -349,6 +349,10 @@ class Main { flag0 = true; break; case 'i': + if (cflag || uflag || xflag || tflag) { + usageError(); + return false; + } // do not increase the counter, files will contain rootjar rootjar = args[count++]; iflag = true; -- cgit v1.2.3 From afff05df4f26172f24766936cb7b2e46c4b40138 Mon Sep 17 00:00:00 2001 From: alexp Date: Tue, 25 May 2010 20:22:44 +0400 Subject: 6786238: api/javax_swing/DefaultDesktopManager/descriptions.html#xxxFrame Fails with NPE since 6u12 b02 Reviewed-by: rupashka --- .../classes/javax/swing/DefaultDesktopManager.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/javax/swing/DefaultDesktopManager.java b/src/share/classes/javax/swing/DefaultDesktopManager.java index 5802f6ffe..1456bab9a 100644 --- a/src/share/classes/javax/swing/DefaultDesktopManager.java +++ b/src/share/classes/javax/swing/DefaultDesktopManager.java @@ -26,17 +26,13 @@ package javax.swing; -import java.awt.*; -import java.beans.PropertyVetoException; -import java.beans.PropertyChangeEvent; -import javax.swing.border.Border; -import java.awt.event.ComponentListener; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; - +import com.sun.awt.AWTUtilities; import sun.awt.AWTAccessor; import sun.awt.SunToolkit; +import java.awt.*; +import java.beans.PropertyVetoException; + /** This is an implementation of the DesktopManager. * It currently implements the basic behaviors for managing * JInternalFrames in an arbitrary parent. @@ -318,7 +314,10 @@ public class DefaultDesktopManager implements DesktopManager, java.io.Serializab dragMode = DEFAULT_DRAG_MODE; if (p != null) { String mode = (String)p.getClientProperty("JDesktopPane.dragMode"); - if (mode != null && mode.equals("outline")) { + Window window = SwingUtilities.getWindowAncestor(f); + if (window != null && !AWTUtilities.isWindowOpaque(window)) { + dragMode = DEFAULT_DRAG_MODE; + } else if (mode != null && mode.equals("outline")) { dragMode = OUTLINE_DRAG_MODE; } else if (mode != null && mode.equals("faster") && f instanceof JInternalFrame -- cgit v1.2.3 From 8b12a98834e4e7b381e006e485577e59b7e532b5 Mon Sep 17 00:00:00 2001 From: alexp Date: Tue, 25 May 2010 20:30:54 +0400 Subject: 6937798: Nimbus: Issues with JTable grid Reviewed-by: rupashka --- src/share/classes/javax/swing/plaf/synth/SynthTableUI.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/javax/swing/plaf/synth/SynthTableUI.java b/src/share/classes/javax/swing/plaf/synth/SynthTableUI.java index 4c16e0b81..036585ab5 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthTableUI.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthTableUI.java @@ -361,12 +361,14 @@ public class SynthTableUI extends BasicTableUI cMax = table.getColumnCount()-1; } - // Paint the grid. - paintGrid(context, g, rMin, rMax, cMin, cMax); - // Paint the cells. paintCells(context, g, rMin, rMax, cMin, cMax); + // Paint the grid. + // it is important to paint the grid after the cells, otherwise the grid will be overpainted + // because in Synth cell renderers are likely to be opaque + paintGrid(context, g, rMin, rMax, cMin, cMax); + paintDropLines(context, g); } -- cgit v1.2.3 From 940983bcbf2d419103e714348df7f444e94c3b19 Mon Sep 17 00:00:00 2001 From: alexp Date: Tue, 25 May 2010 20:39:52 +0400 Subject: 6768387: REGRESSION: JTable no longer serializable Reviewed-by: rupashka --- .../classes/sun/swing/table/DefaultTableCellHeaderRenderer.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/sun/swing/table/DefaultTableCellHeaderRenderer.java b/src/share/classes/sun/swing/table/DefaultTableCellHeaderRenderer.java index 117ca3d4a..af634f079 100644 --- a/src/share/classes/sun/swing/table/DefaultTableCellHeaderRenderer.java +++ b/src/share/classes/sun/swing/table/DefaultTableCellHeaderRenderer.java @@ -24,6 +24,8 @@ */ package sun.swing.table; +import sun.swing.DefaultLookup; + import java.awt.Component; import java.awt.Color; import java.awt.FontMetrics; @@ -31,12 +33,11 @@ import java.awt.Graphics; import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; +import java.io.Serializable; import javax.swing.*; import javax.swing.plaf.UIResource; import javax.swing.border.Border; import javax.swing.table.*; -import sun.swing.DefaultLookup; - public class DefaultTableCellHeaderRenderer extends DefaultTableCellRenderer implements UIResource { @@ -186,7 +187,7 @@ public class DefaultTableCellHeaderRenderer extends DefaultTableCellRenderer return new Point(x, y); } - private class EmptyIcon implements Icon { + private class EmptyIcon implements Icon, Serializable { int width = 0; int height = 0; public void paintIcon(Component c, Graphics g, int x, int y) {} -- cgit v1.2.3 From cb63445d52365686ab6a4b4b4f770c9cdc403c7d Mon Sep 17 00:00:00 2001 From: alexp Date: Tue, 25 May 2010 20:54:59 +0400 Subject: 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table Reviewed-by: rupashka --- .../swing/plaf/windows/WindowsTableHeaderUI.java | 14 +++--- src/share/classes/javax/swing/JTable.java | 18 ++------ .../javax/swing/plaf/basic/BasicTableHeaderUI.java | 35 ++++++++++++--- src/share/classes/sun/swing/SwingUtilities2.java | 52 ++++++++++++++++++++++ 4 files changed, 90 insertions(+), 29 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsTableHeaderUI.java b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsTableHeaderUI.java index a70828092..65fd7358f 100644 --- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsTableHeaderUI.java +++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsTableHeaderUI.java @@ -35,6 +35,7 @@ import javax.swing.table.*; import static com.sun.java.swing.plaf.windows.TMSchema.*; import static com.sun.java.swing.plaf.windows.XPStyle.*; import sun.swing.table.*; +import sun.swing.SwingUtilities2; public class WindowsTableHeaderUI extends BasicTableHeaderUI { @@ -163,18 +164,13 @@ public class WindowsTableHeaderUI extends BasicTableHeaderUI { return this; } - private int viewIndexForColumn(TableColumn aColumn) { - if (aColumn != null) { - return header.getTable().convertColumnIndexToView( - aColumn.getModelIndex()); - } - return -1; - } - public void paint(Graphics g) { Dimension size = getSize(); State state = State.NORMAL; - if (column == viewIndexForColumn(header.getDraggedColumn())) { + TableColumn draggedColumn = header.getDraggedColumn(); + if (draggedColumn != null && + column == SwingUtilities2.convertColumnIndexToView( + header.getColumnModel(), draggedColumn.getModelIndex())) { state = State.PRESSED; } else if (isSelected || hasFocus || hasRollover) { state = State.HOT; diff --git a/src/share/classes/javax/swing/JTable.java b/src/share/classes/javax/swing/JTable.java index 09157ca93..dafe094a7 100644 --- a/src/share/classes/javax/swing/JTable.java +++ b/src/share/classes/javax/swing/JTable.java @@ -2583,10 +2583,8 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @see #convertColumnIndexToView */ public int convertColumnIndexToModel(int viewColumnIndex) { - if (viewColumnIndex < 0) { - return viewColumnIndex; - } - return getColumnModel().getColumn(viewColumnIndex).getModelIndex(); + return SwingUtilities2.convertColumnIndexToModel( + getColumnModel(), viewColumnIndex); } /** @@ -2603,16 +2601,8 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @see #convertColumnIndexToModel */ public int convertColumnIndexToView(int modelColumnIndex) { - if (modelColumnIndex < 0) { - return modelColumnIndex; - } - TableColumnModel cm = getColumnModel(); - for (int column = 0; column < getColumnCount(); column++) { - if (cm.getColumn(column).getModelIndex() == modelColumnIndex) { - return column; - } - } - return -1; + return SwingUtilities2.convertColumnIndexToView( + getColumnModel(), modelColumnIndex); } /** diff --git a/src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java b/src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java index a29a7fb13..5b2b10bbc 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java @@ -98,15 +98,18 @@ public class BasicTableHeaderUI extends TableHeaderUI { private Cursor otherCursor = resizeCursor; public void mouseClicked(MouseEvent e) { + if (SwingUtilities2.shouldIgnore(e, header)) { + return; + } if (e.getClickCount() % 2 == 1 && - SwingUtilities.isLeftMouseButton(e)){ + SwingUtilities.isLeftMouseButton(e)) { JTable table = header.getTable(); RowSorter sorter; if (table != null && (sorter = table.getRowSorter()) != null) { int columnIndex = header.columnAtPoint(e.getPoint()); if (columnIndex != -1) { columnIndex = table.convertColumnIndexToModel( - columnIndex); + columnIndex); sorter.toggleSortOrder(columnIndex); } } @@ -140,6 +143,9 @@ public class BasicTableHeaderUI extends TableHeaderUI { } public void mousePressed(MouseEvent e) { + if (SwingUtilities2.shouldIgnore(e, header)) { + return; + } header.setDraggedColumn(null); header.setResizingColumn(null); header.setDraggedDistance(0); @@ -182,6 +188,9 @@ public class BasicTableHeaderUI extends TableHeaderUI { } public void mouseMoved(MouseEvent e) { + if (SwingUtilities2.shouldIgnore(e, header)) { + return; + } if (canResize(getResizingColumn(e.getPoint()), header) != (header.getCursor() == resizeCursor)) { swapCursor(); @@ -190,6 +199,9 @@ public class BasicTableHeaderUI extends TableHeaderUI { } public void mouseDragged(MouseEvent e) { + if (SwingUtilities2.shouldIgnore(e, header)) { + return; + } int mouseX = e.getX(); TableColumn resizingColumn = header.getResizingColumn(); @@ -217,21 +229,23 @@ public class BasicTableHeaderUI extends TableHeaderUI { if (0 <= newColumnIndex && newColumnIndex < cm.getColumnCount()) { int width = cm.getColumn(newColumnIndex).getWidth(); if (Math.abs(draggedDistance) > (width / 2)) { - JTable table = header.getTable(); mouseXOffset = mouseXOffset + direction * width; header.setDraggedDistance(draggedDistance - direction * width); //Cache the selected column. - int selectedIndex = table.convertColumnIndexToModel( - getSelectedColumnIndex()); + int selectedIndex = + SwingUtilities2.convertColumnIndexToModel( + header.getColumnModel(), + getSelectedColumnIndex()); //Now do the move. cm.moveColumn(columnIndex, newColumnIndex); //Update the selected index. selectColumn( - table.convertColumnIndexToView(selectedIndex), + SwingUtilities2.convertColumnIndexToView( + header.getColumnModel(), selectedIndex), false); return; @@ -244,6 +258,9 @@ public class BasicTableHeaderUI extends TableHeaderUI { } public void mouseReleased(MouseEvent e) { + if (SwingUtilities2.shouldIgnore(e, header)) { + return; + } setDraggedDistance(0, viewIndexForColumn(header.getDraggedColumn())); header.setResizingColumn(null); @@ -253,10 +270,16 @@ public class BasicTableHeaderUI extends TableHeaderUI { } public void mouseEntered(MouseEvent e) { + if (SwingUtilities2.shouldIgnore(e, header)) { + return; + } updateRolloverColumn(e); } public void mouseExited(MouseEvent e) { + if (SwingUtilities2.shouldIgnore(e, header)) { + return; + } int oldRolloverColumn = rolloverColumn; rolloverColumn = -1; rolloverColumnUpdated(oldRolloverColumn, rolloverColumn); diff --git a/src/share/classes/sun/swing/SwingUtilities2.java b/src/share/classes/sun/swing/SwingUtilities2.java index 5b835bfec..3c86fa8a9 100644 --- a/src/share/classes/sun/swing/SwingUtilities2.java +++ b/src/share/classes/sun/swing/SwingUtilities2.java @@ -44,6 +44,8 @@ import javax.swing.text.JTextComponent; import javax.swing.text.DefaultHighlighter; import javax.swing.text.DefaultCaret; import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumnModel; + import sun.swing.PrintColorUIResource; import sun.swing.ImageIconUIResource; import sun.print.ProxyPrintGraphics; @@ -1807,4 +1809,54 @@ public class SwingUtilities2 { boolean three) { return liesIn(rect, p, false, false, three); } + + /** + * Maps the index of the column in the view at + * {@code viewColumnIndex} to the index of the column + * in the table model. Returns the index of the corresponding + * column in the model. If {@code viewColumnIndex} + * is less than zero, returns {@code viewColumnIndex}. + * + * @param cm the table model + * @param viewColumnIndex the index of the column in the view + * @return the index of the corresponding column in the model + * + * @see JTable#convertColumnIndexToModel(int) + * @see javax.swing.plaf.basic.BasicTableHeaderUI + */ + public static int convertColumnIndexToModel(TableColumnModel cm, + int viewColumnIndex) { + if (viewColumnIndex < 0) { + return viewColumnIndex; + } + return cm.getColumn(viewColumnIndex).getModelIndex(); + } + + /** + * Maps the index of the column in the {@code cm} at + * {@code modelColumnIndex} to the index of the column + * in the view. Returns the index of the + * corresponding column in the view; returns {@code -1} if this column + * is not being displayed. If {@code modelColumnIndex} is less than zero, + * returns {@code modelColumnIndex}. + * + * @param cm the table model + * @param modelColumnIndex the index of the column in the model + * @return the index of the corresponding column in the view + * + * @see JTable#convertColumnIndexToView(int) + * @see javax.swing.plaf.basic.BasicTableHeaderUI + */ + public static int convertColumnIndexToView(TableColumnModel cm, + int modelColumnIndex) { + if (modelColumnIndex < 0) { + return modelColumnIndex; + } + for (int column = 0; column < cm.getColumnCount(); column++) { + if (cm.getColumn(column).getModelIndex() == modelColumnIndex) { + return column; + } + } + return -1; + } } -- cgit v1.2.3 From 3e12b514abb0506fa4d992178e2035cd50f72a7c Mon Sep 17 00:00:00 2001 From: jjg Date: Tue, 25 May 2010 15:39:38 -0700 Subject: 6934615: Relative classpaths in jarfile manifests are handled inefficiently by rmic Reviewed-by: darcy --- src/share/classes/sun/rmi/rmic/BatchEnvironment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/share') diff --git a/src/share/classes/sun/rmi/rmic/BatchEnvironment.java b/src/share/classes/sun/rmi/rmic/BatchEnvironment.java index 7e86857fb..7fb911960 100644 --- a/src/share/classes/sun/rmi/rmic/BatchEnvironment.java +++ b/src/share/classes/sun/rmi/rmic/BatchEnvironment.java @@ -429,7 +429,7 @@ public class BatchEnvironment extends sun.tools.javac.BatchEnvironment { st.hasMoreTokens();) { String elt = st.nextToken(); if (jarParent != null) - elt = new File(jarParent, elt).toString(); + elt = new File(jarParent, elt).getCanonicalPath(); addFile(elt, warn); } } finally { -- cgit v1.2.3 From 45542ccf3ef0ad10b4a489793dd669bdf4b806b5 Mon Sep 17 00:00:00 2001 From: peterz Date: Wed, 26 May 2010 20:22:23 +0400 Subject: 6632959: swing html parser doesn't know € or › Reviewed-by: alexp --- .../classes/javax/swing/text/html/parser/html32.bdtd | Bin 16173 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/share/classes/javax/swing/text/html/parser/html32.bdtd (limited to 'src/share') diff --git a/src/share/classes/javax/swing/text/html/parser/html32.bdtd b/src/share/classes/javax/swing/text/html/parser/html32.bdtd deleted file mode 100644 index a48d51ce8..000000000 Binary files a/src/share/classes/javax/swing/text/html/parser/html32.bdtd and /dev/null differ -- cgit v1.2.3 From 03c65b1a7f482f28cdd714092216ae2c9148a4c2 Mon Sep 17 00:00:00 2001 From: rupashka Date: Wed, 26 May 2010 22:02:32 +0400 Subject: 6925473: REGRESSION: JOptionPane in dialog is full-screen height Reviewed-by: peterz --- .../classes/javax/swing/text/WrappedPlainView.java | 64 ++-------------------- 1 file changed, 4 insertions(+), 60 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/javax/swing/text/WrappedPlainView.java b/src/share/classes/javax/swing/text/WrappedPlainView.java index b845419ad..6b8ddbed9 100644 --- a/src/share/classes/javax/swing/text/WrappedPlainView.java +++ b/src/share/classes/javax/swing/text/WrappedPlainView.java @@ -24,8 +24,6 @@ */ package javax.swing.text; -import java.util.Vector; -import java.util.Properties; import java.awt.*; import java.lang.ref.SoftReference; import javax.swing.event.*; @@ -236,9 +234,6 @@ public class WrappedPlainView extends BoxView implements TabExpander { Segment segment = SegmentCache.getSharedSegment(); loadText(segment, p0, p1); int currentWidth = getWidth(); - if (currentWidth == Integer.MAX_VALUE) { - currentWidth = (int) getDefaultSpan(View.X_AXIS); - } if (wordWrap) { p = p0 + Utilities.getBreakLocation(segment, metrics, tabBase, tabBase + currentWidth, @@ -324,53 +319,6 @@ public class WrappedPlainView extends BoxView implements TabExpander { tabSize = getTabSize() * metrics.charWidth('m'); } - /** - * Return reasonable default values for the view dimensions. The standard - * text terminal size 80x24 is pretty suitable for the wrapped plain view. - * - * The size should not be larger than the component housing the view's - * container. - */ - private float getDefaultSpan(int axis) { - Container host = getContainer(); - Component parent = null; - - if (host != null) { - parent = host.getParent(); - } - - switch (axis) { - case View.X_AXIS: - int defaultWidth = 80 * metrics.getWidths()['M']; - int parentWidth = 0; - - if (parent != null) { - parentWidth = parent.getWidth(); - } - - if (defaultWidth > parentWidth) { - return parentWidth; - } - return defaultWidth; - - case View.Y_AXIS: - int defaultHeight = 24 * metrics.getHeight(); - int parentHeight = 0; - - if (parent != null) { - parentHeight = parent.getHeight(); - } - - if (defaultHeight > parentHeight) { - return parentHeight; - } - return defaultHeight; - - default: - throw new IllegalArgumentException("Invalid axis: " + axis); - } - } - // --- TabExpander methods ------------------------------------------ /** @@ -605,18 +553,14 @@ public class WrappedPlainView extends BoxView implements TabExpander { if (width == Integer.MAX_VALUE) { // We have been initially set to MAX_VALUE, but we don't // want this as our preferred. - width = getDefaultSpan(axis); + return 100f; } return width; case View.Y_AXIS: - if (getDocument().getLength() > 0) { - if ((lineCount < 0) || widthChanging) { - breakLines(getStartOffset()); - } - return lineCount * metrics.getHeight(); - } else { - return getDefaultSpan(axis); + if (lineCount < 0 || widthChanging) { + breakLines(getStartOffset()); } + return lineCount * metrics.getHeight(); default: throw new IllegalArgumentException("Invalid axis: " + axis); } -- cgit v1.2.3 From 606238bc39f428357124255de60988e3650ab9de Mon Sep 17 00:00:00 2001 From: weijun Date: Thu, 27 May 2010 17:24:40 +0800 Subject: 6955783: ServiceUnavailableException caught even the secondary DNS is available Reviewed-by: vinnie --- src/share/classes/com/sun/jndi/dns/DnsClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/com/sun/jndi/dns/DnsClient.java b/src/share/classes/com/sun/jndi/dns/DnsClient.java index 790077a4f..19bd6df3a 100644 --- a/src/share/classes/com/sun/jndi/dns/DnsClient.java +++ b/src/share/classes/com/sun/jndi/dns/DnsClient.java @@ -525,11 +525,11 @@ public class DnsClient { } byte[] pkt; if ((pkt = (byte[]) resps.get(xid)) != null) { + checkResponseCode(new Header(pkt, pkt.length)); synchronized (queuesLock) { resps.remove(xid); reqs.remove(xid); } - checkResponseCode(new Header(pkt, pkt.length)); if (debug) { dprint("FOUND (" + Thread.currentThread() + @@ -562,12 +562,12 @@ public class DnsClient { dprint("XID MATCH:" + xid); } + checkResponseCode(hdr); // remove the response for the xid if received by some other thread. synchronized (queuesLock) { resps.remove(xid); reqs.remove(xid); } - checkResponseCode(hdr); return true; } -- cgit v1.2.3 From cd0377f26ab30e5455bb31546b2609c56e2eaa01 Mon Sep 17 00:00:00 2001 From: prr Date: Thu, 27 May 2010 08:53:45 -0700 Subject: 6954424: Support OpenType/CFF fonts in JDK 7 Reviewed-by: bae, igor --- src/share/classes/java/awt/Font.java | 4 ++++ src/share/classes/sun/font/SunFontManager.java | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/java/awt/Font.java b/src/share/classes/java/awt/Font.java index 792acdd07..c0ef91441 100644 --- a/src/share/classes/java/awt/Font.java +++ b/src/share/classes/java/awt/Font.java @@ -343,6 +343,10 @@ public class Font implements java.io.Serializable * Identify a font resource of type TRUETYPE. * Used to specify a TrueType font resource to the * {@link #createFont} method. + * The TrueType format was extended to become the OpenType + * format, which adds support for fonts with Postscript outlines, + * this tag therefore references these fonts, as well as those + * with TrueType outlines. * @since 1.3 */ diff --git a/src/share/classes/sun/font/SunFontManager.java b/src/share/classes/sun/font/SunFontManager.java index 197397a1b..5b9c4b50a 100644 --- a/src/share/classes/sun/font/SunFontManager.java +++ b/src/share/classes/sun/font/SunFontManager.java @@ -73,7 +73,9 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE { return(name.startsWith(".ttf", offset) || name.startsWith(".TTF", offset) || name.startsWith(".ttc", offset) || - name.startsWith(".TTC", offset)); + name.startsWith(".TTC", offset) || + name.startsWith(".otf", offset) || + name.startsWith(".OTF", offset)); } } } @@ -108,7 +110,9 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE { name.startsWith(".ttf", offset) || name.startsWith(".TTF", offset) || name.startsWith(".ttc", offset) || - name.startsWith(".TTC", offset); + name.startsWith(".TTC", offset) || + name.startsWith(".otf", offset) || + name.startsWith(".OTF", offset); if (isTT) { return true; } else if (noType1Font) { -- cgit v1.2.3 From f532ba1c449338a40a6b895c78af795823a4487b Mon Sep 17 00:00:00 2001 From: peterz Date: Fri, 28 May 2010 13:32:40 +0400 Subject: 6954231: SynthTextPaneUI.installUI() doesn't set component to opaque even if prop was not set by client progr Reviewed-by: alexp --- .../javax/swing/plaf/basic/BasicTextUI.java | 16 ++++++--------- .../javax/swing/plaf/synth/SynthTextPaneUI.java | 23 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 11 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/javax/swing/plaf/basic/BasicTextUI.java b/src/share/classes/javax/swing/plaf/basic/BasicTextUI.java index 8d0291103..2c6c5601d 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicTextUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicTextUI.java @@ -779,20 +779,16 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory { if (c instanceof JTextComponent) { editor = (JTextComponent) c; + // common case is background painted... this can + // easily be changed by subclasses or from outside + // of the component. + LookAndFeel.installProperty(editor, "opaque", Boolean.TRUE); + LookAndFeel.installProperty(editor, "autoscrolls", Boolean.TRUE); + // install defaults installDefaults(); installDefaults2(); - // This is a workaround as these should not override what synth has - // set them to - if (! (this instanceof SynthUI)) { - // common case is background painted... this can - // easily be changed by subclasses or from outside - // of the component. - LookAndFeel.installProperty(editor, "opaque", Boolean.TRUE); - LookAndFeel.installProperty(editor, "autoscrolls", Boolean.TRUE); - } - // attach to the model and editor editor.addPropertyChangeListener(updateHandler); Document doc = editor.getDocument(); diff --git a/src/share/classes/javax/swing/plaf/synth/SynthTextPaneUI.java b/src/share/classes/javax/swing/plaf/synth/SynthTextPaneUI.java index 0cef82e2e..f78261e20 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthTextPaneUI.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthTextPaneUI.java @@ -72,7 +72,28 @@ public class SynthTextPaneUI extends SynthEditorPaneUI { } /** - * @inheritDoc + * Installs the UI for a component. This does the following + * things. + *

        + *
      1. + * Sets opaqueness of the associated component according to its style, + * if the opaque property has not already been set by the client program. + *
      2. + * Installs the default caret and highlighter into the + * associated component. These properties are only set if their + * current value is either {@code null} or an instance of + * {@link UIResource}. + *
      3. + * Attaches to the editor and model. If there is no + * model, a default one is created. + *
      4. + * Creates the view factory and the view hierarchy used + * to represent the model. + *
      + * + * @param c the editor component + * @see BasicTextUI#installUI + * @see ComponentUI#installUI */ @Override public void installUI(JComponent c) { -- cgit v1.2.3 From 642334614e757c5e1a50ebd2ccfb4f9d3de92105 Mon Sep 17 00:00:00 2001 From: alexp Date: Fri, 28 May 2010 19:46:26 +0400 Subject: 6889007: No resize cursor during hovering mouse over JTable Reviewed-by: rupashka --- .../classes/javax/swing/plaf/basic/BasicTableHeaderUI.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java b/src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java index 5b2b10bbc..44b97e778 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java @@ -98,7 +98,7 @@ public class BasicTableHeaderUI extends TableHeaderUI { private Cursor otherCursor = resizeCursor; public void mouseClicked(MouseEvent e) { - if (SwingUtilities2.shouldIgnore(e, header)) { + if (!header.isEnabled()) { return; } if (e.getClickCount() % 2 == 1 && @@ -143,7 +143,7 @@ public class BasicTableHeaderUI extends TableHeaderUI { } public void mousePressed(MouseEvent e) { - if (SwingUtilities2.shouldIgnore(e, header)) { + if (!header.isEnabled()) { return; } header.setDraggedColumn(null); @@ -188,7 +188,7 @@ public class BasicTableHeaderUI extends TableHeaderUI { } public void mouseMoved(MouseEvent e) { - if (SwingUtilities2.shouldIgnore(e, header)) { + if (!header.isEnabled()) { return; } if (canResize(getResizingColumn(e.getPoint()), header) != @@ -199,7 +199,7 @@ public class BasicTableHeaderUI extends TableHeaderUI { } public void mouseDragged(MouseEvent e) { - if (SwingUtilities2.shouldIgnore(e, header)) { + if (!header.isEnabled()) { return; } int mouseX = e.getX(); @@ -258,7 +258,7 @@ public class BasicTableHeaderUI extends TableHeaderUI { } public void mouseReleased(MouseEvent e) { - if (SwingUtilities2.shouldIgnore(e, header)) { + if (!header.isEnabled()) { return; } setDraggedDistance(0, viewIndexForColumn(header.getDraggedColumn())); @@ -270,14 +270,14 @@ public class BasicTableHeaderUI extends TableHeaderUI { } public void mouseEntered(MouseEvent e) { - if (SwingUtilities2.shouldIgnore(e, header)) { + if (!header.isEnabled()) { return; } updateRolloverColumn(e); } public void mouseExited(MouseEvent e) { - if (SwingUtilities2.shouldIgnore(e, header)) { + if (!header.isEnabled()) { return; } int oldRolloverColumn = rolloverColumn; -- cgit v1.2.3 From e150109a159cfc1a18d29649485100dd3a95a291 Mon Sep 17 00:00:00 2001 From: alexp Date: Fri, 28 May 2010 19:55:52 +0400 Subject: 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem) Reviewed-by: rupashka --- src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/share') diff --git a/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java b/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java index 5a94a3631..bc9e409e6 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java @@ -3524,7 +3524,11 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { } else if (name =="indexForTitle") { calculatedBaseline = false; - updateHtmlViews((Integer)e.getNewValue()); + Integer index = (Integer) e.getNewValue(); + // remove the current index + // to let updateHtmlViews() insert the correct one + htmlViews.removeElementAt(index); + updateHtmlViews(index); } else if (name == "tabLayoutPolicy") { BasicTabbedPaneUI.this.uninstallUI(pane); BasicTabbedPaneUI.this.installUI(pane); -- cgit v1.2.3 From f6c49fc173256ff0ff0fba157c5604dcf61a64a9 Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 28 May 2010 16:59:44 +0100 Subject: 6956840: (ch) Rawtype warning when compiling sun.nio.ch.CompletedFuture Summary: Add missing generic type to CompletedFuture construction and remove unneeded SuppressWarnings annotations. Reviewed-by: alanb --- src/share/classes/sun/nio/ch/CompletedFuture.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/share') diff --git a/src/share/classes/sun/nio/ch/CompletedFuture.java b/src/share/classes/sun/nio/ch/CompletedFuture.java index c3152db60..ad355d3fe 100644 --- a/src/share/classes/sun/nio/ch/CompletedFuture.java +++ b/src/share/classes/sun/nio/ch/CompletedFuture.java @@ -44,20 +44,17 @@ final class CompletedFuture implements Future { this.exc = exc; } - @SuppressWarnings("unchecked") static CompletedFuture withResult(V result) { return new CompletedFuture(result, null); } - @SuppressWarnings("unchecked") static CompletedFuture withFailure(Throwable exc) { // exception must be IOException or SecurityException if (!(exc instanceof IOException) && !(exc instanceof SecurityException)) exc = new IOException(exc); - return new CompletedFuture(null, exc); + return new CompletedFuture(null, exc); } - @SuppressWarnings("unchecked") static CompletedFuture withResult(V result, Throwable exc) { if (exc == null) { return withResult(result); -- cgit v1.2.3 From 15e677fe29164e1d11f364eba1c541587ddb239e Mon Sep 17 00:00:00 2001 From: ceisserer Date: Fri, 28 May 2010 11:37:44 -0700 Subject: 6307603: [X11] Use RENDER extension for complex operations done in software Reviewed-by: bae, igor, prr --- .../classes/sun/font/GlyphDisposedListener.java | 32 ++++++++ src/share/classes/sun/font/StrikeCache.java | 89 +++++++++++++++++++--- .../classes/sun/java2d/pipe/BufferedPaints.java | 2 +- .../classes/sun/java2d/pipe/RenderBuffer.java | 5 ++ .../services/sun.java2d.pipe.RenderingEngine | 5 +- src/share/native/sun/font/AccelGlyphCache.c | 1 + src/share/native/sun/font/fontscalerdefs.h | 13 +++- src/share/native/sun/font/freetypeScaler.c | 3 +- src/share/native/sun/font/sunFont.c | 11 ++- .../native/sun/java2d/opengl/OGLTextRenderer.c | 10 ++- 10 files changed, 151 insertions(+), 20 deletions(-) create mode 100644 src/share/classes/sun/font/GlyphDisposedListener.java (limited to 'src/share') diff --git a/src/share/classes/sun/font/GlyphDisposedListener.java b/src/share/classes/sun/font/GlyphDisposedListener.java new file mode 100644 index 000000000..41a38380c --- /dev/null +++ b/src/share/classes/sun/font/GlyphDisposedListener.java @@ -0,0 +1,32 @@ +/* + * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package sun.font; + +import java.util.*; + +public interface GlyphDisposedListener { + public void glyphDisposed(ArrayList glyphs); +} diff --git a/src/share/classes/sun/font/StrikeCache.java b/src/share/classes/sun/font/StrikeCache.java index 9e5b02a86..dd9b1b6da 100644 --- a/src/share/classes/sun/font/StrikeCache.java +++ b/src/share/classes/sun/font/StrikeCache.java @@ -31,6 +31,7 @@ import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.SoftReference; import java.lang.ref.WeakReference; +import java.util.*; import sun.java2d.Disposer; import sun.java2d.pipe.BufferedContext; @@ -66,6 +67,9 @@ public final class StrikeCache { static ReferenceQueue refQueue = Disposer.getQueue(); + static ArrayList disposeListeners = new ArrayList(1); + + /* Reference objects may have their referents cleared when GC chooses. * During application client start-up there is typically at least one * GC which causes the hotspot VM to clear soft (not just weak) references @@ -108,6 +112,8 @@ public final class StrikeCache { static int topLeftXOffset; static int topLeftYOffset; static int pixelDataOffset; + static int cacheCellOffset; + static int managedOffset; static long invisibleGlyphPtr; /* Native method used to return information used for unsafe @@ -129,7 +135,7 @@ public final class StrikeCache { static { - long[] nativeInfo = new long[11]; + long[] nativeInfo = new long[13]; getGlyphCacheDescription(nativeInfo); //Can also get address size from Unsafe class :- //nativeAddressSize = unsafe.addressSize(); @@ -144,6 +150,9 @@ public final class StrikeCache { topLeftYOffset = (int)nativeInfo[8]; pixelDataOffset = (int)nativeInfo[9]; invisibleGlyphPtr = nativeInfo[10]; + cacheCellOffset = (int) nativeInfo[11]; + managedOffset = (int) nativeInfo[12]; + if (nativeAddressSize < 4) { throw new InternalError("Unexpected address size for font data: " + nativeAddressSize); @@ -195,10 +204,10 @@ public final class StrikeCache { private static final void doDispose(FontStrikeDisposer disposer) { if (disposer.intGlyphImages != null) { - freeIntMemory(disposer.intGlyphImages, + freeCachedIntMemory(disposer.intGlyphImages, disposer.pScalerContext); } else if (disposer.longGlyphImages != null) { - freeLongMemory(disposer.longGlyphImages, + freeCachedLongMemory(disposer.longGlyphImages, disposer.pScalerContext); } else if (disposer.segIntGlyphImages != null) { /* NB Now making multiple JNI calls in this case. @@ -207,7 +216,7 @@ public final class StrikeCache { */ for (int i=0; i 0) { + ArrayList gids = null; + + for (int i = 0; i < glyphPtrs.length; i++) { + if (glyphPtrs[i] != 0 && unsafe.getByte(glyphPtrs[i] + managedOffset) == 0 + && unsafe.getInt(glyphPtrs[i] + cacheCellOffset) != 0) { + + if (gids == null) { + gids = new ArrayList(); + } + gids.add((long) glyphPtrs[i]); + } + } + + if (gids != null) { + notifyDisposeListeners(gids); + } + } + } + + freeIntMemory(glyphPtrs, pContext); + } + + private static void freeCachedLongMemory(long[] glyphPtrs, long pContext) { + synchronized(disposeListeners) { + if (disposeListeners.size() > 0) { + ArrayList gids = null; + + for (int i=0; i < glyphPtrs.length; i++) { + if (glyphPtrs[i] != 0 + && unsafe.getByte(glyphPtrs[i] + managedOffset) == 0 + && unsafe.getInt(glyphPtrs[i] + cacheCellOffset) != 0) { + + if (gids == null) { + gids = new ArrayList(); + } + gids.add((long) glyphPtrs[i]); + } + } + + if (gids != null) { + notifyDisposeListeners(gids); + } + } + } + + freeLongMemory(glyphPtrs, pContext); + } + + public static void addGlyphDisposedListener(GlyphDisposedListener listener) { + synchronized(disposeListeners) { + disposeListeners.add(listener); + } + } + + private static void notifyDisposeListeners(ArrayList glyphs) { + for (GlyphDisposedListener listener : disposeListeners) { + listener.glyphDisposed(glyphs); + } + } public static Reference getStrikeRef(FontStrike strike) { return getStrikeRef(strike, cacheRefTypeWeak); diff --git a/src/share/classes/sun/java2d/pipe/BufferedPaints.java b/src/share/classes/sun/java2d/pipe/BufferedPaints.java index 604590ff6..3ff1b3b15 100644 --- a/src/share/classes/sun/java2d/pipe/BufferedPaints.java +++ b/src/share/classes/sun/java2d/pipe/BufferedPaints.java @@ -307,7 +307,7 @@ public class BufferedPaints { * linear RGB space. Copied directly from the * MultipleGradientPaintContext class. */ - private static int convertSRGBtoLinearRGB(int color) { + public static int convertSRGBtoLinearRGB(int color) { float input, output; input = color / 255.0f; diff --git a/src/share/classes/sun/java2d/pipe/RenderBuffer.java b/src/share/classes/sun/java2d/pipe/RenderBuffer.java index f0b8069a5..cf4e56918 100644 --- a/src/share/classes/sun/java2d/pipe/RenderBuffer.java +++ b/src/share/classes/sun/java2d/pipe/RenderBuffer.java @@ -117,6 +117,11 @@ public class RenderBuffer { curAddress = baseAddress; } + public final RenderBuffer skip(long numBytes) { + curAddress += numBytes; + return this; + } + /** * putByte() methods... */ diff --git a/src/share/classes/sun/java2d/pisces/META-INF/services/sun.java2d.pipe.RenderingEngine b/src/share/classes/sun/java2d/pisces/META-INF/services/sun.java2d.pipe.RenderingEngine index 607ff5905..66b2ae9c6 100644 --- a/src/share/classes/sun/java2d/pisces/META-INF/services/sun.java2d.pipe.RenderingEngine +++ b/src/share/classes/sun/java2d/pisces/META-INF/services/sun.java2d.pipe.RenderingEngine @@ -1,2 +1,5 @@ +# Jules Rendering Engine module +sun.java2d.jules.JulesRenderingEngine + # Pisces Rendering Engine module -sun.java2d.pisces.PiscesRenderingEngine +sun.java2d.pisces.PiscesRenderingEngine \ No newline at end of file diff --git a/src/share/native/sun/font/AccelGlyphCache.c b/src/share/native/sun/font/AccelGlyphCache.c index 73e94a91c..7d293fd7a 100644 --- a/src/share/native/sun/font/AccelGlyphCache.c +++ b/src/share/native/sun/font/AccelGlyphCache.c @@ -325,6 +325,7 @@ AccelGlyphCache_AddCellInfo(GlyphInfo *glyph, CacheCellInfo *cellInfo) cellInfo->glyphInfo = glyph; cellInfo->nextGCI = glyph->cellInfo; glyph->cellInfo = cellInfo; + glyph->managed = MANAGED_GLYPH; } /** diff --git a/src/share/native/sun/font/fontscalerdefs.h b/src/share/native/sun/font/fontscalerdefs.h index d7fd1fbe6..b83f7e00e 100644 --- a/src/share/native/sun/font/fontscalerdefs.h +++ b/src/share/native/sun/font/fontscalerdefs.h @@ -84,15 +84,26 @@ typedef float t2kScalar; #define t2kScalarAverage(a, b) (((a) + (b)) / (t2kScalar)(2)) + /* managed: 1 means the glyph has a hardware cached + * copy, and its freeing is managed by the the usual + * 2D disposer code. + * A value of 0 means its either unaccelerated (and so has no cellInfos) + * or we want to free this in a different way. + * The field uses previously unused padding, so doesn't enlarge + * the structure. + */ +#define UNMANAGED_GLYPH 0 +#define MANAGED_GLYPH 1 typedef struct GlyphInfo { float advanceX; float advanceY; UInt16 width; UInt16 height; UInt16 rowBytes; + UInt8 managed; float topLeftX; float topLeftY; - struct _CacheCellInfo *cellInfo; + void *cellInfo; UInt8 *image; } GlyphInfo; diff --git a/src/share/native/sun/font/freetypeScaler.c b/src/share/native/sun/font/freetypeScaler.c index 93baaea47..66ec606af 100644 --- a/src/share/native/sun/font/freetypeScaler.c +++ b/src/share/native/sun/font/freetypeScaler.c @@ -782,6 +782,7 @@ Java_sun_font_FreetypeFontScaler_getGlyphImageNative( return ptr_to_jlong(glyphInfo); } glyphInfo->cellInfo = NULL; + glyphInfo->managed = UNMANAGED_GLYPH; glyphInfo->rowBytes = width; glyphInfo->width = width; glyphInfo->height = height; @@ -1130,7 +1131,7 @@ static void addToGP(GPData* gpdata, FT_Outline*outline) { current_type = SEG_LINETO; } } else if (FT_CURVE_TAG(outline->tags[i]) == FT_CURVE_TAG_CUBIC) { - /* Bit 1 is meaningful for ‘off’ points only. + /* Bit 1 is meaningful for 'off' points only. If set, it indicates a third-order Bezier arc control point; and a second-order control point if unset. */ current_type = SEG_CUBICTO; diff --git a/src/share/native/sun/font/sunFont.c b/src/share/native/sun/font/sunFont.c index 3bd914518..84fa28f08 100644 --- a/src/share/native/sun/font/sunFont.c +++ b/src/share/native/sun/font/sunFont.c @@ -233,7 +233,8 @@ JNIEXPORT void JNICALL Java_sun_font_StrikeCache_freeIntMemory for (i=0; i< len; i++) { if (ptrs[i] != 0) { GlyphInfo *ginfo = (GlyphInfo *)ptrs[i]; - if (ginfo->cellInfo != NULL) { + if (ginfo->cellInfo != NULL && + ginfo->managed == MANAGED_GLYPH) { // invalidate this glyph's accelerated cache cell AccelGlyphCache_RemoveAllCellInfos(ginfo); } @@ -264,7 +265,8 @@ JNIEXPORT void JNICALL Java_sun_font_StrikeCache_freeLongMemory for (i=0; i< len; i++) { if (ptrs[i] != 0L) { GlyphInfo *ginfo = (GlyphInfo *) jlong_to_ptr(ptrs[i]); - if (ginfo->cellInfo != NULL) { + if (ginfo->cellInfo != NULL && + ginfo->managed == MANAGED_GLYPH) { AccelGlyphCache_RemoveAllCellInfos(ginfo); } free((void*)ginfo); @@ -285,7 +287,7 @@ Java_sun_font_StrikeCache_getGlyphCacheDescription GlyphInfo *info; size_t baseAddr; - if ((*env)->GetArrayLength(env, results) < 10) { + if ((*env)->GetArrayLength(env, results) < 13) { return; } @@ -310,6 +312,9 @@ Java_sun_font_StrikeCache_getGlyphCacheDescription nresults[8] = (size_t)&(info->topLeftY)-baseAddr; nresults[9] = (size_t)&(info->image)-baseAddr; nresults[10] = (jlong)(uintptr_t)info; /* invisible glyph */ + nresults[11] = (size_t)&(info->cellInfo)-baseAddr; + nresults[12] = (size_t)&(info->managed)-baseAddr; + (*env)->ReleasePrimitiveArrayCritical(env, results, nresults, 0); } diff --git a/src/share/native/sun/java2d/opengl/OGLTextRenderer.c b/src/share/native/sun/java2d/opengl/OGLTextRenderer.c index b709be3cc..fa98114f7 100644 --- a/src/share/native/sun/java2d/opengl/OGLTextRenderer.c +++ b/src/share/native/sun/java2d/opengl/OGLTextRenderer.c @@ -244,6 +244,7 @@ static void OGLTR_AddToGlyphCache(GlyphInfo *glyph, jboolean rgbOrder) { GLenum pixelFormat; + CacheCellInfo *ccinfo; J2dTraceLn(J2D_TRACE_INFO, "OGLTR_AddToGlyphCache"); @@ -258,11 +259,12 @@ OGLTR_AddToGlyphCache(GlyphInfo *glyph, jboolean rgbOrder) } AccelGlyphCache_AddGlyph(glyphCache, glyph); + ccinfo = (CacheCellInfo *) glyph->cellInfo; - if (glyph->cellInfo != NULL) { + if (ccinfo != NULL) { // store glyph image in texture cell j2d_glTexSubImage2D(GL_TEXTURE_2D, 0, - glyph->cellInfo->x, glyph->cellInfo->y, + ccinfo->x, ccinfo->y, glyph->width, glyph->height, pixelFormat, GL_UNSIGNED_BYTE, glyph->image); } @@ -668,7 +670,7 @@ OGLTR_DrawGrayscaleGlyphViaCache(OGLContext *oglc, } } - cell = ginfo->cellInfo; + cell = (CacheCellInfo *) (ginfo->cellInfo); cell->timesRendered++; x1 = (jfloat)x; @@ -871,7 +873,7 @@ OGLTR_DrawLCDGlyphViaCache(OGLContext *oglc, OGLSDOps *dstOps, } } - cell = ginfo->cellInfo; + cell = (CacheCellInfo *) (ginfo->cellInfo); cell->timesRendered++; // location of the glyph in the destination's coordinate space -- cgit v1.2.3 From 9250509d4d1cf6646f820249b7884713609ac148 Mon Sep 17 00:00:00 2001 From: lana Date: Mon, 7 Jun 2010 15:35:36 -0700 Subject: 6888130: SwingSet2: Demo is not launching and throwing NPE. Reviewed-by: prr --- src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/share') diff --git a/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java b/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java index 208790270..0e9e23caf 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java @@ -3527,7 +3527,9 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { Integer index = (Integer) e.getNewValue(); // remove the current index // to let updateHtmlViews() insert the correct one - htmlViews.removeElementAt(index); + if (htmlViews != null) { + htmlViews.removeElementAt(index); + } updateHtmlViews(index); } else if (name == "tabLayoutPolicy") { BasicTabbedPaneUI.this.uninstallUI(pane); -- cgit v1.2.3