本文整理汇总了Java中org.javarosa.model.xform.XPathReference.getPathExpr方法的典型用法代码示例。如果您正苦于以下问题:Java XPathReference.getPathExpr方法的具体用法?Java XPathReference.getPathExpr怎么用?Java XPathReference.getPathExpr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.javarosa.model.xform.XPathReference
的用法示例。
在下文中一共展示了XPathReference.getPathExpr方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseItemsetLabelElement
import org.javarosa.model.xform.XPathReference; //导入方法依赖的package包/类
private void parseItemsetLabelElement(Element child, ItemsetBinding itemset, Vector<String> labelUA) {
String labelXpath = child.getAttributeValue("", REF_ATTR);
boolean labelItext = false;
if (XFormUtils.showUnusedAttributeWarning(child, labelUA)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(child, labelUA), getVagueLocation(child));
}
if (labelXpath != null) {
if (labelXpath.startsWith("jr:itext(") && labelXpath.endsWith(")")) {
labelXpath = labelXpath.substring("jr:itext(".length(), labelXpath.indexOf(")"));
labelItext = true;
}
} else {
throw new XFormParseException("<label> in <itemset> requires 'ref'");
}
XPathPathExpr labelPath = XPathReference.getPathExpr(labelXpath);
itemset.labelRef = FormInstance.unpackReference(getAbsRef(new XPathReference(labelPath), itemset.nodesetRef));
itemset.labelExpr = new XPathConditional(labelPath);
itemset.labelIsItext = labelItext;
}
示例2: getXPathAttrExpression
import org.javarosa.model.xform.XPathReference; //导入方法依赖的package包/类
public static XPathPathExpr getXPathAttrExpression(String attribute) {
//Cache tables can only take in integers due to some terrible 1.3 design issues
//so we have to manually cache our attribute string's hash and follow from there.
XPathPathExpr cached = table.retrieve(attribute);
if (cached == null) {
cached = XPathReference.getPathExpr("@" + attribute);
table.register(attribute, cached);
}
return cached;
}
示例3: getEntityFromID
import org.javarosa.model.xform.XPathReference; //导入方法依赖的package包/类
/**
* Takes an ID and identifies a reference in the provided context which corresponds
* to that element if one can be found.
*
* NOT GUARANTEED TO WORK! May return an entity if one exists
*/
public TreeReference getEntityFromID(EvaluationContext ec, String elementId) {
//The uniqueid here is the value selected, so we can in theory track down the value we're looking for.
//Get root nodeset
TreeReference nodesetRef = this.getNodeset().clone();
Vector<XPathExpression> predicates = nodesetRef.getPredicate(nodesetRef.size() - 1);
if (predicates == null) {
predicates = new Vector<>();
}
// For speed reasons, add a case id selection as the first predicate
// This has potential to change outcomes if other predicates utilize 'position'
XPathEqExpr caseIdSelection =
new XPathEqExpr(XPathEqExpr.EQ, XPathReference.getPathExpr(this.getValue()), new XPathStringLiteral(elementId));
predicates.insertElementAt(caseIdSelection, 0);
nodesetRef.addPredicate(nodesetRef.size() - 1, predicates);
Vector<TreeReference> elements = ec.expandReference(nodesetRef);
if (elements.size() == 1) {
return elements.firstElement();
} else if (elements.size() > 1) {
//Lots of nodes. Can't really choose one yet.
return null;
} else {
return null;
}
}
示例4: parseItemsetValueElement
import org.javarosa.model.xform.XPathReference; //导入方法依赖的package包/类
private void parseItemsetValueElement(Element child, ItemsetBinding itemset, Vector<String> valueUA) {
String valueXpath = child.getAttributeValue("", REF_ATTR);
if (XFormUtils.showUnusedAttributeWarning(child, valueUA)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(child, valueUA), getVagueLocation(child));
}
if (valueXpath == null) {
throw new XFormParseException("<value> in <itemset> requires 'ref'");
}
XPathPathExpr valuePath = XPathReference.getPathExpr(valueXpath);
itemset.valueRef = FormInstance.unpackReference(getAbsRef(new XPathReference(valuePath), itemset.nodesetRef));
itemset.valueExpr = new XPathConditional(valuePath);
itemset.copyMode = false;
}
示例5: parseItemsetSortElement
import org.javarosa.model.xform.XPathReference; //导入方法依赖的package包/类
private void parseItemsetSortElement(Element child, ItemsetBinding itemset) {
String sortXpathString = child.getAttributeValue("", REF_ATTR);
if (sortXpathString == null) {
throw new XFormParseException("<sort> in <itemset> requires 'ref'");
}
XPathPathExpr sortPath = XPathReference.getPathExpr(sortXpathString);
itemset.sortRef = FormInstance.unpackReference(getAbsRef(new XPathReference(sortPath), itemset.nodesetRef));
itemset.sortExpr = new XPathConditional(sortPath);
}
示例6: populateParameters
import org.javarosa.model.xform.XPathReference; //导入方法依赖的package包/类
public static void populateParameters(Intent intent, Map<String, String> exParams, TreeReference reference) throws ExternalParamsException {
FormInstance formInstance = Collect.getInstance().getFormController().getFormDef().getInstance();
EvaluationContext baseEvaluationContext = new EvaluationContext(formInstance);
EvaluationContext evaluationContext = new EvaluationContext(baseEvaluationContext, reference);
if (exParams != null) {
for (Map.Entry<String, String> paramEntry : exParams.entrySet()) {
String paramEntryValue = paramEntry.getValue();
try {
Object result;
if (paramEntryValue.startsWith("'")) {
// treat this as a constant parameter
// but not require an ending quote
if (paramEntryValue.endsWith("'")) {
result = paramEntryValue.substring(1, paramEntryValue.length() - 1);
} else {
result = paramEntryValue.substring(1, paramEntryValue.length());
}
} else if (paramEntryValue.startsWith("/")) {
// treat this is an xpath
XPathPathExpr pathExpr = XPathReference.getPathExpr(paramEntryValue);
XPathNodeset xPathNodeset = pathExpr.eval(formInstance, evaluationContext);
result = XPathFuncExpr.unpack(xPathNodeset);
} else if (paramEntryValue.equals("instanceProviderID()")) {
// instanceProviderID returns -1 if the current instance has not been
// saved to disk already
String path = Collect.getInstance().getFormController().getInstancePath().getAbsolutePath();
String selection = InstanceColumns.INSTANCE_FILE_PATH + "=?";
String selectionArgs[] = {path};
String instanceProviderID = "-1";
Cursor c = Collect.getInstance().getContentResolver().query(InstanceColumns.CONTENT_URI, null, selection, selectionArgs, null);
if (c != null && c.getCount() > 0) {
// should only ever be one
c.moveToFirst();
instanceProviderID = c.getString(c.getColumnIndex(InstanceColumns._ID));
}
if (c != null) {
c.close();
}
result = instanceProviderID;
} else {
// treat this is a function
XPathExpression xPathExpression = XPathParseTool.parseXPath(paramEntryValue);
result = xPathExpression.eval(formInstance, evaluationContext);
}
if (result != null && result instanceof Serializable) {
intent.putExtra(paramEntry.getKey(), (Serializable) result);
}
} catch (Exception e) {
throw new ExternalParamsException("Could not evaluate '" + paramEntryValue + "'", e);
}
}
}
}
示例7: parseItemset
import org.javarosa.model.xform.XPathReference; //导入方法依赖的package包/类
private void parseItemset(QuestionDef q, Element e) {
ItemsetBinding itemset = new ItemsetBinding();
////////////////USED FOR PARSER WARNING OUTPUT ONLY
//catalogue of used attributes in this method/element
Vector<String> usedAtts = new Vector<>();
Vector<String> labelUA = new Vector<>(); //for child with name 'label'
Vector<String> valueUA = new Vector<>(); //for child with name 'value'
Vector<String> copyUA = new Vector<>(); //for child with name 'copy'
usedAtts.addElement(NODESET_ATTR);
labelUA.addElement(REF_ATTR);
valueUA.addElement(REF_ATTR);
valueUA.addElement(FORM_ATTR);
copyUA.addElement(REF_ATTR);
////////////////////////////////////////////////////
String nodesetStr = e.getAttributeValue("", NODESET_ATTR);
if (nodesetStr == null) {
throw new RuntimeException("No nodeset attribute in element: [" + e.getName() + "]. This is required. (Element Printout:" + XFormSerializer.elementToString(e) + ")");
}
XPathPathExpr path = XPathReference.getPathExpr(nodesetStr);
itemset.nodesetExpr = new XPathConditional(path);
itemset.contextRef = getFormElementRef(q);
itemset.nodesetRef = FormInstance.unpackReference(getAbsRef(new XPathReference(path.getReference()), itemset.contextRef));
for (int i = 0; i < e.getChildCount(); i++) {
int type = e.getType(i);
Element child = (type == Node.ELEMENT ? e.getElement(i) : null);
String childName = (child != null ? child.getName() : null);
if (LABEL_ELEMENT.equals(childName)) {
parseItemsetLabelElement(child, itemset, labelUA);
} else if ("copy".equals(childName)) {
parseItemsetCopyElement(child, itemset, copyUA);
} else if (VALUE.equals(childName)) {
parseItemsetValueElement(child, itemset, valueUA);
} else if (SORT.equals(childName)) {
parseItemsetSortElement(child, itemset);
}
}
if (itemset.labelRef == null) {
throw new XFormParseException("<itemset> requires <label>");
} else if (itemset.copyRef == null && itemset.valueRef == null) {
throw new XFormParseException("<itemset> requires <copy> or <value>");
}
if (itemset.copyRef != null) {
if (itemset.valueRef == null) {
reporter.warning(XFormParserReporter.TYPE_TECHNICAL, "<itemset>s with <copy> are STRONGLY recommended to have <value> as well; pre-selecting, default answers, and display of answers will not work properly otherwise", getVagueLocation(e));
} else if (!itemset.copyRef.isParentOf(itemset.valueRef, false)) {
throw new XFormParseException("<value> is outside <copy>");
}
}
q.setDynamicChoices(itemset);
itemsets.addElement(itemset);
if (XFormUtils.showUnusedAttributeWarning(e, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(e, usedAtts), getVagueLocation(e));
}
}