当前位置: 首页>>代码示例>>Java>>正文


Java WebScriptRequest.getHeader方法代码示例

本文整理汇总了Java中org.springframework.extensions.webscripts.WebScriptRequest.getHeader方法的典型用法代码示例。如果您正苦于以下问题:Java WebScriptRequest.getHeader方法的具体用法?Java WebScriptRequest.getHeader怎么用?Java WebScriptRequest.getHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.extensions.webscripts.WebScriptRequest的用法示例。


在下文中一共展示了WebScriptRequest.getHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: streamContentLocal

import org.springframework.extensions.webscripts.WebScriptRequest; //导入方法依赖的package包/类
protected void streamContentLocal(WebScriptRequest req, WebScriptResponse res, NodeRef nodeRef, boolean attach, QName propertyQName, Map<String, Object> model) throws IOException
{
    String userAgent = req.getHeader("User-Agent");
    userAgent = userAgent != null ? userAgent.toLowerCase() : "";
    boolean rfc5987Supported = (userAgent.contains("msie") ||
            userAgent.contains(" trident/") ||
            userAgent.contains(" chrome/") ||
            userAgent.contains(" firefox/") ||
            userAgent.contains(" safari/"));

    if (attach && rfc5987Supported)
    {
        String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
        
        // maintain the original name of the node during the download - do not modify it - see MNT-16510
        streamContent(req, res, nodeRef, propertyQName, attach, name, model);
    }
    else
    {
        streamContent(req, res, nodeRef, propertyQName, attach, null, model);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:23,代码来源:ContentGet.java

示例2: streamContent

import org.springframework.extensions.webscripts.WebScriptRequest; //导入方法依赖的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);
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:74,代码来源:ContentStreamer.java

示例3: setAttachment

import org.springframework.extensions.webscripts.WebScriptRequest; //导入方法依赖的package包/类
/**
 * Set attachment header
 * 
 * @param req WebScriptRequest
 * @param res WebScriptResponse
 * @param attach boolean
 * @param attachFileName String
 */
public void setAttachment(WebScriptRequest req, WebScriptResponse res, boolean attach, String attachFileName)
{
    if (attach == true)
    {
        String headerValue = "attachment";
        if (attachFileName != null && attachFileName.length() > 0)
        {
            if (logger.isDebugEnabled())
                logger.debug("Attaching content using filename: " + attachFileName);

            if (req == null)
            {
                headerValue += "; filename*=UTF-8''" + URLEncoder.encode(attachFileName)
                        + "; filename=\"" + filterNameForQuotedString(attachFileName) + "\"";
            }
            else
            {
                String userAgent = req.getHeader(HEADER_USER_AGENT);
                boolean isLegacy = (null != userAgent) && (userAgent.contains("MSIE 8") || userAgent.contains("MSIE 7"));
                if (isLegacy)
                {
                    headerValue += "; filename=\"" + URLEncoder.encode(attachFileName);
                }
                else
                {
                    headerValue += "; filename=\"" + filterNameForQuotedString(attachFileName) + "\"; filename*=UTF-8''"
                            + URLEncoder.encode(attachFileName);
                }
            }
        }
        
        // set header based on filename - will force a Save As from the browse if it doesn't recognize it
        // this is better than the default response of the browser trying to display the contents
        res.setHeader("Content-Disposition", headerValue);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:45,代码来源:ContentStreamer.java


注:本文中的org.springframework.extensions.webscripts.WebScriptRequest.getHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。