use of org.alfresco.service.cmr.repository.ContentReader in project records-management by Alfresco.
the class CustomEmailMappingServiceImpl method loadConfig.
/**
* Loads the custom mappings from the configuration file.
*
* @return
*/
private Set<CustomMapping> loadConfig() {
Set<CustomMapping> result = new HashSet<CustomMapping>();
ContentReader cr = contentService.getReader(CONFIG_NODE_REF, ContentModel.PROP_CONTENT);
if (cr != null) {
String text = cr.getContentString();
try {
JSONArray jsonArray = new JSONArray(new JSONTokener(text));
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject obj = jsonArray.getJSONObject(i);
CustomMapping mapping = new CustomMapping();
mapping.setFrom(obj.getString("from"));
mapping.setTo(obj.getString("to"));
result.add(mapping);
}
} catch (JSONException je) {
throw new AlfrescoRuntimeException("Unable to read custom email configuration", je);
}
}
return result;
}
use of org.alfresco.service.cmr.repository.ContentReader in project records-management by Alfresco.
the class EagerContentStoreCleaner method cleanseContent.
/**
* Cleanse content
*
* @param contentUrl content url
* @param store content store
*/
private void cleanseContent(String contentUrl, ContentStore store) {
if (contentCleanser == null) {
logger.error("No content cleanser specified. Unable to cleanse: \n" + " URL: " + contentUrl + "\n" + " Source: " + store);
} else {
// First check if the content is present at all
ContentReader reader = store.getReader(contentUrl);
if (reader != null && reader.exists()) {
// Call to implementation's shred
if (logger.isDebugEnabled()) {
logger.debug("About to cleanse: \n" + " URL: " + contentUrl + "\n" + " Source: " + store);
}
try {
if (reader instanceof FileContentReader) {
// get file content
FileContentReader fileReader = (FileContentReader) reader;
File file = fileReader.getFile();
// cleanse content
contentCleanser.cleanse(file);
}
} catch (Exception e) {
logger.error("Content cleansing failed: \n" + " URL: " + contentUrl + "\n" + " Source: " + store + "\n" + " Reader: " + reader, e);
}
} else {
logger.error("Content no longer exists. Unable to cleanse: \n" + " URL: " + contentUrl + "\n" + " Source: " + store);
}
}
}
use of org.alfresco.service.cmr.repository.ContentReader in project records-management by Alfresco.
the class ApplyDodCertModelFixesGet method readCustomContentModel.
private M2Model readCustomContentModel() {
ContentReader reader = this.contentService.getReader(RM_CUSTOM_MODEL_NODE_REF, ContentModel.TYPE_CONTENT);
if (!reader.exists()) {
throw new AlfrescoRuntimeException("RM CustomModel has no content.");
}
InputStream contentIn = null;
M2Model deserializedModel = null;
try {
contentIn = reader.getContentInputStream();
deserializedModel = M2Model.createModel(contentIn);
} finally {
try {
if (contentIn != null) {
contentIn.close();
}
} catch (IOException ignored) {
// Intentionally empty.`
}
}
return deserializedModel;
}
use of org.alfresco.service.cmr.repository.ContentReader in project SearchServices by Alfresco.
the class SolrContentStoreTest method contentByString.
@Test
public void contentByString() {
SolrContentStore store = new SolrContentStore(solrHome);
ContentContext ctx = createContentContext("abc");
ContentWriter writer = store.getWriter(ctx);
File file = new File(store.getRootLocation() + "/" + writer.getContentUrl().replace("solr://", ""));
Assert.assertFalse("File was created before anything was written", file.exists());
String content = "Quick brown fox jumps over the lazy dog.";
writer.putContent(content);
Assert.assertTrue("File was not created.", file.exists());
try {
writer.putContent("Should not work");
} catch (IllegalStateException e) {
// Expected
}
// Now get the reader
ContentReader reader = store.getReader(ctx.getContentUrl());
Assert.assertNotNull(reader);
Assert.assertTrue(reader.exists());
Assert.assertEquals(content, reader.getContentString());
}
use of org.alfresco.service.cmr.repository.ContentReader in project acs-community-packaging by Alfresco.
the class AddContentDialog method finishImpl.
// ------------------------------------------------------------------------------
// Dialog implementation
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
// Try and extract metadata from the file
ContentReader cr = new FileContentReader(this.file);
cr.setMimetype(this.mimeType);
cr.setEncoding(this.encoding);
// create properties for content type
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(5, 1.0f);
if (Repository.extractMetadata(FacesContext.getCurrentInstance(), cr, contentProps)) {
this.author = (String) (contentProps.get(ContentModel.PROP_AUTHOR));
this.title = DefaultTypeConverter.INSTANCE.convert(String.class, contentProps.get(ContentModel.PROP_TITLE));
this.description = DefaultTypeConverter.INSTANCE.convert(String.class, contentProps.get(ContentModel.PROP_DESCRIPTION));
}
// default the title to the file name if not set
if (this.title == null) {
this.title = this.fileName;
}
// determine whether inline editing should be enabled by default.
// if the mime type of the added file is in the list of mime types
// configured in "Content Wizards" then enable inline editing
List<String> mimeTypes = getInlineEditableMimeTypes();
if (mimeTypes.contains(this.mimeType)) {
this.inlineEdit = true;
}
saveContent(this.file, null);
// return default outcome
return outcome;
}
Aggregations