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

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

Introduction

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

Prototype

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

Source Link

Document

Replaces a String with another String inside a larger String, once.

Usage

From source file:org.exoplatform.forum.ForumTransformHTML.java

public static String fixAddBBcodeAction(String b) {
    int tagIndex = 0;
    int lastIndex = 0;
    String start;/*from w w w  . j a  v a 2s.  c  o  m*/
    String end;
    String text_ = ForumUtils.EMPTY_STR;
    StringBuilder builder;
    String[] tagBBcode = new String[] { "quote", "code", "QUOTE", "CODE" };
    for (int i = 0; i < tagBBcode.length; i++) {
        start = "[" + tagBBcode[i];
        end = "[/" + tagBBcode[i] + "]";
        while ((tagIndex = b.indexOf(start, lastIndex)) != -1) {
            lastIndex = tagIndex + 1;
            builder = new StringBuilder();
            try {
                int clsIndex = b.indexOf(end, tagIndex);
                String text = b.substring(tagIndex, clsIndex);
                if (text == null || text.trim().length() == 0)
                    continue;
                text_ = text;
                if (text.indexOf('<' + "p") > text.indexOf('<' + "/p")) {
                    text = StringUtils.replaceOnce(text, "</p>", ForumUtils.EMPTY_STR);
                    int t = text.lastIndexOf('<' + "p>");
                    builder.append(text.substring(0, t));
                    if (text.length() > (t + 3)) {
                        builder.append(text.substring(t + 3));
                    }
                }
                text = builder.toString();
                if (text != null && text.length() > 0) {
                    b = StringUtils.replace(b, text_, text);
                    text_ = text;
                } else
                    text = text_;

                builder = new StringBuilder();
                if (text.indexOf('<' + "span") > text.indexOf('<' + "/span")) {
                    text = StringUtils.replaceOnce(text, "</span>", ForumUtils.EMPTY_STR);
                    int t = text.lastIndexOf('<' + "span");
                    builder.append(text.substring(0, t));
                    if (text.length() > (t + 6)) {
                        builder.append(text.substring((t + 6)));
                    }
                }
                text = builder.toString();
                if (text != null && text.length() > 0) {
                    b = StringUtils.replace(b, text_, text);
                }
            } catch (Exception e) {
                continue;
            }
        }
    }
    return b;
}

From source file:org.exoplatform.ks.ext.impl.ForumTransformHTML.java

public static String fixAddBBcodeAction(String b) {
    int tagIndex = 0;
    int lastIndex = 0;
    String start;//w ww  . ja va2s .c  om
    String end;
    String text_ = "";
    StringBuilder builder = new StringBuilder();
    String[] tagBBcode = new String[] { "quote", "code", "QUOTE", "CODE" };
    for (int i = 0; i < tagBBcode.length; i++) {
        start = "[" + tagBBcode[i];
        end = "[/" + tagBBcode[i] + "]";
        while ((tagIndex = b.indexOf(start, lastIndex)) != -1) {
            lastIndex = tagIndex + 1;
            try {
                int clsIndex = b.indexOf(end, tagIndex);
                String text = b.substring(tagIndex, clsIndex);
                if (text == null || text.trim().length() == 0)
                    continue;
                text_ = text;
                builder = new StringBuilder();
                if (text.indexOf('<' + "p") > text.indexOf('<' + "/p")) {
                    text = StringUtils.replaceOnce(text, "</p>", "");
                    int t = text.lastIndexOf('<' + "p>");
                    builder.append(text.substring(0, t));
                    if (text.length() > (t + 3)) {
                        builder.append(text.substring(t + 3));
                    }
                }
                text = builder.toString();
                if (text != null && text.length() > 0) {
                    b = StringUtils.replace(b, text_, text);
                    text_ = text;
                } else
                    text = text_;

                builder = new StringBuilder();
                if (text.indexOf('<' + "span") > text.indexOf('<' + "/span")) {
                    text = StringUtils.replaceOnce(text, "</span>", "");
                    int t = text.lastIndexOf('<' + "span");
                    builder.append(text.substring(0, t));
                    if (text.length() > (t + 6)) {
                        builder.append(text.substring((t + 6)));
                    }
                }
                text = builder.toString();
                if (text != null && text.length() > 0) {
                    b = StringUtils.replace(b, text_, text);
                }
            } catch (Exception e) {
                continue;
            }
        }
    }
    return b;
}

From source file:org.exoplatform.services.cms.drives.impl.NewUserListener.java

/**
 *
 *///from w w  w . ja v a  2  s. c  om
@SuppressWarnings({ "unused" })
public void preSave(User user, boolean isNew) throws Exception {
    String workspace = initParams_.getValueParam("workspace").getValue();
    String permissions = initParams_.getValueParam("permissions").getValue();
    permissions = permissions.concat("," + user.getUserName());
    //Set personal drive home path 
    SessionProvider sessionProvider = WCMCoreUtils.getSystemSessionProvider();
    Node userNode = nodeHierarchyCreator_.getUserNode(sessionProvider, user.getUserName());
    String homePath = userNode.getPath();
    String views = initParams_.getValueParam("views").getValue();
    String icon = initParams_.getValueParam("icon").getValue();
    boolean viewPreferences = Boolean.parseBoolean(initParams_.getValueParam("viewPreferences").getValue());
    boolean viewNonDocument = Boolean.parseBoolean(initParams_.getValueParam("viewNonDocument").getValue());
    boolean viewSideBar = Boolean.parseBoolean(initParams_.getValueParam("viewSideBar").getValue());
    boolean showHiddenNode = Boolean.parseBoolean(initParams_.getValueParam("showHiddenNode").getValue());
    String allowCreateFolder = initParams_.getValueParam("allowCreateFolder").getValue();
    String allowNodeTypesOnTree = initParams_.getValueParam("allowNodeTypesOnTree").getValue();
    //Only user can access private drive
    String publicPath = nodeHierarchyCreator_.getJcrPath(PUBLIC_ALIAS);
    String privatePath = nodeHierarchyCreator_.getJcrPath(PRIVATE_ALIAS);
    //Get user relPath
    String userRelPath = StringUtils.replaceOnce(userNode.getPath(), userPath_ + "/", "");
    //add drive with user relPath
    driveService_.addDrive(userRelPath + "|" + privatePath, workspace, user.getUserName(),
            homePath + "/" + privatePath, views, icon, viewPreferences, viewNonDocument, viewSideBar,
            showHiddenNode, allowCreateFolder, allowNodeTypesOnTree);
    //User and everyone can see public drive for user
    driveService_.addDrive(userRelPath + "|" + publicPath, workspace, permissions, homePath + "/" + publicPath,
            views, icon, viewPreferences, viewNonDocument, viewSideBar, showHiddenNode, allowCreateFolder,
            allowNodeTypesOnTree);
}

From source file:org.exoplatform.services.cms.drives.impl.NewUserListener.java

/**
 *
 *///w  w w.j  av a2  s  .co m
public void preDelete(User user) throws Exception {
    SessionProvider sessionProvider = WCMCoreUtils.getSystemSessionProvider();
    Node userNode = nodeHierarchyCreator_.getUserNode(sessionProvider, user.getUserName());
    String userRelPath = StringUtils.replaceOnce(userNode.getPath(), userPath_ + "/", "");
    //Remove private drive
    driveService_.removeDrive(userRelPath + "|" + nodeHierarchyCreator_.getJcrPath(PRIVATE_ALIAS));

    //Remove public drive
    driveService_.removeDrive(userRelPath + "|" + nodeHierarchyCreator_.getJcrPath(PUBLIC_ALIAS));
}

From source file:org.exoplatform.services.cms.impl.Utils.java

public static String getPersonalDrivePath(String parameterizedDrivePath, String userId) throws Exception {
    SessionProvider sessionProvider = WCMCoreUtils.getUserSessionProvider();
    NodeHierarchyCreator nodeHierarchyCreator = WCMCoreUtils.getService(NodeHierarchyCreator.class);
    Node userNode = nodeHierarchyCreator.getUserNode(sessionProvider, userId);
    return StringUtils.replaceOnce(parameterizedDrivePath,
            nodeHierarchyCreator.getJcrPath(BasePath.CMS_USERS_PATH) + "/${userId}", userNode.getPath());
}

From source file:org.exoplatform.services.wcm.javascript.XJavascriptService.java

/**
 * Get active java script.//from w  ww .j  av  a 2 s .  c om
 *
 * @param webcontent the webcontent's node
 * @return Code of all js file in home node.
 * @throws Exception the exception
 */
public String getActiveJavaScript(Node webcontent) throws Exception {
    StringBuffer buffer = new StringBuffer();
    String jsQuery = StringUtils.replaceOnce(WEBCONTENT_JS_QUERY, "{path}", webcontent.getPath());

    // Need re-login to get session because this node is get from template and the session is not live anymore.
    NodeLocation webcontentLocation = NodeLocation.getNodeLocationByNode(webcontent);
    RepositoryService repositoryService = WCMCoreUtils.getService(RepositoryService.class);
    ManageableRepository repository = repositoryService.getCurrentRepository();
    Session session = null;
    if (webcontentLocation.getPath().startsWith("/jcr:system"))
        session = repository.getSystemSession(repository.getConfiguration().getSystemWorkspaceName());
    else {
        session = repository.getSystemSession(webcontentLocation.getWorkspace());
    }

    QueryManager queryManager = session.getWorkspace().getQueryManager();
    Query query = queryManager.createQuery(jsQuery, Query.SQL);
    QueryResult queryResult = query.execute();
    NodeIterator iterator = queryResult.getNodes();
    while (iterator.hasNext()) {
        Node registeredJSFile = iterator.nextNode();
        buffer.append(getActivedJSData(registeredJSFile));
    }
    session.logout();
    return buffer.toString();
}

From source file:org.exoplatform.services.wcm.javascript.XJavascriptService.java

/**
 * Adds the javascript.//from  w  ww . ja v  a2s . com
 *
 * @param jsData the js data
 */
private void addPortalJavascript(Node portalNode, Node jsFile, boolean isStartup) throws Exception {
    String javascriptPath = StringUtils.replaceOnce(PATH, "{portalName}", portalNode.getName());

    String moduleName = MODULE_NAME + '.' + portalNode.getName();
    //    jsConfigService.invalidateCachedJScript("/" + servletContext.getServletContextName() +
    //                                            javascriptPath);
    if (!loadedJSModule.contains(moduleName)) {
        loadedJSModule.add(moduleName);
        //      jsConfigService.addPortalJScript(
        //        new PortalJScript(moduleName, javascriptPath,"/" + servletContext.getServletContextName(),
        //                          10, portalNode.getName()));
    }
}

From source file:org.exoplatform.services.wcm.javascript.XJavascriptService.java

/**
 * Adds the javascript./* ww w.j  a va  2  s.  c o  m*/
 *
 * @param jsData the js data
 */
private void addSharedPortalJavascript(Node portalNode, Node jsFile, boolean isStartup) throws Exception {
    String javascriptPath = StringUtils.replaceOnce(PATH, "{portalName}", portalNode.getName());
    String moduleName = MODULE_NAME + '.' + portalNode.getName();
    //    jsConfigService.invalidateMergedCommonJScripts();
    //    jsConfigService.invalidateCachedJScript("/" + servletContext.getServletContextName() +
    //                                            javascriptPath);
    if (!loadedSharedJSModule.contains(moduleName)) {
        loadedSharedJSModule.add(moduleName);
        //      jsConfigService.addCommonJScript(
        //         new Javascript(moduleName, javascriptPath,"/" + servletContext.getServletContextName(), 10));
    }
}

From source file:org.exoplatform.services.wcm.skin.XSkinService.java

/**
 * Adds the portal skin.// w  w w  .java 2s . c  om
 *
 * @param portalNode the portal
 * @param cssFile the css file
 * @param isStartup the flag to decide whether this situation is startup or not
 *
 * @throws Exception the exception
 */
private void addPortalSkin(Node portalNode) throws Exception {
    String skinPath = StringUtils.replaceOnce(SKIN_PATH_PATTERN, "(.*)", portalNode.getName())
            .replaceFirst("\\{docBase\\}", servletContext.getServletContextName());
    Iterator<String> iterator = skinService.getAvailableSkinNames().iterator();
    if (iterator.hasNext() == false) {
        skinPath = StringUtils.replaceOnce(skinPath, "(.*)", "Default");
        skinService.invalidateCachedSkin(skinPath);
        skinService.addSkin(portalNode.getName(), "Default", skinPath);
    } else {
        while (iterator.hasNext()) {
            String skinName = iterator.next();
            skinPath = StringUtils.replaceOnce(skinPath, "(.*)", skinName);
            skinService.invalidateCachedSkin(skinPath);
            skinService.addSkin(portalNode.getName(), skinName, skinPath);
        }
    }
}

From source file:org.exoplatform.services.wcm.skin.XSkinService.java

/**
 * Adds the shared portal skin./*from   w ww . j a v a  2 s.c  o  m*/
 *
 * @param portalNode the portal
 *
 * @throws Exception the exception
 */
private void addSharedPortalSkin(Node portalNode) throws Exception {
    String skinPath = StringUtils.replaceOnce(SKIN_PATH_PATTERN, "(.*)", portalNode.getName())
            .replaceFirst("\\{docBase\\}", servletContext.getServletContextName());
    for (Iterator<String> iterator = skinService.getAvailableSkinNames().iterator(); iterator.hasNext();) {
        String skinName = iterator.next();
        skinPath = StringUtils.replaceOnce(skinPath, "(.*)", skinName);
        skinService.invalidateCachedSkin(skinPath);
        skinService.addPortalSkin(portalNode.getName(), skinName, skinPath);
    }
}