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.importexport.BootstrapUtil.java

/**
 * I.e. given a resource path like <code>/mgnl-bootstrap/foo/config.server.i18n.xml</code> it will return <code>/server/i18n</code>.
 */// ww  w  .  java2 s  .  c o  m
public static String getFullpathFromResource(final String resourcePath) {
    String resourceName = StringUtils.replace(resourcePath, "\\", "/");

    String name = getFilenameFromResource(resourceName, ".xml");
    String fullPath = DataTransporter.revertExportPath(name);
    String repository = StringUtils.substringBefore(fullPath, "/");

    return StringUtils.removeStart(fullPath, repository);
}

From source file:gov.nih.nci.cabig.caaers.domain.TreatmentAssignment.java

/**
 * Gets the html escaped description.//from  w  w  w.  jav a2s.c  o m
 *
 * @return the html escaped description
 */
@Transient
public String getHtmlEscapedDescription() {
    String descriptionHtml = StringUtils.replace(description, "\r\n", "<br>");
    return StringEscapeUtils.escapeJavaScript(descriptionHtml);
}

From source file:net.jonbuck.texteditor.dialog.TextEditorDialog.java

/**
 * {@inheritDoc}//from www.  j a  v a  2s .c  o  m
 */
@Override
protected Control createDialogArea(Composite parent) {

    getShell().setText(TextEditorMessages.shellTitle);

    Composite contents = (Composite) super.createDialogArea(parent);
    final GridLayout gridLayout = new GridLayout();
    gridLayout.verticalSpacing = 0;
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    gridLayout.horizontalSpacing = 0;
    contents.setLayout(gridLayout);

    final Browser browser = new Browser(contents, SWT.NONE);
    browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    URL url = FileLocator.find(Activator.getDefault().getBundle(), new Path("/html/editor.html"), null);

    StringBuilder editorContent = new StringBuilder();
    try {
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            editorContent.append(inputLine);
        }

    } catch (IOException e1) {
        e1.printStackTrace();
    }

    try {
        browser.setUrl(FileLocator.resolve(url).toExternalForm());
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Add text to control if text is being edited
    if (StringUtils.isNotEmpty(this.content)) {
        browser.addProgressListener(new ProgressListener() {

            public void changed(ProgressEvent event) {
            }

            public void completed(ProgressEvent event) {
                String htmlcontent = StringUtils.replace(content, "\"", "'");
                htmlcontent = StringUtils.replace(htmlcontent, "\r", "");
                htmlcontent = StringUtils.replace(htmlcontent, "\n", "");
                String method = "document.forms[0].content.value=\"" + htmlcontent + "\"";
                if (!browser.execute(method)) {
                    System.out.println("Script was not executed");
                }
            }
        });
    }

    browser.addStatusTextListener(new StatusTextListener() {
        public void changed(StatusTextEvent event) {
            if (event.text.startsWith(identifier)) {
                content = StringUtils.removeStart(event.text, identifier);
                content = content.replaceAll("[\\n\\r]", "");
                browser.removeStatusTextListener(this);
                setReturnCode(OK);
                close();
            }
        }
    });

    return contents;
}

From source file:eionet.cr.web.util.JstlFunctions.java

/**
 * Returns a string that is constructed by concatenating the given bean request's getRequestURI() + "?" + the given bean
 * request's getQueryString(), and replacing the sort predicate with the given one. The present sort order is replaced by the
 * opposite./*www .j  a v  a2  s. c  om*/
 *
 * @param request
 * @param sortP
 * @param sortO
 * @return
 */
public static String sortUrl(AbstractActionBean actionBean, SearchResultColumn column) {

    HttpServletRequest request = actionBean.getContext().getRequest();
    StringBuffer buf = new StringBuffer(actionBean.getUrlBinding());
    buf.append("?");
    if (StringUtils.isBlank(column.getActionRequestParameter())) {

        if (!StringUtils.isBlank(request.getQueryString())) {

            QueryString queryString = QueryString.createQueryString(request);
            queryString.removeParameters(actionBean.excludeFromSortAndPagingUrls());
            buf.append(queryString.toURLFormat());
        }
    } else {
        buf.append(column.getActionRequestParameter());
    }

    String sortParamValue = column.getSortParamValue();
    if (sortParamValue == null) {
        sortParamValue = "";
    }

    String curValue = request.getParameter("sortP");
    if (curValue != null && buf.indexOf("sortP=") > 0) {
        buf = new StringBuffer(StringUtils.replace(buf.toString(), "sortP=" + Util.urlEncode(curValue),
                "sortP=" + Util.urlEncode(sortParamValue)));
    } else {
        buf.append("&amp;sortP=").append(Util.urlEncode(sortParamValue));
    }

    curValue = request.getParameter("sortO");
    if (curValue != null && buf.indexOf("sortO=") > 0) {
        buf = new StringBuffer(StringUtils.replace(buf.toString(), "sortO=" + curValue,
                "sortO=" + SortOrder.oppositeSortOrder(curValue)));
    } else {
        buf.append("&amp;sortO=").append(SortOrder.oppositeSortOrder(curValue));
    }

    String result = buf.toString();
    return result.startsWith("/") ? result.substring(1) : result;
}

From source file:eionet.cr.web.action.SaveFilesActionBean.java

public Resolution save() throws DAOException {

    if (selectedFiles != null && selectedFiles.size() > 0) {
        try {/*from ww  w.  j  a v  a 2s .co  m*/
            // If dataset title is empty, then set it to dataset ID
            if (StringUtils.isBlank(datasetTitle) && dataset.equals("new_dataset")) {
                datasetTitle = datasetId;
            }

            // Set folder to null if existing dataset selected
            if (!StringUtils.isBlank(dataset) && !dataset.equals("new_dataset")) {
                folder = null;
            }

            // Construct new dataset uri
            if (!StringUtils.isBlank(dataset) && !StringUtils.isBlank(folder)
                    && dataset.equals("new_dataset")) {
                dataset = folder + "/" + StringUtils.replace(datasetId, " ", "%20");
            }

            CreateDataset cd = new CreateDataset(Predicates.CR_COMPILED_DATASET, getUser());
            cd.create(datasetTitle, dataset, folder, selectedFiles, overwrite, searchCriteria);

        } catch (Exception e) {
            throw new DAOException(e.getMessage(), e);
        }
    }

    return new RedirectResolution(CompiledDatasetActionBean.class).addParameter("uri", dataset);
}

From source file:edu.cornell.med.icb.util.ICBStringUtils.java

/**
 * Fix a URL, encode special characters to hex values.
 * @param toEncode url to encode//w w  w  .  j av a  2  s . co m
 * @return the encoded url
 */
public static String urlFix(final String toEncode) {
    String outval = StringUtils.replace(toEncode, "%", "%25"); // Do this one FIRST

    outval = StringUtils.replace(outval, "$", "%24");
    outval = StringUtils.replace(outval, "&", "%26");
    outval = StringUtils.replace(outval, "+", "%2B");
    outval = StringUtils.replace(outval, ",", "%2C");
    outval = StringUtils.replace(outval, "/", "%2F");
    outval = StringUtils.replace(outval, ":", "%3A");
    outval = StringUtils.replace(outval, ";", "%3B");
    outval = StringUtils.replace(outval, "=", "%3D");
    outval = StringUtils.replace(outval, "?", "%3F");
    outval = StringUtils.replace(outval, "@", "%40");

    outval = StringUtils.replace(outval, " ", "%20");
    outval = StringUtils.replace(outval, "\"", "%22");
    outval = StringUtils.replace(outval, "<", "%3C");
    outval = StringUtils.replace(outval, ">", "%3E");
    outval = StringUtils.replace(outval, "#", "%23");

    outval = StringUtils.replace(outval, "{", "%7B");
    outval = StringUtils.replace(outval, "}", "%7D");
    outval = StringUtils.replace(outval, "|", "%7C");
    outval = StringUtils.replace(outval, "\\", "%5C");
    outval = StringUtils.replace(outval, "^", "%5E");
    outval = StringUtils.replace(outval, "~", "%7E");
    outval = StringUtils.replace(outval, "[", "%5B");
    outval = StringUtils.replace(outval, "]", "%5D");
    outval = StringUtils.replace(outval, "`", "%60");
    return outval;
}

From source file:com.flexive.faces.components.tree.dojo.DojoTreeRenderer.java

/**
 * {@inheritDoc}//  www  .j  ava  2s .c o m
 */
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    DojoTree tree = (DojoTree) component;
    ResponseWriter writer = context.getResponseWriter();
    FxJavascriptUtils.beginJavascript(writer);
    final String treeControllerWidget = (tree.isContentTree() ? "flexive.widget.FxTreeRpcController"
            : "dojo.widget.TreeBasicControllerV3");
    writer.write("dojo.addOnLoad(function() {\n");
    FxJavascriptUtils.writeDojoRequires(writer, "dojo.widget.TreeV3",
            StringUtils.replace(treeControllerWidget, "flexive:", ""), "dojo.widget.TreeSelectorV3",
            "dojo.widget.TreeEmphasizeOnSelect", "dojo.widget.TreeNodeV3", "dojo.widget.TreeContextMenuV3",
            "dojo.widget.TreeLinkExtension", "dojo.widget.TreeDndControllerV3", "dojo.widget.TreeEditor",
            "dojo.widget.TreeDocIconExtension");
    writer.write("var controller = dojo.widget.createWidget(\""
            + FxJavascriptUtils.getWidgetName(treeControllerWidget) + "\"" + ",{RpcUrl: \""
            + FxJsfUtils.getJsonServletUri() + "\"});\n" + "var _listeners = [controller.widgetId];\n");
    addTreeExtension(writer, "selector", "TreeSelectorV3", true, tree.isSelector());
    addTreeExtension(writer, "emphasize", "TreeEmphasizeOnSelect", false, tree.isSelector(),
            "{selector: selector.widgetId}");
    addTreeExtension(writer, "dnd", "TreeDndControllerV3", true, tree.isDragAndDrop(),
            "{controller: controller}");
    addTreeExtension(writer, "docIcons", "TreeDocIconExtension", true, tree.isDocIcons());
    if (tree.isEditor()) {
        writer.write("var editor = dojo.widget.createWidget(\"TreeEditor\");\n"
                + "controller.editor = editor;\n" + "editor.controller = controller;\n");

    }

    final Map<String, List<TreeNodeWriter.Node>> injectedNodes = new HashMap<String, List<TreeNodeWriter.Node>>();
    if (StringUtils.isNotBlank(tree.getExtensionPoint())) {
        // execute plugins, populate injectedNodes map
        TreePluginExecutor executor = new TreePluginExecutor() {
            @Override
            public void addNode(String parentNode, TreeNodeWriter.Node node) {
                if (!injectedNodes.containsKey(parentNode)) {
                    injectedNodes.put(parentNode, new ArrayList<TreeNodeWriter.Node>());
                }
                injectedNodes.get(parentNode).add(node);
            }
        };
        PluginRegistryBean.getInstance()
                .execute(new ExtensionPoint<TreePluginExecutor>(tree.getExtensionPoint()) {
                }, executor);
    }

    writer.write("var children = ");
    // Tree JSON representation follows
    TreeNodeWriter nodeWriter = new PluginAwareTreeWriter(context.getResponseWriter(),
            new JsfRelativeUriMapper(),
            tree.isContentTree() ? TreeNodeWriter.FORMAT_CONTENTTREE
                    : tree.isDocIcons() ? TreeNodeWriter.FORMAT_PLAIN : TreeNodeWriter.FORMAT_ADMINTREE,
            injectedNodes);
    tree.setNodeWriter(nodeWriter);
}

From source file:de.extra.client.core.builder.impl.MessageBuilderLocatorTest.java

/**
 * Test method for//ww  w .  ja  v  a 2 s.c om
 * {@link de.extra.client.core.builder.impl.MessageBuilderLocator#getXmlComplexTypeBuilder(java.lang.String, de.extra.client.core.model.InputDataContainer)}
 * .
 */
@Test
public void testGetXmlComplexMultipleTypeBuilder() {
    final Map<String, IXmlComplexTypeBuilder> complexTypeBuilderMap = new HashMap<String, IXmlComplexTypeBuilder>();
    final IXmlComplexTypeBuilder expectedXmlComplexTypeBuilder = new DataTransformConfigurablePluginsBuilder();
    final IXmlComplexTypeBuilder secondXmlComplexTypeBuilder = new DataTransformPluginsBuilder();
    complexTypeBuilderMap.put("test1", secondXmlComplexTypeBuilder);
    complexTypeBuilderMap.put("test2", expectedXmlComplexTypeBuilder);
    final Properties properties = new Properties();
    final String key = "builder." + StringUtils.replace(expectedXmlComplexTypeBuilder.getXmlType(), ":", ".");
    properties.put(key, "test2");
    final MessageBuilderLocator messageBuilderLocator = createMessageBuilderlocator(complexTypeBuilderMap,
            properties);
    // Implementierung setzen in Propertyes
    final IInputDataContainer senderData = createTestinputData("Dummy Content");
    final IXmlComplexTypeBuilder currentXmlComplexTypeBuilder = messageBuilderLocator
            .getXmlComplexTypeBuilder(expectedXmlComplexTypeBuilder.getXmlType(), senderData);
    Assert.assertEquals("Unexpected XmlComplexTypeBuilder found", currentXmlComplexTypeBuilder,
            expectedXmlComplexTypeBuilder);
}

From source file:gool.generator.cpp.CppCodePrinter.java

@Override
public List<File> printGoolLibraryClass(ClassDef pclass) throws FileNotFoundException {
    String goolClass = pclass.getPackageName() + "." + pclass.getName();

    ArrayList<String> goolClassImplems = new ArrayList<String>();
    for (String Import : GeneratorMatcher.matchImports(goolClass))
        if (Import.startsWith("+"))
            goolClassImplems.add(Import.substring(1));

    List<File> result = new ArrayList<File>();
    for (String goolClassImplem : goolClassImplems) {
        String goolClassImplemName = goolClassImplem.substring(goolClassImplem.lastIndexOf(".") + 1);
        String goolClassImplemPackage = goolClassImplem.substring(0, goolClassImplem.lastIndexOf("."));
        String implemFileName = goolClassImplemName + ".cpp";
        String headerFileName = goolClassImplemName + ".h";
        String codeImplem = GeneratorMatcher.matchGoolClassImplementation(goolClass, implemFileName);
        String codeHeader = GeneratorMatcher.matchGoolClassImplementation(goolClass, headerFileName);
        File dir = new File(getOutputDir().getAbsolutePath(),
                StringUtils.replace(goolClassImplemPackage, ".", File.separator));
        dir.mkdirs();/*from  ww  w.ja  v  a2s .c om*/
        File implemFile = new File(dir, implemFileName);
        File headerFile = new File(dir, headerFileName);

        //print implementation file
        PrintWriter writer = new PrintWriter(implemFile);
        writer.println(codeImplem);
        writer.close();

        //print header file
        writer = new PrintWriter(headerFile);
        writer.println(codeHeader);
        writer.close();
    }
    printedClasses.add(pclass);
    return result;
}

From source file:com.jaeksoft.searchlib.web.controller.CommonController.java

final public static String getRestApiUrl(String path) throws UnsupportedEncodingException {
    Execution exe = Executions.getCurrent();
    StringBuilder sb = getBaseUrl();
    Client client = (Client) exe.getSession().getAttribute(ScopeAttribute.CURRENT_CLIENT.name());
    sb.append("/services/rest");
    sb.append(StringUtils.replace(path, "{index_name}", URLEncoder.encode(client.getIndexName(), "UTF-8")));
    sb.append("?_type=json");
    User user = (User) exe.getSession().getAttribute(ScopeAttribute.LOGGED_USER.name());
    if (user != null)
        user.appendApiCallParameters(sb);
    return sb.toString();
}