1 17 package org.alfresco.repo.template; 18 19 import java.io.StringReader ; 20 21 import org.alfresco.error.AlfrescoRuntimeException; 22 import org.alfresco.model.ContentModel; 23 import org.alfresco.service.ServiceRegistry; 24 import org.alfresco.service.cmr.repository.ContentReader; 25 import org.alfresco.service.cmr.repository.NodeRef; 26 import org.alfresco.service.cmr.repository.TemplateNode; 27 import org.dom4j.Document; 28 import org.dom4j.Element; 29 import org.dom4j.io.SAXReader; 30 31 36 public class SavedSearchResultsMap extends BaseSearchResultsMap 37 { 38 private static final String ELEMENT_QUERY = "query"; 39 40 46 public SavedSearchResultsMap(TemplateNode parent, ServiceRegistry services) 47 { 48 super(parent, services); 49 } 50 51 54 public Object get(Object key) 55 { 56 String search = null; 57 58 if (key != null && key.toString().length() != 0) 59 { 60 try 62 { 63 NodeRef ref = new NodeRef(key.toString()); 64 65 ContentReader content = services.getContentService().getReader(ref, ContentModel.PROP_CONTENT); 66 if (content != null && content.exists()) 67 { 68 SAXReader reader = new SAXReader(); 70 Document document = reader.read(new StringReader (content.getContentString())); 71 Element rootElement = document.getRootElement(); 72 73 Element queryElement = rootElement.element(ELEMENT_QUERY); 74 if (queryElement != null) 75 { 76 search = queryElement.getText(); 77 } 78 } 79 } 80 catch (Throwable err) 81 { 82 throw new AlfrescoRuntimeException("Failed to find or load saved Search: " + key, err); 83 } 84 } 85 86 return query(search); 88 } 89 } 90 | Popular Tags |