if (value == null && xpath == null && !ACTION_REMOVE.equals(type)) {
handleException("value or xpath attribute is required on the action element");
}
RewriteAction action = new RewriteAction();
if (xpath != null) {
try {
action.setXpath(SynapseXPathFactory.getSynapseXPath(actionElement, xpath_Q));
} catch (JaxenException e) {
handleException("Error while parsing the XPath expression: " + xpath, e);
}
} else if (value != null) {
action.setValue(value);
}
String fragment = actionElement.getAttributeValue(ATT_FRAGMENT);
if (fragment != null) {
if (FRAGMENT_PROTOCOL.equals(fragment)) {
action.setFragmentIndex(URIFragments.PROTOCOL);
} else if (FRAGMENT_USER_INFO.equals(fragment)) {
action.setFragmentIndex(URIFragments.USER_INFO);
} else if (FRAGMENT_HOST.equals(fragment)) {
action.setFragmentIndex(URIFragments.HOST);
} else if (FRAGMENT_PORT.equals(fragment)) {
action.setFragmentIndex(URIFragments.PORT);
} else if (FRAGMENT_PATH.equals(fragment)) {
action.setFragmentIndex(URIFragments.PATH);
} else if (FRAGMENT_QUERY.equals(fragment)) {
action.setFragmentIndex(URIFragments.QUERY);
} else if (FRAGMENT_REF.equals(fragment)) {
action.setFragmentIndex(URIFragments.REF);
} else if (FRAGMENT_FULL_URI.equals(fragment)) {
action.setFragmentIndex(URIFragments.FULL_URI);
} else {
handleException("Unknown URL fragment name: " + fragment);
}
}
if (type != null) {
if (ACTION_SET.equals(type)) {
action.setActionType(RewriteAction.ACTION_SET);
} else if (ACTION_APPEND.equals(type)) {
action.setActionType(RewriteAction.ACTION_APPEND);
} else if (ACTION_PREPEND.equals(type)) {
action.setActionType(RewriteAction.ACTION_PREPEND);
} else if (ACTION_REPLACE.equals(type)) {
action.setActionType(RewriteAction.ACTION_REPLACE);
String regex = actionElement.getAttributeValue(ATT_REGEX);
if (regex != null) {
action.setRegex(regex);
} else {
handleException("regex attribute is required for replace action");
}
} else if (ACTION_REMOVE.equals(type)) {
action.setActionType(RewriteAction.ACTION_REMOVE);
} else {
handleException("Unknown URL rewrite action type: " + type);
}
}