Lucio Lelii 2016-12-13 15:01:04 +00:00
parent 81062f433d
commit 8501fde466
1 changed files with 16 additions and 7 deletions

View File

@ -169,13 +169,7 @@ public class Helper {
if (letFound) letPathIndex=letMat.start();
}catch(IllegalStateException e){ log.error("error parsing let statement"); throw new MalformedQueryException("error parsing let statement");}
int indexOfFor = queryFiltered.indexOf("for ");
String functionContainsDeclaration =" declare namespace functx = \"http://www.functx.com\"; declare function functx:is-value-in-sequence "+
" ( $value as xs:anyAtomicType? , $seq as xs:anyAtomicType* ) as xs:boolean { $value = $seq } ; \n";
queryFiltered = queryFiltered.substring(0,indexOfFor)+functionContainsDeclaration+queryFiltered.substring(indexOfFor);
if (!letFound) {
queryFiltered=queryFiltered.substring(0,wherePathIndex)+forInsertFinal +queryFiltered.substring(wherePathIndex);
}
@ -187,6 +181,21 @@ public class Helper {
queryFiltered = queryFiltered.replace(entry.getKey(), entry.getValue());
String functionContainsDeclaration =" declare namespace functx = \"http://www.functx.com\"; declare function functx:is-value-in-sequence "+
" ( $value as xs:anyAtomicType? , $seq as xs:anyAtomicType* ) as xs:boolean { $value = $seq } ; \n";
Pattern declarePattern=Pattern.compile("(declare namespace .*;)*", Pattern.DOTALL);
Matcher declareMat=declarePattern.matcher(queryFiltered);
boolean declareFound = declareMat.find(0);
int declareIndex = 0;
if (declareFound){
declareIndex = declareMat.end();
queryFiltered = queryFiltered.substring(0, declareIndex)+functionContainsDeclaration+queryFiltered.substring(declareIndex);
} else
queryFiltered= functionContainsDeclaration +queryFiltered;
log.trace("submitting filtered query: {}",queryFiltered);
return queryFiltered;
}