Example usage for org.springframework.web.context.request NativeWebRequest getNativeRequest

List of usage examples for org.springframework.web.context.request NativeWebRequest getNativeRequest

Introduction

In this page you can find the example usage for org.springframework.web.context.request NativeWebRequest getNativeRequest.

Prototype

@Nullable
<T> T getNativeRequest(@Nullable Class<T> requiredType);

Source Link

Document

Return the underlying native request object, if available.

Usage

From source file:architecture.ee.web.community.spring.controller.SocialConnectController.java

/**
 * Returns a RedirectView with the URL to redirect to after a connection is
 * created or deleted. Defaults to "/connect/{providerId}" relative to
 * DispatcherServlet's path. May be overridden to handle custom redirection
 * needs./*from   w  w w .  ja  va  2 s. co m*/
 * 
 * @param providerId
 *            the ID of the provider for which a connection was created or
 *            deleted.
 * @param request
 *            the NativeWebRequest used to access the servlet path when
 *            constructing the redirect path.
 */
protected RedirectView connectionStatusRedirect(String providerId, NativeWebRequest request) {
    HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
    String path = "/connect/" + providerId + getPathExtension(servletRequest);
    if (prependServletPath(servletRequest)) {
        path = servletRequest.getServletPath() + path;
    }
    log.debug(path);
    request.getNativeResponse(HttpServletResponse.class).setContentType("text/html;charset=UTF-8");
    return new RedirectView(path, true);
}

From source file:architecture.ee.web.spring.controller.MyCloudDataController.java

@RequestMapping(value = "/files/list.json", method = { RequestMethod.POST, RequestMethod.GET })
@ResponseBody/*from  w w  w .  j av a  2 s .  c  o m*/
public FileList getFileList(
        @RequestParam(value = "objectType", defaultValue = "2", required = false) Integer objectType,
        @RequestParam(value = "startIndex", defaultValue = "0", required = false) Integer startIndex,
        @RequestParam(value = "pageSize", defaultValue = "0", required = false) Integer pageSize,
        NativeWebRequest request) throws NotFoundException {
    User user = SecurityHelper.getUser();
    return getFileList(objectType, startIndex, pageSize, request.getNativeRequest(HttpServletRequest.class));
}

From source file:architecture.ee.web.spring.controller.MyCloudDataController.java

@Secured({ "ROLE_USER" })
@RequestMapping(value = "/me/photo/images/list.json", method = { RequestMethod.POST, RequestMethod.GET })
@ResponseBody/*w  ww. j ava2  s.  co m*/
public ImageList getMyImageList(
        @RequestParam(value = "startIndex", defaultValue = "0", required = false) Integer startIndex,
        @RequestParam(value = "pageSize", defaultValue = "0", required = false) Integer pageSize,
        NativeWebRequest request) throws NotFoundException {
    User user = SecurityHelper.getUser();
    return getImageList(2, user.getUserId(), startIndex, pageSize,
            request.getNativeRequest(HttpServletRequest.class));

}

From source file:org.fao.geonet.api.records.formatters.FormatterApi.java

/**
 * Run the a formatter against a metadata.
 *
 * @param lang           ui language/* w ww  .j a  v a 2 s.  com*/
 * @param type           output type, Must be one of {@link org.fao.geonet.api.records.formatters.FormatType}
 * @param id             the id, uuid or fileIdentifier of the metadata
 * @param xslid          the id of the formatter
 * @param skipPopularity if true then don't increment popularity
 * @param hide_withheld  if true hideWithheld (private) elements even if the current user would
 *                       normally have access to them.
 * @param width          the approximate size of the element that the formatter output will be
 *                       embedded in compared to the full device width.  Allowed options are the
 *                       enum values: {@link org.fao.geonet.api.records.formatters.FormatterWidth}
 *                       The default is _100 (100% of the screen)
 */
@RequestMapping(value = "/{lang}/md.format.{type}")
@ResponseBody
public void exec(@PathVariable final String lang, @PathVariable final String type,
        @RequestParam(value = "id", required = false) final String id,
        @RequestParam(value = "uuid", required = false) final String uuid,
        @RequestParam(value = "xsl", required = false) final String xslid,
        @RequestParam(defaultValue = "n") final String skipPopularity,
        @RequestParam(value = "hide_withheld", required = false) final Boolean hide_withheld,
        @RequestParam(value = "width", defaultValue = "_100") final FormatterWidth width,
        final NativeWebRequest request) throws Exception {
    final FormatType formatType = FormatType.valueOf(type.toLowerCase());

    String resolvedId = resolveId(id, uuid);
    ServiceContext context = createServiceContext(lang, formatType,
            request.getNativeRequest(HttpServletRequest.class));
    Lib.resource.checkPrivilege(context, resolvedId, ReservedOperation.view);

    final boolean hideWithheld = Boolean.TRUE.equals(hide_withheld)
            || !context.getBean(AccessManager.class).canEdit(context, resolvedId);
    Key key = new Key(Integer.parseInt(resolvedId), lang, formatType, xslid, hideWithheld, width);
    final boolean skipPopularityBool = new ParamValue(skipPopularity).toBool();

    ISODate changeDate = context.getBean(SearchManager.class).getDocChangeDate(resolvedId);

    Validator validator;
    if (changeDate != null) {
        final long changeDateAsTime = changeDate.toDate().getTime();
        long roundedChangeDate = changeDateAsTime / 1000 * 1000;
        if (request.checkNotModified(roundedChangeDate)
                && context.getBean(CacheConfig.class).allowCaching(key)) {
            if (!skipPopularityBool) {
                context.getBean(DataManager.class).increasePopularity(context, resolvedId);
            }
            return;
        }

        validator = new ChangeDateValidator(changeDateAsTime);
    } else {
        validator = new NoCacheValidator();
    }
    final FormatMetadata formatMetadata = new FormatMetadata(context, key, request);

    byte[] bytes;
    if (hasNonStandardParameters(request)) {
        // the http headers can cause a formatter to output custom output due to the parameters.
        // because it is not known how the parameters may affect the output then we have two choices
        // 1. make a unique cache for each configuration of parameters
        // 2. don't cache anything that has extra parameters beyond the standard parameters used to
        //    create the key
        // #1 has a major flaw because an attacker could simply make new requests always changing the parameters
        // and completely swamp the cache.  So we go with #2.  The formatters are pretty fast so it is a fine solution
        bytes = formatMetadata.call().data;
    } else {
        bytes = context.getBean(FormatterCache.class).get(key, validator, formatMetadata, false);
    }
    if (bytes != null) {
        if (!skipPopularityBool) {
            context.getBean(DataManager.class).increasePopularity(context, resolvedId);
        }

        writeOutResponse(context, resolvedId, lang, request.getNativeResponse(HttpServletResponse.class),
                formatType, bytes);
    }
}

From source file:architecture.ee.web.spring.controller.MyCloudDataController.java

@Secured({ "ROLE_USER" })
@RequestMapping(value = "/images/list.json", method = { RequestMethod.POST, RequestMethod.GET })
@ResponseBody//from   w w  w .j av a  2s .  c  o  m
public ImageList getImageList(
        @RequestParam(value = "objectType", defaultValue = "2", required = false) Integer objectType,
        @RequestParam(value = "objectId", defaultValue = "0", required = false) Long objectId,
        @RequestParam(value = "startIndex", defaultValue = "0", required = false) Integer startIndex,
        @RequestParam(value = "pageSize", defaultValue = "0", required = false) Integer pageSize,
        NativeWebRequest request) throws NotFoundException {
    User user = SecurityHelper.getUser();

    return getImageList(objectType, objectId, startIndex, pageSize,
            request.getNativeRequest(HttpServletRequest.class));

}

From source file:architecture.ee.web.spring.controller.SecureWebMgmtDataController.java

@RequestMapping(value = "/mgmt/website/get_and_refersh.json", method = { RequestMethod.POST,
        RequestMethod.GET })/* ww  w.  jav  a  2  s . c  om*/
@ResponseBody
public WebSite getWebSite(@RequestParam(value = "siteId", defaultValue = "0", required = false) Long siteId,
        @RequestParam(value = "refresh", defaultValue = "false", required = false) boolean refersh,
        NativeWebRequest request) throws NotFoundException {
    WebSite webSite;
    if (siteId > 0)
        webSite = webSiteManager.getWebSiteById(siteId);
    else
        webSite = WebSiteUtils.getWebSite(request.getNativeRequest(HttpServletRequest.class));

    if (refersh) {
        long webSiteId = webSite.getWebSiteId();
        webSiteManager.refreshWebSite(webSite);
        webSite = webSiteManager.getWebSiteById(webSiteId);
    }
    return webSite;
}

From source file:architecture.ee.web.spring.controller.SecureWebMgmtDataController.java

@RequestMapping(value = "/mgmt/template/get.json", method = { RequestMethod.POST, RequestMethod.GET })
@ResponseBody//from   w  ww  .  j  a v  a 2  s.co  m
public FileInfo getTemplateContent(
        @RequestParam(value = "siteId", defaultValue = "0", required = false) Long siteId,
        @RequestParam(value = "path", defaultValue = "", required = false) String path,
        @RequestParam(value = "customized", defaultValue = "false", required = false) boolean customized,
        NativeWebRequest request) throws NotFoundException, IOException {
    WebSite webSite;
    if (siteId > 0)
        webSite = webSiteManager.getWebSiteById(siteId);
    else
        webSite = WebSiteUtils.getWebSite(request.getNativeRequest(HttpServletRequest.class));

    boolean customizedToUse = customized && isTemplateCustomizedEnabled();
    File file = resourceLoader.getResource(getTemplateSrouceLocation(customizedToUse) + path).getFile();
    FileInfo fileInfo = new FileInfo(file);
    fileInfo.setCustomized(customizedToUse);
    fileInfo.setFileContent(file.isDirectory() ? "" : FileUtils.readFileToString(file));
    return fileInfo;
}

From source file:architecture.ee.web.spring.controller.SecureWebMgmtDataController.java

/**
 * Template/*from   ww w.ja  va 2s. c  o  m*/
 */

@RequestMapping(value = "/mgmt/template/list.json", method = { RequestMethod.POST, RequestMethod.GET })
@ResponseBody
public List<FileInfo> getTemplateList(
        @RequestParam(value = "siteId", defaultValue = "0", required = false) Long siteId,
        @RequestParam(value = "path", defaultValue = "", required = false) String path,
        @RequestParam(value = "customized", defaultValue = "false", required = false) boolean customized,
        NativeWebRequest request) throws NotFoundException {
    WebSite webSite;
    if (siteId > 0)
        webSite = webSiteManager.getWebSiteById(siteId);
    else
        webSite = WebSiteUtils.getWebSite(request.getNativeRequest(HttpServletRequest.class));

    boolean customizedToUse = customized && isTemplateCustomizedEnabled();

    Resource root = resourceLoader.getResource(getTemplateSrouceLocation(customizedToUse));
    List<FileInfo> list = new ArrayList<FileInfo>();
    try {
        File file = root.getFile();
        if (StringUtils.isEmpty(path)) {
            for (File f : file.listFiles()) {
                list.add(new FileInfo(file, f, customizedToUse));
            }
        } else {
            File targetFile = resourceLoader.getResource(getTemplateSrouceLocation(customized) + path)
                    .getFile();
            for (File f : targetFile.listFiles()) {
                list.add(new FileInfo(file, f, customizedToUse));
            }
        }
    } catch (IOException e) {
        log.error(e);
    }
    return list;
}

From source file:org.fao.geonet.api.records.formatters.FormatterApi.java

/**
 * @param lang     ui language//www  . j a  va  2s. c o m
 * @param type     output type, Must be one of {@link org.fao.geonet.api.records.formatters.FormatType}
 * @param xslid    the id of the formatter
 * @param metadata the xml to format (either metadata or url must be defined)
 * @param url      a url to call and format either metadata or url must be defined)
 * @param schema   the schema of the xml retrieved from the url or of the metadata xml
 * @param width    the approximate size of the element that the formatter output will be
 *                 embedded in compared to the full device width.  Allowed options are the enum
 *                 values: {@link org.fao.geonet.api.records.formatters.FormatterWidth} The
 *                 default is _100 (100% of the screen)
 * @param mdPath   (optional) the xpath to the metadata node if it's not the root node of the
 *                 XML
 */
@RequestMapping(value = "/{lang}/xml.format.{type}")
@ResponseBody
@Deprecated
public void execXml(@PathVariable final String lang, @PathVariable final String type,
        @RequestParam(value = "xsl", required = false) final String xslid,
        @RequestParam(value = "metadata", required = false) String metadata,
        @RequestParam(value = "url", required = false) final String url,
        @RequestParam(value = "schema") final String schema,
        @RequestParam(value = "width", defaultValue = "_100") final FormatterWidth width,
        @RequestParam(value = "mdpath", required = false) final String mdPath, final NativeWebRequest request)
        throws Exception {

    if (url == null && metadata == null) {
        throw new IllegalArgumentException("Either the metadata or url parameter must be declared.");
    }
    if (url != null && metadata != null) {
        throw new IllegalArgumentException("Only one of metadata or url parameter must be declared.");
    }

    FormatType formatType = FormatType.valueOf(type.toLowerCase());
    final ServiceContext context = createServiceContext(lang, formatType,
            request.getNativeRequest(HttpServletRequest.class));
    if (metadata == null) {
        metadata = getXmlFromUrl(context, lang, url, request);
    }
    Element metadataEl = Xml.loadString(metadata, false);

    if (mdPath != null) {
        final List<Namespace> namespaces = context.getBean(SchemaManager.class).getSchema(schema)
                .getNamespaces();
        metadataEl = Xml.selectElement(metadataEl, mdPath, namespaces);
        metadataEl.detach();
    }
    Metadata metadataInfo = new Metadata();
    metadataInfo.setData(metadata).setId(1).setUuid("uuid");
    metadataInfo.getDataInfo().setType(MetadataType.METADATA).setRoot(metadataEl.getQualifiedName())
            .setSchemaId(schema);

    Pair<FormatterImpl, FormatterParams> result = createFormatterAndParams(lang, formatType, xslid, width,
            request, context, metadataEl, metadataInfo);
    final String formattedMetadata = result.one().format(result.two());
    byte[] bytes = formattedMetadata.getBytes(Constants.CHARSET);

    writeOutResponse(context, "", lang, request.getNativeResponse(HttpServletResponse.class), formatType,
            bytes);
}