Example usage for org.springframework.http MediaType APPLICATION_XHTML_XML_VALUE

List of usage examples for org.springframework.http MediaType APPLICATION_XHTML_XML_VALUE

Introduction

In this page you can find the example usage for org.springframework.http MediaType APPLICATION_XHTML_XML_VALUE.

Prototype

String APPLICATION_XHTML_XML_VALUE

To view the source code for org.springframework.http MediaType APPLICATION_XHTML_XML_VALUE.

Click Source Link

Document

A String equivalent of MediaType#APPLICATION_XHTML_XML .

Usage

From source file:org.easyj.rest.controller.AbstractGenericEntityController.java

@RequestMapping(value = "/create", produces = { MediaType.TEXT_HTML_VALUE,
        MediaType.APPLICATION_XHTML_XML_VALUE, "application/html+xml" })
public ModelAndView create() throws InstantiationException, IllegalAccessException {
    ModelAndView mav = configMAV(getEntityClass().newInstance(), getCreateViewName());

    return modelToForm(mav);
}

From source file:eionet.webq.web.controller.FileDownloadController.java

/**
 * Writes project file to response.//www  . jav a  2 s  .  c  o m
 *
 * @param name        file name
 * @param projectFile project file object
 * @param response    http response
 * @param disposition inline or attachment
 */
private void writeProjectFileToResponse(String name, ProjectFile projectFile, HttpServletResponse response,
        String disposition, String format) {

    ConfigurableMimeFileTypeMap mimeTypesMap = new ConfigurableMimeFileTypeMap();
    String contentType = mimeTypesMap.getContentType(name);

    // check if default
    if (mimeTypesMap.getContentType("").equals(contentType)) {
        if (name.endsWith(".xhtml")) {
            contentType = MediaType.APPLICATION_XHTML_XML_VALUE;
        } else if (name.endsWith(".js")) {
            contentType = "application/javascript";
        } else if (name.endsWith(".json")) {
            contentType = MediaType.APPLICATION_JSON_VALUE;
        } else {
            contentType = MediaType.APPLICATION_XML_VALUE;
        }
        // TODO check if there are more missing mime types
    }

    byte[] fileContent = projectFile.getFileContent();

    if ("json".equals(format)) {
        fileContent = jsonXMLConverter.convertXmlToJson(projectFile.getFileContent());
        contentType = MediaType.APPLICATION_JSON_VALUE;
        disposition = "inline";
    }

    if (contentType.startsWith("text") || contentType.startsWith("application")) {
        contentType += ";charset=UTF-8";
    }
    response.setContentType(contentType);
    setContentDisposition(response, disposition + ";filename=" + name);
    if (projectFile.getUpdated() != null) {
        response.setDateHeader("Last-Modified", projectFile.getUpdated().getTime());
    } else if (projectFile.getCreated() != null) {
        response.setDateHeader("Last-Modified", projectFile.getCreated().getTime());
    }
    writeToResponse(response, fileContent);
}

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

@RequestMapping(value = { "/api/records/{metadataUuid}/formatters/{formatterId}",
        "/api/" + API.VERSION_0_1
                + "/records/{metadataUuid}/formatters/{formatterId}" }, method = RequestMethod.GET, produces = {
                        MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_XHTML_XML_VALUE, "application/pdf",
                        MediaType.ALL_VALUE
        // TODO: PDF
})
@ApiOperation(value = "Get a formatted metadata record", nickname = "getRecordFormattedBy")
@ResponseBody// ww  w  .j a v a2 s .  co  m
public void getRecordFormattedBy(
        @ApiParam(value = "Formatter type to use.") @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = MediaType.TEXT_HTML_VALUE) String acceptHeader,
        @PathVariable(value = "formatterId") final String formatterId,
        @ApiParam(value = API_PARAM_RECORD_UUID, required = true) @PathVariable String metadataUuid,
        @RequestParam(value = "width", defaultValue = "_100") final FormatterWidth width,
        @RequestParam(value = "mdpath", required = false) final String mdPath,
        @RequestParam(value = "output", required = false) FormatType formatType,
        @ApiIgnore final NativeWebRequest request, final HttpServletRequest servletRequest) throws Exception {

    ApplicationContext applicationContext = ApplicationContextHolder.get();
    Locale locale = languageUtils.parseAcceptLanguage(servletRequest.getLocales());

    // TODO :
    // if text/html > xsl_view
    // if application/pdf > xsl_view and PDF output
    // if application/x-gn-<formatterId>+(xml|html|pdf|text)
    // Force PDF ouutput when URL parameter is set.
    // This is useful when making GET link to PDF which
    // can not use headers.
    if (MediaType.ALL_VALUE.equals(acceptHeader)) {
        acceptHeader = MediaType.TEXT_HTML_VALUE;
    }
    if (formatType == null) {
        formatType = FormatType.find(acceptHeader);
    }
    if (formatType == null) {
        formatType = FormatType.xml;
    }

    final String language = LanguageUtils.locale2gnCode(locale.getISO3Language());
    final ServiceContext context = createServiceContext(language, formatType,
            request.getNativeRequest(HttpServletRequest.class));
    AbstractMetadata metadata = ApiUtils.canViewRecord(metadataUuid, servletRequest);

    Boolean hideWithheld = true;
    //        final boolean hideWithheld = Boolean.TRUE.equals(hide_withheld) ||
    //            !context.getBean(AccessManager.class).canEdit(context, resolvedId);
    Key key = new Key(metadata.getId(), language, formatType, formatterId, hideWithheld, width);
    final boolean skipPopularityBool = false;

    ISODate changeDate = metadata.getDataInfo().getChangeDate();

    Validator validator;
    if (changeDate != null) {
        final long changeDateAsTime = changeDate.toDate().getTime();
        long roundedChangeDate = changeDateAsTime / 1000 * 1000;
        if (request.checkNotModified(language, roundedChangeDate)
                && context.getBean(CacheConfig.class).allowCaching(key)) {
            if (!skipPopularityBool) {
                context.getBean(DataManager.class).increasePopularity(context,
                        String.valueOf(metadata.getId()));
            }
            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, String.valueOf(metadata.getId()));
        }
        writeOutResponse(context, metadataUuid, locale.getISO3Language(),
                request.getNativeResponse(HttpServletResponse.class), formatType, bytes);
    }
}

From source file:org.fao.geonet.api.records.MetadataApi.java

@ApiOperation(value = "Get a metadata record", notes = "Depending on the accept header the appropriate formatter is used. "
        + "When requesting a ZIP, a MEF version 2 file is returned. "
        + "When requesting HTML, the default formatter is used.", nickname = "getRecord")
@RequestMapping(value = "/{metadataUuid:.+}", method = RequestMethod.GET, consumes = {
        MediaType.ALL_VALUE }, produces = { MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_XML_VALUE,
                MediaType.APPLICATION_XHTML_XML_VALUE, MediaType.APPLICATION_JSON_VALUE, "application/pdf",
                "application/zip", MEF_V1_ACCEPT_TYPE, MEF_V2_ACCEPT_TYPE, MediaType.ALL_VALUE })
@ApiResponses(value = { @ApiResponse(code = 200, message = "Return the record."),
        @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW),
        @ApiResponse(code = 404, message = ApiParams.API_RESPONSE_RESOURCE_NOT_FOUND) })
public String getRecord(
        @ApiParam(value = API_PARAM_RECORD_UUID, required = true) @PathVariable String metadataUuid,
        @ApiParam(value = "Accept header should indicate which is the appropriate format "
                + "to return. It could be text/html, application/xml, application/zip, ..."
                + "If no appropriate Accept header found, the XML format is returned.", required = true) @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = MediaType.APPLICATION_XML_VALUE, required = false) String acceptHeader,
        HttpServletResponse response, HttpServletRequest request) throws Exception {
    try {//from  w  w w.java2  s  .  com
        ApiUtils.canViewRecord(metadataUuid, request);
    } catch (SecurityException e) {
        Log.debug(API.LOG_MODULE_NAME, e.getMessage(), e);
        throw new NotAllowedException(ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW);
    }
    List<String> accept = Arrays.asList(acceptHeader.split(","));

    String defaultFormatter = "xsl-view";
    if (accept.contains(MediaType.TEXT_HTML_VALUE) || accept.contains(MediaType.APPLICATION_XHTML_XML_VALUE)
            || accept.contains("application/pdf")) {
        return "forward:" + (metadataUuid + "/formatters/" + defaultFormatter);
    } else if (accept.contains(MediaType.APPLICATION_XML_VALUE)
            || accept.contains(MediaType.APPLICATION_JSON_VALUE)) {
        return "forward:" + (metadataUuid + "/formatters/xml");
    } else if (accept.contains("application/zip") || accept.contains(MEF_V1_ACCEPT_TYPE)
            || accept.contains(MEF_V2_ACCEPT_TYPE)) {
        return "forward:" + (metadataUuid + "/formatters/zip");
    } else {
        // FIXME this else is never reached because any of the accepted medias match one of the previous if conditions.
        response.setHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_XHTML_XML_VALUE);
        //response.sendRedirect(metadataUuid + "/formatters/" + defaultFormatter);
        return "forward:" + (metadataUuid + "/formatters/" + defaultFormatter);
    }
}