Example usage for org.apache.commons.lang StringUtils replace

List of usage examples for org.apache.commons.lang StringUtils replace

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils replace.

Prototype

public static String replace(String text, String searchString, String replacement) 

Source Link

Document

Replaces all occurrences of a String within another String.

Usage

From source file:info.magnolia.jcr.wrapper.HTMLEscapingContentDecorator.java

public String decorate(String raw) {
    final String str = StringEscapeUtils.escapeHtml(raw);
    if (transformLineBreaks) {
        return StringUtils.replace(str, "\n", "<br/>");
    }/*  w w w  . j av  a 2  s. c  om*/
    return str;

}

From source file:com.qualogy.qafe.bind.io.document.LocalXSDResolver.java

private String mergeIncludes(String xsdWithIncludes, List<IncludeSchemaToReplace> includeSchemaToReplaces) {
    String xsdWithoutIncludes = xsdWithIncludes;
    for (IncludeSchemaToReplace includeSchemaToReplace : includeSchemaToReplaces) {
        xsdWithoutIncludes = StringUtils.replace(xsdWithoutIncludes, includeSchemaToReplace.includeToReplace,
                includeSchemaToReplace.includeXSD);
    }//w  w w  . j  ava2s .c  o m
    return xsdWithoutIncludes;
}

From source file:eionet.cr.web.action.admin.endpointquery.EndpointResourceActionBean.java

/**
 *
 * @return/*from w ww  . j av a 2s .c o  m*/
 * @throws DAOException
 */
@DefaultHandler
public Resolution defaultHandler() throws DAOException {

    if (StringUtils.isBlank(url) || StringUtils.isBlank(endpoint)) {
        return new ErrorResolution(400, "Missing URL of resource or endpoint!");
    } else {
        String query = StringUtils.replace(QUERY_TEMPLATE, "URL", url);
        queryResult = DAOFactory.get().getDao(EndpointHarvestQueryDAO.class).testConstructQuery(query,
                endpoint);
        return new ForwardResolution(REMOTE_RESOURCE_JSP);
    }
}

From source file:com.broadwave.android.brut.androlib.res.data.value.ResPluralsValue.java

@Override
public void serializeToResValuesXml(XmlSerializer serializer, ResResource res)
        throws IOException, AndrolibException {
    serializer.startTag(null, "plurals");
    serializer.attribute(null, "name", res.getResSpec().getName());
    for (int i = 0; i < mItems.length; i++) {
        ResScalarValue item = mItems[i];
        if (item == null) {
            continue;
        }//w  w w . jav a  2s  . co m

        ResScalarValue rawValue = item;

        serializer.startTag(null, "item");
        serializer.attribute(null, "quantity", QUANTITY_MAP[i]);
        if (ResXmlEncoders.hasMultipleNonPositionalSubstitutions(rawValue.encodeAsResXmlValue())) {
            serializer.text(item.encodeAsResXmlValueExt());
        } else {
            String recode = item.encodeAsResXmlValue();
            // Dirty, but working fix @miuirussia
            for (int j = 0; j < 10; j++) {
                recode = StringUtils.replace(recode,
                        "%" + Integer.toString(j) + "$" + Integer.toString(j) + "$",
                        "%" + Integer.toString(j) + "$");
            }
            serializer.text(recode);
        }
        serializer.endTag(null, "item");
    }
    serializer.endTag(null, "plurals");
}

From source file:com.doculibre.constellio.wicket.panels.results.MailDetailsPanel.java

public MailDetailsPanel(String id, final Email email) {
    super(id, new CompoundPropertyModel(email));

    add(new Label("froms").setEscapeModelStrings(false));

    String messageContentText = email.getMessageContentHtml();
    String text = email.getMessageContentText();
    //FIXME : hack car les fichiers textes attachs sont ajout comme contenu texte
    if (text.length() > messageContentText.length()) {
        messageContentText = text;/* w  ww. j  a va2s  .co  m*/
    }

    messageContentText = StringUtils.replace(messageContentText, ">>", "&gt;&gt;");
    messageContentText = StringUtils.replace(messageContentText, "\n>", "\n&gt;");
    messageContentText = StringUtils.replace(messageContentText, "\n", "\n<br />");

    //      String encodedString;
    //      try {
    //         encodedString = new String(messageContentText.getBytes(), email.getContentEncoding());
    //      } catch (UnsupportedEncodingException e) {
    //         // TODO Auto-generated catch block
    //         e.printStackTrace();
    //         encodedString = messageContentText;
    //      }
    //      add(new Label("messageContent", encodedString).setEscapeModelStrings(false));

    add(new Label("messageContent", messageContentText).setEscapeModelStrings(false));

    add(new ListView("linksList", email.getAttachments()) {
        @Override
        protected void populateItem(final ListItem item) {
            final Email.AttachmentClass element = (Email.AttachmentClass) item.getModelObject();

            final AJAXDownload download = new AJAXDownload() {
                @Override
                protected IResourceStream getResourceStream() {
                    return createResourceStream(element);
                }

                @Override
                protected String getFileName() {
                    return element.getAttachmentName();
                }

                private IResourceStream createResourceStream(final Email.AttachmentClass element) {
                    IResourceStream resourceStream = new IResourceStream() {
                        private Locale locale = null;
                        private InputStream inputStream = null;

                        @Override
                        public void close() throws IOException {
                            if (inputStream != null) {
                                IOUtils.closeQuietly(inputStream);
                            }
                        }

                        @Override
                        public String getContentType() {
                            return element.getAttachmentType();
                        }

                        @Override
                        public InputStream getInputStream() throws ResourceStreamNotFoundException {
                            if (inputStream == null) {
                                inputStream = new ByteArrayInputStream(element.getAttachmentContent());
                            }
                            return inputStream;
                        }

                        @Override
                        public Locale getLocale() {
                            return locale;
                        }

                        @Override
                        public long length() {
                            return ((Integer) element.getAttachmentContent().length).longValue();
                        }

                        @Override
                        public void setLocale(Locale locale) {
                            this.locale = locale;
                        }

                        @Override
                        public Time lastModifiedTime() {
                            // TODO Auto-generated method stub
                            return null;
                        }

                    };
                    return resourceStream;
                }
            };
            item.add(download);

            AjaxLink link;
            item.add(link = new AjaxLink("attachmentLinks") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    download.initiate(target);
                }
            });
            link.add(new Label("urlTitle", element.getAttachmentName()));

            /*Link link;
            add(link = new DownloadInputStreamLink("attachmentLinks",
                  new LoadableDetachableModel() {
             @Override
             protected Object load() {
                ByteArrayInputStream in = new ByteArrayInputStream(
                      element.getAttachmentContent());
                return in;
             }
                    
                  }, element.getAttachmentName(), element
                .getAttachmentType(),
                  ((Integer) element.getAttachmentContent().length)
                .longValue(), new Date()));
            link.add(new Label("urlTitle", element.getAttachmentName()));*/
            item.add(link);
        }
    });

    add(new Label("recipients").setEscapeModelStrings(false));

    //FIXME 1 by 1
    String flags = StringUtils.join(email.getFlags(), ", ");
    //FIXME i18n
    flags = StringUtils.replace(flags, "seen", getLocalizer().getString("seen", this));
    flags = StringUtils.replace(flags, "flagged", getLocalizer().getString("flagged", this));
    add(new Label("flags", flags).setEscapeModelStrings(false));

    //      add(new Label("folderNames").setEscapeModelStrings(false));
    add(new Label("receivedDate").setEscapeModelStrings(false));

}

From source file:com.mmj.app.biz.service.impl.FileServiceImpl.java

@Override
public Result delFileByPath(String filePath) {
    if (StringUtils.isEmpty(filePath)) {
        return Result.failed();
    }//  ww  w  .  j a  v  a  2 s  .c  om
    filePath = StringUtils.replace(filePath, STATIC_TMP_IMG, StringUtils.EMPTY);
    String tmpPath = UPLOAD_BASE_PATH.replaceAll(STATIC_BASE_IMG, "");
    File file = new File(tmpPath + filePath);
    if (file == null || file.isFile()) {
        FileUtils.deleteQuietly(file);
        return Result.success("?", null);
    }
    return Result.failed();
}

From source file:com.swtxml.events.registry.WidgetEventListenerMethod.java

public String getName() {
    if (StyledText.class == listenerAddMethod.getDeclaringClass()
            && ExtendedModifyListener.class == getListenerInterfaceClass()) {
        return "extendedModifyText";
    }/*  ww w  . jav  a  2s.c  om*/
    if (Browser.class == listenerAddMethod.getDeclaringClass()) {
        return StringUtils
                .uncapitalize(StringUtils.replace(getListenerInterfaceClass().getSimpleName(), "Listener", ""))
                + StringUtils.capitalize(listenerMethod.getName());
    }
    return listenerMethod.getName();
}

From source file:com.sfs.whichdoctor.beans.IsbPayloadBean.java

/**
 * Gets the tabbed xml payload.//w ww.  ja  va2  s  .com
 *
 * @return the tabbed xml payload
 */
private String getTabbedXmlPayload() {
    String htmlPayload = DataFilter.getHtml(getXmlPayload());

    return StringUtils.replace(htmlPayload, "  ", "&nbsp;&nbsp;&nbsp;");
}

From source file:com.tupilabs.pbs.parser.QstatJobsParser.java

@Override
public List<Job> parse(String text) throws ParseException {
    final List<Job> jobs;
    if (StringUtils.isNotBlank(text)) {
        text = StringUtils.replace(text, "\n\t", "");
        jobs = new LinkedList<Job>();
        String separator = "\n";
        if (text.indexOf("\r\n") > 0) {
            separator = "\r\n";
        }//from   w w  w  .  j  ava2s.  com
        final String[] lines = text.split(separator);
        Job job = null;
        for (final String line : lines) {
            Matcher matcher = PATTERN_JOB.matcher(line);
            if (matcher.matches()) {
                if (job != null) {
                    jobs.add(job);
                }
                job = new Job();
                final String id = matcher.group(1).trim();
                job.setId(id);
            } else if (StringUtils.isNotBlank(line)) {
                String[] temp = Utils.splitFirst(line, CHAR_EQUALS);
                if (temp.length == 2) {
                    final String key = temp[0].trim().toLowerCase();
                    final String value = temp[1].trim();
                    if ("job_name".equalsIgnoreCase(key)) {
                        job.setName(value);
                    } else if ("job_owner".equalsIgnoreCase(key)) {
                        job.setOwner(value);
                    } else if (key.startsWith("resources_used.")) {
                        job.getResourcesUsed().put(key, value);
                    } else if ("job_state".equalsIgnoreCase(key)) {
                        job.setState(value);
                    } else if ("queue".equalsIgnoreCase(key)) {
                        job.setQueue(value);
                    } else if ("server".equalsIgnoreCase(key)) {
                        job.setServer(value);
                    } else if ("checkpoint".equalsIgnoreCase(key)) {
                        job.setCheckpoint(value);
                    } else if ("ctime".equalsIgnoreCase(key)) {
                        job.setCtime(value);
                    } else if ("error_path".equalsIgnoreCase(key)) {
                        job.setErrorPath(value);
                    } else if ("exec_host".equalsIgnoreCase(key)) {
                        job.setExecHost(value);
                    } else if ("exec_port".equalsIgnoreCase(key)) {
                        job.setExecPort(value);
                    } else if ("hold_types".equalsIgnoreCase(key)) {
                        job.setHoldTypes(value);
                    } else if ("join_path".equalsIgnoreCase(key)) {
                        job.setJoinPath(value);
                    } else if ("keep_files".equalsIgnoreCase(key)) {
                        job.setKeepFiles(value);
                    } else if ("mail_points".equalsIgnoreCase(key)) {
                        job.setMailPoints(value);
                    } else if ("mail_users".equalsIgnoreCase(key)) {
                        job.setMailUsers(value);
                    } else if ("mtime".equalsIgnoreCase(key)) {
                        job.setMtime(value);
                    } else if ("output_path".equalsIgnoreCase(key)) {
                        job.setOutputPath(value);
                    } else if ("priority".equalsIgnoreCase(key)) {
                        try {
                            job.setPriority(Integer.parseInt(value));
                        } catch (NumberFormatException nfe) {
                            LOGGER.log(Level.WARNING, "Failed parsing job priority: " + nfe.getMessage(), nfe);
                            job.setPriority(-1);
                        }
                    } else if ("qtime".equalsIgnoreCase(key)) {
                        job.setQtime(value);
                    } else if ("rerunable".equalsIgnoreCase(key)) {
                        job.setRerunable(Boolean.parseBoolean(value));
                    } else if (key.startsWith("resource_list.")) {
                        job.getResourceList().put(key, value);
                    } else if ("session_id".equalsIgnoreCase(key)) {
                        try {
                            job.setSessionId(Integer.parseInt(value));
                        } catch (NumberFormatException nfe) {
                            LOGGER.log(Level.WARNING, "Failed parsing job session id: " + nfe.getMessage(),
                                    nfe);
                            job.setSessionId(-1);
                        }
                    } else if ("substate".equalsIgnoreCase(key)) {
                        try {
                            job.setSubstate(Integer.parseInt(value));
                        } catch (NumberFormatException nfe) {
                            LOGGER.log(Level.WARNING, "Failed parsing job substate: " + nfe.getMessage(), nfe);
                            job.setSubstate(-1);
                        }
                    } else if (key.startsWith("variable_list")) {
                        job.getVariableList().put(key, value);
                    } else if ("etime".equalsIgnoreCase(key)) {
                        job.setEtime(value);
                    } else if ("euser".equalsIgnoreCase(key)) {
                        job.setEuser(value);
                    } else if ("egroup".equalsIgnoreCase(key)) {
                        job.setEgroup(value);
                    } else if ("hashname".equalsIgnoreCase(key)) {
                        job.setHashName(value);
                    } else if ("queue_rank".equalsIgnoreCase(key)) {
                        try {
                            job.setQueueRank(Integer.parseInt(value));
                        } catch (NumberFormatException nfe) {
                            LOGGER.log(Level.WARNING, "Failed parsing job queue rank: " + nfe.getMessage(),
                                    nfe);
                            job.setQueueRank(-1);
                        }
                    } else if ("queue_type".equalsIgnoreCase(key)) {
                        job.setQueueType(value);
                    } else if ("comment".equalsIgnoreCase(key)) {
                        job.setComment(value);
                    } else if ("submit_args".equalsIgnoreCase(key)) {
                        job.setSubmitArgs(value);
                    } else if ("submit_host".equalsIgnoreCase(key)) {
                        job.setSubmitHost(value);
                    } else if ("start_time".equalsIgnoreCase(key)) {
                        job.setStartTime(value);
                    } else if ("start_count".equalsIgnoreCase(key)) {
                        try {
                            job.setStartCount(Integer.parseInt(value));
                        } catch (NumberFormatException nfe) {
                            LOGGER.log(Level.WARNING, "Failed parsing job start count: " + nfe.getMessage(),
                                    nfe);
                            job.setStartCount(-1);
                        }
                    } else if ("fault_tolerant".equalsIgnoreCase(key)) {
                        job.setFaultTolerant(Boolean.parseBoolean(value));
                    } else if ("job_array_id".equalsIgnoreCase(key)) {
                        job.setJobArrayId(Integer.parseInt(value));
                    } else if ("job_radix".equalsIgnoreCase(key)) {
                        try {
                            job.setRadix(Integer.parseInt(value));
                        } catch (NumberFormatException nfe) {
                            LOGGER.log(Level.WARNING, "Failed parsing job radix: " + nfe.getMessage(), nfe);
                            job.setRadix(-1);
                        }
                    } else if ("walltime.remaining".equalsIgnoreCase(key)) {
                        try {
                            job.setWalltimeRemaining(Long.parseLong(value));
                        } catch (NumberFormatException nfe) {
                            LOGGER.log(Level.WARNING,
                                    "Failed parsing job walltime remaining: " + nfe.getMessage(), nfe);
                            job.setWalltimeRemaining(-1L);
                        }
                    }
                }
            }
        }
        if (job != null) {
            jobs.add(job);
        }
        return jobs;
    } else {
        return Collections.emptyList();
    }
}

From source file:com.mobileman.filter.SecurityCheckFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {

    HttpServletRequest rq1 = (HttpServletRequest) request;
    String requestURI = rq1.getRequestURI().toLowerCase();
    DataHolder holder = new DataHolder(rq1);
    boolean error = false;
    if (requestURI.contains("/patient/")) {
        //check patient loaded         
        if (!holder.isPatient()) {
            error = true;/*from   w w  w.  j  ava2s.com*/
        }
    } else if (requestURI.contains("/arzt/")) {
        //check doctor loaded
        if (!holder.isDoctor()) {
            error = true;
        }
    } else if (requestURI.contains("/admin/") && !requestURI.contains("/admin/anmeldung")) {
        //check admin loaded
        if (!holder.isAdmin()) {
            error = true;
        }
    }

    ///////////////
    if (requestURI.contains("/public")) {
        //redirect to /behandlung
        StringBuffer sb = rq1.getRequestURL();
        String newUrl = StringUtils.replace(sb.toString(), "/public", "/behandlung");
        java.io.PrintWriter out = response.getWriter();
        response.setContentType("text/html");

        out.println("<html>");
        out.println("<head>");
        out.println("<meta http-equiv=\"refresh\" content=\"0;url=");
        out.print(newUrl);
        out.println("\" />");
        out.println("</head>");
        out.println("<body>");
        out.println("</body>");
        out.println("</html>");

        return;
    }

    if (error) {
        //redirect
        request.getRequestDispatcher("/").forward(request, response);
        return;
    }
    filterChain.doFilter(request, response);
}