Search in sources :

Example 1 with RewriteAction

use of org.apache.synapse.mediators.transform.url.RewriteAction in project wso2-synapse by wso2.

the class URLRewriteMediatorSerializer method serializeRule.

private OMElement serializeRule(RewriteRule r) throws EvaluatorException {
    OMElement rule = fac.createOMElement("rewriterule", synNS);
    Evaluator condition = r.getCondition();
    if (condition != null) {
        OMElement conditionElt = fac.createOMElement("condition", synNS);
        EvaluatorSerializer serializer = EvaluatorSerializerFinder.getInstance().getSerializer(condition.getName());
        serializer.serialize(conditionElt, condition);
        rule.addChild(conditionElt);
    }
    List<RewriteAction> actions = r.getActions();
    for (RewriteAction a : actions) {
        OMElement action = serializeAction(a);
        rule.addChild(action);
    }
    return rule;
}
Also used : RewriteAction(org.apache.synapse.mediators.transform.url.RewriteAction) OMElement(org.apache.axiom.om.OMElement) Evaluator(org.apache.synapse.commons.evaluators.Evaluator) EvaluatorSerializer(org.apache.synapse.commons.evaluators.config.EvaluatorSerializer)

Example 2 with RewriteAction

use of org.apache.synapse.mediators.transform.url.RewriteAction in project wso2-synapse by wso2.

the class URLRewriteMediatorFactory method parseAction.

private RewriteAction parseAction(OMElement actionElement) {
    String value = actionElement.getAttributeValue(ATT_VALUE);
    String xpath = actionElement.getAttributeValue(ATT_XPATH);
    String type = actionElement.getAttributeValue(ATT_TYPE);
    QName xpath_Q = new QName(XMLConfigConstants.NULL_NAMESPACE, "xpath");
    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);
        }
    }
    return action;
}
Also used : QName(javax.xml.namespace.QName) RewriteAction(org.apache.synapse.mediators.transform.url.RewriteAction) JaxenException(org.jaxen.JaxenException)

Aggregations

RewriteAction (org.apache.synapse.mediators.transform.url.RewriteAction)2 QName (javax.xml.namespace.QName)1 OMElement (org.apache.axiom.om.OMElement)1 Evaluator (org.apache.synapse.commons.evaluators.Evaluator)1 EvaluatorSerializer (org.apache.synapse.commons.evaluators.config.EvaluatorSerializer)1 JaxenException (org.jaxen.JaxenException)1