本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentWriter.setLocale方法的典型用法代码示例。如果您正苦于以下问题:Java ContentWriter.setLocale方法的具体用法?Java ContentWriter.setLocale怎么用?Java ContentWriter.setLocale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.service.cmr.repository.ContentWriter
的用法示例。
在下文中一共展示了ContentWriter.setLocale方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSimpleNonTempWriter
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* 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());
}
示例2: writeContent
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* @param nodeToUpdate NodeRef
* @param contentProps Map<QName, Serializable>
* @return true if any content property has been updated for the needToUpdate node
*/
private boolean writeContent(NodeRef nodeToUpdate, Map<QName, Serializable> contentProps)
{
boolean contentUpdated = false;
File stagingDir = getStagingFolder();
for (Map.Entry<QName, Serializable> contentEntry : contentProps.entrySet())
{
ContentData contentData = (ContentData) contentEntry.getValue();
String contentUrl = contentData.getContentUrl();
if(contentUrl == null || contentUrl.isEmpty())
{
log.debug("content data is null or empty:" + nodeToUpdate);
ContentData cd = new ContentData(null, null, 0, null);
nodeService.setProperty(nodeToUpdate, contentEntry.getKey(), cd);
contentUpdated = true;
}
else
{
String fileName = TransferCommons.URLToPartName(contentUrl);
File stagedFile = new File(stagingDir, fileName);
if (!stagedFile.exists())
{
error(MSG_REFERENCED_CONTENT_FILE_MISSING);
}
ContentWriter writer = contentService.getWriter(nodeToUpdate, contentEntry.getKey(), true);
writer.setEncoding(contentData.getEncoding());
writer.setMimetype(contentData.getMimetype());
writer.setLocale(contentData.getLocale());
writer.putContent(stagedFile);
contentUpdated = true;
}
}
return contentUpdated;
}
示例3: writeDestinationReport
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
public NodeRef writeDestinationReport(String transferName,
TransferTarget target,
File tempFile)
{
String title = transferName + "_destination";
String description = "Transfer Destination Report - target: " + target.getName();
String name = title + ".xml";
logger.debug("writing destination transfer report " + title);
logger.debug("parent node ref " + target.getNodeRef());
Map<QName, Serializable> properties = new HashMap<QName, Serializable> ();
properties.put(ContentModel.PROP_NAME, name);
properties.put(ContentModel.PROP_TITLE, title);
properties.put(ContentModel.PROP_DESCRIPTION, description);
ChildAssociationRef ref = nodeService.createNode(target.getNodeRef(),
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
TransferModel.TYPE_TRANSFER_REPORT_DEST,
properties);
ContentWriter writer = contentService.getWriter(ref.getChildRef(),
ContentModel.PROP_CONTENT, true);
writer.setLocale(Locale.getDefault());
writer.setMimetype(MimetypeMap.MIMETYPE_XML);
writer.setEncoding(DEFAULT_ENCODING);
writer.putContent(tempFile);
logger.debug("written " + name + ", " + ref.getChildRef());
return ref.getChildRef();
}
示例4: testMimetypAndEncodingAndLocale
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@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);
}
示例5: testWriteToNodeWithoutAnyContentProperties
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
public void testWriteToNodeWithoutAnyContentProperties() throws Exception
{
// previously, the node was populated with the mimetype, etc
// check that the write has these
ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, writer.getMimetype());
assertEquals("UTF-16", writer.getEncoding());
assertEquals(Locale.CHINESE, writer.getLocale());
// now remove the content property from the node
nodeService.setProperty(contentNodeRef, ContentModel.PROP_CONTENT, null);
writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
assertNull(writer.getMimetype());
assertEquals("UTF-8", writer.getEncoding());
assertEquals(Locale.getDefault(), writer.getLocale());
// now set it on the writer
writer.setMimetype("text/plain");
writer.setEncoding("UTF-16");
writer.setLocale(Locale.FRENCH);
String content = "The quick brown fox ...";
writer.putContent(content);
// the properties should have found their way onto the node
ContentData contentData = (ContentData) nodeService.getProperty(contentNodeRef, ContentModel.PROP_CONTENT);
assertEquals("metadata didn't get onto node", writer.getContentData(), contentData);
// check that the reader's metadata is set
ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT);
assertEquals("Metadata didn't get set on reader", writer.getContentData(), reader.getContentData());
}
示例6: createTransferReport
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* Write exception transfer report
*
* @return NodeRef the node ref of the new transfer report
*/
public NodeRef createTransferReport(String transferName,
Exception e,
TransferTarget target,
TransferDefinition definition,
List<TransferEvent> events,
File snapshotFile)
{
Map<QName, Serializable> properties = new HashMap<QName, Serializable> ();
String title = transferName;
String description = "Transfer Report - target: " + target.getName();
String name = transferName + ".xml";
properties.put(ContentModel.PROP_NAME, name);
properties.put(ContentModel.PROP_TITLE, title);
properties.put(ContentModel.PROP_DESCRIPTION, description);
ChildAssociationRef ref = nodeService.createNode(target.getNodeRef(), ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name), TransferModel.TYPE_TRANSFER_REPORT, properties);
ContentWriter writer = contentService.getWriter(ref.getChildRef(), ContentModel.PROP_CONTENT, true);
writer.setLocale(Locale.getDefault());
writer.setMimetype(MimetypeMap.MIMETYPE_XML);
writer.setEncoding(DEFAULT_ENCODING);
XMLTransferReportWriter reportWriter = new XMLTransferReportWriter();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(writer.getContentOutputStream()));
try
{
reportWriter.startTransferReport(DEFAULT_ENCODING, bufferedWriter);
reportWriter.writeTarget(target);
reportWriter.writeDefinition(definition);
reportWriter.writeException(e);
reportWriter.writeTransferEvents(events);
reportWriter.endTransferReport();
return ref.getChildRef();
}
catch (SAXException se)
{
return null;
}
finally
{
try
{
bufferedWriter.close();
}
catch (IOException error)
{
error.printStackTrace();
}
}
}
示例7: testGetReader
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* Checks that the various methods of obtaining a reader are supported.
*/
@Test
public synchronized void testGetReader() throws Exception
{
ContentStore store = getStore();
ContentWriter writer = store.getWriter(ContentStore.NEW_CONTENT_CONTEXT);
String contentUrl = writer.getContentUrl();
// Check that a reader is available from the store
ContentReader readerFromStoreBeforeWrite = store.getReader(contentUrl);
assertNotNull("A reader must always be available from the store", readerFromStoreBeforeWrite);
// check that a reader is available from the writer
ContentReader readerFromWriterBeforeWrite = writer.getReader();
assertNotNull("A reader must always be available from the writer", readerFromWriterBeforeWrite);
String content = "Content for testGetReader";
// write some content
long before = System.currentTimeMillis();
this.wait(1000L);
writer.setMimetype("text/plain");
writer.setEncoding("UTF-8");
writer.setLocale(Locale.CHINESE);
writer.putContent(content);
this.wait(1000L);
long after = System.currentTimeMillis();
// get a reader from the store
ContentReader readerFromStore = store.getReader(contentUrl);
assertNotNull(readerFromStore);
assertTrue(readerFromStore.exists());
// Store-provided readers don't have context other than URLs
// assertEquals(writer.getContentData(), readerFromStore.getContentData());
assertEquals(content, readerFromStore.getContentString());
// get a reader from the writer
ContentReader readerFromWriter = writer.getReader();
assertNotNull(readerFromWriter);
assertTrue(readerFromWriter.exists());
assertEquals(writer.getContentData(), readerFromWriter.getContentData());
assertEquals(content, readerFromWriter.getContentString());
// get another reader from the reader
ContentReader readerFromReader = readerFromWriter.getReader();
assertNotNull(readerFromReader);
assertTrue(readerFromReader.exists());
assertEquals(writer.getContentData(), readerFromReader.getContentData());
assertEquals(content, readerFromReader.getContentString());
// check that the length is correct
int length = content.getBytes(writer.getEncoding()).length;
assertEquals("Reader content length is incorrect", length, readerFromWriter.getSize());
// check that the last modified time is correct
long modifiedTimeCheck = readerFromWriter.getLastModified();
// On some versionms of Linux (e.g. Centos) this test won't work as the
// modified time accuracy is only to the second.
long beforeSeconds = before/1000L;
long afterSeconds = after/1000L;
long modifiedTimeCheckSeconds = modifiedTimeCheck/1000L;
assertTrue("Reader last modified is incorrect", beforeSeconds <= modifiedTimeCheckSeconds);
assertTrue("Reader last modified is incorrect", modifiedTimeCheckSeconds <= afterSeconds);
}