GUACAMOLE-1007: Use Translatable versions of GuacamoleException subclasses where translation keys are in use.

This commit is contained in:
Michael Jumper
2020-04-13 00:23:19 -07:00
parent 907dfcd151
commit 0d1f42f6f4
6 changed files with 42 additions and 110 deletions

View File

@@ -1,86 +0,0 @@
/*
* 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.guacamole.auth.quickconnect;
import org.apache.guacamole.GuacamoleClientException;
import org.apache.guacamole.language.Translatable;
import org.apache.guacamole.language.TranslatableMessage;
/**
* An exception that is thrown by this extension when an error occurs
* attempting to create and establish a connection with a user-provided
* URI.
*/
public class QuickConnectException extends GuacamoleClientException
implements Translatable {
/**
* A message that can be passed through the translation service
* to provide information about the error that occurred.
*/
private final TranslatableMessage translatableMessage;
/**
* Create a QuickConnectException with the given message and translationKey.
* The message will not be passed through the translation system; the
* translationKey will be passed through the translation system. Both should
* describe the error.
*
* @param message
* A string describing the error that occurred when trying to create
* or establish the connection. This will not be passed through the
* translation system.
*
* @param translationKey
* A key known to the translation system describing the error that
* occurred when trying to create or establish the connection.
* This will be passed through the translation system to provide
* a localized version of the message.
*/
public QuickConnectException(String message, String translationKey) {
super(message);
this.translatableMessage = new TranslatableMessage(translationKey);
}
/**
* Create a new QuickConnectException given the human-readable message,
* which will not be passed through the translation system, and the
* translatableMessage, which will be passed through the translation system.
* Both parameters should describe the error preventing the connection
* from being created or established.
*
* @param message
* The human-readable message describing the error, which will not
* be passed through the translation system.
*
* @param translatableMessage
* The human-readable message describing the error, which will be
* passed through the translation system.
*/
public QuickConnectException(String message, TranslatableMessage translatableMessage) {
super(message);
this.translatableMessage = translatableMessage;
}
@Override
public TranslatableMessage getTranslatableMessage() {
return translatableMessage;
}
}

View File

@@ -32,7 +32,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.guacamole.GuacamoleServerException;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.auth.quickconnect.QuickConnectException;
import org.apache.guacamole.language.TranslatableGuacamoleClientException;
import org.apache.guacamole.protocol.GuacamoleConfiguration;
/**
@@ -78,11 +78,11 @@ public class QCParser {
try {
qcUri = new URI(uri);
if (!qcUri.isAbsolute())
throw new QuickConnectException("URI must be absolute.",
throw new TranslatableGuacamoleClientException("URI must be absolute.",
"QUICKCONNECT.ERROR_NOT_ABSOLUTE_URI");
}
catch (URISyntaxException e) {
throw new QuickConnectException("Invalid URI Syntax",
throw new TranslatableGuacamoleClientException("Invalid URI Syntax",
"QUICKCONNECT.ERROR_INVALID_URI");
}
@@ -100,7 +100,7 @@ public class QCParser {
if (protocol != null && !protocol.isEmpty())
qcConfig.setProtocol(protocol);
else
throw new QuickConnectException("No protocol specified.",
throw new TranslatableGuacamoleClientException("No protocol specified.",
"QUICKCONNECT.ERROR_NO_PROTOCOL");
// Check for provided port number
@@ -111,7 +111,7 @@ public class QCParser {
if (host != null && !host.isEmpty())
qcConfig.setParameter("hostname", host);
else
throw new QuickConnectException("No host specified.",
throw new TranslatableGuacamoleClientException("No host specified.",
"QUICKCONNECT.ERROR_NO_HOST");
// Look for extra query parameters and parse them out.