Java 类com.liferay.portal.kernel.util.ContentTypes 实例源码

项目:liferay-dummy-factory    文件:PageMVCResourceCommand.java   
@Override
protected void doServeResource(ResourceRequest request, ResourceResponse response)
        throws Exception {
    String cmd = ParamUtil.getString(request, Constants.CMD);
    String serializedJson = "";

    if(cmd.equals(CMD_PAGELIST)) {
        serializedJson = getPageLists(request,response );
    } else {
        _log.error("Unknown command is passed <" + cmd + ">");
    }

    HttpServletResponse servletResponse = _portal.getHttpServletResponse(
            response);

    servletResponse.setContentType(ContentTypes.APPLICATION_JSON);

    ServletResponseUtil.write(servletResponse, serializedJson);     
}
项目:liferay-dummy-factory    文件:RoleMVCResourceCommand.java   
@Override
protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
    String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);
    String serializedJson = "";

    if (cmd.equals(CMD_ROLELIST)) {
        serializedJson = getRoleLists(resourceRequest, resourceResponse);
    } else {
        _log.error("Unknown command is passed <" + cmd + ">");
    }

    HttpServletResponse response = _portal.getHttpServletResponse(resourceResponse);

    response.setContentType(ContentTypes.APPLICATION_JSON);

    ServletResponseUtil.write(response, serializedJson);
}
项目:liferay-dummy-factory    文件:MBMVCResourceCommand.java   
@Override
protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {
    String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);
    String serializedJson = "";

    if(cmd.equals(CMD_THREAD_LIST)) {
        serializedJson = getThreadList(resourceRequest,resourceResponse );

    } else if (cmd.equals(CMD_CATEGORY_LIST)) {
        serializedJson = getCategoryList(resourceRequest,resourceResponse );

    } else {
        _log.error("Unknown command is passed <" + cmd + ">");
    }

    HttpServletResponse response = _portal.getHttpServletResponse(
            resourceResponse);

    response.setContentType(ContentTypes.APPLICATION_JSON);

    ServletResponseUtil.write(response, serializedJson);        
}
项目:liferay-blade-samples    文件:BladeServlet.java   
/**
 * Write sample HTML
 *
 * @param resp
 */
private void _writeSampleHTML(HttpServletResponse resp) {
    resp.setCharacterEncoding(StringPool.UTF8);
    resp.setContentType(ContentTypes.TEXT_HTML_UTF8);
    resp.setStatus(HttpServletResponse.SC_OK);

    try {
        ServletResponseUtil.write(resp, _generateSampleHTML());
    }
    catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e, e);
        }

        resp.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED);
    }
}
项目:liferay-blade-samples    文件:BladeServlet.java   
/**
 * Write sample HTML
 *
 * @param resp
 */
private void _writeSampleHTML(HttpServletResponse resp) {
    resp.setCharacterEncoding(StringPool.UTF8);
    resp.setContentType(ContentTypes.TEXT_HTML_UTF8);
    resp.setStatus(HttpServletResponse.SC_OK);

    try {
        ServletResponseUtil.write(resp, _generateSampleHTML());
    }
    catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e, e);
        }

        resp.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED);
    }
}
项目:liferay-blade-samples    文件:BladeServlet.java   
/**
 * Write sample HTML
 *
 * @param resp
 */
private void _writeSampleHTML(HttpServletResponse resp) {
    resp.setCharacterEncoding(StringPool.UTF8);
    resp.setContentType(ContentTypes.TEXT_HTML_UTF8);
    resp.setStatus(HttpServletResponse.SC_OK);

    try {
        ServletResponseUtil.write(resp, _generateSampleHTML());
    }
    catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e, e);
        }

        resp.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED);
    }
}
项目:liferaylms-portlet    文件:CompetenceLocalServiceImpl.java   
@Indexable(type=IndexableType.REINDEX)
public Competence updateCompetence(Competence competence, ServiceContext serviceContext) throws SystemException, PortalException {

    competence = LmsLocaleUtil.checkDefaultLocale(Competence.class, competence, "title");
    competence = LmsLocaleUtil.checkDefaultLocale(Competence.class, competence, "description");

    Competence competenceReturn = competencePersistence.update(competence, true);
    Locale locale=new Locale(serviceContext.getLanguageId());

    long userId=serviceContext.getUserId();
    AssetEntryLocalServiceUtil.updateEntry(
            userId, competence.getGroupId(), Competence.class.getName(),
            competence.getCompetenceId(), competence.getUuid(),0, serviceContext.getAssetCategoryIds(),
            serviceContext.getAssetTagNames(), true, null, null,
            new java.util.Date(System.currentTimeMillis()), null,
            ContentTypes.TEXT_HTML, competence.getTitle(), competence.getDescription(locale), competence.getDescription(locale), null, null, 0, 0,
            null, false);
    return competenceReturn;
}
项目:liferaylms-portlet    文件:CompetenceLocalServiceImpl.java   
@Indexable(type=IndexableType.REINDEX)
public Competence modCompetence (Competence competence, ServiceContext serviceContext) throws SystemException, PortalException {
        competence.setExpandoBridgeAttributes(serviceContext);

        competence = LmsLocaleUtil.checkDefaultLocale(Competence.class, competence, "title");
        competence = LmsLocaleUtil.checkDefaultLocale(Competence.class, competence, "description");

        Locale locale=new Locale(serviceContext.getLanguageId());
        competencePersistence.update(competence, true);
        long userId=serviceContext.getUserId();
        AssetEntryLocalServiceUtil.updateEntry(
                userId, competence.getGroupId(), Competence.class.getName(),
                competence.getCompetenceId(), competence.getUuid(),0, serviceContext.getAssetCategoryIds(),
                serviceContext.getAssetTagNames(), true, null, null,
                new java.util.Date(System.currentTimeMillis()), null,
                ContentTypes.TEXT_HTML, competence.getTitle(), competence.getDescription(locale), competence.getDescription(locale), null, null, 0, 0,
                null, false);
        return competence;

}
项目:jukebox-portlet    文件:AlbumLocalServiceImpl.java   
public void updateAsset(
        long userId, Album album, long[] assetCategoryIds,
        String[] assetTagNames, long[] assetLinkEntryIds)
    throws PortalException {

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(
        userId, album.getGroupId(), album.getCreateDate(),
        album.getModifiedDate(), Album.class.getName(), album.getAlbumId(),
        album.getUuid(), 0, assetCategoryIds, assetTagNames, true, null,
        null, null, ContentTypes.TEXT_HTML, album.getName(), null, null,
        null, null, 0, 0, null, false);

    assetLinkLocalService.updateLinks(
        userId, assetEntry.getEntryId(), assetLinkEntryIds,
        AssetLinkConstants.TYPE_RELATED);
}
项目:jukebox-portlet    文件:SongLocalServiceImpl.java   
public void updateAsset(
        long userId, Song song, long[] assetCategoryIds,
        String[] assetTagNames, long[] assetLinkEntryIds)
    throws PortalException {

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(
        userId, song.getGroupId(), song.getCreateDate(),
        song.getModifiedDate(), Song.class.getName(), song.getSongId(),
        song.getUuid(), 0, assetCategoryIds, assetTagNames, true, null,
        null, null, ContentTypes.TEXT_HTML, song.getName(), null, null,
        null, null, 0, 0, null, false);

    assetLinkLocalService.updateLinks(
        userId, assetEntry.getEntryId(), assetLinkEntryIds,
        AssetLinkConstants.TYPE_RELATED);
}
项目:jukebox-portlet    文件:ArtistLocalServiceImpl.java   
public void updateAsset(
        long userId, Artist artist, long[] assetCategoryIds,
        String[] assetTagNames, long[] assetLinkEntryIds)
    throws PortalException {

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(
        userId, artist.getGroupId(), artist.getCreateDate(),
        artist.getModifiedDate(), Artist.class.getName(),
        artist.getArtistId(), artist.getUuid(), 0, assetCategoryIds,
        assetTagNames, true, null, null, null, ContentTypes.TEXT_HTML,
        artist.getName(), null, null, null, null, 0, 0, null, false);

    assetLinkLocalService.updateLinks(
        userId, assetEntry.getEntryId(), assetLinkEntryIds,
        AssetLinkConstants.TYPE_RELATED);
}
项目:xipi    文件:RSSAction.java   
public ActionForward strutsExecute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    try {
        _log.info("strutsExecute");
        ServletResponseUtil.sendFile(request, response, null,
                getRSS(request), ContentTypes.TEXT_XML_UTF8);
        System.out
                .println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

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

        return null;
    }
}
项目:xipi    文件:RSSAction.java   
public void processAction(ActionMapping mapping, ActionForm form,
        PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse) throws Exception {

    try {
        HttpServletRequest request = PortalUtil
                .getHttpServletRequest(actionRequest);
        HttpServletResponse response = PortalUtil
                .getHttpServletResponse(actionResponse);
        _log.info("processAction");
        System.out
                .println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        ServletResponseUtil.sendFile(request, response, null,
                getRSS(request), ContentTypes.TEXT_XML_UTF8);

        mapping.setForward("/common/null.jsp");
    } catch (Exception e) {
        PortalUtil.sendError(e, actionRequest, actionResponse);
    }
}
项目:jukebox    文件:AlbumLocalServiceImpl.java   
public void updateAsset(
        long userId, Album album, long[] assetCategoryIds,
        String[] assetTagNames, long[] assetLinkEntryIds)
    throws PortalException, SystemException {

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(
        userId, album.getGroupId(), album.getCreateDate(),
        album.getModifiedDate(), Album.class.getName(), album.getAlbumId(),
        album.getUuid(), 0, assetCategoryIds, assetTagNames, true, null,
        null, null, ContentTypes.TEXT_HTML, album.getName(), null, null,
        null, null, 0, 0, null, false);

    assetLinkLocalService.updateLinks(
        userId, assetEntry.getEntryId(), assetLinkEntryIds,
        AssetLinkConstants.TYPE_RELATED);
}
项目:jukebox    文件:SongLocalServiceImpl.java   
public void updateAsset(
        long userId, Song song, long[] assetCategoryIds,
        String[] assetTagNames, long[] assetLinkEntryIds)
    throws PortalException, SystemException {

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(
        userId, song.getGroupId(), song.getCreateDate(),
        song.getModifiedDate(), Song.class.getName(), song.getSongId(),
        song.getUuid(), 0, assetCategoryIds, assetTagNames, true, null,
        null, null, ContentTypes.TEXT_HTML, song.getName(), null, null,
        null, null, 0, 0, null, false);

    assetLinkLocalService.updateLinks(
        userId, assetEntry.getEntryId(), assetLinkEntryIds,
        AssetLinkConstants.TYPE_RELATED);
}
项目:jukebox    文件:ArtistLocalServiceImpl.java   
public void updateAsset(
        long userId, Artist artist, long[] assetCategoryIds,
        String[] assetTagNames, long[] assetLinkEntryIds)
    throws PortalException, SystemException {

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(
        userId, artist.getGroupId(), artist.getCreateDate(),
        artist.getModifiedDate(), Artist.class.getName(),
        artist.getArtistId(), artist.getUuid(), 0, assetCategoryIds,
        assetTagNames, true, null, null, null, ContentTypes.TEXT_HTML,
        artist.getName(), null, null, null, null, 0, 0, null, false);

    assetLinkLocalService.updateLinks(
        userId, assetEntry.getEntryId(), assetLinkEntryIds,
        AssetLinkConstants.TYPE_RELATED);
}
项目:lims    文件:LIMSPortlet.java   
/**
 * This method is called whenever the server gets an AJAX request from client. All asynchronous requests
 * should go over this method.
 *
 * @param request  Asynchronous request from client
 * @param response Response from server
 * @throws PortletException
 * @throws IOException
 */
@Override
public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    // Do not continue if the user is not signed in
    if (!isCorrectAttempt(request)) {
        // Return unauthorized response code
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, HttpStatus.UNAUTHORIZED.toString());
        return;
    }

    // Environment needs to be set up at the beginning of the request
    propertiesManager.setup(request.getPreferences());

    // Response content type is JSON
    response.setContentType(ContentTypes.APPLICATION_JSON);

    // This is an entry point to the whole app. Processor will do all the necessary work and fill the response.
    processor.processRequest(request, response);
}
项目:ch-inofix-timetracker    文件:TaskRecordLocalServiceImpl.java   
@Override
public void updateAsset(long userId, TaskRecord taskRecord, long[] assetCategoryIds, String[] assetTagNames,
        long[] assetLinkEntryIds, Double priority) throws PortalException {

    // TODO
    boolean visible = true;
    // boolean visible = false;
    // if (taskRecord.isApproved()) {
    // visible = true;
    // publishDate = taskRecord.getCreateDate();
    // }

    Date publishDate = null;

    String summary = HtmlUtil.extractText(StringUtil.shorten(taskRecord.getWorkPackage(), 500));

    String className = TaskRecord.class.getName();
    long classPK = taskRecord.getTaskRecordId();

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, taskRecord.getGroupId(),
            taskRecord.getCreateDate(), taskRecord.getModifiedDate(), className, classPK, taskRecord.getUuid(), 0,
            assetCategoryIds, assetTagNames, true, visible, null, null, publishDate, null, ContentTypes.TEXT_HTML,
            taskRecord.getWorkPackage(), taskRecord.getWorkPackage(), summary, null, null, 0, 0, priority);

    assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds,
            AssetLinkConstants.TYPE_RELATED);
}
项目:ch-inofix-contact-manager    文件:ContactLocalServiceImpl.java   
@Override
public void updateAsset(long userId, Contact contact, long[] assetCategoryIds, String[] assetTagNames,
        long[] assetLinkEntryIds, Double priority) throws PortalException {

    // TODO
    boolean visible = true;
    // boolean visible = false;
    // if (contact.isApproved()) {
    // visible = true;
    // publishDate = contact.getCreateDate();
    // }

    Date publishDate = contact.getCreateDate();

    // TODO
    String description = "TODO: contact description";
    String summary = HtmlUtil.extractText(StringUtil.shorten(contact.getCard(), 500));

    String className = Contact.class.getName();
    long classPK = contact.getContactId();

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, contact.getGroupId(),
            contact.getCreateDate(), contact.getModifiedDate(), className, classPK, contact.getUuid(), 0,
            assetCategoryIds, assetTagNames, true, visible, null, null, publishDate, null, ContentTypes.TEXT_HTML,
            // contact.getName(),
            "TODO: contact.getName()", description, summary, null, null, 0, 0, priority);

    assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds,
            AssetLinkConstants.TYPE_RELATED);

    // assetEntryLocalService.updateVisible(Contact.class.getName(),
    // classPK, visible);

}
项目:liferay-dummy-factory    文件:ImageLinksMVCResourceCommand.java   
@Override
protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {
    int numberOfCrawlers = ParamUtil.getInteger(resourceRequest, "numberOfCrawlers", -1);
    int maxDepthOfCrawling = ParamUtil.getInteger(resourceRequest, "maxDepthOfCrawling", -1);
    int maxPagesToFetch = ParamUtil.getInteger(resourceRequest, "maxPagesToFetch", -1);
    String tmpUrls = ParamUtil.getString(resourceRequest, "urls", "https://www.shutterstock.com/photos");
    String[] strArray = tmpUrls.split(",");
    List<String> urls = new ArrayList<>(Arrays.asList(strArray));
    List<String> result = Lists.newArrayList();

    if(_log.isDebugEnabled()) {
        _log.debug("numberOfCrawlers : " + String.valueOf(numberOfCrawlers));
        _log.debug("maxDepthOfCrawling : " + String.valueOf(maxDepthOfCrawling));
        _log.debug("maxPagesToFetch : " + String.valueOf(maxPagesToFetch));
    }

    if( numberOfCrawlers >= 0 && 
        maxDepthOfCrawling >= 0 && 
        maxPagesToFetch >= 0 ) {

        // Run image links crawler
        result = run(numberOfCrawlers, maxDepthOfCrawling, maxPagesToFetch, urls);
    }

    HttpServletResponse response = _portal.getHttpServletResponse(resourceResponse);

    response.setContentType(ContentTypes.APPLICATION_JSON);

    String serializedJson = createReturnJson(resourceRequest, resourceResponse, result);

    ServletResponseUtil.write(response, serializedJson);        
}
项目:ch-inofix-data-manager    文件:MeasurementLocalServiceImpl.java   
@Override
public void updateAsset(long userId, Measurement measurement,
        long[] assetCategoryIds, String[] assetTagNames, Double priority)
        throws PortalException {

    // TODO
    boolean visible = true;
    // boolean visible = false;
    // if (measurement.isApproved()) {
    // visible = true;
    // publishDate = measurement.getCreateDate();
    // }

    Date publishDate = null;

    String summary = HtmlUtil
            .extractText(StringUtil.shorten(measurement.getData(), 500));

    String className = Measurement.class.getName();
    long classPK = measurement.getMeasurementId();

    assetEntryLocalService.updateEntry(userId, measurement.getGroupId(),
            measurement.getCreateDate(), measurement.getModifiedDate(),
            className, classPK, measurement.getUuid(), 0, assetCategoryIds,
            assetTagNames, true, visible, null, null, publishDate, null,
            ContentTypes.TEXT_HTML, measurement.getName(),
            measurement.getName(), summary, null, null, 0, 0, priority);
}
项目:liferaylms-portlet    文件:LearningActivityLocalServiceImpl.java   
public LearningActivity modLearningActivity (LearningActivity larn, 
        ServiceContext serviceContext)
                throws SystemException, PortalException {

    larn = LmsLocaleUtil.checkDefaultLocale(LearningActivity.class, larn, "title");
    larn = LmsLocaleUtil.checkDefaultLocale(LearningActivity.class, larn, "description");
    learningActivityPersistence.update(larn, false);
    long userId=serviceContext.getUserId();

    assetEntryLocalService.updateEntry(
            userId, larn.getGroupId(), LearningActivity.class.getName(),
            larn.getActId(), larn.getUuid(),larn.getTypeId(), serviceContext.getAssetCategoryIds(),
            serviceContext.getAssetTagNames(), true, null, null, 
            new java.util.Date(System.currentTimeMillis()), null,
            ContentTypes.TEXT_HTML, larn.getTitle(), null, larn.getDescription(),null, null, 0, 0,
            null, false);
    SocialActivityLocalServiceUtil.addActivity(
            larn.getUserId(), larn.getGroupId(),
            LearningActivity.class.getName(), larn.getActId(),
            1, StringPool.BLANK, 0);

    //auditing
    AuditingLogFactory.audit(larn.getCompanyId(), larn.getGroupId(), LearningActivity.class.getName(), larn.getPrimaryKey(), serviceContext.getUserId(), AuditConstants.UPDATE, null);

    return larn;

}
项目:liferaylms-portlet    文件:UserProgress.java   
public void serveResource(ResourceRequest resourceRequest,
        ResourceResponse resourceResponse) throws IOException,
        PortletException {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    try {

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

        loadFonts();

        write_IEC_Pdf(baos,themeDisplay,PortalUtil.getHttpServletRequest(resourceRequest));

        ServletResponseUtil.sendFile(PortalUtil.getHttpServletRequest(resourceRequest),
                 PortalUtil.getHttpServletResponse(resourceResponse),
                 fileName,
                 baos.toByteArray(), 
                 ContentTypes.APPLICATION_PDF);

    } catch (Exception e) {
        e.printStackTrace();
        SessionErrors.add(resourceRequest, "export.pdf.userstats.error");
    } finally{
        baos.close();
    }

}
项目:liferaylms-portlet    文件:CourseStats.java   
private CSVWriter initCsv(ResourceResponse resourceResponse)
        throws IOException, UnsupportedEncodingException {
    //Necesario para crear el fichero csv.
    resourceResponse.setCharacterEncoding(StringPool.UTF8);
    resourceResponse.setContentType(ContentTypes.TEXT_CSV_UTF8);
    resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION,"attachment; fileName=Statistics.csv");
    byte b[] = {(byte)0xEF, (byte)0xBB, (byte)0xBF};

    resourceResponse.getPortletOutputStream().write(b);

    CSVWriter writer = new CSVWriter(new OutputStreamWriter(resourceResponse.getPortletOutputStream(),StringPool.UTF8),CharPool.SEMICOLON);
    return writer;
}
项目:ch-inofix-timetracker    文件:ImportTaskRecordsMVCActionCommand.java   
protected void handleUploadException(ActionRequest actionRequest, ActionResponse actionResponse, String folderName,
        Exception e) throws Exception {

    _log.info("handleUploadException()");

    HttpServletResponse response = _portal.getHttpServletResponse(actionResponse);

    response.setContentType(ContentTypes.TEXT_HTML);
    response.setStatus(HttpServletResponse.SC_OK);

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

    deleteTempFileEntry(themeDisplay.getScopeGroupId(), folderName);

    JSONObject jsonObject = StagingUtil.getExceptionMessagesJSONObject(themeDisplay.getLocale(), e,
            (ExportImportConfiguration) null);

    JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
}
项目:flashlight-search    文件:FlashlightSearchPortlet.java   
/**
 * Performs the "load more" AJAX request
 *
 * @param request The resource request
 * @param response The resource response
 *
 * @throws PortletException If something goes wrong
 * @throws IOException If something goes wrong
 */
public void doLoadMore(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    response.setContentType(ContentTypes.APPLICATION_JSON);
    response.setCharacterEncoding(StandardCharsets.UTF_8.name());
    response.setProperty(HTTP_HEADER_CACHE_CONTROL, CACHE_CONTROL_NO_CACHE);
    response.setProperty(ResourceResponse.EXPIRATION_CACHE, ZERO);

    String tabId = ParamUtil.get(request, PortletRequestParameter.TAB_ID.getName(), StringPool.BLANK);
    int offset = ParamUtil.getInteger(request, PortletRequestParameter.PAGE_OFFSET.getName(), 0);
    if(offset < 0) {
        offset = 0;
    }

    FlashlightSearchConfiguration config = this.searchService.readConfiguration(request.getPreferences());
    Map<String, FlashlightSearchConfigurationTab> tabs = config.getTabs();

    if(tabs.containsKey(tabId)) {
        try {
            SearchResultsContainer container = this.searchService.search(request, response, tabId, offset, true);
            JSONPayloadFactory jsonPayloadFactory = new JSONPayloadFactory(this.jsonFactory);
            if(container.hasSearchResults(tabId)) {
                FlashlightSearchConfigurationTab tab = tabs.get(tabId);
                SearchPage page = container.getSearchPage(tabId);

                ResourceURL loadMoreUrl = response.createResourceURL();
                loadMoreUrl.setResourceID(PortletResource.LOAD_MORE.getResourceId());
                loadMoreUrl.setParameter(PortletRequestParameter.TAB_ID.getName(), tabId);
                loadMoreUrl.setParameter(PortletRequestParameter.KEYWORDS.getName(), ParamUtil.get(request, PortletRequestParameter.KEYWORDS.getName(), StringPool.BLANK));
                loadMoreUrl.setParameter(PortletRequestParameter.PAGE_OFFSET.getName(), Integer.toString(offset + 1));
                loadMoreUrl.setParameter(PortletRequestParameter.RANDOM_CACHE.getName(), randomCacheParamValue());

                JSONObject payload = jsonPayloadFactory.createJSONPayload(tab, page, offset, loadMoreUrl.toString());
                response.getWriter().print(payload.toJSONString());
            } else {
                // No search results with the given tab
                LOG.debug("A search tab was found, but no pages were returned");
                response.setProperty(ResourceResponse.HTTP_STATUS_CODE, STATUS_CODE_NOT_FOUND);
            }
        } catch (SearchException e) {
            // Cannot perform search, return a 500 error
            LOG.error("Cannot perform search", e);
            response.setProperty(ResourceResponse.HTTP_STATUS_CODE, STATUS_CODE_INTERNAL_ERROR);
        }
    } else {
        // No tab with given ID. Return 404
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, STATUS_CODE_NOT_FOUND);
    }
}
项目:ch-inofix-contact-manager    文件:ImportContactsMVCActionCommand.java   
protected void handleUploadException(ActionRequest actionRequest, ActionResponse actionResponse, String folderName,
        Exception e) throws Exception {

    _log.info("handleUploadException()");

    HttpServletResponse response = _portal.getHttpServletResponse(actionResponse);

    response.setContentType(ContentTypes.TEXT_HTML);
    response.setStatus(HttpServletResponse.SC_OK);

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

    deleteTempFileEntry(themeDisplay.getScopeGroupId(), folderName);

    JSONObject jsonObject = StagingUtil.getExceptionMessagesJSONObject(themeDisplay.getLocale(), e,
            (ExportImportConfiguration) null);

    JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
}
项目:ch-inofix-contact-manager    文件:ExportContactsMVCResourceCommand.java   
protected void download(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws PortalException, IOException {

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

    Contact contact = _contactService.getContact(contactId);

    String card = contact.getCard();
    String name = contact.getFullName(true);

    PortletResponseUtil.sendFile(resourceRequest, resourceResponse, name + ".vcf", card.getBytes(),
            ContentTypes.TEXT_PLAIN_UTF8);

}
项目:liferay-dummy-factory    文件:DLDefaultDummyGenerator.java   
@Override
protected void exec(ActionRequest request, DLContext paramContext) throws PortalException {

    //Tracking progress start
    ProgressManager progressManager = new ProgressManager();
    progressManager.start(request);

    System.out.println("Starting to create " + paramContext.getNumberOfDocuments() + " documents");

    for (long i = 1; i <= paramContext.getNumberOfDocuments(); i++) {
        //Update progress
        progressManager.trackProgress(i, paramContext.getNumberOfDocuments());

        StringBundler title = new StringBundler(2);
        title.append(paramContext.getBaseDocumentTitle());

        //Add number more then one docunent
        if(1 < paramContext.getNumberOfDocuments()) {
            title.append(i);
        }

        StringBundler sourceFileName = new StringBundler(2);
        sourceFileName.append(title.toString());
        sourceFileName.append(".txt");

        byte[] dummyFile = new byte[0];

        try {

            _dLAppLocalService.addFileEntry(
                paramContext.getServiceContext().getUserId(), //userId, 
                paramContext.getGroupId(), // repositoryId,
                paramContext.getFolderId(), // folderId,
                sourceFileName.toString(), //sourceFileName, 
                ContentTypes.APPLICATION_OCTET_STREAM, //mimeType, 
                title.toString(), //title, 
                paramContext.getBaseDocumentDescription(), //description,
                StringPool.BLANK, //changeLog, 
                dummyFile, //file,
                paramContext.getServiceContext());

        } catch (Exception e) {
            //Finish progress
            progressManager.finish();   
            throw e;
        }
    }

    //Finish progress
    progressManager.finish();   

    System.out.println("Finished creating " + paramContext.getNumberOfDocuments() + " documents");

}
项目:ch-inofix-data-manager    文件:ImportMeasurementsMVCActionCommand.java   
protected void handleUploadException(ActionRequest actionRequest, ActionResponse actionResponse, String folderName,
        Exception e) throws Exception {

    _log.info("handleUploadException()");

    HttpServletResponse response = _portal.getHttpServletResponse(actionResponse);

    response.setContentType(ContentTypes.TEXT_HTML);
    response.setStatus(HttpServletResponse.SC_OK);

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

    deleteTempFileEntry(themeDisplay.getScopeGroupId(), folderName);

    JSONObject jsonObject = StagingUtil.getExceptionMessagesJSONObject(themeDisplay.getLocale(), e,
            (ExportImportConfiguration) null);

    JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
}
项目:liferaylms-portlet    文件:OfflineActivity.java   
@Override
public void serveResource(ResourceRequest resourceRequest,
        ResourceResponse resourceResponse) throws IOException,
        PortletException {
    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
    String action = ParamUtil.getString(resourceRequest, "action");
    long actId = ParamUtil.getLong(resourceRequest, "actId",0);


    if(action.equals("export")){

        try {

            CalificationType ct = new CalificationTypeRegistry().getCalificationType(CourseLocalServiceUtil.getCourseByGroupCreatedId(themeDisplay.getScopeGroupId()).getCalificationType());

            //Necesario para crear el fichero csv.
            resourceResponse.setCharacterEncoding(StringPool.UTF8);
            resourceResponse.setContentType(ContentTypes.TEXT_CSV_UTF8);
            resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION,"attachment; fileName=data.csv");
            byte b[] = {(byte)0xEF, (byte)0xBB, (byte)0xBF};

            resourceResponse.getPortletOutputStream().write(b);

            CSVWriter writer = new CSVWriter(new OutputStreamWriter(resourceResponse.getPortletOutputStream(),StringPool.UTF8),CharPool.SEMICOLON);
            String[] cabeceras = new String[4];


            //En esta columna vamos a tener el nombre del usuario.
            cabeceras[0]= LanguageUtil.get(getPortletConfig(), themeDisplay.getLocale(), "onlinetaskactivity.export.user");
            cabeceras[1]= LanguageUtil.get(getPortletConfig(), themeDisplay.getLocale(), "onlinetaskactivity.export.date");
            cabeceras[2]= LanguageUtil.get(getPortletConfig(), themeDisplay.getLocale(), "onlinetaskactivity.export.result");
            cabeceras[3]= LanguageUtil.get(getPortletConfig(), themeDisplay.getLocale(), "onlinetaskactivity.export.comment");

            writer.writeNext(cabeceras);
            DynamicQuery dq=DynamicQueryFactoryUtil.forClass(LearningActivityResult.class);
            Criterion criterion=PropertyFactoryUtil.forName("actId").eq(actId);
            dq.add(criterion);

            //Partiremos del usuario para crear el csv para que sea más facil ver los intentos.
            List<LearningActivityResult> listresult = LearningActivityResultLocalServiceUtil.dynamicQuery(dq);
            for(LearningActivityResult learningActivityResult:listresult){
                //Array con los resultados de los intentos.
                String[] resultados = new String[4];
                //En la primera columna del csv introducidos el nombre del estudiante.
                resultados[0] = UserLocalServiceUtil.getUser(learningActivityResult.getUserId()).getScreenName();
                resultados[1] = _dateFormat.format(learningActivityResult.getEndDate());
                resultados[2] = ct.translate(themeDisplay.getLocale(), themeDisplay.getScopeGroupId(), learningActivityResult.getResult());
                resultados[3] = learningActivityResult.getComments()!=null?learningActivityResult.getComments():"";

                //Escribimos las respuestas obtenidas para el intento en el csv.
                writer.writeNext(resultados);
            }
            writer.flush();
            writer.close();
            resourceResponse.getPortletOutputStream().flush();
            resourceResponse.getPortletOutputStream().close();

        } catch (NestableException e) {

        }finally{
            resourceResponse.getPortletOutputStream().flush();
            resourceResponse.getPortletOutputStream().close();
        }
    } 
}
项目:liferaylms-portlet    文件:CompetenceLocalServiceImpl.java   
@Indexable(type=IndexableType.REINDEX)
public Competence addCompetence (String title, String description,boolean generateCertificate,ServiceContext serviceContext)
        throws SystemException, PortalException 
        {
    long userId=serviceContext.getUserId();
    Competence competence = competencePersistence.create(counterLocalService.increment(Competence.class.getName()));    
        competence.setCompanyId(serviceContext.getCompanyId());
        competence.setGroupId(serviceContext.getScopeGroupId());
        competence.setDiplomaTemplate(ParamUtil.getString(serviceContext.getRequest(),"template",StringPool.BLANK ),serviceContext.getLocale());
        competence.setDiplomaBackground(ParamUtil.getLong(serviceContext.getRequest(), "diplomaBackground", 0));
        competence.setDiplomaAdditional(ParamUtil.getLong(serviceContext.getRequest(), "diplomaAdditional", 0));
        competence.setGenerateCertificate(generateCertificate);
        competence.setUserId(userId);
        competence.setDescription(description,serviceContext.getLocale());
        competence.setTitle(title,serviceContext.getLocale());
        competence.setStatus(WorkflowConstants.STATUS_APPROVED);
        competence.setExpandoBridgeAttributes(serviceContext);
        competence.setPage((String)serviceContext.getAttribute("page"));
        competencePersistence.update(competence, true);


        competence = LmsLocaleUtil.checkDefaultLocale(Competence.class, competence, "title");
        competence = LmsLocaleUtil.checkDefaultLocale(Competence.class, competence, "description");

        try
        {
        resourceLocalService.addResources(serviceContext.getCompanyId(), serviceContext.getScopeGroupId(),
                userId,Competence.class.getName(), competence.getPrimaryKey(), false,true, true);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        AssetEntryLocalServiceUtil.updateEntry(userId, competence.getGroupId(), Competence.class.getName(),
                competence.getCompetenceId(), competence.getUuid(),0, serviceContext.getAssetCategoryIds(),
                serviceContext.getAssetTagNames(), true, null, null,new java.util.Date(System.currentTimeMillis()), null,
                ContentTypes.TEXT_HTML, competence.getTitle(),
                competence.getDescription(serviceContext.getLocale()), competence.getDescription(serviceContext.getLocale()),
                null, null, 0, 0,null, false);
        //creating group
    return competence;


}
项目:inline-edit-journal-hook    文件:EditArticle.java   
protected void writeJSON(
    PortletRequest portletRequest, ActionResponse actionResponse,
    Object json)
    throws IOException {

    HttpServletResponse response =
        PortalUtil.getHttpServletResponse(actionResponse);

    response.setContentType(ContentTypes.APPLICATION_JSON);

    ServletResponseUtil.write(response, json.toString());

    response.flushBuffer();

    setForward(portletRequest, COMMON_NULL);
}
项目:liferay-dummy-factory    文件:CategoryMVCResourceCommand.java   
@Override
protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {
    String serializedJson = "";

    serializedJson = getCategoryList(resourceRequest, resourceResponse);

    HttpServletResponse response = _portal.getHttpServletResponse(resourceResponse);

    response.setContentType(ContentTypes.APPLICATION_JSON);

    ServletResponseUtil.write(response, serializedJson);
}