/** * Populates a file with the content in the reader. */ public void saveContentInFile(String sourceMimetype, ContentReader reader, File file) throws ContentIOException { String encoding = reader.getEncoding(); if (encodeAsUtf8(sourceMimetype, encoding)) { saveContentInUtf8File(reader, file); } else { reader.getContent(file); } }
public Reader getReader(String encoding) throws IOException { inputStream = conn.getContentInputStream(); return new InputStreamReader(inputStream, conn.getEncoding()); }
public String getContent() { ContentService contentService = services.getContentService(); ContentReader reader = contentService.getReader(nodeRef, property); return (reader != null && reader.exists()) ? reader.getContentString() : ""; }
public InputStream getInputStream() { ContentService contentService = services.getContentService(); ContentReader reader = contentService.getReader(nodeRef, property); return (reader != null && reader.exists()) ? reader.getContentInputStream() : null; }
@Test public void testMimetypAndEncodingAndLocale() throws Exception { ContentWriter writer = getWriter(); // set mimetype and encoding writer.setMimetype("text/plain"); writer.setEncoding("UTF-16"); writer.setLocale(Locale.CHINESE); // create a UTF-16 string String content = "A little bit o' this and a little bit o' that"; byte[] bytesUtf16 = content.getBytes("UTF-16"); // write the bytes directly to the writer OutputStream os = writer.getContentOutputStream(); os.write(bytesUtf16); os.close(); // now get a reader from the writer ContentReader reader = writer.getReader(); assertEquals("Writer -> Reader content URL mismatch", writer.getContentUrl(), reader.getContentUrl()); assertEquals("Writer -> Reader mimetype mismatch", writer.getMimetype(), reader.getMimetype()); assertEquals("Writer -> Reader encoding mismatch", writer.getEncoding(), reader.getEncoding()); assertEquals("Writer -> Reader locale mismatch", writer.getLocale(), reader.getLocale()); // now get the string directly from the reader String contentCheck = reader.getContentString(); // internally it should have taken care of the encoding assertEquals("Encoding and decoding of strings failed", content, contentCheck); }
assertTrue(readerFromStore.exists()); assertEquals(content, readerFromStore.getContentString()); assertTrue(readerFromWriter.exists()); assertEquals(writer.getContentData(), readerFromWriter.getContentData()); assertEquals(content, readerFromWriter.getContentString()); ContentReader readerFromReader = readerFromWriter.getReader(); assertNotNull(readerFromReader); assertTrue(readerFromReader.exists()); assertEquals(writer.getContentData(), readerFromReader.getContentData()); assertEquals(content, readerFromReader.getContentString()); assertEquals("Reader content length is incorrect", length, readerFromWriter.getSize()); long modifiedTimeCheck = readerFromWriter.getLastModified();
@Override public Void execute() throws Throwable { // Now validate that the target node exists and has similar properties to the source NodeRef destNodeRef = testNodeFactory.getMappedNodeRef(testContext.contentNodeRef); ContentReader reader = contentService.getReader(destNodeRef, ContentModel.PROP_CONTENT); assertNotNull("content reader is null", reader); assertTrue("content encoding is wrong", reader.getEncoding().equalsIgnoreCase(CONTENT_ENCODING)); assertEquals("content locale is wrong", reader.getLocale(), CONTENT_LOCALE); assertTrue("content does not exist", reader.exists()); String contentStr = reader.getContentString(); assertEquals("Content is wrong", contentStr, testContext.contentString); return null; } };
" Retrieved reader for URL " + contentUrl); boolean exists = reader.exists(); if (!exists) ContentData contentData = reader.getContentData(); System.out.println( " Retrieved content data: " + contentData); ByteBuffer buffer = ByteBuffer.allocate((int)reader.getSize()); FileChannel channel = reader.getFileChannel(); try if (count != reader.getSize()) System.err.println("The number of bytes read was " + count + " but expected " + reader.getSize()); return;
public void testDITAFileWithoutDoctype() throws Exception { // Munge the file to skip the doctype ContentReader reader = getReader(FILE_DITA_FILE); assertTrue(reader.exists()); String contents = reader.getContentString(); String noDocType = contents.replaceAll("<!DOCTYPE.*?>", ""); File tmp = File.createTempFile("alfresco", ".xml"); tmp.deleteOnExit(); ContentWriter w = new FileContentWriter(tmp); w.setEncoding(reader.getEncoding()); w.setMimetype(reader.getMimetype()); w.putContent(noDocType); // Now test extraction doTestDITAFile(w.getReader()); } private void doTestDITAFile(ContentReader reader) throws Exception
public boolean isDefinitionDeployed(NodeRef workflowDefinition) { if (!nodeService.getType(workflowDefinition).equals(WorkflowModel.TYPE_WORKFLOW_DEF)) { throw new WorkflowException( "Node " + workflowDefinition + " is not of type 'bpm:workflowDefinition'"); } String engineId = (String) nodeService.getProperty(workflowDefinition, WorkflowModel.PROP_WORKFLOW_DEF_ENGINE_ID); ContentReader contentReader = contentService.getReader(workflowDefinition, ContentModel.PROP_CONTENT); return isDefinitionDeployed(engineId, contentReader.getContentInputStream(), contentReader.getMimetype()); }
@Test public void canUseCachingContentStore() { // Write through the caching content store - cache during the process. ContentWriter writer = store.getWriter(ContentContext.NULL_CONTEXT); final String content = makeContent(); writer.putContent(content); ContentReader reader = store.getReader(writer.getContentUrl()); assertEquals("Reader and writer should have same URLs", writer.getContentUrl(), reader.getContentUrl()); assertEquals("Reader should get correct content", content, reader.getContentString()); }
/** * Performs checks and copies required reader attributes */ public final ContentReader getReader() throws ContentIOException { ContentReader reader = createReader(); if (reader == null) { throw new AlfrescoRuntimeException("ContentReader failed to create new reader: \n" + " reader: " + this); } else if (reader.getContentUrl() == null || !reader.getContentUrl().equals(getContentUrl())) { throw new AlfrescoRuntimeException("ContentReader has different URL: \n" + " reader: " + this + "\n" + " new reader: " + reader); } // copy across common attributes reader.setMimetype(this.getMimetype()); reader.setEncoding(this.getEncoding()); reader.setLocale(this.getLocale()); // done if (logger.isDebugEnabled()) { logger.debug("Reader spawned new reader: \n" + " reader: " + this + "\n" + " new reader: " + reader); } return reader; }
if (!parameters.isCrawlContent() || reader == null || reader.exists() == false) InputStream inputStream = reader.getContentInputStream(); try exporter.content(nodeRef, property, inputStream, reader.getContentData(), index);
@Override public InputStream getContentInputStream() throws ContentIOException { InputStream result = delegatee.getContentInputStream(); if (null == releaseableResource) { releaseableResource = result; } return result; }
@Override public void getContent(File file) throws ContentIOException { delegatee.getContent(file); }
String sourceMimetype = reader.getMimetype(); if (sourceMimetype == null) long sourceSize = reader.getSize(); try transformerDebug.pushAvailable(reader.getContentUrl(), sourceMimetype, targetMimetype, options); List<ContentTransformer> transformers = getActiveTransformers(sourceMimetype, sourceSize, targetMimetype, options); transformerDebug.availableTransformers(transformers, sourceSize, options, "ContentService.isTransformable(...)");
@Override public String getContentString(int length) throws ContentIOException { return delegatee.getContentString(length); }
@Override public boolean put(String contentUrl, ContentReader source) { File tempFile = createCacheFile(); // Copy the content from the source into a cache file if (source.getSize() > 0L) { source.getContent(tempFile); File cacheFile = renameTempToActive(tempFile); // Add a record of the cached file to the in-memory cache. recordCacheEntries(contentUrl, cacheFile); return true; } return false; }
public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable { String sourceMimetype = reader.getMimetype(); if (logger.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("Extracting metadata content from ") .append(sourceMimetype); logger.debug(msg.toString()); } // create temporary files to convert from and to File tempFile = TempFileProvider.createTempFile(this.getClass() .getSimpleName() + "-", "." + mimetypeService.getExtension(sourceMimetype)); // download the content from the source reader reader.getContent(tempFile); ResultsCallback callback = new ResultsCallback(); jodc.getOfficeManager().execute(new ExtractMetadataOfficeTask(tempFile, callback)); return callback.getResults(); }
/** * Check that a valid writer into the content store can be retrieved and used. */ public void testSimpleNonTempWriter() throws Exception { ContentWriter writer = contentService.getWriter(null, null, false); assertNotNull("Writer should not be null", writer); assertNotNull("Content URL should not be null", writer.getContentUrl()); // write some content writer.putContent(SOME_CONTENT); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-16"); writer.setLocale(Locale.CHINESE); // set the content property manually nodeService.setProperty(contentNodeRef, ContentModel.PROP_CONTENT, writer.getContentData()); // get the reader ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT); assertNotNull("Reader should not be null", reader); assertNotNull("Content URL should not be null", reader.getContentUrl()); assertEquals("Content Encoding was not set", "UTF-16", reader.getEncoding()); assertEquals("Content Locale was not set", Locale.CHINESE, reader.getLocale()); }