Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/Main.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/Main.java (revision 674165) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/Main.java (working copy) @@ -20,8 +20,8 @@ import org.apache.harmony.tools.policytool.view.MainFrame; /** - * The main class that parses command line parameters, and starts the - * GUI if everything everything is ok. + * The main class that parses command line parameters, and starts the GUI if everything everything is ok. + * */ public class Main { @@ -64,15 +64,18 @@ if ( arguments.length < 2 ) { // policy file name must be provided printErrorMessageAndUsage( "Missing policy file name!" ); return false; - } else { + } + else { policyFileName = arguments[ 1 ]; return true; } - } else { + } + else { printErrorMessageAndUsage( "Illegal option: " + arguments[ 0 ] ); return false; - } else - return true; // else the arguments are ignored + } + else + return true; // else the arguments are ignored } } @@ -77,8 +80,7 @@ } /** - * Prints an error message to the standard output followed by the - * program ussage. + * Prints an error message to the standard output followed by the program ussage. * @param errorMessage error message to be printed */ private static void printErrorMessageAndUsage( final String errorMessage ) { Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/GrantEntry.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/GrantEntry.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/GrantEntry.java (revision 0) @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.tools.policytool.model; + +import java.util.ArrayList; +import java.util.List; + +/** + * Represents an entry which specifies some grant permission. + */ +public class GrantEntry extends PolicyEntry { + + /** Keyword of the keystore entry in the policy text. */ + public static final String KEYWORD = "grant"; + + /** Code base of the grant entry. */ + private String codeBase; + /** Signed by alias (from the keystore). */ + private String signedBy; + + /** List of principals of the entry. */ + private List< Principal > principalList = new ArrayList< Principal >(); + /** List of permissions of the entry. */ + private List< Permission > permissionList = new ArrayList< Permission >(); + + /** + * Returns the code base of the entry. + * @return the code base of the entry + */ + public String getCodeBase() { + return codeBase; + } + + /** + * Sets the code base of the entry. + * @param codeBase the code base of the entry + */ + public void setCodeBase( final String codeBase ) { + this.codeBase = codeBase; + } + + /** + * Returns the signed by alias of the entry. + * @return the signed by alias of the entry + */ + public String getSignedBy() { + return signedBy; + } + + /** + * Returns the signed by alias of the entry. + * @param signedBy the signed by alias of the entry to be set + */ + public void setSignedBy( final String signedBy ) { + this.signedBy = signedBy; + } + + /** + * Returns the list of principals of the entry. + * @return the list of principals of the entry + */ + public List< Principal > getPrincipalList() { + return principalList; + } + + /** + * Sets the list of principals of the entry. + * @param principalList list of principals of the entry to be set + */ + public void setPrincipalList( final List< Principal > principalList ) { + this.principalList = principalList; + } + + /** + * Returns the list of permissions of the entry. + * @return the list of permissions of the entry + */ + public List< Permission > getPermissionList() { + return permissionList; + } + + /** + * Sets the list of permissions of the entry. + * @param permissionList list of permissions of the entry to be set + */ + public void setPermissionList( final List< Permission > permissionList ) { + this.permissionList = permissionList; + } + + @Override + public String getText() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setText( final String entryText ) { + // TODO Auto-generated method stub + } + +} Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Permission.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Permission.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Permission.java (revision 0) @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.tools.policytool.model; + +/** + * Represents a principal for the grant entries. + */ +public class Permission { + + /** Name of the class of the permission. */ + private String className; + /** Name of target of the permission. */ + private String targetName; + /** Actions of the permission. */ + private String actions; + /** Signed by alias of the permission (from the keystore). */ + private String signedBy; + + /** + * Returns the name of the class of the permission. + * @return the name of the class of the permission + */ + public String getClassName() { + return className; + } + + /** + * Sets the name of the class of the permission. + * @param className the name of the class of the permission to be set + */ + public void setClassName( final String className ) { + this.className = className; + } + + /** + * Returns the name of target of the permission. + * @return the name of target of the permission + */ + public String getTargetName() { + return targetName; + } + + /** + * Sets the name of target of the permission + * @param targetName the name of target of the permission to be set + */ + public void setTargetName( final String targetName ) { + this.targetName = targetName; + } + + /** + * Returns the actions of the permission. + * @return the actions of the permission + */ + public String getActions() { + return actions; + } + + /** + * Sets the actions of the permission + * @param actions actions of the permission to be set + */ + public void setActions( final String actions ) { + this.actions = actions; + } + + /** + * Returns the signed by alias of the permission. + * @return the signed by alias of the permission + */ + public String getSignedBy() { + return signedBy; + } + + /** + * Returns the signed by alias of the permission. + * @param signedBy the signed by alias of the permission to be set + */ + public void setSignedBy( final String signedBy ) { + this.signedBy = signedBy; + } + +} Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Principal.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Principal.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Principal.java (revision 0) @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.tools.policytool.model; + +/** + * Represents a principal for the grant entries. + */ +public class Principal { + + /** Type of the principal. */ + private String type; + /** Name of the principal. */ + private String name; + + /** + * Returns the type. + * @return the type + */ + public String getType() { + return type; + } + + /** + * Sets the type of the principal. + * @param type type of the principal to be set + */ + public void setType( final String type ) { + this.type = type; + } + + /** + * Returns the name of the principal. + * @return the name of the principal + */ + public String getName() { + return name; + } + + /** + * Sets the name of the principal. + * @param name name of the principal to be set + */ + public void setName( final String name ) { + this.name = name; + } + +} Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystoreEntry.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystoreEntry.java (revision 674165) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystoreEntry.java (working copy) @@ -39,6 +39,54 @@ /** Provider of the keystore. */ private String provider; + /** + * Returns the keystore url. + * @return the keystore url + */ + public String getUrl() { + return url; + } + + /** + * Sets the keystore url. + * @param url keystore url to be set + */ + public void setUrl( final String url ) { + this.url = url; + } + + /** + * Returns the keystore type. + * @return the keystore type + */ + public String getType() { + return type; + } + + /** + * Sets the keystore type. + * @param type keystore type to be set + */ + public void setType( final String type ) { + this.type = type; + } + + /** + * Returns the keystore provider. + * @return the keystore provider + */ + public String getProvider() { + return provider; + } + + /** + * sets the keystore provider. + * @param provider keystore provider to be set + */ + public void setProvider( final String provider ) { + this.provider = provider; + } + @Override public String getText() { final StringBuilder textBuilder = new StringBuilder( KEYWORD ); Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystorePasswordURLEntry.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystorePasswordURLEntry.java (revision 674165) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystorePasswordURLEntry.java (working copy) @@ -33,6 +33,22 @@ /** URL of the keystore password. */ private String url; + /** + * Returns the keystore password url. + * @return the keystore password url + */ + public String getUrl() { + return url; + } + + /** + * Sets the keystore password URL + * @param url the keystore password URL to be set + */ + public void setUrl( final String url ) { + this.url = url; + } + @Override public String getText() { return KEYWORD + " \"" + url + '\"' + TERMINATOR_CHAR; Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/BaseFormDialog.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/BaseFormDialog.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/BaseFormDialog.java (revision 0) @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.tools.policytool.view; + +import java.awt.BorderLayout; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JPanel; + +/** + * Represents a base form dialog which will be used to query data of policy entries. + */ +public abstract class BaseFormDialog extends JDialog implements ActionListener { + + /** Reference to the owner frame. */ + private final Frame ownerFrame; + + /** Ok button of the form dialog. */ + private final JButton okButton = new JButton( "OK" ); + /** Cancel button of the form dialog. */ + private final JButton cancelButton = new JButton( "Cancel" ); + + /** Reference to the owner editor panel. This reference can (will) be used to indicate new data/dirty state. */ + protected final EditorPanel ownerEditorPanel; + + /** + * Creates a new BaseFormDialog. + * @param ownerFrame owner frame of the dialog + * @param title title of the dialog + * @param ownerEditorPanel reference to the owner editor panel + */ + public BaseFormDialog( final Frame ownerFrame, final String title, final EditorPanel ownerEditorPanel ) { + super( ownerFrame, title, true ); + + this.ownerFrame = ownerFrame; + this.ownerEditorPanel = ownerEditorPanel; + + buildBaseGUI(); + setDefaultCloseOperation( DISPOSE_ON_CLOSE ); + } + + /** + * Builds the graphical user interface of the base dialog.
+ * Adds a button panel to the bottom of the dialog containing an ok and a cancel button. + */ + protected void buildBaseGUI() { + final JPanel panel = new JPanel(); + + okButton.setMnemonic( okButton.getText().charAt( 0 ) ); + okButton.addActionListener( this ); + panel.add( okButton ); + + cancelButton.setMnemonic( cancelButton.getText().charAt( 0 ) ); + cancelButton.addActionListener( this ); + panel.add( cancelButton ); + + add( panel, BorderLayout.SOUTH ); + } + + /** + * Centers the dialog to its owner frame. + */ + public void center() { + setLocation( ownerFrame.getX() + ownerFrame.getWidth () / 2 - getWidth () / 2, + ownerFrame.getY() + ownerFrame.getHeight() / 2 - getHeight() / 2 ); + } + + /** + * Handles the action events of the dialog's ok and cancel button. + */ + public void actionPerformed( final ActionEvent ae ) { + if ( ae.getSource() == okButton ) + onOkButtonPressed(); + if ( ae.getSource() == cancelButton ) + onCancelButtonPressed(); + } + + /** + * Called when the ok button of the dialog is pressed. + */ + public abstract void onOkButtonPressed(); + + /** + * Called when the cancel button of the dialog is pressed.
+ * Simply disposes the dialog. + */ + public void onCancelButtonPressed() { + dispose(); + } + +} Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java (revision 674165) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java (working copy) @@ -18,23 +18,24 @@ package org.apache.harmony.tools.policytool.view; import java.awt.BorderLayout; +import java.util.ArrayList; import java.util.List; +import org.apache.harmony.tools.policytool.model.GrantEntry; +import org.apache.harmony.tools.policytool.model.KeystoreEntry; +import org.apache.harmony.tools.policytool.model.KeystorePasswordURLEntry; import org.apache.harmony.tools.policytool.model.PolicyEntry; /** - * An editor panel which provides an interface for direct editing the - * policy text. + * An editor panel which provides an interface for direct editing the policy text. */ public class GraphicalEditorPanel extends EditorPanel { - /** Holds the invalid policy text or null if the loaded policy - * text is valid. */ - private String invalidPolicyText; + /** Holds the invalid policy text or null if the loaded policy text is valid. */ + private String invalidPolicyText; - /** The list of the policy text's entries or null if invalid - * policy text was loaded. */ - private List< PolicyEntry > policyEntryList; + /** The list of the policy text's entries or null if invalid policy text was loaded. */ + private List< PolicyEntry > policyEntryList = new ArrayList< PolicyEntry >(); /** * Creates a new GraphicalEditorPanel.
@@ -39,24 +40,54 @@ /** * Creates a new GraphicalEditorPanel.
* Sets a BorderLayout as the layout manager. + * @param mainFrame reference to the main frame */ - public GraphicalEditorPanel() { - super( new BorderLayout(), true ); - } + public GraphicalEditorPanel( final MainFrame mainFrame ) { + super( mainFrame, "Graphical editing", new BorderLayout(), true ); - @Override - public String getPanelTitle() { - return "Graphical editing"; + // buildGUI: + add( new ListAndEditPanel< PolicyEntry >( "Policy Entry", policyEntryList, new ListAndEditPanel.Filter< PolicyEntry > () { + public boolean includeEntity( final PolicyEntry entity ) { + return entity instanceof GrantEntry; + } + } ), BorderLayout.CENTER ); } @Override - public void loadPolicyText( final String policyText ) { + public boolean loadPolicyText( final String policyText ) { this.invalidPolicyText = policyText; + + policyEntryList = new ArrayList< PolicyEntry >(); + + return true; } @Override - public String getPolicyText() { + public String getPolicyText() { return invalidPolicyText; } + /** + * Shows the keystore entry edit dialog.
+ * This dialog handles both the keystore entry and the keystore password URL entries. + */ + public void showKeystoreEntryEditDialog() { + KeystoreEntry keystoreEntry = null; + KeystorePasswordURLEntry keystorePasswordURLEntry = null; + + for ( final PolicyEntry policyEntry : policyEntryList ) { + if ( keystoreEntry == null ) + if ( policyEntry instanceof KeystoreEntry ) + keystoreEntry = (KeystoreEntry) policyEntry; + if ( keystorePasswordURLEntry == null ) + if ( policyEntry instanceof KeystorePasswordURLEntry ) + keystorePasswordURLEntry = (KeystorePasswordURLEntry) policyEntry; + + if ( keystoreEntry != null && keystorePasswordURLEntry != null ) + break; + } + + new KeystoreEntryEditFormDialog( mainFrame, this, keystoreEntry, keystorePasswordURLEntry, policyEntryList ).setVisible( true ); + } + } Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/ListAndEditPanel.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/ListAndEditPanel.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/ListAndEditPanel.java (revision 0) @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.tools.policytool.view; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; + +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +/** + * The abstraction of a panel which can list entities and provide GUI components to offer and handle certain actions on the entities.
+ * The entities are listed in a listbox, + * @param type of the entities listed on and edited by this panel + */ +public class ListAndEditPanel< EntityType > extends JPanel implements ActionListener { + + /** The component to list he entities. */ + private final JList entityListComponent = new JList(); + + /** Add new entity button. */ + private final JButton addButton = new JButton(); + /** Edit selected entity button. */ + private final JButton editButton = new JButton(); + /** Remove selected entity button. */ + private final JButton removeButton = new JButton(); + + /** Reference to the list whose elements are to be listed and edited, and where to put new entities. */ + private final List< ? > entityList; + + /** + * Can be used to filter the input entity list, hide elements from displaying. + * @param type of the entities filtered by this filter + */ + public interface Filter< EntityType > { + /** + * Tells whether to include an entity in the list-and-edit process + * @param entity entity to be tested + * @return true if the entity should be listed and edited; false if it should be and excluded and hid + */ + boolean includeEntity( final EntityType entity ); + } + + /** + * Creates a new ListAndEditPanel.
+ * Sets a BorderLayout for ourselves. + * @param entityName name of the listed and edited entity (this will be displayed on the buttons) + * @param entityList reference to the list whose elements are to be listed and edited, and where to put new entities + */ + public ListAndEditPanel( final String entityName, final List< EntityType > entityList ) { + this( entityName, entityList, null ); + } + + /** + * Creates a new ListAndEditPanel.
+ * Sets a BorderLayout for ourselves. + * @param entityName name of the listed and edited entity (this will be displayed on the buttons) + * @param entityList reference to the list whose elements are to be listed and edited, and where to put new entities + * @param entityFilter filter to be used when listing the entities + */ + public ListAndEditPanel( final String entityName, final List< EntityType > entityList, final Filter< EntityType > entityFilter ) { + super( new BorderLayout() ); + + this.entityList = entityList; + + final DefaultListModel listModel = new DefaultListModel(); + for ( final EntityType entity : entityList ) + if ( entityFilter == null || entityFilter.includeEntity( entity ) ) + listModel.addElement( entity ); + + entityListComponent.setModel( listModel ); + + buildGUI( entityName ); + } + + /** + * Builds the graphical user interface of the panel. + * @param entityName name of the listed and edited entity (this will be displayed on the buttons) + */ + private void buildGUI( final String entityName ) { + final JPanel buttonsPanel = new JPanel(); + + addButton .setText ( "Add " + entityName ); + addButton .setMnemonic ( addButton .getText().charAt( 0 ) ); + addButton .addActionListener( this ); + buttonsPanel.add( addButton ); + + editButton .setText ( "Edit " + entityName ); + editButton .setMnemonic ( editButton .getText().charAt( 0 ) ); + editButton .addActionListener( this ); + buttonsPanel.add( editButton ); + + removeButton.setText ( "Remove " + entityName ); + removeButton.setMnemonic ( removeButton.getText().charAt( 0 ) ); + removeButton.addActionListener( this ); + buttonsPanel.add( removeButton ); + + add( buttonsPanel, BorderLayout.NORTH ); + + add( new JScrollPane( entityListComponent ), BorderLayout.CENTER ); + } + + /** + * Handles the action events of the buttons for adding new, editing and removing entities. + * @param ae details of the action event + */ + public void actionPerformed( final ActionEvent ae ) { + } + +} Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java (revision 674165) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java (working copy) @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.harmony.tools.policytool.view; @@ -20,12 +20,17 @@ import java.awt.BorderLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.io.File; +import java.io.IOException; import javax.swing.JFrame; +import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; +import javax.swing.JPanel; import javax.swing.JTabbedPane; +import javax.swing.JTextField; import org.apache.harmony.tools.policytool.Consts; import org.apache.harmony.tools.policytool.control.Controller; @@ -35,6 +40,9 @@ */ public class MainFrame extends JFrame { + /** Text field to display the current policy file. */ + private final JTextField policyFileDisplayerTextField = new JTextField(); + /** * Creates a new MainFrame with no initial poilcy file. */ @@ -49,7 +57,7 @@ public MainFrame( final String policyFileName ) { super( Consts.APPLICATION_NAME ); - final EditorPanel[] editorPanels = new EditorPanel[] { new GraphicalEditorPanel(), new DirectTextEditorPanel() }; + final EditorPanel[] editorPanels = new EditorPanel[] { new GraphicalEditorPanel( this ), new DirectTextEditorPanel( this ) }; final Controller controller = new Controller( this, editorPanels, policyFileName ); buildGUI( controller ); @@ -55,13 +63,13 @@ buildGUI( controller ); setLocation( Consts.MAIN_FRAME_START_POS_X, Consts.MAIN_FRAME_START_POS_X ); - setSize( 400, 400 ); + setSize( 500, 500 ); setDefaultCloseOperation( DO_NOTHING_ON_CLOSE ); addWindowListener( new WindowAdapter() { - public void windowClosing( final WindowEvent we ) { - controller.exit(); - } - } ); + public void windowClosing( final WindowEvent we ) { + controller.exit(); + } + } ); } /** @@ -70,7 +78,15 @@ */ private void buildGUI( final Controller controller ) { buildMenusAndMenuBar( controller ); - buildTabbedPane ( controller ); + + final JPanel panel = new JPanel( new BorderLayout( 5, 0 ) ); + panel.add( new JLabel( " Policy file:" ), BorderLayout.WEST ); + + policyFileDisplayerTextField.setEditable( false ); + panel.add( policyFileDisplayerTextField, BorderLayout.CENTER ); + add( panel, BorderLayout.NORTH ); + + buildTabbedPane( controller ); } /** @@ -79,22 +95,22 @@ public static enum MenuItemEnum { /** File menu */ FILE ( true, "File" ), - /** New menu item */ - NEW ( "New" ), - /** Save menu item */ - OPEN ( "Open" ), - /** Save menu item */ - SAVE ( "Save" ), - /** Save as menu item */ - SAVE_AS ( "Save As...", 'a' ), - /** View warning log menu item */ - VIEW_WARNING_LOG( "View Warning Log" ), - /** Exit menu item */ - EXIT ( "Exit", 'x' ), - /** KeyStore menu */ - KEY_STORE ( true, "KeyStore" ), - /** Edit menu item */ - EDIT ( "Edit" ); + /** New menu item */ + NEW ( "New" ), + /** Save menu item */ + OPEN ( "Open" ), + /** Save menu item */ + SAVE ( "Save" ), + /** Save as menu item */ + SAVE_AS ( "Save As...", 'a' ), + /** View warning log menu item */ + VIEW_WARNING_LOG( "View Warning Log" ), + /** Exit menu item */ + EXIT ( "Exit", 'x' ), + /** KeyStore menu */ + KEY_STORE ( true, "KeyStore" ), + /** Edit menu item */ + EDIT ( "Edit" ); /** If true, then this represents a menu instead of a menu item. */ public final boolean isMenu; @@ -142,7 +158,7 @@ } }; - + /** * Builds the menus and the menu bar. * @param controller reference to the controller @@ -156,7 +172,8 @@ menu = new JMenu( menuItemEnum.text ); menu.setMnemonic( menuItemEnum.mnemonic ); menuBar.add( menu ); - } else { + } + else { final JMenuItem menuItem = new JMenuItem( menuItemEnum.text ); menuItem.setMnemonic( menuItemEnum.mnemonic ); menuItem.addActionListener( controller ); @@ -193,4 +210,17 @@ add( tabbedPane , BorderLayout.CENTER ); } + /** + * Sets the displayed policy file. + * @param displayedPolicyFile displayed policy file to be set + */ + public void setDisplayedPolicyFile( final File displayedPolicyFile ) { + try { + policyFileDisplayerTextField.setText( displayedPolicyFile == null ? null : displayedPolicyFile.getCanonicalPath() ); + } catch ( final IOException ie ) { + // This should never happen... + ie.printStackTrace(); + } + } + } Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java (revision 674165) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java (working copy) @@ -22,15 +22,20 @@ import javax.swing.JPanel; /** - * Defines an abstract editor panel which can provide a GUI for - * editing a policy text. + * Defines an abstract editor panel which can provide a GUI for editing a policy text. */ public abstract class EditorPanel extends JPanel { + /** Reference to the main frame. */ + protected final MainFrame mainFrame; + + /** The title of the panel. */ + protected String panelTitle; + /** Tells whether this editor panel has unsaved changes. */ - protected boolean hasDirty; + protected boolean hasDirty; /** Tells whether this editor panel supports graphical keystore edit. */ - protected boolean supportsGraphicalKeystoreEdit; + protected boolean supportsGraphicalKeystoreEdit; /** * Creates a new EditorPanel.
@@ -35,11 +40,16 @@ /** * Creates a new EditorPanel.
* Awaits a layout manager to be sent to the super class. + * @param mainFrame reference to the main frame + * @param panelTitle the title of the panel * @param layoutManager layout manager to be used * @param supportsGraphicalKeystoreEdit true if this editor panel supports graphical keystore edit; false otherwise */ - public EditorPanel( final LayoutManager layoutManager, final boolean supportsGraphicalKeystoreEdit ) { + public EditorPanel( final MainFrame mainFrame, final String panelTitle, final LayoutManager layoutManager, final boolean supportsGraphicalKeystoreEdit ) { super( layoutManager ); + + this.mainFrame = mainFrame; + this.panelTitle = panelTitle; this.supportsGraphicalKeystoreEdit = supportsGraphicalKeystoreEdit; } @@ -47,13 +57,17 @@ * Returns the title of the panel. * @return the title of the panel */ - public abstract String getPanelTitle(); + public String getPanelTitle() { + return panelTitle; + } /** - * Loads the specified policy text into the editor panel. + * Loads the specified policy text into the editor panel.
+ * If loading fails, leaves the current policy text intact. * @param policyText policy text to be loaded + * @return true if loading was successful; false otherwise */ - public abstract void loadPolicyText( final String policyText ); + public abstract boolean loadPolicyText( final String policyText ); /** * Returns the policy text hold by this editor panel. Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/KeystoreEntryEditFormDialog.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/KeystoreEntryEditFormDialog.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/KeystoreEntryEditFormDialog.java (revision 0) @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.tools.policytool.view; + +import java.awt.BorderLayout; +import java.awt.Frame; +import java.awt.GridLayout; +import java.util.List; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; + +import org.apache.harmony.tools.policytool.model.CommentEntry; +import org.apache.harmony.tools.policytool.model.KeystoreEntry; +import org.apache.harmony.tools.policytool.model.KeystorePasswordURLEntry; +import org.apache.harmony.tools.policytool.model.PolicyEntry; + +/** + * Form dialog to view and edit the keystore and the keystore password url entries. + */ +public class KeystoreEntryEditFormDialog extends BaseFormDialog { + + /** Reference to the initial editable keystore entry. */ + private final KeystoreEntry initialKeystoreEntry; + /** Reference to the initial editable keystore password URL entry. */ + private final KeystorePasswordURLEntry initialKeystorePasswordURLEntry; + /** List of policy entries where to store if new entries are to be created. */ + private final List< PolicyEntry > policyEntryList; + + /** Text field to view and edit the value of keystore URL. */ + private final JTextField keystoreURLTextField = new JTextField( 10 ); + /** Text field to view and edit the value of keystore type. */ + private final JTextField keystoreTypeTextField = new JTextField( 10 ); + /** Text field to view and edit the value of keystore provider. */ + private final JTextField keystoreProviderTextField = new JTextField( 10 ); + /** Text field to view and edit the value of keystore password URL. */ + private final JTextField keystorePasswordURLTextField = new JTextField( 10 ); + + /** + * Creates a new KeystoreEntryEditFormDialog. + * @param ownerFrame reference to the owner frame + * @param ownerEditorPanel reference to the owner editor panel + * @param keystoreEntry reference to the editable keystore entry + * @param keystorePasswordURLEntry reference to the editable password URL entry + * @param policyEntryList list of policy entries where to store if new entries are to be created + */ + public KeystoreEntryEditFormDialog( final Frame ownerFrame, final EditorPanel ownerEditorPanel, final KeystoreEntry keystoreEntry, final KeystorePasswordURLEntry keystorePasswordURLEntry, final List< PolicyEntry > policyEntryList ) { + super( ownerFrame, "KeyStore", ownerEditorPanel ); + + this.initialKeystoreEntry = keystoreEntry; + this.initialKeystorePasswordURLEntry = keystorePasswordURLEntry; + this.policyEntryList = policyEntryList; + + buildGUI(); + pack(); + center(); + } + + /** + * Builds the GUI of the dialog. + */ + private void buildGUI() { + final JPanel panel = new JPanel( new GridLayout( 4, 2, 5, 10 ) ); + + panel.add( new JLabel( "KeyStore URL:" ) ); + panel.add( keystoreURLTextField ); + + panel.add( new JLabel( "KeyStore Type:" ) ); + panel.add( keystoreTypeTextField ); + + panel.add( new JLabel( "KeyStore Provider:" ) ); + panel.add( keystoreProviderTextField ); + + panel.add( new JLabel( "KeyStore Password URL:" ) ); + panel.add( keystorePasswordURLTextField ); + + if ( initialKeystoreEntry != null ) { + keystoreURLTextField .setText( initialKeystoreEntry.getUrl () ); + keystoreTypeTextField .setText( initialKeystoreEntry.getType () ); + keystoreProviderTextField.setText( initialKeystoreEntry.getProvider() ); + } + + if ( initialKeystorePasswordURLEntry != null ) { + keystorePasswordURLTextField.setText( initialKeystorePasswordURLEntry.getUrl() ); + } + + final JPanel flowPanel = new JPanel(); + flowPanel.add( panel ); + add( new JScrollPane( flowPanel ), BorderLayout.CENTER ); + } + + @Override + public void onOkButtonPressed() { + // TODO: validation + + final KeystoreEntry keystoreEntry = initialKeystoreEntry == null ? new KeystoreEntry() : initialKeystoreEntry; + + if ( keystoreURLTextField.getText().length() == 0 && keystoreTypeTextField.getText().length() == 0 && keystoreProviderTextField.getText().length() == 0 ) { + // We want no keystore entry! + if ( initialKeystoreEntry != null ) + policyEntryList.remove( initialKeystoreEntry ); + } + else { + keystoreEntry.setUrl ( keystoreURLTextField .getText() ); + keystoreEntry.setType ( keystoreTypeTextField .getText() ); + keystoreEntry.setProvider( keystoreProviderTextField.getText() ); + + if ( initialKeystoreEntry == null ) { // If it is a new, we have to add it to the "global" list + // We want to add it to be the first non-comment entry + int index = 0; + for ( ; index < policyEntryList.size(); index++ ) + if ( !( policyEntryList.get( index ) instanceof CommentEntry ) ) + break; + policyEntryList.add( index, keystoreEntry ); + } + } + + if ( keystorePasswordURLTextField.getText().length() == 0 ) { + // We want no keystore password URL entry! + if ( initialKeystorePasswordURLEntry != null ) + policyEntryList.remove( initialKeystorePasswordURLEntry ); + } + else { + final KeystorePasswordURLEntry keystorePasswordURLEntry = initialKeystorePasswordURLEntry == null ? new KeystorePasswordURLEntry() : initialKeystorePasswordURLEntry; + keystorePasswordURLEntry.setUrl( keystorePasswordURLTextField.getText() ); + + if ( initialKeystorePasswordURLEntry == null ) { // If it is a new, we have to add it to the "global" list + // We want to add it after the keystore entry + int index = policyEntryList.indexOf( keystoreEntry ); + if ( index < 0 ) { // No such entry exists, we want it to be the first non-comment entry then + index = 0; + for ( ; index < policyEntryList.size(); index++ ) + if ( !( policyEntryList.get( index ) instanceof CommentEntry ) ) + break; + } + else + index++; // => after the keystore entry (not before) + policyEntryList.add( index, keystorePasswordURLEntry ); + } + } + + ownerEditorPanel.setHasDirty( true ); + + dispose(); + } + +} Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/DirectTextEditorPanel.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/DirectTextEditorPanel.java (revision 674165) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/DirectTextEditorPanel.java (working copy) @@ -38,9 +38,10 @@ /** * Creates a new DirectTextEditorPanel.
* Sets a BorderLayout as the layout manager. + * @param mainFrame reference to the main frame */ - public DirectTextEditorPanel() { - super( new BorderLayout(), false ); + public DirectTextEditorPanel( final MainFrame mainFrame ) { + super( mainFrame, "Direct editing", new BorderLayout(), false ); policyTextTextArea.setFont( new Font( "Courier New", Font.PLAIN, Consts.DIRECT_EDITING_FONT_SIZE ) ); @@ -46,15 +47,15 @@ // We want to track changes of the document so we can ask confirmation on exit policyTextTextArea.getDocument().addDocumentListener( new DocumentListener() { - public void changedUpdate( final DocumentEvent de ) { - } - public void insertUpdate ( final DocumentEvent de ) { - setHasDirty( true ); - } - public void removeUpdate ( final DocumentEvent de ) { - setHasDirty( true ); - } - } ); + public void changedUpdate( final DocumentEvent de ) { + } + public void insertUpdate ( final DocumentEvent de ) { + setHasDirty( true ); + } + public void removeUpdate ( final DocumentEvent de ) { + setHasDirty( true ); + } + } ); add( new JScrollPane( policyTextTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS ), BorderLayout.CENTER ); } @@ -60,13 +61,9 @@ } @Override - public String getPanelTitle() { - return "Direct editing"; - } - - @Override - public void loadPolicyText( final String policyText ) { + public boolean loadPolicyText( final String policyText ) { policyTextTextArea.setText( policyText ); + return true; } @Override Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java (revision 674165) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java (working copy) @@ -17,7 +17,6 @@ package org.apache.harmony.tools.policytool.control; -import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; @@ -30,16 +29,17 @@ import javax.swing.event.ChangeListener; import org.apache.harmony.tools.policytool.view.EditorPanel; +import org.apache.harmony.tools.policytool.view.GraphicalEditorPanel; +import org.apache.harmony.tools.policytool.view.MainFrame; import org.apache.harmony.tools.policytool.view.MainFrame.MenuItemEnum; /** - * The controller handles the user actions, drives the GUI and - * connects it to the model. + * The controller handles the user actions, drives the GUI and connects it to the model. */ public class Controller implements ChangeListener, ActionListener{ - /** Reference to the main frame component. */ - private final Component mainFrame; + /** Reference to the main frame. */ + private final MainFrame mainFrame; /** Array of the editor panels. */ private final EditorPanel[] editorPanels; /** Reference to the active editor panel. */ @@ -49,15 +49,15 @@ private JMenuItem keystoreEditMenuItem; /** The currently edited policy file. */ - private File editedPolicyFile; + private File editedPolicyFile; /** * Creates a new Controller. - * @param mainFrame reference to the main frame component + * @param mainFrame reference to the main frame * @param editorPanels array of the editor panels * @param policyFileName policy file name to be loaded initially */ - public Controller( final Component mainFrame, final EditorPanel[] editorPanels, final String policyFileName ) { + public Controller( final MainFrame mainFrame, final EditorPanel[] editorPanels, final String policyFileName ) { this.mainFrame = mainFrame; this.editorPanels = editorPanels; activeEditorPanel = editorPanels[ 0 ]; @@ -64,8 +64,11 @@ PolicyFileHandler.setDialogParentComponent( mainFrame ); - editedPolicyFile = new File( policyFileName ); - activeEditorPanel.loadPolicyText( PolicyFileHandler.loadPoilcyFile( editedPolicyFile ) ); + if ( policyFileName != null ) { + final File editedPolicyFile_ = new File( policyFileName ); + if ( activeEditorPanel.loadPolicyText( PolicyFileHandler.loadPolicyFile( editedPolicyFile_ ) ) ) + setEditedPolicyFile( editedPolicyFile_ ); + } } /** @@ -90,13 +93,28 @@ * There might be unsaved changes in which case confirmation will be asked. */ public void exit() { - boolean exitOk = false; + if ( allowedDirtySensitiveOperation( "exit" ) ) + System.exit( 0 ); + } + /** + * Determines if a dirty sensitive operation is allowed to be executed.
+ * There are operation which will throw away the edited policy text currently hold in the active editor + * (for example exit or load a file, or start a new).
+ * This method checks whether there are unsaved changes, and if so, ask confirmation on what to do with them.
+ * Finally returns true, if the dirty data can be thrown away or has been saved successfully. + * Returns false, if the effect of the operation (throwing away unsaved changes) is unwanted and therefore the operation is disallowed. + * + * @param operationName name of the operation which will be included in the confirmation messages + * @return true, if the operation now can be performed safely; false otherwise + */ + private boolean allowedDirtySensitiveOperation( final String operationName ) { if ( activeEditorPanel.getHasDirty() ) { - switch ( JOptionPane.showConfirmDialog( mainFrame, "There are unsaved changes. Save before exit?", "Warning", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE ) ) { + switch ( JOptionPane.showConfirmDialog( mainFrame, "There are unsaved changes. Save before " + operationName + "?", "Warning", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE ) ) { case JOptionPane.YES_OPTION: + // We chose to save file first final JFileChooser fileChooser = new JFileChooser(); if ( editedPolicyFile == null ) { @@ -105,19 +123,21 @@ } if ( editedPolicyFile != null ) { if ( !PolicyFileHandler.savePolicyFile( editedPolicyFile, activeEditorPanel.getPolicyText() ) ) { - switch ( JOptionPane.showConfirmDialog( mainFrame, "Saving failed. Do you still want to exit?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE ) ) { + switch ( JOptionPane.showConfirmDialog( mainFrame, "Saving failed. Do you still want to " + operationName + "?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE ) ) { case JOptionPane.YES_OPTION: - exitOk = true; - break; + // We chose to still proceed + return true; case JOptionPane.NO_OPTION: case JOptionPane.CLOSED_OPTION: - // We chose not to exit. exitOk = false - break; + // We chose not to proceed + return false; } - } else {// Changes saved successfully + } + else {// Changes saved successfully activeEditorPanel.setHasDirty( false ); - exitOk = true; + mainFrame.setDisplayedPolicyFile( editedPolicyFile ); + return true; } } break; @@ -123,21 +143,19 @@ break; case JOptionPane.NO_OPTION: - exitOk = true; - break; + // We chose not to save and proceed + return true; case JOptionPane.CANCEL_OPTION: case JOptionPane.CLOSED_OPTION: - // We chose not to exit. exitOk = false - break; + // We chose not to proceed + return false; } - } else - exitOk = true; + } - if ( exitOk ) - System.exit( 0 ); + return true; } /** @@ -146,7 +164,7 @@ */ public void stateChanged( final ChangeEvent ce ) { final EditorPanel newActiveEditorPanel = (EditorPanel) ( (JTabbedPane) ce.getSource() ).getSelectedComponent(); - + newActiveEditorPanel.loadPolicyText( activeEditorPanel.getPolicyText() ); newActiveEditorPanel.setHasDirty ( activeEditorPanel.getHasDirty () ); activeEditorPanel = newActiveEditorPanel; @@ -162,6 +180,8 @@ // The action command is the ordinal of the menu item enum. final MenuItemEnum menuItemEnum = MenuItemEnum.values()[ Integer.parseInt( ae.getActionCommand() ) ]; + File editedPolicyFile_ = null; + final JFileChooser fileChooser = new JFileChooser(); switch ( menuItemEnum ) { @@ -166,13 +186,19 @@ switch ( menuItemEnum ) { case NEW : + if ( allowedDirtySensitiveOperation( "starting new file" ) ) { + activeEditorPanel.loadPolicyText( null ); + setEditedPolicyFile( null ); + } break; case OPEN : - if ( fileChooser.showOpenDialog( mainFrame ) == JFileChooser.APPROVE_OPTION ) { - editedPolicyFile = fileChooser.getSelectedFile(); - activeEditorPanel.loadPolicyText( PolicyFileHandler.loadPoilcyFile( editedPolicyFile ) ); - } + if ( allowedDirtySensitiveOperation( "opening file" ) ) + if ( fileChooser.showOpenDialog( mainFrame ) == JFileChooser.APPROVE_OPTION ) { + editedPolicyFile_ = fileChooser.getSelectedFile(); + if ( activeEditorPanel.loadPolicyText( PolicyFileHandler.loadPolicyFile( editedPolicyFile_ ) ) ) + setEditedPolicyFile( editedPolicyFile_ ); + } break; case SAVE : @@ -178,11 +204,14 @@ case SAVE : if ( editedPolicyFile == null ) { if ( fileChooser.showSaveDialog( mainFrame ) == JFileChooser.APPROVE_OPTION ) - editedPolicyFile = fileChooser.getSelectedFile(); + editedPolicyFile_ = fileChooser.getSelectedFile(); } - if ( editedPolicyFile != null ) - if ( PolicyFileHandler.savePolicyFile( editedPolicyFile, activeEditorPanel.getPolicyText() ) ) - activeEditorPanel.setHasDirty( false ); + else + editedPolicyFile_ = editedPolicyFile; + + if ( editedPolicyFile_ != null ) + if ( PolicyFileHandler.savePolicyFile( editedPolicyFile_, activeEditorPanel.getPolicyText() ) ) + setEditedPolicyFile( editedPolicyFile_ ); break; case SAVE_AS : @@ -187,9 +216,9 @@ case SAVE_AS : if ( fileChooser.showSaveDialog( mainFrame ) == JFileChooser.APPROVE_OPTION ) { - editedPolicyFile = fileChooser.getSelectedFile(); - if ( PolicyFileHandler.savePolicyFile( editedPolicyFile, activeEditorPanel.getPolicyText() ) ) - activeEditorPanel.setHasDirty( false ); + editedPolicyFile_ = fileChooser.getSelectedFile(); + if ( PolicyFileHandler.savePolicyFile( editedPolicyFile_, activeEditorPanel.getPolicyText() ) ) + setEditedPolicyFile( editedPolicyFile_ ); } break; @@ -201,6 +230,8 @@ break; case EDIT : + if ( activeEditorPanel instanceof GraphicalEditorPanel ) + ( (GraphicalEditorPanel) activeEditorPanel ).showKeystoreEntryEditDialog(); break; } @@ -207,4 +238,14 @@ } + /** + * Sets the edited policy file and displays its name in the main frame. Also clears the dirty flag. + * @param editedPolicyFile edited policy file to be set + */ + private void setEditedPolicyFile( final File editedPolicyFile ) { + activeEditorPanel.setHasDirty( false ); + this.editedPolicyFile = editedPolicyFile; + mainFrame.setDisplayedPolicyFile( editedPolicyFile ); + } + } Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyFileHandler.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyFileHandler.java (revision 674165) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyFileHandler.java (working copy) @@ -58,7 +58,7 @@ * @param policyFile policy file whose content to be loaded * @return the policy text within the given policy file */ - public static String loadPoilcyFile( final File policyFile ) { + public static String loadPolicyFile( final File policyFile ) { final StringBuilder policyTextBuilder = new StringBuilder(); BufferedReader input = null; @@ -68,21 +68,27 @@ String line; while ( ( line = input.readLine() ) != null ) policyTextBuilder.append( line ).append( LINE_SEPARATOR ); - } catch ( final FileNotFoundException fnfe ) { + + } + catch ( final FileNotFoundException fnfe ) { JOptionPane.showMessageDialog( dialogParentComponent, "The file does not exist!", "Error", JOptionPane.ERROR_MESSAGE ); return null; - } catch ( final UnsupportedEncodingException uee ) { + } + catch ( final UnsupportedEncodingException uee ) { // This should never happen. uee.printStackTrace(); return null; - } catch ( final IOException ie ) { + } + catch ( final IOException ie ) { JOptionPane.showMessageDialog( dialogParentComponent, new String[] { "I/O error occured, can't read the file!", ie.getMessage() }, "Error", JOptionPane.ERROR_MESSAGE ); return null; - } finally { + } + finally { if ( input != null ) try { input.close(); - } catch ( final IOException ie ) { + } + catch ( final IOException ie ) { ie.printStackTrace(); } } @@ -104,10 +110,12 @@ output.write( policyText ); return true; - } catch ( final UnsupportedEncodingException uee ) { + } + catch ( final UnsupportedEncodingException uee ) { // This should never happen. uee.printStackTrace(); - } catch ( final FileNotFoundException ffe ) { + } + catch ( final FileNotFoundException ffe ) { JOptionPane.showMessageDialog( dialogParentComponent, new String[] { "Cannot open file for writing!", ffe.getMessage() }, "Error", JOptionPane.ERROR_MESSAGE ); ffe.printStackTrace(); } catch ( final IOException ie ) { @@ -113,11 +121,13 @@ } catch ( final IOException ie ) { JOptionPane.showMessageDialog( dialogParentComponent, new String[] { "Write error!", ie.getMessage() }, "Error", JOptionPane.ERROR_MESSAGE ); ie.printStackTrace(); - } finally { + } + finally { if ( output != null ) try { output.close(); - } catch ( final IOException ie ) { + } + catch ( final IOException ie ) { ie.printStackTrace(); } }