use of org.jaxen.saxpath.SAXPathException in project intellij-community by JetBrains.
the class XPathEvalAction method evaluateExpression.
private boolean evaluateExpression(EvalExpressionDialog.Context context, XmlElement contextNode, Editor editor, Config cfg) {
final Project project = editor.getProject();
try {
final XPathSupport support = XPathSupport.getInstance();
final XPath xpath = support.createXPath((XmlFile) contextNode.getContainingFile(), context.input.expression, context.input.namespaces);
xpath.setVariableContext(new CachedVariableContext(context.input.variables, xpath, contextNode));
// evaluate the expression on the whole document
final Object result = xpath.evaluate(contextNode);
LOG.debug("result = " + result);
LOG.assertTrue(result != null, "null result?");
if (result instanceof List<?>) {
final List<?> list = (List<?>) result;
if (!list.isEmpty()) {
if (cfg.HIGHLIGHT_RESULTS) {
highlightResult(contextNode, editor, list);
}
if (cfg.SHOW_USAGE_VIEW) {
showUsageView(editor, xpath, contextNode, list);
}
if (!cfg.SHOW_USAGE_VIEW && !cfg.HIGHLIGHT_RESULTS) {
final String s = StringUtil.pluralize("match", list.size());
Messages.showInfoMessage(project, "Expression produced " + list.size() + " " + s, "XPath Result");
}
} else {
return Messages.showOkCancelDialog(project, "Sorry, your expression did not return any result", "XPath Result", "OK", "Edit Expression", Messages.getInformationIcon()) != Messages.OK;
}
} else if (result instanceof String) {
Messages.showMessageDialog("'" + result.toString() + "'", "XPath result (String)", Messages.getInformationIcon());
} else if (result instanceof Number) {
Messages.showMessageDialog(result.toString(), "XPath result (Number)", Messages.getInformationIcon());
} else if (result instanceof Boolean) {
Messages.showMessageDialog(result.toString(), "XPath result (Boolean)", Messages.getInformationIcon());
} else {
LOG.error("Unknown XPath result: " + result);
}
} catch (XPathSyntaxException e) {
LOG.debug(e);
// TODO: Better layout of the error message with non-fixed size fonts
return Messages.showOkCancelDialog(project, e.getMultilineMessage(), "XPath syntax error", "Edit Expression", "Cancel", Messages.getErrorIcon()) == Messages.OK;
} catch (SAXPathException e) {
LOG.debug(e);
Messages.showMessageDialog(project, e.getMessage(), "XPath error", Messages.getErrorIcon());
}
return false;
}
use of org.jaxen.saxpath.SAXPathException in project SearchServices by Alfresco.
the class Solr4QueryParser method getFieldQuery.
/**
* @param field
* @param queryText
* @param analysisMode
* @param luceneFunction
* @return the query
* @throws ParseException
* @throws IOException
*/
@SuppressWarnings("deprecation")
public Query getFieldQuery(String field, String queryText, AnalysisMode analysisMode, LuceneFunction luceneFunction) throws ParseException {
try {
if (field.equals(FIELD_PATH)) {
return createPathQuery(queryText, false);
} else if (field.equals(FIELD_PATHWITHREPEATS)) {
return createPathQuery(queryText, true);
} else if (field.equals(FIELD_TEXT)) {
return createTextQuery(queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_ID)) {
return createIdQuery(queryText);
} else if (field.equals(FIELD_SOLR4_ID)) {
return createSolr4IdQuery(queryText);
} else if (field.equals(FIELD_DBID)) {
return createDbidQuery(queryText);
} else if (field.equals(FIELD_ACLID)) {
return createAclIdQuery(queryText);
} else if (field.equals(FIELD_OWNER)) {
return createOwnerQuery(queryText);
} else if (field.equals(FIELD_OWNERSET)) {
return createOwnerSetQuery(queryText);
} else if (field.equals(FIELD_READER)) {
return createReaderQuery(queryText);
} else if (field.equals(FIELD_READERSET)) {
return createReaderSetQuery(queryText);
} else if (field.equals(FIELD_AUTHORITY)) {
return createAuthorityQuery(queryText);
} else if (field.equals(FIELD_AUTHORITYSET)) {
return createAuthoritySetQuery(queryText);
} else if (field.equals(FIELD_DENIED)) {
return createDeniedQuery(queryText);
} else if (field.equals(FIELD_DENYSET)) {
return createDenySetQuery(queryText);
} else if (field.equals(FIELD_ISROOT)) {
return createIsRootQuery(queryText);
} else if (field.equals(FIELD_ISCONTAINER)) {
return createIsContainerQuery(queryText);
} else if (field.equals(FIELD_ISNODE)) {
return createIsNodeQuery(queryText);
} else if (field.equals(FIELD_TX)) {
return createTransactionQuery(queryText);
} else if (field.equals(FIELD_INTXID)) {
return createInTxIdQuery(queryText);
} else if (field.equals(FIELD_INACLTXID)) {
return createInAclTxIdQuery(queryText);
} else if (field.equals(FIELD_PARENT)) {
return createParentQuery(queryText);
} else if (field.equals(FIELD_PRIMARYPARENT)) {
return createPrimaryParentQuery(queryText);
} else if (field.equals(FIELD_QNAME)) {
return createQNameQuery(queryText);
} else if (field.equals(FIELD_PRIMARYASSOCQNAME)) {
return createPrimaryAssocQNameQuery(queryText);
} else if (field.equals(FIELD_PRIMARYASSOCTYPEQNAME)) {
return createPrimaryAssocTypeQNameQuery(queryText);
} else if (field.equals(FIELD_ASSOCTYPEQNAME)) {
return createAssocTypeQNameQuery(queryText);
} else if (field.equals(FIELD_CLASS)) {
ClassDefinition target = QueryParserUtils.matchClassDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, queryText);
if (target == null) {
return new TermQuery(new Term(FIELD_TYPE, "_unknown_"));
}
return getFieldQuery(target.isAspect() ? FIELD_ASPECT : FIELD_TYPE, queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_TYPE)) {
return createTypeQuery(queryText, false);
} else if (field.equals(FIELD_EXACTTYPE)) {
return createTypeQuery(queryText, true);
} else if (field.equals(FIELD_ASPECT)) {
return createAspectQuery(queryText, false);
} else if (field.equals(FIELD_EXACTASPECT)) {
return createAspectQuery(queryText, true);
} else if (isPropertyField(field)) {
Query query = attributeQueryBuilder(field, queryText, new FieldQuery(), analysisMode, luceneFunction);
return query;
} else if (field.equals(FIELD_ALL)) {
return createAllQuery(queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_ISUNSET)) {
return createIsUnsetQuery(queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_ISNULL)) {
return createIsNullQuery(queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_ISNOTNULL)) {
return createIsNotNull(queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_EXISTS)) {
return createExistsQuery(queryText, analysisMode, luceneFunction);
} else if (QueryParserUtils.matchDataTypeDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, field) != null) {
return createDataTypeDefinitionQuery(field, queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_FTSSTATUS)) {
return createTermQuery(field, queryText);
} else if (field.equals(FIELD_TXID)) {
return createTxIdQuery(queryText);
} else if (field.equals(FIELD_ACLTXID)) {
return createAclTxIdQuery(queryText);
} else if (field.equals(FIELD_TXCOMMITTIME)) {
return createTxCommitTimeQuery(queryText);
} else if (field.equals(FIELD_ACLTXCOMMITTIME)) {
return createAclTxCommitTimeQuery(queryText);
} else if (field.equals(FIELD_TAG)) {
return createTagQuery(queryText);
} else if (field.equals(FIELD_SITE)) {
return createSiteQuery(queryText);
} else if (field.equals(FIELD_PNAME)) {
return createPNameQuery(queryText);
} else if (field.equals(FIELD_NPATH)) {
return createNPathQuery(queryText);
} else if (field.equals(FIELD_TENANT)) {
return createTenantQuery(queryText);
} else if (field.equals(FIELD_ANCESTOR)) {
return createAncestorQuery(queryText);
} else if (field.equals(FIELD_FINGERPRINT)) {
String[] parts = queryText.split("_");
Collection values = null;
String nodeId = parts[0];
JSONObject json = (JSONObject) request.getContext().get(AbstractQParser.ALFRESCO_JSON);
String fingerPrint = null;
if (json != null) {
// Was the fingerprint passed in
String fingerPrintKey = "fingerprint." + nodeId;
if (json.has(fingerPrintKey)) {
fingerPrint = (String) json.get("fingerprint." + nodeId);
if (fingerPrint != null) {
List l = new ArrayList();
String[] hashes = fingerPrint.split(" ");
for (String hash : hashes) {
l.add(hash);
}
values = l;
}
}
} else {
json = new JSONObject();
}
// Is the fingerprint in the local SolrContentStore
if (values == null) {
long dbid = fetchDBID(nodeId);
if (dbid == -1 && isNumber(nodeId)) {
dbid = Long.parseLong(nodeId);
}
if (dbid > -1) {
SolrInputDocument solrDoc = solrContentStore.retrieveDocFromSolrContentStore(AlfrescoSolrDataModel.getTenantId(TenantService.DEFAULT_DOMAIN), dbid);
if (solrDoc != null) {
SolrInputField mh = solrDoc.getField("MINHASH");
if (mh != null) {
values = mh.getValues();
}
}
}
}
String shards = this.solrParams.get("shards");
if (values == null && shards != null) {
// we are in distributed mode
// Fetch the fingerPrint from the shards.
// The UUID and DBID will both work for method call.
values = fetchFingerPrint(shards, nodeId);
}
// If we're in distributed mode then add the fingerprint to the json
if (values != null && shards != null && fingerPrint == null) {
ModifiableSolrParams newParams = new ModifiableSolrParams();
newParams.add(solrParams);
solrParams = newParams;
json.put("fingerprint." + nodeId, join(values, " "));
String jsonString = json.toString();
newParams.add(AbstractQParser.ALFRESCO_JSON, jsonString);
request.getContext().put(AbstractQParser.ALFRESCO_JSON, json);
request.setParams(newParams);
}
return createFingerPrintQuery(field, queryText, values, analysisMode, luceneFunction);
} else {
return getFieldQueryImpl(field, queryText, analysisMode, luceneFunction);
}
} catch (SAXPathException e) {
throw new ParseException("Failed to parse XPath...\n" + e.getMessage());
} catch (IOException e) {
throw new ParseException("IO: " + e.getMessage());
}
}
Aggregations