use of org.alfresco.service.cmr.repository.ContentWriter in project acs-community-packaging by Alfresco.
the class SaveSearchDialog method saveNewSearchOK.
public String saveNewSearchOK(FacesContext newContext, String newOutcome) {
String outcome = newOutcome;
NodeRef searchesRef;
if (properties.isSearchSaveGlobal()) {
searchesRef = getGlobalSearchesRef();
} else {
searchesRef = getUserSearchesRef();
}
final SearchContext search = this.navigator.getSearchContext();
if (searchesRef != null && search != null) {
try {
// FacesContext.getCurrentInstance();
final FacesContext context = newContext;
final NodeRef searchesRefFinal = searchesRef;
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// create new content node as the saved search object
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
props.put(ContentModel.PROP_NAME, properties.getSearchName());
props.put(ContentModel.PROP_DESCRIPTION, properties.getSearchDescription());
ChildAssociationRef childRef = getNodeService().createNode(searchesRefFinal, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.ALFRESCO_URI, QName.createValidLocalName(properties.getSearchName())), ContentModel.TYPE_CONTENT, props);
ContentService contentService = Repository.getServiceRegistry(context).getContentService();
ContentWriter writer = contentService.getWriter(childRef.getChildRef(), 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 org.alfresco.service.cmr.repository.ContentWriter in project acs-community-packaging by Alfresco.
the class EditContentWizard method saveContent.
@Override
protected void saveContent(File fileContent, String strContent) throws Exception {
ContentWriter writer = getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(strContent);
}
use of org.alfresco.service.cmr.repository.ContentWriter in project acs-community-packaging by Alfresco.
the class CreateTopicDialog method finishImpl.
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
super.finishImpl(context, outcome);
// do topic specific processing
// get the node ref of the node that will contain the content
NodeRef containerNodeRef = this.createdNode;
// create a unique file name for the message content
String fileName = ForumsBean.createPostFileName();
FileInfo fileInfo = this.getFileFolderService().create(containerNodeRef, fileName, ForumModel.TYPE_POST);
NodeRef postNodeRef = fileInfo.getNodeRef();
if (logger.isDebugEnabled())
logger.debug("Created post node with filename: " + fileName);
// apply the titled aspect - title and description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(3, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, fileName);
this.getNodeService().addAspect(postNodeRef, ContentModel.ASPECT_TITLED, titledProps);
if (logger.isDebugEnabled())
logger.debug("Added titled aspect with properties: " + titledProps);
Map<QName, Serializable> editProps = new HashMap<QName, Serializable>(1, 1.0f);
editProps.put(ApplicationModel.PROP_EDITINLINE, true);
this.getNodeService().addAspect(postNodeRef, ApplicationModel.ASPECT_INLINEEDITABLE, editProps);
if (logger.isDebugEnabled())
logger.debug("Added inlineeditable aspect with properties: " + editProps);
// get a writer for the content and put the file
ContentWriter writer = getContentService().getWriter(postNodeRef, ContentModel.PROP_CONTENT, true);
// set the mimetype and encoding
writer.setMimetype(Repository.getMimeTypeForFileName(context, fileName));
writer.setEncoding("UTF-8");
writer.putContent(Utils.replaceLineBreaks(this.message, false));
return outcome;
}
use of org.alfresco.service.cmr.repository.ContentWriter in project SearchServices by Alfresco.
the class SolrContentStoreTest method delete.
@Test
public void delete() throws Exception {
SolrContentStore store = new SolrContentStore(solrHome);
ContentContext ctx = createContentContext("abc");
String url = ctx.getContentUrl();
ContentWriter writer = store.getWriter(ctx);
writer.putContent("Content goes here.");
// Check the reader
ContentReader reader = store.getReader(url);
Assert.assertNotNull(reader);
Assert.assertTrue(reader.exists());
// Delete
store.delete(url);
reader = store.getReader(url);
Assert.assertNotNull(reader);
Assert.assertFalse(reader.exists());
// Delete when already gone; should just not fail
store.delete(url);
}
use of org.alfresco.service.cmr.repository.ContentWriter in project SearchServices by Alfresco.
the class SolrContentStoreTest method contentByStream.
@Test
public void contentByStream() throws Exception {
SolrContentStore store = new SolrContentStore(solrHome);
ContentContext ctx = createContentContext("abc");
ContentWriter writer = store.getWriter(ctx);
byte[] bytes = new byte[] { 1, 7, 13 };
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
writer.putContent(bis);
// Now get the reader
ContentReader reader = store.getReader(ctx.getContentUrl());
ByteArrayOutputStream bos = new ByteArrayOutputStream(3);
reader.getContent(bos);
Assert.assertEquals(bytes[0], bos.toByteArray()[0]);
Assert.assertEquals(bytes[1], bos.toByteArray()[1]);
Assert.assertEquals(bytes[2], bos.toByteArray()[2]);
}
Aggregations