use of org.alfresco.service.cmr.repository.ContentReader in project acs-community-packaging by Alfresco.
the class DownloadRawContentServlet method processRequest.
/**
* Processes the request using the current context i.e. no
* authentication checks are made, it is presumed they have already
* been done.
*
* @param req The HTTP request
* @param res The HTTP response
*/
private void processRequest(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
String uri = req.getRequestURI();
String contentUrl = req.getParameter(ARG_CONTENT_URL);
if (contentUrl == null || contentUrl.length() == 0) {
throw new IllegalArgumentException("Download URL did not contain parameter '" + ARG_CONTENT_URL + "':" + uri);
}
String infoOnlyStr = req.getParameter(ARG_INFO_ONLY);
boolean infoOnly = (infoOnlyStr == null) ? false : Boolean.parseBoolean(infoOnlyStr);
ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
ContentService contentService = serviceRegistry.getContentService();
// Attempt to get the reader
ContentReader reader = null;
try {
reader = contentService.getRawReader(contentUrl);
// If the content doesn't exist, generate an error
if (!reader.exists()) {
if (logger.isDebugEnabled()) {
logger.debug("Returning 204 Not Found error...");
}
res.sendError(HttpServletResponse.SC_NO_CONTENT);
return;
}
} catch (AccessDeniedException e) {
if (logger.isDebugEnabled()) {
logger.debug("Returning 403 Forbidden error after exception: ", e);
}
res.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
long readerSize = reader.getSize();
Date readerLastModified = new Date(reader.getLastModified());
String readerMimetype = reader.getMimetype();
String readerEncoding = reader.getEncoding();
Locale readerLocale = reader.getLocale();
// Set the content info
res.setHeader("alfresco.dr.size", DefaultTypeConverter.INSTANCE.convert(String.class, readerSize));
res.setHeader("alfresco.dr.lastModified", DefaultTypeConverter.INSTANCE.convert(String.class, readerLastModified));
res.setHeader("alfresco.dr.mimetype", readerMimetype);
res.setHeader("alfresco.dr.encoding", readerEncoding);
res.setHeader("alfresco.dr.locale", DefaultTypeConverter.INSTANCE.convert(String.class, readerLocale));
// Pass the stream to the response, unless only the content info was requested
if (infoOnly) {
// Fill response details
res.setContentType(DEFAULT_MIMETYPE);
res.setCharacterEncoding(DEFAULT_ENCODING);
} else {
// Fill response details
res.setContentType(readerMimetype);
res.setCharacterEncoding(readerEncoding);
try {
OutputStream clientOs = res.getOutputStream();
// Streams closed for us
reader.getContent(clientOs);
} catch (SocketException e1) {
// Not a problem
if (logger.isDebugEnabled()) {
logger.debug("Client aborted stream read:\n" + " Content URL: " + contentUrl);
}
} catch (ContentIOException e2) {
// Not a problem
if (logger.isDebugEnabled()) {
logger.debug("Client aborted stream read:\n" + " Content URL: " + contentUrl);
}
}
}
}
use of org.alfresco.service.cmr.repository.ContentReader in project acs-community-packaging by Alfresco.
the class AdvancedSearchDialog method selectSearch.
/**
* Action handler called when a saved search is selected by the user
*/
public void selectSearch(ActionEvent event) {
if (NO_SELECTION.equals(properties.getSavedSearch()) == false) {
// read an XML serialized version of the SearchContext object
NodeRef searchSearchRef = new NodeRef(Repository.getStoreRef(), properties.getSavedSearch());
ServiceRegistry services = Repository.getServiceRegistry(FacesContext.getCurrentInstance());
ContentService cs = services.getContentService();
try {
if (services.getNodeService().exists(searchSearchRef)) {
ContentReader reader = cs.getReader(searchSearchRef, ContentModel.PROP_CONTENT);
SearchContext search = new SearchContext().fromXML(reader.getContentString());
// if we get here we read the serialized object successfully
// now setup the UI to match the new SearchContext object
initialiseFromContext(search);
}
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_RESTORE_SEARCH), err.getMessage()), err);
}
}
}
use of org.alfresco.service.cmr.repository.ContentReader in project acs-community-packaging by Alfresco.
the class UsersBeanProperties method getPersonDescription.
public String getPersonDescription() {
ContentService cs = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getContentService();
ContentReader reader = cs.getReader(this.person.getNodeRef(), ContentModel.PROP_PERSONDESC);
if (reader != null && reader.exists()) {
return Utils.stripUnsafeHTMLTags(reader.getContentString()).replace("\r\n", "<p>");
} else {
return null;
}
}
use of org.alfresco.service.cmr.repository.ContentReader 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.ContentReader 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