Ignore:
Timestamp:
2012-03-14T23:33:27+01:00 (12 years ago)
Author:
simon04
Message:

fix #5824 - remotecontrol: add command for opening local files + refactoring of permission preference

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandler.java

    r5008 r5085  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.text.MessageFormat;
    67import java.util.HashMap;
    78import java.util.LinkedList;
    89import java.util.List;
    9 import java.util.StringTokenizer;
    1010
    1111import javax.swing.JOptionPane;
     
    5050    public final void handle() throws RequestHandlerForbiddenException, RequestHandlerBadRequestException, RequestHandlerErrorException
    5151    {
     52        checkMandatoryParams();
    5253        checkPermission();
    53         checkMandatoryParams();
    5454        handleRequest();
    5555    }
     
    8686     * @return the preference name and error message or null
    8787     */
    88     public PermissionPrefWithDefault getPermissionPref()
    89     {
    90         /* Example:
    91         return new PermissionPrefWithDefault("fooobar.remotecontrol",
    92         true
    93         "RemoteControl: foobar forbidden by preferences");
    94         */
    95         return null;
    96     }
    97 
    98     public String[] getMandatoryParams() {
    99         return null;
    100     }
     88    abstract public PermissionPrefWithDefault getPermissionPref();
     89
     90    abstract public String[] getMandatoryParams();
    10191
    10292    /**
     
    119109        {
    120110            if (!Main.pref.getBoolean(permissionPref.pref, permissionPref.defaultVal)) {
    121                 System.out.println(permissionPref.message);
    122                 throw new RequestHandlerForbiddenException();
     111                String err = MessageFormat.format("RemoteControl: ''{0}'' forbidden by preferences", myCommand);
     112                System.out.println(err);
     113                throw new RequestHandlerForbiddenException(err);
    123114            }
    124115        }
     
    133124                tr("Confirm Remote Control action"),
    134125                JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
    135                     throw new RequestHandlerForbiddenException();
     126                    String err = MessageFormat.format("RemoteControl: ''{0}'' forbidden by user''s choice", myCommand);
     127                    throw new RequestHandlerForbiddenException(err);
    136128            }
    137129        }
     
    178170        List<String> missingKeys = new LinkedList<String>();
    179171        boolean error = false;
    180         for (int i = 0; i < mandatory.length; ++i) {
    181             String key = mandatory[i];
     172        for (String key : mandatory) {
    182173            String value = args.get(key);
    183174            if ((value == null) || (value.length() == 0)) {
     
    243234    public static class RequestHandlerForbiddenException extends RequestHandlerException {
    244235        private static final long serialVersionUID = 2263904699747115423L;
     236
     237        public RequestHandlerForbiddenException(String message) {
     238            super(message);
     239        }
    245240    }
    246241}
Note: See TracChangeset for help on using the changeset viewer.