mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
Move Attribute awareness to new init() event of TagHandler.
This commit is contained in:
@@ -104,13 +104,16 @@ public class DocumentHandler extends DefaultHandler {
|
||||
// Otherwise, get handler from parent
|
||||
else {
|
||||
TagHandler parent_handler = current.getTagHandler();
|
||||
handler = parent_handler.childElement(localName, attributes);
|
||||
handler = parent_handler.childElement(localName);
|
||||
}
|
||||
|
||||
// If no handler returned, the element was not expected
|
||||
if (handler == null)
|
||||
throw new SAXException("Unexpected element: '" + localName + "'");
|
||||
|
||||
// Initialize handler
|
||||
handler.init(attributes);
|
||||
|
||||
// Append new element state to stack
|
||||
stack.addLast(new DocumentHandlerState(handler));
|
||||
|
||||
|
@@ -33,16 +33,25 @@ public interface TagHandler {
|
||||
* Called when a child element of the current element is parsed.
|
||||
*
|
||||
* @param localName The local name of the child element seen.
|
||||
* @param attributes The attributes of the child element seen.
|
||||
* @return The TagHandler which should handle all element-level events
|
||||
* related to the child element.
|
||||
* @throws SAXException If the child element being parsed was not expected,
|
||||
* or some other error prevents a proper TagHandler
|
||||
* from being constructed for the child element.
|
||||
*/
|
||||
public TagHandler childElement(String localName, Attributes attributes)
|
||||
public TagHandler childElement(String localName)
|
||||
throws SAXException;
|
||||
|
||||
/**
|
||||
* Called when the element corresponding to this TagHandler is first seen,
|
||||
* just after an instance is created.
|
||||
*
|
||||
* @param attributes The attributes of the element seen.
|
||||
* @throws SAXException If an error prevents a the TagHandler from being
|
||||
* from being initialized.
|
||||
*/
|
||||
public void init(Attributes attributes) throws SAXException;
|
||||
|
||||
/**
|
||||
* Called when this element, and all child elements, have been fully parsed,
|
||||
* and the entire text content of this element (if any) is available.
|
||||
|
@@ -44,14 +44,8 @@ public class AuthorizeTagHandler implements TagHandler {
|
||||
*/
|
||||
private GuacamoleConfiguration default_config = null;
|
||||
|
||||
/**
|
||||
* Creates a new handler for an "authorize" tag having the given
|
||||
* attributes.
|
||||
*
|
||||
* @param attributes The attributes of the "authorize" tag.
|
||||
* @throws SAXException If the attributes given are not valid.
|
||||
*/
|
||||
public AuthorizeTagHandler(Attributes attributes) throws SAXException {
|
||||
@Override
|
||||
public void init(Attributes attributes) throws SAXException {
|
||||
|
||||
// Init username and password
|
||||
authorization.setUsername(attributes.getValue("username"));
|
||||
@@ -79,13 +73,13 @@ public class AuthorizeTagHandler implements TagHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagHandler childElement(String localName, Attributes attributes) throws SAXException {
|
||||
public TagHandler childElement(String localName) throws SAXException {
|
||||
|
||||
// "connection" tag
|
||||
if (localName.equals("connection")) {
|
||||
|
||||
// Get tag handler for connection tag
|
||||
ConnectionTagHandler tagHandler = new ConnectionTagHandler(attributes);
|
||||
ConnectionTagHandler tagHandler = new ConnectionTagHandler();
|
||||
|
||||
// Store configuration stub
|
||||
GuacamoleConfiguration config_stub = tagHandler.asGuacamoleConfiguration();
|
||||
@@ -103,7 +97,7 @@ public class AuthorizeTagHandler implements TagHandler {
|
||||
authorization.addConfiguration("DEFAULT", default_config);
|
||||
}
|
||||
|
||||
return new ParamTagHandler(default_config, attributes);
|
||||
return new ParamTagHandler(default_config);
|
||||
}
|
||||
|
||||
// "protocol" tag
|
||||
|
@@ -40,22 +40,16 @@ public class ConnectionTagHandler implements TagHandler {
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Creates a new handler for an "connection" tag having the given
|
||||
* attributes.
|
||||
*
|
||||
* @param attributes The attributes of the "connection" tag.
|
||||
* @throws SAXException If the attributes given are not valid.
|
||||
*/
|
||||
public ConnectionTagHandler(Attributes attributes) throws SAXException {
|
||||
@Override
|
||||
public void init(Attributes attributes) throws SAXException {
|
||||
name = attributes.getValue("name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagHandler childElement(String localName, Attributes attributes) throws SAXException {
|
||||
public TagHandler childElement(String localName) throws SAXException {
|
||||
|
||||
if (localName.equals("param"))
|
||||
return new ParamTagHandler(config, attributes);
|
||||
return new ParamTagHandler(config);
|
||||
|
||||
if (localName.equals("protocol"))
|
||||
return new ProtocolTagHandler(config);
|
||||
|
@@ -47,19 +47,18 @@ public class ParamTagHandler implements TagHandler {
|
||||
*
|
||||
* @param config The GuacamoleConfiguration to update with the data parsed
|
||||
* from the "protocol" tag.
|
||||
* @param attributes The attributes of the "param" tag.
|
||||
* @throws SAXException If the attributes given are not valid.
|
||||
*/
|
||||
public ParamTagHandler(GuacamoleConfiguration config,
|
||||
Attributes attributes) throws SAXException {
|
||||
|
||||
public ParamTagHandler(GuacamoleConfiguration config) {
|
||||
this.config = config;
|
||||
this.name = attributes.getValue("name");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagHandler childElement(String localName, Attributes attributes) throws SAXException {
|
||||
public void init(Attributes attributes) throws SAXException {
|
||||
this.name = attributes.getValue("name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagHandler childElement(String localName) throws SAXException {
|
||||
throw new SAXException("The 'param' tag can contain no elements.");
|
||||
}
|
||||
|
||||
|
@@ -49,7 +49,12 @@ public class ProtocolTagHandler implements TagHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagHandler childElement(String localName, Attributes attributes) throws SAXException {
|
||||
public void init(Attributes attributes) throws SAXException {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagHandler childElement(String localName) throws SAXException {
|
||||
throw new SAXException("The 'protocol' tag can contain no elements.");
|
||||
}
|
||||
|
||||
|
@@ -37,14 +37,18 @@ public class UserMappingTagHandler implements TagHandler {
|
||||
private UserMapping user_mapping = new UserMapping();
|
||||
|
||||
@Override
|
||||
public TagHandler childElement(String localName, Attributes attributes) throws SAXException {
|
||||
public void init(Attributes attributes) throws SAXException {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagHandler childElement(String localName) throws SAXException {
|
||||
|
||||
// Start parsing of authorize tags, add to list of all authorizations
|
||||
if (localName.equals("authorize")) {
|
||||
|
||||
// Get tag handler for authorize tag
|
||||
AuthorizeTagHandler tagHandler =
|
||||
new AuthorizeTagHandler(attributes);
|
||||
AuthorizeTagHandler tagHandler = new AuthorizeTagHandler();
|
||||
|
||||
// Store authorization stub in map of authorizations
|
||||
Authorization auth_stub = tagHandler.asAuthorization();
|
||||
|
Reference in New Issue
Block a user