use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class AdvancedSearchDialog method getGlobalSearchesRef.
/**
* @return the cached reference to the global Saved Searches folder
*/
protected NodeRef getGlobalSearchesRef() {
if (properties.getGlobalSearchesRef() == null) {
FacesContext fc = FacesContext.getCurrentInstance();
String xpath = Application.getRootPath(fc) + "/" + Application.getGlossaryFolderName(fc) + "/" + Application.getSavedSearchesFolderName(fc);
List<NodeRef> results = null;
try {
results = getSearchService().selectNodes(getNodeService().getRootNode(Repository.getStoreRef()), xpath, null, getNamespaceService(), false);
} catch (AccessDeniedException err) {
// ignore and return null
}
if (results != null && results.size() == 1) {
properties.setGlobalSearchesRef(results.get(0));
}
}
return properties.getGlobalSearchesRef();
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class AdvancedSearchDialog method getSavedSearches.
/**
* @return list of saved searches as SelectItem objects
*/
public List<SelectItem> getSavedSearches() {
List<SelectItem> savedSearches = properties.getCachedSavedSearches().get();
if (savedSearches == null) {
FacesContext fc = FacesContext.getCurrentInstance();
ServiceRegistry services = Repository.getServiceRegistry(fc);
// get the searches list from the current user or global searches location
NodeRef searchesRef = null;
if (SAVED_SEARCHES_USER.equals(properties.getSavedSearchMode()) == true) {
searchesRef = getUserSearchesRef();
} else if (SAVED_SEARCHES_GLOBAL.equals(properties.getSavedSearchMode()) == true) {
searchesRef = getGlobalSearchesRef();
}
// read the content nodes under the folder
if (searchesRef != null) {
DictionaryService dd = services.getDictionaryService();
List<ChildAssociationRef> childRefs = getNodeService().getChildAssocs(searchesRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
savedSearches = new ArrayList<SelectItem>(childRefs.size() + 1);
if (childRefs.size() != 0) {
for (ChildAssociationRef ref : childRefs) {
Node childNode = new Node(ref.getChildRef());
if (dd.isSubClass(childNode.getType(), ContentModel.TYPE_CONTENT)) {
savedSearches.add(new SelectItem(childNode.getId(), childNode.getName()));
}
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(savedSearches, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
} else {
// handle missing/access denied folder case
savedSearches = new ArrayList<SelectItem>(1);
}
// add an entry (at the start) to instruct the user to select a saved search
savedSearches.add(0, new SelectItem(NO_SELECTION, Application.getMessage(FacesContext.getCurrentInstance(), MSG_SELECT_SAVED_SEARCH)));
// store in the cache (will auto-expire)
properties.getCachedSavedSearches().put(savedSearches);
}
return savedSearches;
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class AdvancedSearchDialog method getContentTypes.
/**
* @return Returns a list of content object types to allow the user to select from
*/
public List<SelectItem> getContentTypes() {
if ((properties.getContentTypes() == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
FacesContext context = FacesContext.getCurrentInstance();
DictionaryService dictionaryService = Repository.getServiceRegistry(context).getDictionaryService();
// add the well known cm:content object type by default
properties.setContentTypes(new ArrayList<SelectItem>(5));
properties.getContentTypes().add(new SelectItem(ContentModel.TYPE_CONTENT.toString(), dictionaryService.getType(ContentModel.TYPE_CONTENT).getTitle(dictionaryService)));
// add any configured content sub-types to the list
List<String> types = getSearchConfig().getContentTypes();
if (types != null) {
for (String type : types) {
QName idQName = Repository.resolveToQName(type);
if (idQName != null) {
TypeDefinition typeDef = dictionaryService.getType(idQName);
if (typeDef != null && dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_CONTENT)) {
// try and get label from the dictionary
String label = typeDef.getTitle(dictionaryService);
// else just use the localname
if (label == null) {
label = idQName.getLocalName();
}
properties.getContentTypes().add(new SelectItem(idQName.toString(), label));
}
}
}
}
}
return properties.getContentTypes();
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class EditSearchDialog method saveEditSearchOK.
public String saveEditSearchOK(FacesContext newContext, String newOutcome) {
String outcome = newOutcome;
final SearchContext search = this.navigator.getSearchContext();
if (search != null) {
try {
final FacesContext context = newContext;
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// handle Edit e.g. Overwrite of existing search
// detect if was previously selected saved search (e.g.
// NodeRef not null)
NodeRef searchRef = new NodeRef(Repository.getStoreRef(), properties.getSavedSearch());
if (getNodeService().exists(searchRef)) {
Map<QName, Serializable> props = getNodeService().getProperties(searchRef);
props.put(ContentModel.PROP_NAME, properties.getSearchName());
props.put(ContentModel.PROP_DESCRIPTION, properties.getSearchDescription());
getNodeService().setProperties(searchRef, props);
ContentService contentService = Repository.getServiceRegistry(context).getContentService();
ContentWriter writer = contentService.getWriter(searchRef, ContentModel.PROP_CONTENT, true);
// get a writer to our new node ready for XML
// content
writer.setMimetype(MimetypeMap.MIMETYPE_XML);
writer.setEncoding("UTF-8");
// output an XML serialized version of the
// SearchContext object
writer.putContent(search.toXML());
}
return null;
}
};
callback.execute();
properties.getCachedSavedSearches().clear();
properties.setSavedSearch(null);
} catch (Throwable e) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(newContext, MSG_ERROR_SAVE_SEARCH), e.getMessage()), e);
outcome = null;
this.isFinished = false;
ReportedException.throwIfNecessary(e);
}
}
return outcome;
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class SearchContext method getPathFromSpaceRef.
/**
* Generate a search XPATH pointing to the specified node, optionally return an XPATH
* that includes the child nodes.
*
* @param ref Of the node to generate path too
* @param children Whether to include children of the node
*
* @return the path
*/
public static String getPathFromSpaceRef(NodeRef ref, boolean children) {
FacesContext context = FacesContext.getCurrentInstance();
Path path = Repository.getServiceRegistry(context).getNodeService().getPath(ref);
NamespaceService ns = Repository.getServiceRegistry(context).getNamespaceService();
StringBuilder buf = new StringBuilder(64);
for (int i = 0; i < path.size(); i++) {
String elementString = "";
Path.Element element = path.get(i);
if (element instanceof Path.ChildAssocElement) {
ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef();
if (elementRef.getParentRef() != null) {
Collection<String> prefixes = ns.getPrefixes(elementRef.getQName().getNamespaceURI());
if (prefixes.size() > 0) {
elementString = '/' + (String) prefixes.iterator().next() + ':' + ISO9075.encode(elementRef.getQName().getLocalName());
}
}
}
buf.append(elementString);
}
if (children == true) {
// append syntax to get all children of the path
buf.append("//*");
} else {
// append syntax to just represent the path, not the children
buf.append("/*");
}
return buf.toString();
}
Aggregations