List of usage examples for org.apache.commons.lang3 StringUtils replace
public static String replace(final String text, final String searchString, final String replacement)
Replaces all occurrences of a String within another String.
A null reference passed to this method is a no-op.
StringUtils.replace(null, *, *) = null StringUtils.replace("", *, *) = "" StringUtils.replace("any", null, *) = "any" StringUtils.replace("any", *, null) = "any" StringUtils.replace("any", "", *) = "any" StringUtils.replace("aba", "a", null) = "aba" StringUtils.replace("aba", "a", "") = "b" StringUtils.replace("aba", "a", "z") = "zbz"
From source file:com.hiperf.common.ui.server.storage.impl.PersistenceHelper.java
@Override public String checkExists(String className, com.hiperf.common.ui.shared.util.Id id, String attribute, String value, Locale locale) throws PersistenceException { EntityManager em = null;// w ww . j a va 2 s . com try { Set<PropertyDescriptor> ids = idsByClassName.get(className); PropertyDescriptor[] idsArr = (PropertyDescriptor[]) ids.toArray(new PropertyDescriptor[0]); em = getEntityManager(); int i; if (value != null) { boolean isNumber = false; boolean isString = false; PropertyDescriptor[] pds = (PropertyDescriptor[]) propertyDescriptorsByClassName.get(className); Class<?> propertyType; for (PropertyDescriptor pd : pds) { if (pd.getName().equals(attribute)) { propertyType = pd.getPropertyType(); if ((propertyType.isPrimitive()) || (Number.class.isAssignableFrom(propertyType))) { isNumber = true; break; } if (!(String.class.isAssignableFrom(propertyType))) break; isString = true; break; } } StringBuilder q = getCheckExistsQuery(className, attribute, value, isNumber, isString); q.append(" and o."); i = 0; for (String att : id.getFieldNames()) { q.append(att); q.append(" != "); if (StorageService.isNumber(att, idsArr)) { q.append(id.getFieldValues().get(i)); } else { q.append(" '").append(StringUtils.replace(id.getFieldValues().get(i).toString(), "'", "''")) .append("'"); } ++i; if (i < id.getFieldNames().size()) q.append(" and o."); } Query q1 = em.createQuery(q.toString()); if (isString) q1.setParameter(1, value.toLowerCase()); List l = q1.getResultList(); if ((l != null) && (l.size() > 0)) { return getUniqueErrorMsg(attribute, value, locale); } return null; } StringBuilder q = new StringBuilder( "select 1 from " + className + " o where o." + attribute + " is null and o."); i = 0; for (String att : id.getFieldNames()) { q.append(att); q.append(" != "); if (StorageService.isNumber(att, idsArr)) { q.append(id.getFieldValues().get(i)); } else { q.append(" '"); q.append(StringUtils.replace(id.getFieldValues().get(i).toString(), "'", "''")); q.append("'"); } ++i; if (i < id.getFieldNames().size()) q.append(" and o."); } List l = em.createQuery(q.toString()).getResultList(); if ((l != null) && (l.size() > 0)) { return getUniqueErrorMsg(attribute, value, locale); } return null; } catch (Exception e) { logger.log(Level.SEVERE, "Exception in checkExists " + e.getMessage(), e); throw new PersistenceException("Exception in checkExists " + e.getMessage(), e); } finally { closeEntityManager(em); } }
From source file:com.xpn.xwiki.doc.XWikiDocument.java
/** * Extract all the unique static (i.e. not generated by macros) wiki links (pointing to wiki page) from this 1.0 * document's content to others documents. * //from www . ja va 2s .com * @param context the XWiki context. * @return the document names for linked pages, if null an error append. * @since 1.9M2 */ private Set<String> getUniqueLinkedPages10(XWikiContext context) { Set<String> pageNames; try { List<String> list = context.getUtil().getUniqueMatches(getContent(), "\\[(.*?)\\]", 1); pageNames = new HashSet<String>(list.size()); DocumentReference currentDocumentReference = getDocumentReference(); for (String name : list) { int i1 = name.indexOf('>'); if (i1 != -1) { name = name.substring(i1 + 1); } i1 = name.indexOf(">"); if (i1 != -1) { name = name.substring(i1 + 4); } i1 = name.indexOf('#'); if (i1 != -1) { name = name.substring(0, i1); } i1 = name.indexOf('?'); if (i1 != -1) { name = name.substring(0, i1); } // Let's get rid of anything that's not a real link if (name.trim().equals("") || (name.indexOf('$') != -1) || (name.indexOf("://") != -1) || (name.indexOf('"') != -1) || (name.indexOf('\'') != -1) || (name.indexOf("..") != -1) || (name.indexOf(':') != -1) || (name.indexOf('=') != -1)) { continue; } // generate the link String newname = StringUtils.replace(Util.noaccents(name), " ", ""); // If it is a local link let's add the space if (newname.indexOf('.') == -1) { newname = getSpace() + "." + name; } if (context.getWiki().exists(newname, context)) { name = newname; } else { // If it is a local link let's add the space if (name.indexOf('.') == -1) { name = getSpace() + "." + name; } } // If the reference is empty, the link is an autolink if (!StringUtils.isEmpty(name)) { // The reference may not have the space or even document specified (in case of an empty // string) // Thus we need to find the fully qualified document name DocumentReference documentReference = this.currentDocumentReferenceResolver.resolve(name); // Verify that the link is not an autolink (i.e. a link to the current document) if (!documentReference.equals(currentDocumentReference)) { pageNames.add(this.compactEntityReferenceSerializer.serialize(documentReference)); } } } return pageNames; } catch (Exception e) { // This should never happen LOGGER.error("Failed to get linked documents", e); return null; } }
From source file:com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration.java
/** * Gets the CSS property value./*w w w . j a v a 2 s .c o m*/ * @param name the name of the property to retrieve * @return the value */ @JsxFunction(@WebBrowser(FF)) public CSSValue getPropertyCSSValue(final String name) { LOG.info("getPropertyCSSValue(" + name + "): getPropertyCSSValue support is experimental"); // following is a hack, just to have basic support for getPropertyCSSValue // TODO: rework the whole CSS processing here! we should *always* parse the style! if (styleDeclaration_ == null) { final String uri = getDomNodeOrDie().getPage().getWebResponse().getWebRequest().getUrl() .toExternalForm(); final String styleAttribute = jsElement_.getDomNodeOrDie().getAttribute("style"); final InputSource source = new InputSource(new StringReader(styleAttribute)); source.setURI(uri); final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); parser.setErrorHandler(errorHandler); try { styleDeclaration_ = parser.parseStyleDeclaration(source); } catch (final IOException e) { throw new RuntimeException(e); } } org.w3c.dom.css.CSSValue cssValue = styleDeclaration_.getPropertyCSSValue(name); if (cssValue == null) { final CSSValueImpl newValue = new CSSValueImpl(); newValue.setFloatValue(CSSPrimitiveValue.CSS_PX, 0); cssValue = newValue; } // FF has spaces next to "," final String cssText = cssValue.getCssText(); if (cssText.startsWith("rgb(")) { final String formatedCssText = StringUtils.replace(cssText, ",", ", "); cssValue.setCssText(formatedCssText); } return new CSSPrimitiveValue(jsElement_, (org.w3c.dom.css.CSSPrimitiveValue) cssValue); }
From source file:com.sonicle.webtop.mail.Service.java
public void processGetReplyMessage(HttpServletRequest request, HttpServletResponse response, PrintWriter out) { MailAccount account = getAccount(request); UserProfile profile = environment.getProfile(); //WebTopApp webtopapp=environment.getWebTopApp(); String pfoldername = request.getParameter("folder"); String puidmessage = request.getParameter("idmessage"); String preplyall = request.getParameter("replyall"); boolean replyAll = false; if (preplyall != null && preplyall.equals("1")) { replyAll = true;//w ww.j av a 2 s . c om } String sout = null; try { String format = us.getFormat(); boolean isHtml = format.equals("html"); account.checkStoreConnected(); FolderCache mcache = account.getFolderCache(pfoldername); Message m = mcache.getMessage(Long.parseLong(puidmessage)); if (m.isExpunged()) { throw new MessagingException("Message " + puidmessage + " expunged"); } int newmsgid = getNewMessageID(); SimpleMessage smsg = getReplyMsg(getNewMessageID(), account, m, replyAll, account.isSentFolder(pfoldername), isHtml, profile.getEmailAddress(), mprofile.isIncludeMessageInReply(), lookupResource(MailLocaleKey.MSG_FROMTITLE), lookupResource(MailLocaleKey.MSG_TOTITLE), lookupResource(MailLocaleKey.MSG_CCTITLE), lookupResource(MailLocaleKey.MSG_DATETITLE), lookupResource(MailLocaleKey.MSG_SUBJECTTITLE)); sout = "{\n result: true,"; Identity ident = mprofile.getIdentity(pfoldername); String inreplyto = smsg.getInReplyTo(); String references[] = smsg.getReferences(); sout += " replyfolder: '" + StringEscapeUtils.escapeEcmaScript(pfoldername) + "',"; if (inreplyto != null) { sout += " inreplyto: '" + StringEscapeUtils.escapeEcmaScript(inreplyto) + "',"; } if (references != null) { String refs = ""; for (String s : references) { refs += StringEscapeUtils.escapeEcmaScript(s) + " "; } sout += " references: '" + refs.trim() + "',"; } String subject = smsg.getSubject(); sout += " subject: '" + StringEscapeUtils.escapeEcmaScript(subject) + "',\n"; sout += " recipients: [\n"; String tos[] = smsg.getTo().split(";"); boolean first = true; for (String to : tos) { if (!first) { sout += ",\n"; } sout += " {rtype:'to',email:'" + StringEscapeUtils.escapeEcmaScript(to) + "'}"; first = false; } String ccs[] = smsg.getCc().split(";"); for (String cc : ccs) { if (!first) { sout += ",\n"; } sout += " {rtype:'cc',email:'" + StringEscapeUtils.escapeEcmaScript(cc) + "'}"; first = false; } sout += "\n ],\n"; sout += " identityId: " + ident.getIdentityId() + ",\n"; sout += " origuid:" + puidmessage + ",\n"; if (isHtml) { String html = smsg.getContent(); //cid inline attachments and relative html href substitution HTMLMailData maildata = mcache.getMailData((MimeMessage) m); first = true; sout += " attachments: [\n"; for (int i = 0; i < maildata.getAttachmentPartCount(); ++i) { try { Part part = maildata.getAttachmentPart(i); String filename = getPartName(part); String cids[] = part.getHeader("Content-ID"); if (cids != null && cids[0] != null) { String cid = cids[0]; if (cid.startsWith("<")) cid = cid.substring(1); if (cid.endsWith(">")) cid = cid.substring(0, cid.length() - 1); String mime = MailUtils.getMediaTypeFromHeader(part.getContentType()); UploadedFile upfile = addAsUploadedFile("" + newmsgid, filename, mime, part.getInputStream()); if (!first) { sout += ",\n"; } sout += "{ " + " uploadId: '" + StringEscapeUtils.escapeEcmaScript(upfile.getUploadId()) + "', " + " fileName: '" + StringEscapeUtils.escapeEcmaScript(filename) + "', " + " cid: '" + StringEscapeUtils.escapeEcmaScript(cid) + "', " + " inline: true, " + " fileSize: " + upfile.getSize() + ", " + " editable: " + isFileEditableInDocEditor(filename) + " " + " }"; first = false; //TODO: change this weird matching of cids2urls! html = StringUtils.replace(html, "cid:" + cid, "service-request?csrf=" + getEnv().getCSRFToken() + "&service=" + SERVICE_ID + "&action=PreviewAttachment&nowriter=true&uploadId=" + upfile.getUploadId() + "&cid=" + cid); } } catch (Exception exc) { Service.logger.error("Exception", exc); } } sout += "\n ],\n"; sout += " content:'" + StringEscapeUtils.escapeEcmaScript(html) + "',\n"; } else { String text = smsg.getTextContent(); sout += " content:'" + StringEscapeUtils.escapeEcmaScript(text) + "',\n"; } sout += " format:'" + format + "'\n"; sout += "\n}"; } catch (Exception exc) { Service.logger.error("Exception", exc); sout = "{\nresult: false, text:'" + StringEscapeUtils.escapeEcmaScript(exc.getMessage()) + "'\n}"; } if (sout != null) { out.println(sout); } }
From source file:com.sonicle.webtop.mail.Service.java
public void processGetForwardMessage(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {//from w w w . j a va2 s.com MailAccount account = getAccount(request); UserProfile profile = environment.getProfile(); String pfoldername = request.getParameter("folder"); String puidmessage = request.getParameter("idmessage"); String pnewmsgid = request.getParameter("newmsgid"); String pattached = request.getParameter("attached"); boolean attached = (pattached != null && pattached.equals("1")); long newmsgid = Long.parseLong(pnewmsgid); String sout = null; try { String format = us.getFormat(); boolean isHtml = format.equals("html"); account.checkStoreConnected(); FolderCache mcache = account.getFolderCache(pfoldername); Message m = mcache.getMessage(Long.parseLong(puidmessage)); if (m.isExpunged()) { throw new MessagingException("Message " + puidmessage + " expunged"); } SimpleMessage smsg = getForwardMsg(newmsgid, m, isHtml, lookupResource(MailLocaleKey.MSG_FROMTITLE), lookupResource(MailLocaleKey.MSG_TOTITLE), lookupResource(MailLocaleKey.MSG_CCTITLE), lookupResource(MailLocaleKey.MSG_DATETITLE), lookupResource(MailLocaleKey.MSG_SUBJECTTITLE), attached); sout = "{\n result: true,"; Identity ident = mprofile.getIdentity(pfoldername); String forwardedfrom = smsg.getForwardedFrom(); sout += " forwardedfolder: '" + StringEscapeUtils.escapeEcmaScript(pfoldername) + "',"; if (forwardedfrom != null) { sout += " forwardedfrom: '" + StringEscapeUtils.escapeEcmaScript(forwardedfrom) + "',"; } String subject = smsg.getSubject(); sout += " subject: '" + StringEscapeUtils.escapeEcmaScript(subject) + "',\n"; String html = smsg.getContent(); String text = smsg.getTextContent(); if (!attached) { HTMLMailData maildata = mcache.getMailData((MimeMessage) m); boolean first = true; sout += " attachments: [\n"; for (int i = 0; i < maildata.getAttachmentPartCount(); ++i) { try { Part part = maildata.getAttachmentPart(i); String filename = getPartName(part); if (!part.isMimeType("message/*")) { String cids[] = part.getHeader("Content-ID"); String cid = null; //String cid=filename; if (cids != null && cids[0] != null) { cid = cids[0]; if (cid.startsWith("<")) cid = cid.substring(1); if (cid.endsWith(">")) cid = cid.substring(0, cid.length() - 1); } if (filename == null) filename = cid; String mime = MailUtils.getMediaTypeFromHeader(part.getContentType()); UploadedFile upfile = addAsUploadedFile(pnewmsgid, filename, mime, part.getInputStream()); boolean inline = false; if (part.getDisposition() != null) { inline = part.getDisposition().equalsIgnoreCase(Part.INLINE); } if (!first) { sout += ",\n"; } sout += "{ " + " uploadId: '" + StringEscapeUtils.escapeEcmaScript(upfile.getUploadId()) + "', " + " fileName: '" + StringEscapeUtils.escapeEcmaScript(filename) + "', " + " cid: " + (cid == null ? null : "'" + StringEscapeUtils.escapeEcmaScript(cid) + "'") + ", " + " inline: " + inline + ", " + " fileSize: " + upfile.getSize() + ", " + " editable: " + isFileEditableInDocEditor(filename) + " " + " }"; first = false; //TODO: change this weird matching of cids2urls! html = StringUtils.replace(html, "cid:" + cid, "service-request?csrf=" + getEnv().getCSRFToken() + "&service=" + SERVICE_ID + "&action=PreviewAttachment&nowriter=true&uploadId=" + upfile.getUploadId() + "&cid=" + cid); } } catch (Exception exc) { Service.logger.error("Exception", exc); } } sout += "\n ],\n"; //String surl = "service-request?service="+SERVICE_ID+"&action=PreviewAttachment&nowriter=true&newmsgid=" + newmsgid + "&cid="; //html = replaceCidUrls(html, maildata, surl); } else { String filename = m.getSubject() + ".eml"; UploadedFile upfile = addAsUploadedFile(pnewmsgid, filename, "message/rfc822", ((IMAPMessage) m).getMimeStream()); sout += " attachments: [\n"; sout += "{ " + " uploadId: '" + StringEscapeUtils.escapeEcmaScript(upfile.getUploadId()) + "', " + " fileName: '" + StringEscapeUtils.escapeEcmaScript(filename) + "', " + " cid: null, " + " inline: false, " + " fileSize: " + upfile.getSize() + ", " + " editable: " + isFileEditableInDocEditor(filename) + " " + " }"; sout += "\n ],\n"; } sout += " identityId: " + ident.getIdentityId() + ",\n"; sout += " origuid:" + puidmessage + ",\n"; if (isHtml) { sout += " content:'" + StringEscapeUtils.escapeEcmaScript(html) + "',\n"; } else { sout += " content:'" + StringEscapeUtils.escapeEcmaScript(text) + "',\n"; } sout += " format:'" + format + "'\n"; sout += "\n}"; out.println(sout); } 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 processGetEditMessage(HttpServletRequest request, HttpServletResponse response, PrintWriter out) { MailAccount account = getAccount(request); String pfoldername = request.getParameter("folder"); String puidmessage = request.getParameter("idmessage"); String pnewmsgid = request.getParameter("newmsgid"); long newmsgid = Long.parseLong(pnewmsgid); String sout = null;/*from w w w. j a va 2 s . c o m*/ try { MailEditFormat editFormat = ServletUtils.getEnumParameter(request, "format", null, MailEditFormat.class); if (editFormat == null) editFormat = EnumUtils.forSerializedName(us.getFormat(), MailEditFormat.HTML, MailEditFormat.class); boolean isPlainEdit = MailEditFormat.PLAIN_TEXT.equals(editFormat); account.checkStoreConnected(); FolderCache mcache = account.getFolderCache(pfoldername); IMAPMessage m = (IMAPMessage) mcache.getMessage(Long.parseLong(puidmessage)); m.setPeek(us.isManualSeen()); //boolean wasseen = m.isSet(Flags.Flag.SEEN); String vheader[] = m.getHeader("Disposition-Notification-To"); boolean receipt = false; int priority = 3; boolean recipients = false; boolean toDelete = false; if (account.isDraftsFolder(pfoldername)) { if (vheader != null && vheader[0] != null) { receipt = true; } priority = getPriority(m); recipients = true; //if autosaved drafts, delete String values[] = m.getHeader(HEADER_X_WEBTOP_MSGID); if (values != null && values.length > 0) { try { long msgId = Long.parseLong(values[0]); if (msgId > 0) { toDelete = true; } } catch (NumberFormatException exc) { } } } sout = "{\n result: true,"; String subject = m.getSubject(); if (subject == null) { subject = ""; } sout += " subject: '" + StringEscapeUtils.escapeEcmaScript(subject) + "',\n"; String inreplyto = null; String references[] = null; String vs[] = m.getHeader("In-Reply-To"); if (vs != null && vs[0] != null) { inreplyto = vs[0]; } references = m.getHeader("References"); if (inreplyto != null) { vs = m.getHeader("Sonicle-reply-folder"); String replyfolder = null; if (vs != null && vs[0] != null) { replyfolder = vs[0]; } if (replyfolder != null) { sout += " replyfolder: '" + StringEscapeUtils.escapeEcmaScript(replyfolder) + "',"; } sout += " inreplyto: '" + StringEscapeUtils.escapeEcmaScript(inreplyto) + "',"; } if (references != null) { String refs = ""; for (String s : references) { refs += StringEscapeUtils.escapeEcmaScript(s) + " "; } sout += " references: '" + refs.trim() + "',"; } String forwardedfrom = null; vs = m.getHeader("Forwarded-From"); if (vs != null && vs[0] != null) { forwardedfrom = vs[0]; } if (forwardedfrom != null) { vs = m.getHeader("Sonicle-forwarded-folder"); String forwardedfolder = null; if (vs != null && vs[0] != null) { forwardedfolder = vs[0]; } if (forwardedfolder != null) { sout += " forwardedfolder: '" + StringEscapeUtils.escapeEcmaScript(forwardedfolder) + "',"; } sout += " forwardedfrom: '" + StringEscapeUtils.escapeEcmaScript(forwardedfrom) + "',"; } sout += " receipt: " + receipt + ",\n"; sout += " priority: " + (priority >= 3 ? false : true) + ",\n"; Identity ident = null; Address from[] = m.getFrom(); InternetAddress iafrom = null; if (from != null && from.length > 0) { iafrom = (InternetAddress) from[0]; String email = iafrom.getAddress(); String displayname = iafrom.getPersonal(); if (displayname == null) displayname = email; //sout+=" from: { email: '"+StringEscapeUtils.escapeEcmaScript(email)+"', displayname: '"+StringEscapeUtils.escapeEcmaScript(displayname)+"' },\n"; ident = mprofile.getIdentity(displayname, email); } sout += " recipients: [\n"; if (recipients) { Address tos[] = m.getRecipients(RecipientType.TO); String srec = ""; if (tos != null) { for (Address to : tos) { if (srec.length() > 0) { srec += ",\n"; } srec += " { " + "rtype: 'to', " + "email: '" + StringEscapeUtils.escapeEcmaScript(getDecodedAddress(to)) + "'" + " }"; } } Address ccs[] = m.getRecipients(RecipientType.CC); if (ccs != null) { for (Address cc : ccs) { if (srec.length() > 0) { srec += ",\n"; } srec += " { " + "rtype: 'cc', " + "email: '" + StringEscapeUtils.escapeEcmaScript(getDecodedAddress(cc)) + "'" + " }"; } } Address bccs[] = m.getRecipients(RecipientType.BCC); if (bccs != null) { for (Address bcc : bccs) { if (srec.length() > 0) { srec += ",\n"; } srec += " { " + "rtype: 'bcc', " + "email: '" + StringEscapeUtils.escapeEcmaScript(getDecodedAddress(bcc)) + "'" + " }"; } } sout += srec; } else { sout += " { " + "rtype: 'to', " + "email: ''" + " }"; } sout += " ],\n"; String html = ""; boolean balanceTags = isPreviewBalanceTags(iafrom); ArrayList<String> htmlparts = mcache.getHTMLParts((MimeMessage) m, newmsgid, true, balanceTags); for (String xhtml : htmlparts) { html += xhtml + "<BR><BR>"; } HTMLMailData maildata = mcache.getMailData((MimeMessage) m); //if(!wasseen){ // if (us.isManualSeen()) { // m.setFlag(Flags.Flag.SEEN, false); // } //} boolean first = true; sout += " attachments: [\n"; for (int i = 0; i < maildata.getAttachmentPartCount(); ++i) { Part part = maildata.getAttachmentPart(i); String filename = getPartName(part); String cids[] = part.getHeader("Content-ID"); String cid = null; //String cid=filename; if (cids != null && cids[0] != null) { cid = cids[0]; if (cid.startsWith("<")) cid = cid.substring(1); if (cid.endsWith(">")) cid = cid.substring(0, cid.length() - 1); } if (filename == null) { filename = cid; } String mime = part.getContentType(); UploadedFile upfile = addAsUploadedFile(pnewmsgid, filename, mime, part.getInputStream()); boolean inline = false; if (part.getDisposition() != null) { inline = part.getDisposition().equalsIgnoreCase(Part.INLINE); } if (!first) { sout += ",\n"; } sout += "{ " + " uploadId: '" + StringEscapeUtils.escapeEcmaScript(upfile.getUploadId()) + "', " + " fileName: '" + StringEscapeUtils.escapeEcmaScript(filename) + "', " + " cid: " + (cid == null ? null : "'" + StringEscapeUtils.escapeEcmaScript(cid) + "'") + ", " + " inline: " + inline + ", " + " fileSize: " + upfile.getSize() + " " + " }"; first = false; //TODO: change this weird matching of cids2urls! html = StringUtils.replace(html, "cid:" + cid, "service-request?csrf=" + getEnv().getCSRFToken() + "&service=" + SERVICE_ID + "&action=PreviewAttachment&nowriter=true&uploadId=" + upfile.getUploadId() + "&cid=" + cid); } sout += "\n ],\n"; if (ident != null) sout += " identityId: " + ident.getIdentityId() + ",\n"; sout += " origuid:" + puidmessage + ",\n"; sout += " deleted:" + toDelete + ",\n"; sout += " folder:'" + pfoldername + "',\n"; sout += " content:'" + (isPlainEdit ? StringEscapeUtils.escapeEcmaScript(MailUtils.htmlToText(MailUtils.htmlunescapesource(html))) : StringEscapeUtils.escapeEcmaScript(html)) + "',\n"; sout += " format:'" + EnumUtils.toSerializedName(editFormat) + "'\n"; sout += "\n}"; m.setPeek(false); if (toDelete) { m.setFlag(Flags.Flag.DELETED, true); m.getFolder().expunge(); } out.println(sout); } catch (Exception exc) { Service.logger.error("Exception", exc); sout = "{\nresult: false, text:'" + StringEscapeUtils.escapeEcmaScript(exc.getMessage()) + "'\n}"; } }
From source file:net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory.java
private String cleanup(String message, Object[] args) { if (message != null) { // Escape PMD specific variable message format, specifically the { // in the ${, so MessageFormat doesn't bitch. final String escapedMessage = StringUtils.replace(message, "${", "$'{'"); return MessageFormat.format(escapedMessage, args != null ? args : NO_ARGS); } else {//from w w w. j a v a 2s. c o m return message; } }
From source file:net.theblackchamber.crypto.implementations.SecureProperties.java
/** * @see java.util.Properties#setProperty(java.lang.String, java.lang.String) * If property key ends in -unencrypted this method will attempt to * encrypt the value prior to adding it. If the property key is * "key-path" then the encryption will be re-initialized using the * specified key. NOTE: If you specify key-path its important to have * FIRST specified entry-name and keystore-password or an error will * occur./* www. ja va 2 s . c o m*/ * @throws RuntimeCryptoException * If no encryption key was configured. This usually happens * when no key was successfully loaded. */ @Override public synchronized Object setProperty(String key, String value) { if (StringUtils.equalsIgnoreCase("key-path", key)) { super.setProperty(key, value); loadKeystore(); initializeEncryptionProvider(); } String property = attemptEncryption(key, value); if (!StringUtils.equals(property, value)) { key = StringUtils.replace(key, UNENCRYPTED_SUFFIX, ENCRYPTED_SUFFIX); } return super.setProperty(key, property); }
From source file:nl.imvertor.common.file.XmlFile.java
/** * Replace special characters in XML string. * // w w w . j av a 2 s . co m * @param s * @return */ private String safe(String s) { s = StringUtils.replace(s, "&", "&"); s = StringUtils.replace(s, "<", "<"); s = StringUtils.replace(s, ">", ">"); s = StringUtils.replace(s, "\"", """); return s; }
From source file:nl.imvertor.ConceptCollector.ConceptCollector.java
/** * run the main translation/*w w w .ja va2 s.c o m*/ */ public boolean run() { try { // set up the configuration for this step configurator.setActiveStepName(STEP_NAME); prepare(); // determine the path of the concepts file // This is the file holding imvert representation of all concepts // The parameter file holds a name in which the release date is placed between [YYYYMMDD]. String infoConceptsFilePath = StringUtils.replace( configurator.getParm("properties", "CONCEPT_DOCUMENTATION_PATH"), "[release]", configurator.getParm("appinfo", "release")); infoConceptsFile = new XmlFile(infoConceptsFilePath); configurator.setParm("appinfo", "concepts-file", infoConceptsFile.getCanonicalPath()); // determine if concepts must be read. // This is when forced, of when the concepts file is not available, or when the application phase is 3 (final). boolean forc = configurator.isTrue("cli", "refreshconcepts"); boolean must = (!infoConceptsFile.isFile() || !infoConceptsFile.isWellFormed() || infoConceptsFile.xpath("//*:concept").equals("")); boolean finl = configurator.getParm("appinfo", "phase").equals("3"); if (forc) configurator.setParm("appinfo", "concepts-extraction-reason", "forced by user"); if (must) configurator.setParm("appinfo", "concepts-extraction-reason", "must be refreshed"); if (finl) configurator.setParm("appinfo", "concepts-extraction-reason", "final release"); if (forc || must || finl) { runner.info(logger, "Collecting concepts"); configurator.setParm("appinfo", "concepts-extraction", "true"); // This implementation accsses the internet, and reads RDF statements. Check if internet s avilable. if (!runner.activateInternet()) runner.fatal(logger, "Cannot access the internet, cannot read concepts", null); // create a transformer Transformer transformer = new Transformer(); // transform; if anything goes wrong remove the concept file so that next time try again. //IM-216 boolean succeeds = true; //TODO this extracts the RDF XML to a location in the managed output folder. Better is to check the common managed input folder, copy that and procesds, or recomnpile when not available in common input folder? boolean okay = transformer.transformStep("system/cur-imvertor-filepath", "appinfo/concepts-file", "properties/IMVERTOR_EXTRACTCONCEPTS_XSLPATH"); if (okay) configurator.setParm("appinfo", "concepts-extraction-succeeds", "true"); else { configurator.setParm("appinfo", "concepts-extraction-succeeds", "false"); infoConceptsFile.delete(); } succeeds = succeeds ? okay : false; configurator.setStepDone(STEP_NAME); } else { configurator.setParm("appinfo", "concepts-extraction", "false"); configurator.setParm("appinfo", "concepts-extraction-reason", "precompiled"); configurator.setParm("appinfo", "concepts-extraction-succeeds", "true"); } // save any changes to the work configuration for report and future steps configurator.save(); // generate report report(); return runner.succeeds(); } catch (Exception e) { runner.fatal(logger, "Step fails by system error.", e); return false; } }