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 686697) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Permission.java (working copy) @@ -113,7 +113,7 @@ if ( actions != null && actions.length() > 0 ) stringBuilder.append( ", \"" ).append( actions ).append( '"'); if ( signedBy != null && signedBy.length() > 0 ) - stringBuilder.append( "," ).append( signedByPartPrefix ).append( "signedBy \"" ).append( signedBy ).append( '"' ); + stringBuilder.append( ", " ).append( signedByPartPrefix ).append( "signedBy \"" ).append( signedBy ).append( '"' ); return stringBuilder.toString(); } 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 686697) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Principal.java (working copy) @@ -69,7 +69,7 @@ try { return super.clone(); } catch ( final CloneNotSupportedException cnse ) { - // This is never going to happen. + // This' never gonna happen. cnse.printStackTrace(); return null; } 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 686169) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/BaseFormDialog.java (working copy) @@ -33,6 +33,9 @@ */ public abstract class BaseFormDialog extends JDialog implements ActionListener { + /** Error message for not allowed quotation marks. */ + public static final String NOT_ALLOWED_QUOTATION_MARKS_MESSAGE = "The following fields may not contain quotation marks: "; + /** Reference to the owner window. */ protected final Window ownerWindow; @@ -130,7 +133,7 @@ } /** - * Handles the action events of the dialog's ok and cancel button. + * Handles the action events of the dialog's ok and cancel buttons. */ public void actionPerformed( final ActionEvent ae ) { if ( ae.getSource() == okButton ) 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 686169) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java (working copy) @@ -24,6 +24,7 @@ import javax.swing.JOptionPane; import org.apache.harmony.tools.policytool.Consts; +import org.apache.harmony.tools.policytool.control.Controller; import org.apache.harmony.tools.policytool.control.InvalidPolicyTextException; import org.apache.harmony.tools.policytool.control.PolicyTextParser; import org.apache.harmony.tools.policytool.model.GrantEntry; @@ -93,6 +94,7 @@ policyEntryList = PolicyTextParser.parsePolicyText( policyText ); } catch ( final InvalidPolicyTextException ipte ) { + Controller.logError( ipte.getMessage() ); JOptionPane.showMessageDialog( this, new String[] { ipte.getMessage(), " ", "Graphical editor is disabled, correct the error in the direct editor or load a valid policy file." }, "Parse error!", JOptionPane.ERROR_MESSAGE ); invalidPolicyText = policyText; policyEntryList = new ArrayList< PolicyEntry >(); Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PrincipalEditFormDialog.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PrincipalEditFormDialog.java (revision 686169) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PrincipalEditFormDialog.java (working copy) @@ -26,6 +26,7 @@ import javax.swing.JComboBox; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; @@ -30,6 +31,7 @@ import javax.swing.JScrollPane; import javax.swing.JTextField; +import org.apache.harmony.tools.policytool.control.Controller; import org.apache.harmony.tools.policytool.model.Principal; /** @@ -108,8 +110,27 @@ @Override public void onOkButtonPressed() { - // TODO: validation - // Class name and target name are mandatory! + // validation + final StringBuilder errorStringBuilder = new StringBuilder( NOT_ALLOWED_QUOTATION_MARKS_MESSAGE ); + boolean validationFails = false; + if ( principalNameTextField.getText().indexOf( '"' ) >= 0 ) { + validationFails = true; + errorStringBuilder.append( "Principal Name" ); + } + + if ( !validationFails ) + if ( principalTypeTextField.getText().length() == 0 || principalNameTextField.getText().length() == 0 ) { + validationFails = true; + errorStringBuilder.setLength( 0 ); + errorStringBuilder.append( "Principal Type and Principal Name must have a value!" ); + } + + if ( validationFails ) { + Controller.logError( errorStringBuilder.toString() ); + JOptionPane.showMessageDialog( this, errorStringBuilder.toString(), "Error!", JOptionPane.ERROR_MESSAGE ); + return; + } + // validation end final Principal principal = initialPrincipal == null ? new Principal() : initialPrincipal; Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/WarningLogDialog.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/WarningLogDialog.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/WarningLogDialog.java (revision 0) @@ -0,0 +1,96 @@ +/* + * 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; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import org.apache.harmony.tools.policytool.Consts; + +/** + * Dialog to view the warning and error logs. + */ +public class WarningLogDialog extends JDialog implements ActionListener { + + /** Text area to store and display the log. */ + private final JTextArea logTextArea; + /** Reference to the owner frame. */ + private final Frame ownerFrame; + + /** + * Creates a new WarningLogDialog. + * @param ownerFrame reference to the owner frame + */ + public WarningLogDialog( final Frame ownerFrame ) { + super( ownerFrame, "Warning log", false ); + this.ownerFrame = ownerFrame; + setDefaultCloseOperation( HIDE_ON_CLOSE ); + + logTextArea = new JTextArea( 15, 50 ); + logTextArea.setEditable( false ); + add( new JScrollPane( logTextArea ), BorderLayout.CENTER ); + + final JPanel panel = new JPanel(); + + final JButton closeButton = new JButton( "Close" ); + closeButton.setMnemonic( closeButton.getText().charAt( 0 ) ); + closeButton.addActionListener( this ); + panel.add( closeButton ); + + add( panel, BorderLayout.SOUTH ); + + pack(); + } + + /** + * If parameter visibility is true, first centers the dialog. Calls super.setVisible() afterwards. + */ + @Override + public void setVisible( final boolean visibility ) { + if ( visibility ) + setLocation( ownerFrame.getX() + ownerFrame.getWidth () / 2 - getWidth () / 2, + ownerFrame.getY() + ownerFrame.getHeight() / 2 - getHeight() / 2 ); + super.setVisible( visibility ); + } + + /** + * Adds a message to the log. + * @param message message to be added + */ + public void addMessage( final String message ) { + logTextArea.append( message ); + logTextArea.append( Consts.NEW_LINE_STRING ); + logTextArea.setCaretPosition( logTextArea.getDocument().getLength() ); + } + + /** + * Handles the action events of the close button. + */ + public void actionPerformed( final ActionEvent ae ) { + setVisible( false ); + } + +} Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GrantEntryEditFormDialog.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GrantEntryEditFormDialog.java (revision 686169) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GrantEntryEditFormDialog.java (working copy) @@ -25,9 +25,11 @@ import javax.swing.Box; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; +import org.apache.harmony.tools.policytool.control.Controller; import org.apache.harmony.tools.policytool.model.GrantEntry; import org.apache.harmony.tools.policytool.model.Permission; import org.apache.harmony.tools.policytool.model.PolicyEntry; @@ -173,7 +175,24 @@ @Override public void onOkButtonPressed() { - // TODO: validation + // validation + final StringBuilder errorStringBuilder = new StringBuilder( NOT_ALLOWED_QUOTATION_MARKS_MESSAGE ); + boolean validationFails = false; + if ( codeBaseTextField.getText().indexOf( '"' ) >= 0 ) { + validationFails = true; + errorStringBuilder.append( "codeBase" ); + } + if ( signedByTextField.getText().indexOf( '"' ) >= 0 ) { + errorStringBuilder.append( validationFails ? ", signedBy" : "signedBy" ); + validationFails = true; + } + + if ( validationFails ) { + Controller.logError( errorStringBuilder.toString() ); + JOptionPane.showMessageDialog( this, errorStringBuilder.toString(), "Error!", JOptionPane.ERROR_MESSAGE ); + return; + } + // validation end final GrantEntry grantEntry = initialGrantEntry == null ? newGrantEntry : initialGrantEntry; 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 686169) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/KeystoreEntryEditFormDialog.java (working copy) @@ -23,6 +23,7 @@ import java.util.List; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; @@ -27,6 +28,7 @@ import javax.swing.JScrollPane; import javax.swing.JTextField; +import org.apache.harmony.tools.policytool.control.Controller; import org.apache.harmony.tools.policytool.model.CommentEntry; import org.apache.harmony.tools.policytool.model.KeystoreEntry; import org.apache.harmony.tools.policytool.model.KeystorePasswordURLEntry; @@ -104,7 +106,32 @@ @Override public void onOkButtonPressed() { - // TODO: validation + // validation + final StringBuilder errorStringBuilder = new StringBuilder( NOT_ALLOWED_QUOTATION_MARKS_MESSAGE ); + boolean validationFails = false; + if ( keystoreURLTextField.getText().indexOf( '"' ) >= 0 ) { + validationFails = true; + errorStringBuilder.append( "Keystore URL" ); + } + if ( keystoreTypeTextField.getText().indexOf( '"' ) >= 0 ) { + errorStringBuilder.append( validationFails ? ", Keystore Type" : "Keystore Type" ); + validationFails = true; + } + if ( keystoreProviderTextField.getText().indexOf( '"' ) >= 0 ) { + errorStringBuilder.append( validationFails ? ", Keystore Provider" : "Keystore Provider" ); + validationFails = true; + } + if ( keystorePasswordURLTextField.getText().indexOf( '"' ) >= 0 ) { + errorStringBuilder.append( validationFails ? ", Keystore Password URL" : "Keystore Password URL" ); + validationFails = true; + } + + if ( validationFails ) { + Controller.logError( errorStringBuilder.toString() ); + JOptionPane.showMessageDialog( this, errorStringBuilder.toString(), "Error!", JOptionPane.ERROR_MESSAGE ); + return; + } + // validation end final KeystoreEntry keystoreEntry = initialKeystoreEntry == null ? new KeystoreEntry() : initialKeystoreEntry; Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PermissionEditFormDialog.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PermissionEditFormDialog.java (revision 686169) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PermissionEditFormDialog.java (working copy) @@ -34,6 +34,7 @@ import javax.swing.JScrollPane; import javax.swing.JTextField; +import org.apache.harmony.tools.policytool.control.Controller; import org.apache.harmony.tools.policytool.model.Permission; /** @@ -230,11 +231,35 @@ @Override public void onOkButtonPressed() { - // TODO: validation - if ( permissionTypeTextField.getText().length() == 0 || targetNameTextField.isEnabled() && targetNameTextField.getText().length() == 0 ) { - JOptionPane.showMessageDialog( this, "Permission and target name must have a value!", "Error", JOptionPane.ERROR_MESSAGE ); + // validation + final StringBuilder errorStringBuilder = new StringBuilder( NOT_ALLOWED_QUOTATION_MARKS_MESSAGE ); + boolean validationFails = false; + if ( targetNameTextField.getText().indexOf( '"' ) >= 0 ) { + validationFails = true; + errorStringBuilder.append( "Target Name" ); + } + if ( actionsTextField.getText().indexOf( '"' ) >= 0 ) { + errorStringBuilder.append( validationFails ? ", Actions" : "Actions" ); + validationFails = true; + } + if ( signedByTextField.getText().indexOf( '"' ) >= 0 ) { + errorStringBuilder.append( validationFails ? ", Signed By" : "Signed By" ); + validationFails = true; + } + + if ( !validationFails ) + if ( permissionTypeTextField.getText().length() == 0 || targetNameTextField.isEnabled() && targetNameTextField.getText().length() == 0 ) { + validationFails = true; + errorStringBuilder.setLength( 0 ); + errorStringBuilder.append( "Permission and target name must have a value!" ); + } + + if ( validationFails ) { + Controller.logError( errorStringBuilder.toString() ); + JOptionPane.showMessageDialog( this, errorStringBuilder.toString(), "Error!", JOptionPane.ERROR_MESSAGE ); return; } + // validation end final Permission permission = initialPermission == null ? new Permission() : initialPermission; Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/LAEFormDialog.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/LAEFormDialog.java (revision 686169) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/LAEFormDialog.java (working copy) @@ -75,8 +75,12 @@ * Should be called if the entities of the list might have changed but the list model was not modified. */ public void refreshVisualizationList() { - visualizationJListforLAE.revalidate(); - visualizationJListforLAE.repaint(); + final Object newTempItem = new String(); + // There is a bug if we edit an item, we change it in a way that its toString() method will return a very long string + // (long as it won't fit in the displayed width), its string will be truncated (ended with "..."), and no scrollbars will be displayed + // The addElement() operation causes to recalculate the viewport size. + listModel.addElement ( newTempItem ); + listModel.removeElement( newTempItem ); } } 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 686697) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java (working copy) @@ -31,6 +31,7 @@ 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.WarningLogDialog; import org.apache.harmony.tools.policytool.view.MainFrame.MenuItemEnum; /** @@ -38,6 +39,9 @@ */ public class Controller implements ChangeListener, ActionListener{ + /** Thee warning log dialog. */ + private static WarningLogDialog warningLogDialog; + /** Reference to the main frame. */ private final MainFrame mainFrame; /** Array of the editor panels. */ @@ -52,6 +56,22 @@ private File editedPolicyFile; /** + * Logs an error message to the warning/error log. + * @param errorMessage error message to be logged + */ + public static void logError( final String errorMessage ) { + warningLogDialog.addMessage( "Error: " + errorMessage ); + } + + /** + * Logs a warning message to the warning/error log. + * @param warningMessage warning message to be logged + */ + public static void logWarning( final String warningMessage ) { + warningLogDialog.addMessage( "Warning: " + warningMessage ); + } + + /** * Creates a new Controller. * @param mainFrame reference to the main frame * @param editorPanels array of the editor panels @@ -60,6 +80,7 @@ public Controller( final MainFrame mainFrame, final EditorPanel[] editorPanels, final String policyFileName ) { this.mainFrame = mainFrame; this.editorPanels = editorPanels; + warningLogDialog = new WarningLogDialog( mainFrame ); activeEditorPanel = editorPanels[ 0 ]; PolicyFileHandler.setDialogParentComponent( mainFrame ); @@ -221,6 +242,7 @@ break; case VIEW_WARNING_LOG : + warningLogDialog.setVisible( true ); break; case EXIT : Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyTextParser.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyTextParser.java (revision 686697) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyTextParser.java (working copy) @@ -363,7 +363,7 @@ if ( peekNextNonWhiteSpaceChar( signedByIndices[ 1 ] ) != PolicyEntry.TERMINATOR_CHAR ) throw new InvalidPolicyTextException( "Was expecting semicolon but found something else!" ); else - newIndex = skipWhiteSpaces( newIndex ) + 1; + newIndex = skipWhiteSpaces( signedByIndices[ 1 ] ) + 1; } else newIndex = skipWhiteSpaces( newIndex ) + 1;