Empty Document Title

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Empty Document Title

Matthias Wegner
This post was updated on .
Hi All,

i have a working groovy script which is:
         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)
            }
         }
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
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);
     }
}
  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 not the title back.

You know why?

Regards,
Matthias
Reply | Threaded
Open this post in threaded view
|

Re: Empty Document Title

jerem
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 <[hidden email]>:

> 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
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Empty Document Title

Matthias Wegner
Dear Jeremie,

sorry for the distracting. The object is here not important. I only search for ALL documents which contain one object. From that document i want to read the title (if i get no value from the object). I tried now the queryModule with

List<DocumentReference> foundReferences = new ArrayList<DocumentReference>();
            try {
                Query query = queryManager.createQuery("SELECT doc.space, doc.name FROM Document doc, doc.object(" + className + ") AS obj", Query.XWQL);
                List<Object[]> queryResults = query.execute();
                for (Object[] result : queryResults) {
                    foundReferences.add(new DocumentReference(context.getDatabase(), (String) result[0], (String) result[1]));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (foundReferences.size()>0) {
                for (DocumentReference documentReference : foundReferences) {
                    XWikiDocument doc = context.getWiki().getDocument(documentReference, context);
                    System.out.println(doc.getTitle());
                }
            }

That doens't help at all. I don't get the title from documents. Why is that? You have an idea? Should title = doc.getTitle(); not give back the title? It has nothing to do with the attachend object.

PS: I created all the documents with "AppWithinAMinute". The documents show a title when i open the document in the browser, so why can i read the title with a query from java-side? If you have no idea, than it seems that it is a bug. Then i send an example-code which reproduce this to jira.

Regards,
Matthias

Am 26.01.2015 um 10:23 schrieb jerem [via XWiki]:
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 <[hidden email]>:

> 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
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users



If you reply to this email, your message will be added to the discussion below:
http://xwiki.475771.n2.nabble.com/Empty-Document-Title-tp7593748p7593758.html
To unsubscribe from Empty Document Title, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Empty Document Title

jerem
Hi,

2015-01-27 10:39 GMT+01:00 Matthias Wegner <[hidden email]>:

> Dear Jeremie,
>
> sorry for the distracting. The object is here not important. I only
> search for ALL documents which contain one object. From that document i
> want to read the title (if i get no value from the object). I tried now
> the queryModule with
>
> List<DocumentReference> foundReferences = new
> ArrayList<DocumentReference>();
>              try {
>                  Query query = queryManager.createQuery("SELECT
> doc.space, doc.name FROM Document doc, doc.object(" + className + ") AS
> obj", Query.XWQL);
>                  List<Object[]> queryResults = query.execute();
>                  for (Object[] result : queryResults) {
>                      foundReferences.add(new
> DocumentReference(context.getDatabase(), (String) result[0], (String)
> result[1]));
>                  }
>              } catch (Exception e) {
>                  e.printStackTrace();
>              }
>              if (foundReferences.size()>0) {
>                  for (DocumentReference documentReference :
> foundReferences) {
>                      XWikiDocument doc =
> context.getWiki().getDocument(documentReference, context);
>                      System.out.println(doc.getTitle());
>                  }
>              }
>
> That doens't help at all. I don't get the title from documents. Why is
> that? You have an idea? Should title = doc.getTitle(); not give back the
> title? It has nothing to do with the attachend object.
>
> PS: I created all the documents with "AppWithinAMinute". The documents
> show a title when i open the document in the browser, so why can i read
> the title with a query from java-side? If you have no idea, than it
> seems that it is a bug. Then i send an example-code which reproduce this
> to jira.
>

When you browse a page/document created with AppWithinMinutes, you see a
title, but please could you edit this page (in "wiki" edit mode), and check
if there is something in the "title" field at the top of the editor ?
There is a possibility that the "title" is automatically rendered by the
Sheet document generated by AppWithinMinutes, from a field in the object
(I'm not sure about this).


>
> Regards,
> Matthias
>
> Am 26.01.2015 um 10:23 schrieb jerem [via XWiki]:
> > 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 <[hidden email]
> > </user/SendEmail.jtp?type=node&node=7593758&i=0>>:
> >
> > > 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
> > > [hidden email] </user/SendEmail.jtp?type=node&node=7593758&i=1>
> > > http://lists.xwiki.org/mailman/listinfo/users
> > >
> > _______________________________________________
> > users mailing list
> > [hidden email] </user/SendEmail.jtp?type=node&node=7593758&i=2>
> > http://lists.xwiki.org/mailman/listinfo/users
> >
> >
> > ------------------------------------------------------------------------
> > If you reply to this email, your message will be added to the
> > discussion below:
> >
> http://xwiki.475771.n2.nabble.com/Empty-Document-Title-tp7593748p7593758.html
> >
> > To unsubscribe from Empty Document Title, click here
> > <
> >.
> > NAML
> > <
>
http://xwiki.475771.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
> >
> >
>
>
>
>
>
> --
> View this message in context:
> http://xwiki.475771.n2.nabble.com/Empty-Document-Title-tp7593748p7593774.html
> Sent from the XWiki- Users mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Empty Document Title

Matthias Wegner
Hi Jeremie,

if i edit the page i always see a title. That's strange, right?

Regards,
Matthias

Am 27.01.2015 um 11:23 schrieb jerem [via XWiki]:
Hi,

2015-01-27 10:39 GMT+01:00 Matthias Wegner <[hidden email]>:

> Dear Jeremie,
>
> sorry for the distracting. The object is here not important. I only
> search for ALL documents which contain one object. From that document i
> want to read the title (if i get no value from the object). I tried now
> the queryModule with
>
> List<DocumentReference> foundReferences = new
> ArrayList<DocumentReference>();
>              try {
>                  Query query = queryManager.createQuery("SELECT
> doc.space, doc.name FROM Document doc, doc.object(" + className + ") AS
> obj", Query.XWQL);
>                  List<Object[]> queryResults = query.execute();
>                  for (Object[] result : queryResults) {
>                      foundReferences.add(new
> DocumentReference(context.getDatabase(), (String) result[0], (String)
> result[1]));
>                  }
>              } catch (Exception e) {
>                  e.printStackTrace();
>              }
>              if (foundReferences.size()>0) {
>                  for (DocumentReference documentReference :
> foundReferences) {
>                      XWikiDocument doc =
> context.getWiki().getDocument(documentReference, context);
>                      System.out.println(doc.getTitle());
>                  }
>              }
>
> That doens't help at all. I don't get the title from documents. Why is
> that? You have an idea? Should title = doc.getTitle(); not give back the
> title? It has nothing to do with the attachend object.
>
> PS: I created all the documents with "AppWithinAMinute". The documents
> show a title when i open the document in the browser, so why can i read
> the title with a query from java-side? If you have no idea, than it
> seems that it is a bug. Then i send an example-code which reproduce this
> to jira.
>

When you browse a page/document created with AppWithinMinutes, you see a
title, but please could you edit this page (in "wiki" edit mode), and check
if there is something in the "title" field at the top of the editor ?
There is a possibility that the "title" is automatically rendered by the
Sheet document generated by AppWithinMinutes, from a field in the object
(I'm not sure about this).


>
> Regards,
> Matthias
>
> Am 26.01.2015 um 10:23 schrieb jerem [via XWiki]:
> > 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 <[hidden email]
> > </user/SendEmail.jtp?type=node&node=7593758&i=0>>:
> >
> > > 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
> > > [hidden email] </user/SendEmail.jtp?type=node&node=7593758&i=1>
> > > http://lists.xwiki.org/mailman/listinfo/users
> > >
> > _______________________________________________
> > users mailing list
> > [hidden email] </user/SendEmail.jtp?type=node&node=7593758&i=2>
> > http://lists.xwiki.org/mailman/listinfo/users
> >
> >
> > ------------------------------------------------------------------------
> > If you reply to this email, your message will be added to the
> > discussion below:
> >
> http://xwiki.475771.n2.nabble.com/Empty-Document-Title-tp7593748p7593758.html
> >
> > To unsubscribe from Empty Document Title, click here
> > <
> >.
> > NAML
> > <
>
http://xwiki.475771.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
> >
> >
>
>
>
>
>
> --
> View this message in context:
> http://xwiki.475771.n2.nabble.com/Empty-Document-Title-tp7593748p7593774.html
> Sent from the XWiki- Users mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users



If you reply to this email, your message will be added to the discussion below:
http://xwiki.475771.n2.nabble.com/Empty-Document-Title-tp7593748p7593775.html
To unsubscribe from Empty Document Title, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Empty Document Title

Matthias Wegner
In reply to this post by jerem
Ha, ha. I found a solution. I didn't understood why doc.getTitle() is not working under Java, but works in Velocity or Groovy-Script. But in Java i found that
doc.getRenderedTitle(Syntax.PLAIN_1_0, context) is working.

Regards,
Matthias


Am 27.01.2015 um 10:39 schrieb Matthias Wegner:
Dear Jeremie,

sorry for the distracting. The object is here not important. I only search for ALL documents which contain one object. From that document i want to read the title (if i get no value from the object). I tried now the queryModule with

List<DocumentReference> foundReferences = new ArrayList<DocumentReference>();
            try {
                Query query = queryManager.createQuery("SELECT doc.space, doc.name FROM Document doc, doc.object(" + className + ") AS obj", Query.XWQL);
                List<Object[]> queryResults = query.execute();
                for (Object[] result : queryResults) {
                    foundReferences.add(new DocumentReference(context.getDatabase(), (String) result[0], (String) result[1]));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (foundReferences.size()>0) {
                for (DocumentReference documentReference : foundReferences) {
                    XWikiDocument doc = context.getWiki().getDocument(documentReference, context);
                    System.out.println(doc.getTitle());
                }
            }

That doens't help at all. I don't get the title from documents. Why is that? You have an idea? Should title = doc.getTitle(); not give back the title? It has nothing to do with the attachend object.

PS: I created all the documents with "AppWithinAMinute". The documents show a title when i open the document in the browser, so why can i read the title with a query from java-side? If you have no idea, than it seems that it is a bug. Then i send an example-code which reproduce this to jira.

Regards,
Matthias

Am 26.01.2015 um 10:23 schrieb jerem [via XWiki]:
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 <[hidden email]>:

> 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
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users



If you reply to this email, your message will be added to the discussion below:
http://xwiki.475771.n2.nabble.com/Empty-Document-Title-tp7593748p7593758.html
To unsubscribe from Empty Document Title, click here.
NAML


Reply | Threaded
Open this post in threaded view
|

Re: Empty Document Title

vmassol
Administrator
Hi Matthias,

On 29 Jan 2015 at 20:36:20, Matthias Wegner ([hidden email](mailto:[hidden email])) wrote:

> Ha, ha. I found a solution. I didn't understood why doc.getTitle() is
> not working under Java, but works in Velocity or Groovy-Script.

There’s no reason it wouldn’t work. It just returns the title set in the document.

> But in
> Java i found that
> doc.getRenderedTitle(Syntax.PLAIN_1_0, context) is working.

This is different: if there’s no title set in the document then it’s going to extract one from the document’s content.

So my guess is that your doc has not title set.

Thanks
-Vincent

> Regards,
> Matthias
>  
>  
> Am 27.01.2015 um 10:39 schrieb Matthias Wegner:
> > Dear Jeremie,
> >
> > sorry for the distracting. The object is here not important. I only
> > search for ALL documents which contain one object. From that document
> > i want to read the title (if i get no value from the object). I tried
> > now the queryModule with
> >
> > List foundReferences = new
> > ArrayList();
> > try {
> > Query query = queryManager.createQuery("SELECT
> > doc.space, doc.name FROM Document doc, doc.object(" + className + ")
> > AS obj", Query.XWQL);
> > List queryResults = query.execute();
> > for (Object[] result : queryResults) {
> > foundReferences.add(new
> > DocumentReference(context.getDatabase(), (String) result[0], (String)
> > result[1]));
> > }
> > } catch (Exception e) {
> > e.printStackTrace();
> > }
> > if (foundReferences.size()>0) {
> > for (DocumentReference documentReference :
> > foundReferences) {
> > XWikiDocument doc =
> > context.getWiki().getDocument(documentReference, context);
> > System.out.println(doc.getTitle());
> > }
> > }
> >
> > That doens't help at all. I don't get the title from documents. Why is
> > that? You have an idea? Should title = doc.getTitle(); not give back
> > the title? It has nothing to do with the attachend object.
> >
> > PS: I created all the documents with "AppWithinAMinute". The documents
> > show a title when i open the document in the browser, so why can i
> > read the title with a query from java-side? If you have no idea, than
> > it seems that it is a bug. Then i send an example-code which reproduce
> > this to jira.
> >
> > Regards,
> > Matthias
> >
> > Am 26.01.2015 um 10:23 schrieb jerem [via XWiki]:
> >> 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 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 <[hidden email]
> >> >:
> >>
> >> > 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
> >> > [hidden email]  
> >> > http://lists.xwiki.org/mailman/listinfo/users
> >> >
> >> _______________________________________________
> >> users mailing list
> >> [hidden email]  
> >> http://lists.xwiki.org/mailman/listinfo/users
> >>
> >>
> >> ------------------------------------------------------------------------
> >> If you reply to this email, your message will be added to the
> >> discussion below:
> >> http://xwiki.475771.n2.nabble.com/Empty-Document-Title-tp7593748p7593758.html
> >>
> >> To unsubscribe from Empty Document Title, click here
> >> .
> >> NAML
> >>  
> >>
> >
>  
>  
>  
>  
>  
> --
> View this message in context: http://xwiki.475771.n2.nabble.com/Empty-Document-Title-tp7593748p7593808.html
> Sent from the XWiki- Users mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users