Example usage for com.liferay.portal.kernel.util ContentTypes TEXT_PLAIN_UTF8

List of usage examples for com.liferay.portal.kernel.util ContentTypes TEXT_PLAIN_UTF8

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util ContentTypes TEXT_PLAIN_UTF8.

Prototype

String TEXT_PLAIN_UTF8

To view the source code for com.liferay.portal.kernel.util ContentTypes TEXT_PLAIN_UTF8.

Click Source Link

Usage

From source file:com.liferay.dynamic.data.mapping.web.internal.portlet.action.GetTemplateMVCResourceCommand.java

License:Open Source License

@Override
protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    long templateId = ParamUtil.getLong(resourceRequest, "templateId");

    DDMTemplate template = _ddmTemplateService.getTemplate(templateId);

    String script = template.getScript();

    String contentType = null;/*from  w w  w. j  av  a2  s.c o m*/

    String type = template.getType();

    String language = GetterUtil.getString(template.getLanguage(), TemplateConstants.LANG_TYPE_VM);

    if (type.equals(DDMTemplateConstants.TEMPLATE_TYPE_FORM)) {
        contentType = ContentTypes.APPLICATION_JSON;
    } else if (language.equals(TemplateConstants.LANG_TYPE_XSL)) {
        contentType = ContentTypes.TEXT_XML_UTF8;
    } else {
        contentType = ContentTypes.TEXT_PLAIN_UTF8;
    }

    PortletResponseUtil.sendFile(resourceRequest, resourceResponse, null, script.getBytes(), contentType);
}

From source file:com.liferay.hadoop.action.HadoopJob.java

License:Open Source License

public String doExecute(HttpServletRequest request, HttpServletResponse response) throws Exception {

    response.setContentType(ContentTypes.TEXT_PLAIN_UTF8);

    PrintWriter writer = response.getWriter();

    FileSystem fileSystem = HadoopManager.getFileSystem();

    JobClient jobClient = HadoopManager.getJobClient();

    writer.println("-- Job Status --");

    Path inputPath = new Path("/index/*/*");
    Path outputPath = new Path("/wordcount/results");

    try {//  www.  j  ava 2s. c om
        if (_runningJob == null) {
            writer.println("Creating job");

            if (fileSystem.exists(_jobPath)) {
                fileSystem.delete(_jobPath, false);
            }

            if (!fileSystem.exists(_jobPath)) {
                writer.println("Deploying the job code to cluster");

                FSDataOutputStream outputStream = null;

                try {
                    outputStream = fileSystem.create(_jobPath);

                    ServletContext servletContext = HadoopManager.getServletContext();

                    InputStream inputStream = servletContext.getResourceAsStream("/WEB-INF/lib/hadoop-job.jar");

                    StreamUtil.transfer(inputStream, outputStream, false);
                } finally {
                    StreamUtil.cleanUp(outputStream);
                }

                writer.println("Job code deployed to cluster");
            }

            if (fileSystem.exists(outputPath)) {
                writer.println("A previous job output was found, backing it up");

                fileSystem.rename(outputPath,
                        outputPath.getParent().suffix("/.results-" + System.currentTimeMillis()));
            }

            _jobConf = HadoopManager.createNewJobConf();

            _jobConf.setJobName("Word Count");

            writer.println("Job '" + _jobConf.getJobName() + "' is being configured");

            _jobConf.setJarByClass(Map.class);
            _jobConf.setOutputKeyClass(Text.class);
            _jobConf.setOutputValueClass(IntWritable.class);
            _jobConf.setMapperClass(Map.class);
            _jobConf.setCombinerClass(Reduce.class);
            _jobConf.setReducerClass(Reduce.class);
            _jobConf.setInputFormat(TextInputFormat.class);
            _jobConf.setOutputFormat(TextOutputFormat.class);

            writer.println("Job code deployed to distributed cache's classpath");

            DistributedCache.addArchiveToClassPath(_jobPath, _jobConf, fileSystem);

            FileInputFormat.setInputPaths(_jobConf, inputPath);
            FileOutputFormat.setOutputPath(_jobConf, outputPath);

            writer.println("Submitting job the first time");

            _runningJob = jobClient.submitJob(_jobConf);

            writer.println("Job submitted");
        }

        int jobState = _runningJob.getJobState();

        writer.println(
                "Job status: " + jobState + " (RUNNING = 1, SUCCEEDED = 2, FAILED = 3, PREP = 4, KILLED = 5)");

        if ((jobState != JobStatus.RUNNING) && (jobState != JobStatus.PREP)) {

            writer.println("Re-issuing the job");

            if (fileSystem.exists(outputPath)) {
                writer.println("A previous job output was found, backing it up");

                fileSystem.rename(outputPath,
                        outputPath.getParent().suffix("/.results-" + System.currentTimeMillis()));
            }

            writer.println("Submitting job the first time");

            _runningJob = jobClient.submitJob(_jobConf);

            writer.println("Job submitted");
        }
    } catch (Exception ioe) {
        writer.println("Job error: ");

        ioe.printStackTrace(writer);
    }

    writer.flush();
    writer.close();

    return null;
}

From source file:com.liferay.portlet.journal.action.GetTemplateAction.java

License:Open Source License

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    try {/*from w  w w  .ja v a 2  s . c  o  m*/
        long groupId = ParamUtil.getLong(request, "groupId");
        String templateId = getTemplateId(request);

        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

        Map<String, String> tokens = JournalUtil.getTokens(groupId, themeDisplay);

        tokens.put("template_id", templateId);

        String languageId = LanguageUtil.getLanguageId(request);

        boolean transform = ParamUtil.getBoolean(request, "transform", true);

        JournalTemplate template = JournalTemplateServiceUtil.getTemplate(groupId, templateId, true);

        String script = JournalUtil.getTemplateScript(template, tokens, languageId, transform);

        String extension = JournalTemplateConstants.LANG_TYPE_VM;

        if (template.getLangType() != null) {
            extension = template.getLangType();
        }

        String fileName = null;
        byte[] bytes = script.getBytes();

        String contentType = ContentTypes.TEXT_PLAIN_UTF8;

        if (Validator.equals(extension, JournalTemplateConstants.LANG_TYPE_CSS)) {

            contentType = ContentTypes.TEXT_CSS_UTF8;
        } else if (Validator.equals(extension, JournalTemplateConstants.LANG_TYPE_XSL)) {

            contentType = ContentTypes.TEXT_XML_UTF8;
        }

        ServletResponseUtil.sendFile(request, response, fileName, bytes, contentType);

        return null;
    } catch (Exception e) {
        PortalUtil.sendError(e, request, response);

        return null;
    }
}

From source file:com.liferay.portlet.layoutsadmin.action.RobotsAction.java

License:Open Source License

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    try {/*from www.j a va  2 s  . c  o m*/
        String host = GetterUtil.getString(PortalUtil.getHost(request));

        LayoutSet layoutSet = null;

        try {
            layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(host);
        } catch (LayoutSetVirtualHostException lsvhe) {
            Company company = PortalUtil.getCompany(request);

            if (host.equals(company.getVirtualHostname())
                    && Validator.isNotNull(PropsValues.VIRTUAL_HOSTS_DEFAULT_SITE_NAME)) {

                Group defaultGroup = GroupLocalServiceUtil.getGroup(company.getCompanyId(),
                        PropsValues.VIRTUAL_HOSTS_DEFAULT_SITE_NAME);

                layoutSet = defaultGroup.getPublicLayoutSet();
            }
        }
        /*================ start changes ================*/
        catch (NoSuchLayoutSetException | NoSuchVirtualHostException nse) {
            if (_log.isErrorEnabled()) {
                _log.error(
                        "Ignored exception: " + nse.getMessage() + " Headers: " + printRequestHeaders(request));
            }
        }
        /*================ end changes ================*/

        String robots = RobotsUtil.getRobots(layoutSet);

        ServletResponseUtil.sendFile(request, response, null, robots.getBytes(StringPool.UTF8),
                ContentTypes.TEXT_PLAIN_UTF8);
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e, e);
        }

        PortalUtil.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e, request, response);
    }

    return null;
}

From source file:com.liferay.sampleservicebuilder.service.impl.FooLocalServiceImpl.java

License:Open Source License

public void updateAsset(long userId, Foo foo, long[] assetCategoryIds, String[] assetTagNames)
        throws PortalException {

    assetEntryLocalService.updateEntry(userId, foo.getGroupId(), Foo.class.getName(), foo.getFooId(),
            foo.getUuid(), 0, assetCategoryIds, assetTagNames, true, null, null, null, null,
            ContentTypes.TEXT_PLAIN_UTF8, foo.getField1(), null, foo.getField1(), null, null, 0, 0, null,
            false);//from www  . ja v a2s.  c o  m
}

From source file:com.liferay.support.tomcat.poller.comet.CatalinaCometProcessor.java

License:Open Source License

protected void startCometHandler(CometEvent cometEvent, HttpServletRequest request, HttpSession session)
        throws Exception {

    CometSession cometSession = new CatalinaCometSession(cometEvent);

    cometSession.setCometRequest(new CatalinaCometRequest(cometEvent));
    cometSession.setCometResponse(new CatalinaCometResponse(cometEvent));

    String sessionId = CatalinaCometSessionUtil.getSessionId(cometEvent);

    cometSession.setSessionId(sessionId);

    CometHandler cometHandler = _cometHandler.clone();

    CometHandlerPoolUtil.startCometHandler(cometSession, cometHandler);

    HttpServletResponse response = cometEvent.getHttpServletResponse();

    response.setContentType(ContentTypes.TEXT_PLAIN_UTF8);
}