use of org.apache.synapse.util.xpath.SynapseJsonPath in project wso2-synapse by wso2.
the class Value method getExpression.
/**
* Retrieving dynamic key
*
* @return SynapsePath
*/
public SynapsePath getExpression() {
if (expression == null && keyValue != null && hasExprTypeKey()) {
try {
String expressionString = keyValue.substring(1, keyValue.length() - 1);
if (expressionString.startsWith("json-eval(")) {
// Remove "json-eval" and extract the json expression
SynapseJsonPath expressionTypeKey = new SynapseJsonPath(expressionString.substring(10, expressionString.length() - 1));
expression = expressionTypeKey;
} else {
SynapseXPath expressionTypeKey = new SynapseXPath(expressionString);
for (OMNamespace aNamespaceList : namespaceList) {
expressionTypeKey.addNamespace(aNamespaceList);
}
expression = expressionTypeKey;
}
} catch (JaxenException e) {
expression = null;
handleException("Can not evaluate escaped expression..");
}
}
return expression;
}
use of org.apache.synapse.util.xpath.SynapseJsonPath in project wso2-synapse by wso2.
the class ValueFactory method createTextValue.
/**
* Create a key instance
*
* @param elem OMElement
* @return Key
*/
public Value createTextValue(OMElement elem) {
Value key = null;
// OMAttribute attKey = elem.getAttribute(new QName(name));
String textValue = elem.getText();
if (textValue != null) {
boolean hasEscape = isEscapedExpression(textValue);
if (!hasEscape && isDynamicKey(textValue)) {
// Filter json-eval expressions
if (textValue.startsWith("{json-eval(")) {
// Get the JSON expression in-between "{}"
textValue = textValue.substring(1, textValue.length() - 1);
SynapseJsonPath synJsonPath = createSynJsonPath(textValue);
key = new Value(synJsonPath);
} else {
SynapseXPath synXpath = createSynXpath(elem, textValue);
key = new Value(synXpath);
}
} else if (hasEscape) {
/**
* escaped expr
*/
key = new Value(getEscapedExpression(textValue));
key.setNamespaces(elem);
} else {
/**
* static key
*/
key = new Value(textValue);
}
} else {
handleException("Text value is required for the element '" + elem.getLocalName() + "'");
}
return key;
}
use of org.apache.synapse.util.xpath.SynapseJsonPath in project wso2-synapse by wso2.
the class SynapsePathFactory method getSynapsePath.
public static SynapsePath getSynapsePath(OMElement elem, QName attribName) throws JaxenException {
SynapsePath path = null;
OMAttribute pathAttrib = elem.getAttribute(attribName);
if (pathAttrib != null && pathAttrib.getAttributeValue() != null) {
if (pathAttrib.getAttributeValue().startsWith("json-eval(")) {
path = new SynapseJsonPath(pathAttrib.getAttributeValue().substring(10, pathAttrib.getAttributeValue().length() - 1));
} else {
try {
path = new SynapseXPath(pathAttrib.getAttributeValue());
} catch (org.jaxen.XPathSyntaxException ex) {
/* Try and see whether the expression can be compiled with XPath 2.0
* This will only be done if the failover DOM XPath 2.0 is enabled */
if (Boolean.parseBoolean(SynapsePropertiesLoader.loadSynapseProperties().getProperty(SynapseConstants.FAIL_OVER_DOM_XPATH_PROCESSING))) {
if (log.isDebugEnabled()) {
log.debug("Trying to compile the expression in XPath 2.0: " + pathAttrib.getAttributeValue());
}
path = new SynapseXPath(pathAttrib.getAttributeValue(), elem);
} else {
throw ex;
}
}
}
OMElementUtils.addNameSpaces(path, elem, log);
path.addNamespacesForFallbackProcessing(elem);
} else {
handleException("Couldn't find the XPath attribute with the QName : " + attribName.toString() + " in the element : " + elem.toString());
}
return path;
}
use of org.apache.synapse.util.xpath.SynapseJsonPath in project wso2-synapse by wso2.
the class ValueFactory method createSynJsonPath.
/**
* Create synapse jsonpath expression
*
* @param key jsonpath expression eg: json-eval($.info)
* @return SynapseJsonPath
*/
public SynapseJsonPath createSynJsonPath(String key) {
// Derive JsonPath Expression from key removing "json-eval(" & ")"
String jsonPathExpr = key.trim().substring(10, key.length() - 1);
SynapseJsonPath synapseJsonPath = null;
try {
synapseJsonPath = SynapseJsonPathFactory.getSynapseJsonPath(jsonPathExpr);
} catch (JaxenException e) {
handleException("Can not create SynapseJsonPath from given: " + key);
}
return synapseJsonPath;
}
use of org.apache.synapse.util.xpath.SynapseJsonPath in project wso2-synapse by wso2.
the class ValueFactory method createValue.
/**
* Create a key instance
*
* @param elem OMElement
* @return Key
*/
public Value createValue(String name, OMElement elem) {
Value key = null;
OMAttribute attKey = elem.getAttribute(new QName(name));
if (attKey != null) {
String attributeValue = attKey.getAttributeValue();
boolean hasEscape = isEscapedExpression(attributeValue);
if (!hasEscape && isDynamicKey(attributeValue)) {
// Filter json-eval expressions
if (attributeValue.startsWith("{json-eval(")) {
// Get the expression in-between "{}"
attributeValue = attributeValue.substring(1, attributeValue.length() - 1);
SynapseJsonPath synJsonPath = createSynJsonPath(attributeValue);
key = new Value(synJsonPath);
} else {
SynapseXPath synXpath = createSynXpath(elem, attributeValue);
key = new Value(synXpath);
}
} else if (hasEscape) {
/**
* escaped expr
*/
key = new Value(getEscapedExpression(attributeValue));
key.setNamespaces(elem);
} else {
/**
* static key
*/
key = new Value(attributeValue);
}
} else {
handleException("The '" + name + "' attribute is required for the element '" + elem.getLocalName() + "'");
}
return key;
}
Aggregations