Skip to content

Instantly share code, notes, and snippets.

@mweststrate
Created July 6, 2012 13:55
Show Gist options
  • Save mweststrate/3060283 to your computer and use it in GitHub Desktop.
Save mweststrate/3060283 to your computer and use it in GitHub Desktop.
xpath example java 1
private String implementation1(String name, Category category, Long offset) throws CoreException
{
StringBuilder b = new StringBuilder();
//create the xpath
String xpath =
"//Products.Product[Products.Product_ProductState/Products.ProductState[Published = true() or PublishAnyway = true()]]" +
"[Products.Product_Category = '" + category.getGUID() + "']" +
"[Name = '" + name + "']";
//count
long count = Core.retrieveXPathQueryAggregate(getContext(), "count(" + xpath + ")");
b.append(count).append("\n");
//retrieve all
List<IMendixObject> products = Core.retrieveXPathQuery(getContext(), xpath, 0, offset.intValue(),
ImmutableMap.of("Nr","Asc")
);
//add number of the first
if (products.size() > 0) {
Product proxy = Product.initialize(getContext(), products.get(0));
b.append(proxy.getNr()).append("\n");
}
//add descriptions of the others
for(IMendixObject p : products) {
Product proxy = Product.initialize(getContext(), p);
b.append(proxy.getDescription()).append("\n");
}
return b.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment