cancel
Showing results for 
Search instead for 
Did you mean: 

URGENT!!! Query String

enkidu
Champ in-the-making
Champ in-the-making
hi mates,

i have a query problem and dont know the answer.. this code works:



      StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
      ResultSet rs = searchService.query(storeRef, SearchService.LANGUAGE_XPATH, "/app:company_home/st:sites");
      NodeRef companyHomeNodeRef = null;
      try
      {
          if (rs.length() == 0)
          {
              throw new AlfrescoRuntimeException("Didn't find Company Home");
          }
          companyHomeNodeRef = rs.getNodeRef(0);
          fileFolderService.create(companyHomeNodeRef, "new Folder", ContentModel.TYPE_FOLDER);
      }
      finally
      {
          rs.close();
      }



can u tell me how the code should look like after the new folder is created?



      StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
      ResultSet rs = searchService.query(storeRef, SearchService.LANGUAGE_XPATH, "/app:company_home/st:sites/??:new Folder"); <– problems with query !!!
      NodeRef companyHomeNodeRef = null;
      try
      {
          if (rs.length() == 0)
          {
              throw new AlfrescoRuntimeException("Didn't find Company Home");
          }
          companyHomeNodeRef = rs.getNodeRef(0);
          fileFolderService.create(companyHomeNodeRef, "new new Folder", ContentModel.TYPE_FOLDER);
      }
      finally
      {
          rs.close();
      }

9 REPLIES 9

mrogers
Star Contributor
Star Contributor
If you use the node browser in either alfresco share or alfresco explorer it will tell you.

Here is an example  from my node browser.   In this case my test site "pies" and an image in the Share doclib 

/app:company_home/st:sites/cmSmiley Tongueies/cm:documentLibrary/cmSmiley Very HappyMG-130806-Parrot_Cay-7580569.jpg

afaust
Legendary Innovator
Legendary Innovator
Hello,

please check the XPath spec to learn about proper encoding of fragments in an XPath expression. In your case, you will most likely have a problem with your folder name which contain spaces. Spaces must be encoded in XPath. The encoding for that one character is _x0020_. For other characters, please refer to the spec or use the org.alfresco.util.ISO9075 utility for encoding.
The prefix for any file / folder manually created is "cm:".

Regards
Axel

enkidu
Champ in-the-making
Champ in-the-making
that _x0020_ solved the problem.. thnx a lot for ur help. im trying to find any tutorial about xpath expression and alfresco.. but to be honest and i dont wanna start flame so let it me say that way:

maybe there are some tutorials out there, but i didnt find them

it would be great if u can place a link to a tutorial.. i think this link would help a lot of people.

afaust
Legendary Innovator
Legendary Innovator
Hello,

this is documented in the <a href="http://wiki.alfresco.com/wiki/Search#ISO_9075_encoding">Alfresco wiki</a>. This has basically nothing to do with Alfresco specifically rather with the universal standard ISO 9075. Any character that is invalid in its current context needs to be escaped. See <a href="http://www.jtc1sc32.org/doc/N2151-2200/32N2157T-text_for_ballot-FDIS_9075-14.pdf">this draft on ISO/IEC 9075:2011 - Part 14: XML-Related Specifications</a> for reference.
Since this is a widely used and known standard, and there are also multiple utilities in Java (not limited to but containing org.alfresco.util.ISO9075) there are no Alfresco-specific tutorials.

Regards
Axel

enkidu
Champ in-the-making
Champ in-the-making
thnx.. for posting the link.. i will read it carefully.. can u tell me why sites i created with java causing problems in SHARE! (alfresco explorer NP)..?

when i click sites -> site finder -> the site didnt appear.
when i click repository -> sites -> no site will be shown although there must be at least 3

afaust
Legendary Innovator
Legendary Innovator
Hello,

since I do not know <b>how</b> you have created the sites with Java it is difficult to say. The only way sites <b>should</b> be created via Java is by using the SiteService.createSite() operation. Sites created that way should show up in the site finder. <b>BUT</b> even those sites will not be complete and will not work fully in Share without some more work. You also need to create the surf-config data structure within the site which should contain the configuration for the site dashboard that also defines what tools are available (document library, calendar …).

Please have a look at the structure of a site you create through Share and use that as a template for any kind of automatic logic.

Regards
Axel

enkidu
Champ in-the-making
Champ in-the-making
i got an error when i query a folder who are just numbers.. like the year 2013. (query string looks like this: //app:company_home/st:sites/cm:mysites/cm:2013)


Search failed due to: org.alfresco.repo.search.impl.lucene.LuceneQueryParserException: 11130033 Request failed 400 /solr/alfresco/afts?wt=json&fl=DBID%2Cscore&rows=1000&df=TEXT&start=0&locale=de_DE&alternativeDic=DEFAULT_DICTIONARY&fq=%7B%21afts%7DAUTHORITY_FILTER_FROM_JSON&fq=%7B%21afts%7DTENANT_FILTER_FROM_JSON


when i use a string e.g. mynewfolder instead of 2013 the query worked.. any ideas?

Hi,

if the first character of the name is a number, it is necessary to encode it. For example:

/app:company_home/st:sites/cm:test/cm:documentLibrary/cm:_x0032_013


To obtain the encoded name (with javascript API) you can use the method in the search object:

search.ISO9075Encode("2013")


By the way, if you are creating the path manually, it is always better to encode the names.

enkidu
Champ in-the-making
Champ in-the-making
thnx to all ;O) it worked