本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentReader.exists方法的典型用法代码示例。如果您正苦于以下问题:Java ContentReader.exists方法的具体用法?Java ContentReader.exists怎么用?Java ContentReader.exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.service.cmr.repository.ContentReader
的用法示例。
在下文中一共展示了ContentReader.exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getReader
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public Reader getReader()
{
ContentService contentService = services.getContentService();
ContentReader reader = contentService.getReader(nodeRef, property);
if (reader != null && reader.exists())
{
try
{
return (contentData.getEncoding() == null) ? new InputStreamReader(reader.getContentInputStream()) : new InputStreamReader(reader.getContentInputStream(), contentData.getEncoding());
}
catch (IOException e)
{
// NOTE: fall-through
}
}
return null;
}
示例2: getRelativeResource
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
@Override
protected InputStream getRelativeResource(String name)
{
InputStream stream = null;
NodeRef parentRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
NodeRef child = nodeService.getChildByName(parentRef, ContentModel.ASSOC_CONTAINS, name);
if (child != null)
{
ContentReader contentReader = contentService.getReader(child, ContentModel.PROP_CONTENT);
if (contentReader.exists())
{
stream = contentReader.getContentInputStream();
}
}
return stream;
}
示例3: sourceNodeIsXml
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
protected boolean sourceNodeIsXml(NodeRef sourceNode)
{
boolean result = false;
// TODO: BJR 20100211: We can do better than this...
ContentReader reader = serviceRegistry.getContentService().getReader(sourceNode, ContentModel.PROP_CONTENT);
if ((reader != null) && reader.exists())
{
result = (reader.getContentData().getMimetype().equals("text/xml"));
}
return result;
}
示例4: makeContentReader
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public ContentReader makeContentReader()
{
QName srcContentProp = getParamWithDefault(PARAM_SOURCE_CONTENT_PROPERTY, DEFAULT_CONTENT_PROPERTY);
ContentReader contentReader = contentService.getReader(sourceNode, srcContentProp);
if (contentReader == null || !contentReader.exists())
{
throw new UnimportantTransformException(CONTENT_READER_NOT_FOUND_MESSAGE);
}
return contentReader;
}
示例5: getReader
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Forwards the call directly to the first store in the list of stores.
*/
public ContentReader getReader(String contentUrl) throws ContentIOException
{
if (primaryStore == null)
{
throw new AlfrescoRuntimeException("ReplicatingContentStore not initialised");
}
// get a read lock so that we are sure that no replication is underway
readLock.lock();
try
{
// get a reader from the primary store
ContentReader primaryReader = primaryStore.getReader(contentUrl);
// give it straight back if the content is there
if (primaryReader.exists())
{
return primaryReader;
}
// the content is not in the primary reader so we have to go looking for it
for (ContentStore store : secondaryStores)
{
ContentReader reader = store.getReader(contentUrl);
if (reader.exists())
{
// found the content in a secondary store
return reader;
}
}
return primaryReader;
}
finally
{
readLock.unlock();
}
}
示例6: getSafeContentReader
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Checks the existing reader provided and replaces it with a reader onto some
* fake content if required. If the existing reader is invalid, an debug message
* will be logged under this classname category.
* <p>
* It is a convenience method that clients can use to cheaply get a reader that
* is valid, regardless of whether the initial reader is valid.
*
* @param existingReader a potentially invalid reader or null
* @param msgTemplate the template message that will used to format the final <i>fake</i> content
* @param args arguments to put into the <i>fake</i> content
* @return Returns a the existing reader or a new reader onto some generated text content
*/
public static ContentReader getSafeContentReader(ContentReader existingReader, String msgTemplate, Object ... args)
{
ContentReader reader = existingReader;
if (existingReader == null || !existingReader.exists())
{
// the content was never written to the node or the underlying content is missing
String fakeContent = MessageFormat.format(msgTemplate, args);
// log it
if (logger.isDebugEnabled())
{
logger.debug(fakeContent);
}
// fake the content
File tempFile = TempFileProvider.createTempFile("getSafeContentReader_", ".txt");
ContentWriter writer = new FileContentWriter(tempFile);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(fakeContent);
// grab the reader from the temp writer
reader = writer.getReader();
}
// done
if (logger.isDebugEnabled())
{
logger.debug("Created safe content reader: \n" +
" existing reader: " + existingReader + "\n" +
" safe reader: " + reader);
}
return reader;
}
示例7: beforeDelete
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public void beforeDelete(ContentStore sourceStore, String contentUrl) throws ContentIOException
{
// First check if the content is present at all
ContentReader reader = sourceStore.getReader(contentUrl);
if (reader != null && reader.exists())
{
// Call to implementation's shred
if (logger.isDebugEnabled())
{
logger.debug(
"About to shread: \n" +
" URL: " + contentUrl + "\n" +
" Source: " + sourceStore);
}
try
{
shred(reader);
}
catch (Throwable e)
{
logger.error(
"Content shredding failed: \n" +
" URL: " + contentUrl + "\n" +
" Source: " + sourceStore + "\n" +
" Reader: " + reader,
e);
}
}
else
{
logger.error(
"Content no longer exists. Unable to shred: \n" +
" URL: " + contentUrl + "\n" +
" Source: " + sourceStore);
}
}
示例8: beforeDelete
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public void beforeDelete(ContentStore sourceStore, String contentUrl) throws ContentIOException
{
if (store.isContentUrlSupported(contentUrl))
{
ContentContext context = new ContentContext(null, contentUrl);
ContentReader reader = sourceStore.getReader(contentUrl);
if (!reader.exists())
{
// Nothing to copy over
return;
}
// write the content into the target store
ContentWriter writer = store.getWriter(context);
// copy across
writer.putContent(reader);
// done
if (logger.isDebugEnabled())
{
logger.debug(
"Moved content before deletion: \n" +
" URL: " + contentUrl + "\n" +
" Source: " + sourceStore + "\n" +
" Target: " + store);
}
}
else
{
if (logger.isDebugEnabled())
{
logger.debug(
"Content cannot be moved during deletion. A backup will not be made: \n" +
" URL: " + contentUrl + "\n" +
" Source: " + sourceStore + "\n" +
" Target: " + store);
}
}
}
示例9: exists
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Simple implementation that uses the
* {@link ContentReader#exists() reader's exists} method as its implementation.
* Override this method if a more efficient implementation is possible.
*/
@Override
public boolean exists(String contentUrl)
{
ContentReader reader = getReader(contentUrl);
return reader.exists();
}
示例10: execute
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* @see org.alfresco.service.cmr.repository.ScriptProcessor#execute(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.util.Map)
*/
public Object execute(NodeRef nodeRef, QName contentProp, Map<String, Object> model)
{
try
{
if (this.services.getNodeService().exists(nodeRef) == false)
{
throw new AlfrescoRuntimeException("Script Node does not exist: " + nodeRef);
}
if (contentProp == null)
{
contentProp = ContentModel.PROP_CONTENT;
}
ContentReader cr = this.services.getContentService().getReader(nodeRef, contentProp);
if (cr == null || cr.exists() == false)
{
throw new AlfrescoRuntimeException("Script Node content not found: " + nodeRef);
}
// compile the script based on the node content
Script script;
Context cx = Context.enter();
try
{
script = cx.compileString(resolveScriptImports(cr.getContentString()), nodeRef.toString(), 1, null);
}
finally
{
Context.exit();
}
return executeScriptImpl(script, model, false, nodeRef.toString());
}
catch (Throwable err)
{
throw new ScriptException("Failed to execute script '" + nodeRef.toString() + "': " + err.getMessage(), err);
}
}
示例11: get
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* @see org.alfresco.repo.template.BaseTemplateMap#get(java.lang.Object)
*/
public Object get(Object key)
{
String search = null;
if (key != null && key.toString().length() != 0)
{
// read the Saved Search XML on the specified node - and get the Lucene search from it
try
{
NodeRef ref = new NodeRef(key.toString());
ContentReader content = services.getContentService().getReader(ref, ContentModel.PROP_CONTENT);
if (content != null && content.exists())
{
// get the root element
SAXReader reader = new SAXReader();
Document document = reader.read(new StringReader(content.getContentString()));
Element rootElement = document.getRootElement();
Element queryElement = rootElement.element(ELEMENT_QUERY);
if (queryElement != null)
{
search = queryElement.getText();
}
}
}
catch (Throwable err)
{
throw new AlfrescoRuntimeException("Failed to find or load saved Search: " + key, err);
}
}
// execute the search
return query(search);
}
示例12: getContent
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* @return the content stream
*/
public String getContent()
{
ContentService contentService = services.getContentService();
ContentReader reader = contentService.getReader(getNodeRef(), property);
return (reader != null && reader.exists()) ? reader.getContentString() : "";
}
示例13: getContentMaxLength
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* @return the content stream to the specified maximum length in characters
*/
public String getContentMaxLength(int length)
{
ContentService contentService = services.getContentService();
ContentReader reader = contentService.getReader(getNodeRef(), property);
return (reader != null && reader.exists()) ? reader.getContentString(length) : "";
}
示例14: checkForExistence
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
private void checkForExistence(Set<String> urls, boolean mustExist)
{
for (String url : urls)
{
ContentReader rawReader = contentService.getRawReader(url);
if (mustExist && !rawReader.exists())
{
fail("Content URL should have existed but did not: " + url);
}
else if (!mustExist && rawReader.exists())
{
fail("Content URL should not have existed but did: " + url);
}
}
}
示例15: streamContent
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Streams the content on a given node's content property to the response of the web script.
*
* @param req Request
* @param res Response
* @param nodeRef The node reference
* @param propertyQName The content property name
* @param attach Indicates whether the content should be streamed as an attachment or not
* @param attachFileName Optional file name to use when attach is <code>true</code>
* @throws IOException
*/
public void streamContent(WebScriptRequest req,
WebScriptResponse res,
NodeRef nodeRef,
QName propertyQName,
boolean attach,
String attachFileName,
Map<String, Object> model) throws IOException
{
if (logger.isDebugEnabled())
logger.debug("Retrieving content from node ref " + nodeRef.toString() + " (property: " + propertyQName.toString() + ") (attach: " + attach + ")");
// TODO
// This was commented out to accomadate records management permissions. We need to review how we cope with this
// hard coded permission checked.
// check that the user has at least READ_CONTENT access - else redirect to the login page
// if (permissionService.hasPermission(nodeRef, PermissionService.READ_CONTENT) == AccessStatus.DENIED)
// {
// throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Permission denied");
// }
// check If-Modified-Since header and set Last-Modified header as appropriate
Date modified = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
if (modified != null)
{
long modifiedSince = -1;
String modifiedSinceStr = req.getHeader("If-Modified-Since");
if (modifiedSinceStr != null)
{
try
{
modifiedSince = dateFormat.parse(modifiedSinceStr).getTime();
}
catch (Throwable e)
{
if (logger.isInfoEnabled())
logger.info("Browser sent badly-formatted If-Modified-Since header: " + modifiedSinceStr);
}
if (modifiedSince > 0L)
{
// round the date to the ignore millisecond value which is not supplied by header
long modDate = (modified.getTime() / 1000L) * 1000L;
if (modDate <= modifiedSince)
{
res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
}
}
}
// get the content reader
ContentReader reader = contentService.getReader(nodeRef, propertyQName);
if (reader == null || !reader.exists())
{
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to locate content for node ref " + nodeRef + " (property: " + propertyQName.toString() + ")");
}
// Stream the content
streamContentImpl(req, res, reader, nodeRef, propertyQName, attach, modified, modified == null ? null : Long.toString(modified.getTime()), attachFileName, model);
}