Example usage for org.apache.commons.lang3 StringEscapeUtils escapeEcmaScript

List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeEcmaScript

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils escapeEcmaScript.

Prototype

public static final String escapeEcmaScript(final String input) 

Source Link

Document

Escapes the characters in a String using EcmaScript String rules.

Escapes any values it finds into their EcmaScript String form.

Usage

From source file:cloudlens.parser.ASTBuilder.java

@Override
public Void visitRegex(CloudLensParser.RegexContext ctx) {
    visitChildren(ctx);//  www  . j  av  a  2s.c  o  m
    final List<String> rg = new ArrayList<>();
    if (ctx.IDENT() != null) {
        rg.add(ctx.IDENT().getText());
    } else if (ctx.STRING() != null) {
        final int a = ctx.start.getStartIndex();
        final int b = ctx.stop.getStopIndex();
        // remove opening and closing "."
        final Interval interval = new Interval(a + 1, b - 1);
        final CharStream source = ctx.start.getInputStream();
        final String r = source.getText(interval);
        rg.add("\"" + StringEscapeUtils.escapeEcmaScript(r) + "\"");
    } else if (ctx.regex() != null) {
        for (final RegexContext r : ctx.regex()) {
            rg.add(r.ast);
        }
    }
    ctx.ast = StringUtils.join(rg, "+");
    return null;
}

From source file:com.vmware.identity.openidconnect.server.AuthenticationRequestProcessor.java

private ModelAndView generateLoginForm() throws ServerException {
    AuthorizationServerInfo authzServerInfo = this.serverInfoRetriever.retrieveAuthorizationServerInfo();

    this.model.addAttribute("spn",
            StringEscapeUtils.escapeEcmaScript(authzServerInfo.getServicePrincipalName()));

    this.model.addAttribute("protocol", "openidconnect");
    this.model.addAttribute("cac_endpoint", "/openidconnect/oidc/cac");
    this.model.addAttribute("sso_endpoint", "/openidconnect/oidc/authorize");
    this.model.addAttribute("responseMode", this.authnRequest.getResponseMode().getValue());

    this.model.addAttribute("tenant", this.tenant);
    this.model.addAttribute("tenant_brandname",
            StringEscapeUtils.escapeEcmaScript(this.tenantInfo.getBrandName()));
    this.model.addAttribute("tenant_logonbanner_title",
            StringEscapeUtils.escapeEcmaScript(this.tenantInfo.getLogonBannerTitle()));
    this.model.addAttribute("tenant_logonbanner_content",
            StringEscapeUtils.escapeEcmaScript(this.tenantInfo.getLogonBannerContent()));
    this.model.addAttribute("enable_logonbanner_checkbox", this.tenantInfo.getLogonBannerEnableCheckbox());

    this.model.addAttribute("username_placeholder", localize("LoginForm.UserName.Placeholder"));
    this.model.addAttribute("username", localize("LoginForm.UserName"));
    this.model.addAttribute("password", localize("LoginForm.Password"));
    this.model.addAttribute("passcode", localize("LoginForm.Passcode"));
    this.model.addAttribute("submit", localize("LoginForm.Submit"));
    this.model.addAttribute("error", localize("LoginForm.Error"));
    this.model.addAttribute("login", localize("LoginForm.Login"));
    this.model.addAttribute("help", localize("LoginForm.Help"));
    this.model.addAttribute("winSession", localize("LoginForm.WinSession"));
    this.model.addAttribute("downloadCIP", localize("LoginForm.DownloadCIP"));
    this.model.addAttribute("unsupportedBrowserWarning", localize("LoginForm.UnsupportedBrowserWarning"));
    this.model.addAttribute("smartcard", localize("LoginForm.Smartcard"));
    this.model.addAttribute("iAgreeTo", localize("LoginForm.IAgreeTo"));
    this.model.addAttribute("logonBannerAlertMessage", localize("LoginForm.LogonBannerAlertMessage"));
    this.model.addAttribute("rsaam", localize("LoginForm.RsaSecurID"));

    this.model.addAttribute("enable_password_auth", this.tenantInfo.getAuthnPolicy().isPasswordAuthnEnabled());
    this.model.addAttribute("enable_windows_auth", this.tenantInfo.getAuthnPolicy().isWindowsAuthnEnabled());
    this.model.addAttribute("enable_tlsclient_auth",
            this.tenantInfo.getAuthnPolicy().isClientCertAuthnEnabled());
    this.model.addAttribute("enable_rsaam_auth", this.tenantInfo.getAuthnPolicy().isSecurIDAuthnEnabled());

    if (this.tenantInfo.getAuthnPolicy().isSecurIDAuthnEnabled()) {
        this.model.addAttribute("rsaam_reminder",
                StringEscapeUtils.escapeEcmaScript(this.tenantInfo.getAuthnPolicy().getSecurIDLoginGuide()));
    }//from   w  w w  .ja va2  s  . com

    return new ModelAndView("unpentry");
}

From source file:de.blizzy.documentr.web.FunctionsTest.java

@Test
public void escapeJavaScript() {
    assertEquals(StringEscapeUtils.escapeEcmaScript("\"'{}"), Functions.escapeJavaScript("\"'{}")); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:com.netsteadfast.greenstep.util.MenuSupportUtils.java

/**
 * ??/*from  w  ww.j  a v  a 2 s . c o  m*/
 * 
 * @param basePath
 * @param sys
 * @return
 * @throws ServiceException
 * @throws Exception
 */
public static Map<String, String> getMenuData(String basePath, TbSys sys, String jsessionId, String localeCode)
        throws ServiceException, Exception {
    Map<String, String> menuData = new HashMap<String, String>();
    List<SysMenuVO> menuList = loadSysMenuData(sys.getSysId());
    if (menuList == null || menuList.size() < 1) {
        return menuData;
    }
    StringBuilder htmlSb = new StringBuilder();
    StringBuilder jsSb = new StringBuilder();
    StringBuilder dlgSb = new StringBuilder();
    Map<String, String> jsFunctionMap = new HashMap<String, String>();

    /*
    for (SysMenuVO sysMenu : menuList) { // create combobox menu javascript
       if (!YesNo.YES.equals(sysMenu.getEnableFlag())) {
    continue;
       }
       if (TYPE_IS_FOLDER.equals(sysMenu.getItemType())) { // ?? 
    continue;
       }
       String openTabFn = sysMenu.getProgId() + "_TabShow()";
       String refreshTabFn = sysMenu.getProgId() + "_TabRefresh()";
       String closeTabFn = sysMenu.getProgId() + "_TabClose()";
       String tabId = sysMenu.getProgId() + "_ChildTab";   
       jsSb.append("function ").append( openTabFn ).append(" { ");
       jsSb.append("   viewPage.addOrUpdateContentPane(   ");
       jsSb.append("      '").append(Constants.MAIN_TabContainer_ID).append("',   ");
       jsSb.append("      '").append(tabId).append("',   ");
       jsSb.append("      '").append( StringEscapeUtils.escapeEcmaScript(IconUtils.getMenuIcon(basePath, sysMenu.getIcon()) ) ).append(StringEscapeUtils.escapeEcmaScript(sysMenu.getName())).append("',   ");
       jsSb.append("      '").append( getUrl(basePath, sys, sysMenu, jsessionId) ).append("',   ");         
       jsSb.append("      true,   ");
       jsSb.append("      true");
       jsSb.append("   );   ");
       jsSb.append("}   ");
       jsSb.append("\n");
       jsSb.append("function ").append( refreshTabFn ).append(" { ");
       jsSb.append("   viewPage.refreshContentPane('").append(tabId).append("'); ");
       jsSb.append("}   ");
       jsSb.append("\n");
       jsSb.append("function ").append( closeTabFn ).append(" { ");
       jsSb.append("   viewPage.closeContentPane('").append(Constants.MAIN_TabContainer_ID).append("', '").append(tabId).append("'); ");
       jsSb.append("}   ");
       jsSb.append("\n");         
       jsFunctionMap.put(sysMenu.getProgId(), openTabFn );
    }
    */
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("progSystem", sys.getSysId());
    List<TbSysProg> sysProgList = sysProgService.findListByParams(params);
    for (int i = 0; sysProgList != null && i < sysProgList.size(); i++) {
        TbSysProg sysProg = sysProgList.get(i);
        if (MenuItemType.FOLDER.equals(sysProg.getItemType())) { // ?? 
            continue;
        }
        String openTabFn = sysProg.getProgId() + "_TabShow()";
        if (YesNo.YES.equals(sysProg.getEditMode())) {
            openTabFn = sysProg.getProgId() + "_TabShow(oid)";
        }
        String refreshTabFn = sysProg.getProgId() + "_TabRefresh()";
        String closeTabFn = sysProg.getProgId() + "_TabClose()";
        String tabId = sysProg.getProgId() + "_ChildTab";
        boolean iframeMode = false;
        if (YesNo.YES.equals(sysProg.getIsWindow())) {
            iframeMode = true;
        }
        String progMultiName = getProgramMultiName(sysProg, localeCode);
        jsSb.append("function ").append(openTabFn).append(" { ");
        jsSb.append("   viewPage.addOrUpdateContentPane(   ");
        jsSb.append("      '").append(Constants.MAIN_TabContainer_ID).append("',   ");
        jsSb.append("      '").append(tabId).append("',   ");
        //jsSb.append("      '").append( StringEscapeUtils.escapeEcmaScript(IconUtils.getMenuIcon(basePath, sysProg.getIcon()) ) ).append(StringEscapeUtils.escapeEcmaScript(sysProg.getName())).append("',   ");
        jsSb.append("      '")
                .append(StringEscapeUtils.escapeEcmaScript(IconUtils.getMenuIcon(basePath, sysProg.getIcon())))
                .append(StringEscapeUtils.escapeEcmaScript(progMultiName)).append("',   "); // ???
        if (YesNo.YES.equals(sysProg.getEditMode())) { // Edit ?
            jsSb.append("      '").append(getUrl(basePath, sys, sysProg, jsessionId))
                    .append("&fields.oid=' + oid,   ");
        } else { // Query  Create ?
            jsSb.append("      '").append(getUrl(basePath, sys, sysProg, jsessionId)).append("',   ");
        }
        jsSb.append("      true,   ");
        jsSb.append("      true,   ");
        jsSb.append("   ").append(String.valueOf(iframeMode)).append("   ");
        jsSb.append("   );   ");
        jsSb.append("}   ");
        jsSb.append("\n");
        jsSb.append("function ").append(refreshTabFn).append(" { ");
        jsSb.append("   viewPage.refreshContentPane('").append(tabId).append("'); ");
        jsSb.append("}   ");
        jsSb.append("\n");
        jsSb.append("function ").append(closeTabFn).append(" { ");
        jsSb.append("   viewPage.closeContentPane('").append(Constants.MAIN_TabContainer_ID).append("', '")
                .append(tabId).append("'); ");
        jsSb.append("}   ");
        jsSb.append("\n");
        //jsSb.append(Constants.GS_GET_APPLICATION_NAME_SCRIPT_OBJ).append("['").append( sysProg.getProgId() ).append("'] = '").append( StringEscapeUtils.escapeEcmaScript( sysProg.getName() ) ).append("';");
        jsSb.append(Constants.GS_GET_APPLICATION_NAME_SCRIPT_OBJ).append("['").append(sysProg.getProgId())
                .append("'] = '").append(StringEscapeUtils.escapeEcmaScript(progMultiName)).append("';"); // ???
        jsSb.append("\n");
        jsFunctionMap.put(sysProg.getProgId(), openTabFn);

        String dlgId = "";
        if (YesNo.YES.equals(sysProg.getIsDialog())) {
            dlgId = sysProg.getProgId() + "_Dlg";
        }
        if (!StringUtils.isBlank(dlgId)) { //  dialog 
            dlgSb.append("<div id=\"" + dlgId + "\" data-dojo-type=\"dojox.widget.DialogSimple\" ")
                    .append("data-dojo-props='href:\"").append(getUrl(basePath, sys, sysProg, jsessionId))
                    .append("\",").append("   style:\"width: ").append(sysProg.getDialogW())
                    .append("px; height: ").append(sysProg.getDialogH()).append("px\",")
                    //.append("   title:\"").append( IconUtils.getMenuIcon(basePath, sysProg.getIcon()).replaceAll("'", "\\\\\"") ).append( StringEscapeUtils.escapeEcmaScript(sysProg.getName()) ).append("\",")
                    .append("   title:\"")
                    .append(IconUtils.getMenuIcon(basePath, sysProg.getIcon()).replaceAll("'", "\\\\\""))
                    .append(StringEscapeUtils.escapeEcmaScript(progMultiName)).append("\",") // ???
                    .append("   refreshOnShow:\"true\", executeScripts:\"true\" ").append(" '></div>")
                    .append("\n");
            String dlgOpenFn = sysProg.getProgId() + "_DlgShow()";
            String dlgHideFn = sysProg.getProgId() + "_DlgHide()";
            if (YesNo.YES.equals(sysProg.getEditMode())) {
                dlgOpenFn = sysProg.getProgId() + "_DlgShow(oid)";
            }
            jsSb.append("function ").append(dlgOpenFn).append(" { ");
            String dlgUrl = "";
            if (YesNo.YES.equals(sysProg.getEditMode())) { // Edit ?               
                dlgUrl = "'" + getUrl(basePath, sys, sysProg, jsessionId) + "&fields.oid=' + oid; ";
                jsSb.append("   var dlgUrl=").append(dlgUrl);
                jsSb.append("   dijit.byId('").append(dlgId).append("').set('href', dlgUrl); ");
            }
            jsSb.append("   dijit.byId('").append(dlgId).append("').show();   ");
            jsSb.append("}   ");
            jsSb.append("\n");
            jsSb.append("function ").append(dlgHideFn).append(" { ");
            jsSb.append("   dijit.byId('").append(dlgId).append("').hide();   ");
            jsSb.append("}   ");
            jsSb.append("\n");
        }

    }

    // create combobox menu html
    htmlSb.append("<div data-dojo-type='dijit.PopupMenuItem' >");
    //htmlSb.append("   <span>").append( IconUtils.getMenuIcon(basePath, sys.getIcon()) ).append(sys.getName()).append("</span>");      
    htmlSb.append("   <span>").append(IconUtils.getMenuIcon(basePath, sys.getIcon()))
            .append(getSystemMultiName(sys, localeCode)).append("</span>"); // 
    List<SysMenuVO> parentSysMenuList = searchFolder(menuList);
    htmlSb.append("<div dojoType='dijit.Menu' >");
    for (SysMenuVO sysMenu : parentSysMenuList) {
        List<SysMenuVO> itemSysMenuList = searchItem(sysMenu.getOid(), menuList);
        if (itemSysMenuList == null || itemSysMenuList.size() < 1) {
            continue;
        }
        String multiProgName = getProgramMultiName(sysMenu, localeCode);
        htmlSb.append("<div data-dojo-type='dijit.PopupMenuItem' >");
        //htmlSb.append("<span>").append( IconUtils.getMenuIcon(basePath, sysMenu.getIcon()) ).append(sysMenu.getName()).append("</span>");
        htmlSb.append("<span>").append(IconUtils.getMenuIcon(basePath, sysMenu.getIcon())).append(multiProgName)
                .append("</span>"); // 
        htmlSb.append("<div data-dojo-type='dijit.Menu' >");
        for (SysMenuVO itemMenu : itemSysMenuList) {
            String itemMultiProgName = getProgramMultiName(itemMenu, localeCode);
            htmlSb.append("<div data-dojo-type='dijit.MenuItem' data-dojo-props='onClick:function(){ ")
                    .append(StringUtils.defaultString(jsFunctionMap.get(itemMenu.getProgId()))).append(" }'>")
                    .append(IconUtils.getMenuIcon(basePath, itemMenu.getIcon()))
                    //.append(itemMenu.getName())
                    .append(itemMultiProgName) // 
                    .append("</div>");
        }
        htmlSb.append("</div>");
        htmlSb.append("</div>");
    }
    htmlSb.append("</div>");
    htmlSb.append("</div>");

    menuData.put(MENU_ITEM_JAVASCRIPT, jsSb.toString());
    menuData.put(MENU_ITEM_HTML, htmlSb.toString());
    menuData.put(MENU_ITEM_DIALOG, dlgSb.toString());
    return menuData;
}

From source file:com.xavax.json.JSON.java

/**
 * Append a JSON field value to the builder.
 *
 * @param builder  the string builder used for output.
 * @param format   the format for formatting the JSON.
 * @param level    the indentation level.
 * @param value    the value to append./*  w w  w  .  j  a  v  a2  s  . c o  m*/
 */
public static void appendValue(final StringBuilder builder, final Format format, final int level,
        final Object value) {
    if (value instanceof JSON) {
        ((JSON) value).toString(builder, format, level);
    } else if (value instanceof JSONArray) {
        ((JSONArray) value).toString(builder, format, level);
    } else if (value instanceof String) {
        final String string = StringEscapeUtils.escapeEcmaScript((String) value);
        builder.append(format.quoteString).append(string).append(format.quoteString);
    } else {
        builder.append(value);
    }
}

From source file:com.addthis.hydra.job.web.resources.JobsResource.java

private static Response buildServerError(Exception exception) {
    log.warn("", exception);
    String message = exception.getMessage();
    if (message == null) {
        message = exception.toString();/* w  w  w . j a  v a  2 s  .  c  om*/
    }
    final String response = "{" + "\"error\": \"A java exception was thrown.\", " + "\"message\": \""
            + StringEscapeUtils.escapeEcmaScript(message) + "\"" + "}";
    return Response.serverError().entity(response).build();
}

From source file:com.sonicle.webtop.mail.Service.java

public void processMoveMessages(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
    MailAccount fromaccount = getAccount(request.getParameter("fromaccount"));
    String fromfolder = request.getParameter("fromfolder");
    MailAccount toaccount = getAccount(request.getParameter("toaccount"));
    String tofolder = request.getParameter("tofolder");
    String allfiltered = request.getParameter("allfiltered");
    String smultifolder = request.getParameter("multifolder");
    boolean multifolder = smultifolder != null && smultifolder.equals("true");
    String sfullthreads = request.getParameter("fullthreads");
    boolean fullthreads = sfullthreads != null && sfullthreads.equals("true");
    String uids[] = null;/*from w  w  w.j ava2s . c om*/
    String sout = null;
    boolean archiving = false;
    try {
        fromaccount.checkStoreConnected();
        toaccount.checkStoreConnected();
        FolderCache mcache = fromaccount.getFolderCache(fromfolder);
        FolderCache tomcache = toaccount.getFolderCache(tofolder);
        String foldertrash = toaccount.getFolderTrash();
        String folderspam = toaccount.getFolderSpam();
        String folderarchive = toaccount.getFolderArchive();

        //check if tofolder is my Spam, and there is spamadm, move there
        if (toaccount.isSpamFolder(tofolder)) {
            String spamadmSpam = ss.getSpamadmSpam();
            if (spamadmSpam != null) {
                folderspam = spamadmSpam;
                FolderCache fc = toaccount.getFolderCache(spamadmSpam);
                if (fc != null)
                    tomcache = fc;
            } else if (toaccount.isUnderSharedFolder(fromfolder)) {
                String mainfolder = toaccount.getMainSharedFolder(fromfolder);
                if (mainfolder != null) {
                    folderspam = mainfolder + toaccount.getFolderSeparator()
                            + toaccount.getLastFolderName(folderspam);
                    FolderCache fc = toaccount.getFolderCache(folderspam);
                    if (fc != null)
                        tomcache = fc;
                }
            }
            tofolder = folderspam;
        }
        //if trashing, check for shared profile trash
        else if (toaccount.isTrashFolder(tofolder)) {
            if (toaccount.isUnderSharedFolder(fromfolder)) {
                String mainfolder = toaccount.getMainSharedFolder(fromfolder);
                if (mainfolder != null) {
                    foldertrash = mainfolder + toaccount.getFolderSeparator()
                            + toaccount.getLastFolderName(foldertrash);
                    FolderCache fc = toaccount.getFolderCache(foldertrash);
                    if (fc != null)
                        tomcache = fc;
                }
            }
            tofolder = foldertrash;
        }
        //if archiving, determine destination folder based on settings and shared profile
        else if (toaccount.isArchiveFolder(tofolder)) {
            if (toaccount.isUnderSharedFolder(fromfolder)) {
                String mainfolder = toaccount.getMainSharedFolder(fromfolder);
                if (mainfolder != null) {
                    folderarchive = mainfolder + toaccount.getFolderSeparator()
                            + toaccount.getLastFolderName(folderarchive);
                }
            }
            tofolder = folderarchive;
            archiving = true;
        }

        if (allfiltered == null) {
            uids = request.getParameterValues("ids");
            boolean norows = false;
            if (uids.length == 1 && uids[0].length() == 0)
                norows = true;
            if (!norows) {
                if (!multifolder) {
                    if (archiving)
                        archiveMessages(mcache, folderarchive, toLongs(uids), fullthreads);
                    else
                        moveMessages(mcache, tomcache, toLongs(uids), fullthreads);
                } else {
                    long iuids[] = new long[1];
                    for (String uid : uids) {
                        int ix = uid.indexOf("|");
                        fromfolder = uid.substring(0, ix);
                        uid = uid.substring(ix + 1);
                        mcache = fromaccount.getFolderCache(fromfolder);
                        iuids[0] = Long.parseLong(uid);
                        if (archiving)
                            archiveMessages(mcache, folderarchive, iuids, fullthreads);
                        else
                            moveMessages(mcache, tomcache, iuids, fullthreads);
                    }
                }
            }
            long millis = System.currentTimeMillis();
            sout = "{\nresult: true, millis: " + millis + ", tofolder: '"
                    + StringEscapeUtils.escapeEcmaScript(tofolder) + "', archiving: " + archiving + "\n}";
        } else {
            uids = getMessageUIDs(mcache, request);
            if (archiving)
                archiveMessages(mcache, folderarchive, toLongs(uids), fullthreads);
            else
                moveMessages(mcache, tomcache, toLongs(uids), fullthreads);
            tomcache.refreshUnreads();
            mcache.setForceRefresh();
            long millis = System.currentTimeMillis();
            sout = "{\nresult: true, unread: " + tomcache.getUnreadMessagesCount() + ", millis: " + millis
                    + ", tofolder: '" + StringEscapeUtils.escapeEcmaScript(tofolder) + "', archiving: "
                    + archiving + "\n}";
        }
    } catch (Exception exc) {
        Service.logger.error("Exception", exc);
        sout = "{\nresult: false, text:'" + StringEscapeUtils.escapeEcmaScript(exc.getMessage()) + "'\n}";
    }
    out.println(sout);
}

From source file:com.sonicle.webtop.mail.Service.java

public void processCopyMessages(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
    MailAccount fromaccount = getAccount(request.getParameter("fromaccount"));
    String fromfolder = request.getParameter("fromfolder");
    MailAccount toaccount = getAccount(request.getParameter("toaccount"));
    String tofolder = request.getParameter("tofolder");
    String allfiltered = request.getParameter("allfiltered");
    String smultifolder = request.getParameter("multifolder");
    boolean multifolder = smultifolder != null && smultifolder.equals("true");
    String sfullthreads = request.getParameter("fullthreads");
    boolean fullthreads = sfullthreads != null && sfullthreads.equals("true");
    String sout = null;/*from  w w  w. j  av  a 2  s .c  o m*/
    String uids[] = null;
    try {
        fromaccount.checkStoreConnected();
        toaccount.checkStoreConnected();
        FolderCache mcache = fromaccount.getFolderCache(fromfolder);
        FolderCache tomcache = toaccount.getFolderCache(tofolder);
        if (allfiltered == null) {
            uids = request.getParameterValues("ids");
            if (!multifolder)
                copyMessages(mcache, tomcache, toLongs(uids), fullthreads);
            else {
                long iuids[] = new long[1];
                for (String uid : uids) {
                    int ix = uid.indexOf("|");
                    fromfolder = uid.substring(0, ix);
                    uid = uid.substring(ix + 1);
                    mcache = fromaccount.getFolderCache(fromfolder);
                    iuids[0] = Long.parseLong(uid);
                    copyMessages(mcache, tomcache, iuids, fullthreads);
                }
            }
            long millis = System.currentTimeMillis();
            sout = "{\nresult: true, millis: " + millis + "\n}";
        } else {
            uids = getMessageUIDs(mcache, request);
            copyMessages(mcache, tomcache, toLongs(uids), fullthreads);
            tomcache.refreshUnreads();
            mcache.setForceRefresh();
            long millis = System.currentTimeMillis();
            sout = "{\nresult: true, unread: " + tomcache.getUnreadMessagesCount() + ", millis: " + millis
                    + "\n}";
        }
    } catch (Exception exc) {
        Service.logger.error("Exception", exc);
        sout = "{\nresult: false, text:'" + StringEscapeUtils.escapeEcmaScript(exc.getMessage()) + "'\n}";
    }
    out.println(sout);
}

From source file:com.sonicle.webtop.mail.Service.java

public void processDmsArchiveMessages(HttpServletRequest request, HttpServletResponse response,
        PrintWriter out) {//from  ww  w  . j  av a  2 s.c  o  m
    MailAccount account = getAccount(request);
    String fromfolder = request.getParameter("fromfolder");
    String tofolder = request.getParameter("tofolder");
    int ix = tofolder.indexOf("|");
    String idcategory = tofolder.substring(0, ix);
    String idsubcategory = tofolder.substring(ix + 1);
    String smultifolder = request.getParameter("multifolder");
    boolean multifolder = smultifolder != null && smultifolder.equals("true");
    String sfullthreads = request.getParameter("fullthreads");
    boolean fullthreads = sfullthreads != null && sfullthreads.equals("true");
    String uids[] = null;
    String sout = null;
    try {
        account.checkStoreConnected();
        FolderCache mcache = account.getFolderCache(fromfolder);
        uids = request.getParameterValues("ids");
        if (!multifolder)
            dmsArchiveMessages(mcache, toLongs(uids), idcategory, idsubcategory, fullthreads);
        else {
            long iuids[] = new long[1];
            for (String uid : uids) {
                ix = uid.indexOf("|");
                fromfolder = uid.substring(0, ix);
                uid = uid.substring(ix + 1);
                mcache = account.getFolderCache(fromfolder);
                iuids[0] = Integer.parseInt(uid);
                dmsArchiveMessages(mcache, iuids, idcategory, idsubcategory, fullthreads);
            }
        }
        long millis = System.currentTimeMillis();
        sout = "{\nresult: true, millis: " + millis + "\n}";
    } catch (Exception exc) {
        Service.logger.error("Exception", exc);
        sout = "{\nresult: false, text:'" + StringEscapeUtils.escapeEcmaScript(exc.getMessage()) + "'\n}";
    }
    out.println(sout);
}

From source file:com.sonicle.webtop.mail.Service.java

public void processDeleteMessages(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
    MailAccount account = getAccount(request);
    String fromfolder = request.getParameter("fromfolder");
    String allfiltered = request.getParameter("allfiltered");
    String smultifolder = request.getParameter("multifolder");
    boolean multifolder = smultifolder != null && smultifolder.equals("true");
    String sfullthreads = request.getParameter("fullthreads");
    boolean fullthreads = sfullthreads != null && sfullthreads.equals("true");
    String sout = null;/* ww w.j ava  2  s  .c o  m*/
    String uids[];
    try {
        account.checkStoreConnected();
        FolderCache mcache = account.getFolderCache(fromfolder);

        if (allfiltered == null) {
            uids = request.getParameterValues("ids");
            if (!multifolder) {
                deleteMessages(mcache, toLongs(uids), fullthreads);
            } else {
                long iuids[] = new long[1];
                for (String uid : uids) {
                    int ix = uid.indexOf("|");
                    fromfolder = uid.substring(0, ix);
                    uid = uid.substring(ix + 1);
                    mcache = account.getFolderCache(fromfolder);
                    iuids[0] = Long.parseLong(uid);
                    deleteMessages(mcache, iuids, fullthreads);
                }
            }
            sout = "{\nresult: true\n}";
        } else {
            uids = getMessageUIDs(mcache, request);
            deleteMessages(mcache, toLongs(uids), true);
            sout = "{\nresult: true\n}";
        }
    } catch (Exception exc) {
        Service.logger.error("Exception", exc);
        sout = "{\nresult: false, text:'" + StringEscapeUtils.escapeEcmaScript(exc.getMessage()) + "'\n}";
    }
    out.println(sout);
}