Hi,
You should be careful with Nabble (or such tools) formatting, that
generates syntax that is neither plain text nor html, and your code samples
are then not displayed at all in regular email clients ...
I put your samples back below:
groovy:
String hql = "SELECT obj.name FROM BaseObject obj WHERE
obj.className='Space.SomeClass'";
def results = xwiki.search(hql);
for (int i = 0; i < results.size(); i++) {
if(!results.get(i).equals("Space.SomeClassTemplate")) {
Document doc = xwiki.getDocument(results.get(i));
Object obj = document.getObject("Space.SomeClass");
if (obj!=null) {
Property property = obj.getProperty("title");
if (property!=null) {
title = property.getValue();
} else {
title = document.getTitle();
}
println(title)
}
}
java:
String className = "Space.SomeClass";
String sql = "SELECT obj.name FROM BaseObject obj WHERE obj.className='" +
className + "'";
List<Object> results = context.getWiki().search(sql, context);
if (results != null) {
for (Object object : results) {
String docName = object.toString();
XWikiDocument doc = context.getWiki().getDocument(docName, context);
EntityReference entRef = doc.resolveClassReference(className);
BaseObject baseObject = doc.getXObject(entRef);
if (baseObject != null) {
System.out.println(doc.getTitle()+ baseObject);
}
}
Note that you don't do the same thing regarding title in groovy and in
java, obj.getProperty("title") is not at all equivalent to
document.getTitle() ...
It's likely that your document has no title, and what "works" in groovy is
to get a property "title" from an object of this doc. At least, I don't see
any other reason for this empty title :)
Side note, in java you could inject the QueryManager instead of using the
"search" api, as you only do a read-only query:
@Inject
private QueryManager queryManager;
See :
http://extensions.xwiki.org/xwiki/bin/view/Extension/Query+Module
Hope this helps,
Jeremie
2015-01-23 17:39 GMT+01:00 Matthias Wegner <mic.mat.wegner(a)web.de>de>:
Hi All,
i have a working groovy script which is:
I use a class and add an object to a document. Everytime a object is
attached i look for it with the query and do something with the objects.
the
strange thing is that i try to port it to a service to java. where i get in
groovy an title of the document it is NOT given in java.
The java code of the service
I didn't get it. Did i do something wrong? i never get a title of the
document. I can read the document, the object of the document, but i did
not
get the title. I tried also to get translated documents because i use
locals
de and en. But even there i get the title back.
You know why?
Regards,
Matthias
--
View this message in context:
http://xwiki.475771.n2.nabble.com/Empty-Document-Title-tp7593748.html
Sent from the XWiki- Users mailing list archive at
Nabble.com.
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users