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

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

Introduction

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

Prototype

public static String replaceChars(String str, String searchChars, String replaceChars) 

Source Link

Document

Replaces multiple characters in a String in one go.

Usage

From source file:org.apache.myfaces.custom.skin.AdapterSkinRenderer.java

/**
 * Get the style base name for the indicate component.
 * /*from w w w.j ava2 s  .c om*/
 * @param component
 * @return
 */
public String getBaseStyleName(UIComponent component) {

    String baseStyleClass = this.getComponentTagName();

    if (baseStyleClass == null) {
        baseStyleClass = SkinConstants.DEFAULT_NAMESPACE
                + StringUtils.replaceChars(component.getClass().getName(), '.', '_');
    }

    return baseStyleClass;
}

From source file:org.apache.myfaces.custom.skin.GenericSkinRenderer.java

public void encodeGenericComponent(FacesContext context, UIComponent component, SkinRenderingContext arc)
        throws IOException {

    // 2. the skin class for this component looks like this:
    // af|javax_faces_component_html_HtmlXXX::class

    String contentStyleClass = component.getClass().getName();

    //Map<String, String> m = arc.getSkin().getStyleClassMap(arc);

    String baseStyleClass = SkinConstants.DEFAULT_NAMESPACE
            + StringUtils.replaceChars(contentStyleClass, '.', '_');

    Method method;//  w  w w .j  a  va 2  s . c  om
    // Check it has a getStyleClass property
    contentStyleClass = null;
    try {
        method = component.getClass().getMethod("getStyleClass", (Class[]) null);
        contentStyleClass = baseStyleClass + SkinConstants.STYLE_CLASS_SUFFIX;
    } catch (SecurityException e) {
        // Nothing happends
        //e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // Nothing happends
        // e.printStackTrace();
    }

    int otherStyles = 0;

    // Its necesary to add other style properties like
    // p_AFReadOnly and p_AFDisabled
    Map attributes = component.getAttributes();
    String styleClass = (String) attributes.get("styleClass");
    String disabledStyleClass = null;
    String readOnlyStyleClass = null;

    try {
        method = component.getClass().getMethod("isReadonly", (Class[]) null);
        if ((Boolean) method.invoke(component, (Object[]) null)) {
            readOnlyStyleClass = SkinSelectors.STATE_READ_ONLY;
            otherStyles += 1;
        }
    } catch (SecurityException e) {
        // Nothing happends
        //e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // Nothing happends
        // e.printStackTrace();
    } catch (InvocationTargetException e) {
        // Nothing happends
        //e.printStackTrace();
    } catch (IllegalAccessException e) {
        // Nothing happends
        //e.printStackTrace();
    }

    try {
        method = component.getClass().getMethod("isDisabled", (Class[]) null);
        if ((Boolean) method.invoke(component, (Object[]) null)) {
            disabledStyleClass = SkinSelectors.STATE_DISABLED;
            otherStyles += 1;
        }
    } catch (SecurityException e) {
        // Nothing happends
        // e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // Nothing happends
        // e.printStackTrace();
    } catch (InvocationTargetException e) {
        // Nothing happends
        // e.printStackTrace();
    } catch (IllegalAccessException e) {
        // Nothing happends
        // e.printStackTrace();
    }

    List<String> parsedStyleClasses = OutputUtils.parseStyleClassList(styleClass);
    int userStyleClassCount;
    if (parsedStyleClasses == null)
        userStyleClassCount = (styleClass == null) ? 0 : 1;
    else
        userStyleClassCount = parsedStyleClasses.size();

    String[] styleClasses = new String[userStyleClassCount + 3];
    int i = 0;
    if (parsedStyleClasses != null) {
        while (i < userStyleClassCount) {
            styleClasses[i] = parsedStyleClasses.get(i);
            i++;
        }
    } else if (styleClass != null) {
        styleClasses[i++] = styleClass;
    }

    styleClasses[i++] = contentStyleClass;
    styleClasses[i++] = disabledStyleClass;
    styleClasses[i++] = readOnlyStyleClass;

    // 3. set the property styleClass, setting it.
    if (otherStyles > 0) {
        _renderStyleClasses(component, context, arc, styleClasses);
    } else {
        _renderStyleClass(component, context, arc, contentStyleClass);
    }
}

From source file:org.apache.myfaces.custom.skin.GenericSkinRenderer.java

public void encodeGenericWithRequiredComponent(FacesContext context, UIComponent component,
        SkinRenderingContext arc) throws IOException {

    log.debug("Component class " + component.getClass().getName());

    // 2. the skin class for this component looks like this:
    // af|javax_faces_component_html_HtmlXXX::class

    String contentStyleClass = component.getClass().getName();

    //Map<String, String> m = arc.getSkin().getStyleClassMap(arc);

    String baseStyleClass = SkinConstants.DEFAULT_NAMESPACE
            + StringUtils.replaceChars(contentStyleClass, '.', '_');

    Method method;//  w  ww . j a va 2  s  . co  m
    // Check it has a getStyleClass property
    contentStyleClass = null;
    try {
        method = component.getClass().getMethod("getStyleClass", (Class[]) null);
        contentStyleClass = baseStyleClass + SkinConstants.STYLE_CLASS_SUFFIX;
    } catch (SecurityException e) {
        // Nothing happends
        //e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // Nothing happends
        // e.printStackTrace();
    }

    int otherStyles = 0;

    // Its necesary to add other style properties like
    // p_AFReadOnly and p_AFDisabled
    Map attributes = component.getAttributes();
    String styleClass = (String) attributes.get("styleClass");
    String disabledStyleClass = null;
    String readOnlyStyleClass = null;
    String requiredStyleClass = null;

    try {
        method = component.getClass().getMethod("isReadonly", (Class[]) null);
        if ((Boolean) method.invoke(component, (Object[]) null)) {
            readOnlyStyleClass = SkinSelectors.STATE_READ_ONLY;
            otherStyles += 1;
        }
    } catch (SecurityException e) {
        //e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // Nothing happends
        // e.printStackTrace();
    } catch (InvocationTargetException e) {
        // Nothing happends
        //e.printStackTrace();
    } catch (IllegalAccessException e) {
        // Nothing happends
        //e.printStackTrace();
    }

    try {
        method = component.getClass().getMethod("isDisabled", (Class[]) null);
        if ((Boolean) method.invoke(component, (Object[]) null)) {
            disabledStyleClass = SkinSelectors.STATE_DISABLED;
            otherStyles += 1;
        }
    } catch (SecurityException e) {
        // Nothing happends
        //e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // Nothing happends
        // e.printStackTrace();
    } catch (InvocationTargetException e) {
        // Nothing happends
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // Nothing happends
        e.printStackTrace();
    }

    try {
        method = component.getClass().getMethod("isRequired", (Class[]) null);
        if ((Boolean) method.invoke(component, (Object[]) null)) {
            requiredStyleClass = baseStyleClass + "::required";
            otherStyles += 1;
        }
    } catch (SecurityException e) {
        //e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // Nothing happends
        // e.printStackTrace();
    } catch (InvocationTargetException e) {
        // Nothing happends
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // Nothing happends
        e.printStackTrace();
    }

    List<String> parsedStyleClasses = OutputUtils.parseStyleClassList(styleClass);
    int userStyleClassCount;
    if (parsedStyleClasses == null)
        userStyleClassCount = (styleClass == null) ? 0 : 1;
    else
        userStyleClassCount = parsedStyleClasses.size();

    String[] styleClasses = new String[userStyleClassCount + 4];
    int i = 0;
    if (parsedStyleClasses != null) {
        while (i < userStyleClassCount) {
            styleClasses[i] = parsedStyleClasses.get(i);
            i++;
        }
    } else if (styleClass != null) {
        styleClasses[i++] = styleClass;
    }

    styleClasses[i++] = contentStyleClass;
    styleClasses[i++] = disabledStyleClass;
    styleClasses[i++] = readOnlyStyleClass;
    styleClasses[i++] = requiredStyleClass;

    // 3. set the property styleClass, setting it.
    if (otherStyles > 0) {
        _renderStyleClasses(component, context, arc, styleClasses);
    } else {
        _renderStyleClass(component, context, arc, contentStyleClass);
    }
}

From source file:org.apache.myfaces.custom.skin.html.HtmlColumnSkinRenderer.java

@Override
protected void _addStyleClassesToComponent(FacesContext context, UIComponent component, RenderingContext arc)
        throws IOException {
    String footerStyleClass = null;
    String headerStyleClass = null;

    String baseStyleClass = SkinConstants.DEFAULT_NAMESPACE
            + StringUtils.replaceChars(component.getClass().getName(), '.', '_');

    footerStyleClass = baseStyleClass + "::footer";
    headerStyleClass = baseStyleClass + "::header";

    _renderStyleClass(component, context, arc, footerStyleClass, "footerClass");
    _renderStyleClass(component, context, arc, headerStyleClass, "headerClass");
}

From source file:org.apache.myfaces.custom.skin.renderkit.html.HtmlColumnSkinRenderer.java

@Override
protected void _addStyleClassesToComponent(FacesContext context, UIComponent component,
        SkinRenderingContext arc) throws IOException {
    String footerStyleClass = null;
    String headerStyleClass = null;

    String baseStyleClass = SkinConstants.DEFAULT_NAMESPACE
            + StringUtils.replaceChars(component.getClass().getName(), '.', '_');

    footerStyleClass = baseStyleClass + "::footer";
    headerStyleClass = baseStyleClass + "::header";

    _renderStyleClass(component, context, arc, footerStyleClass, "footerClass");
    _renderStyleClass(component, context, arc, headerStyleClass, "headerClass");
}

From source file:org.apache.qpid.server.security.access.Permission.java

public static Permission parse(String text) {

    for (Permission permission : values()) {
        if (permission.name().equalsIgnoreCase(StringUtils.replaceChars(text, '-', '_'))) {
            return permission;
        }/*w w  w  .  ja  v  a 2 s.co  m*/
    }
    throw new IllegalArgumentException("Not a valid permission: " + text);
}

From source file:org.apache.wiki.attachment.AttachmentManager.java

/**
 *  Validates the filename and makes sure it is legal.  It trims and splits
 *  and replaces bad characters.//  w  ww.j a  v a2  s .  c om
 *  
 *  @param filename
 *  @return A validated name with annoying characters replaced.
 *  @throws WikiException If the filename is not legal (e.g. empty)
 */
static String validateFileName(String filename) throws WikiException {
    if (filename == null || filename.trim().length() == 0) {
        log.error("Empty file name given.");

        // the caller should catch the exception and use the exception text as an i18n key
        throw new WikiException("attach.empty.file");
    }

    //
    //  Should help with IE 5.22 on OSX
    //
    filename = filename.trim();

    // If file name ends with .jsp or .jspf, the user is being naughty!
    if (filename.toLowerCase().endsWith(".jsp") || filename.toLowerCase().endsWith(".jspf")) {
        log.info("Attempt to upload a file with a .jsp/.jspf extension.  In certain cases this "
                + "can trigger unwanted security side effects, so we're preventing it.");
        //
        // the caller should catch the exception and use the exception text as an i18n key
        throw new WikiException("attach.unwanted.file");
    }

    //
    //  Some browser send the full path info with the filename, so we need
    //  to remove it here by simply splitting along slashes and then taking the path.
    //

    String[] splitpath = filename.split("[/\\\\]");
    filename = splitpath[splitpath.length - 1];

    //
    //  Remove any characters that might be a problem. Most
    //  importantly - characters that might stop processing
    //  of the URL.
    //
    filename = StringUtils.replaceChars(filename, "#?\"'", "____");

    return filename;
}

From source file:org.apache.wiki.search.LuceneSearchProvider.java

/**
 *  Indexes page using the given IndexWriter.
 *
 *  @param page WikiPage/*ww w  .j  av a  2s . c  o  m*/
 *  @param text Page text to index
 *  @param writer The Lucene IndexWriter to use for indexing
 *  @return the created index Document
 *  @throws IOException If there's an indexing problem
 */
protected Document luceneIndexPage(WikiPage page, String text, IndexWriter writer) throws IOException {
    if (log.isDebugEnabled())
        log.debug("Indexing " + page.getName() + "...");

    // make a new, empty document
    Document doc = new Document();

    if (text == null)
        return doc;

    // Raw name is the keyword we'll use to refer to this document for updates.
    Field field = new Field(LUCENE_ID, page.getName(), Field.Store.YES, Field.Index.NOT_ANALYZED);
    doc.add(field);

    // Body text.  It is stored in the doc for search contexts.
    field = new Field(LUCENE_PAGE_CONTENTS, text, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO);
    doc.add(field);

    // Allow searching by page name. Both beautified and raw
    String unTokenizedTitle = StringUtils.replaceChars(page.getName(), MarkupParser.PUNCTUATION_CHARS_ALLOWED,
            c_punctuationSpaces);

    field = new Field(LUCENE_PAGE_NAME, TextUtil.beautifyString(page.getName()) + " " + unTokenizedTitle,
            Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO);
    doc.add(field);

    // Allow searching by authorname

    if (page.getAuthor() != null) {
        field = new Field(LUCENE_AUTHOR, page.getAuthor(), Field.Store.YES, Field.Index.ANALYZED,
                Field.TermVector.NO);
        doc.add(field);
    }

    // Now add the names of the attachments of this page
    try {
        Collection attachments = m_engine.getAttachmentManager().listAttachments(page);
        String attachmentNames = "";

        for (Iterator it = attachments.iterator(); it.hasNext();) {
            Attachment att = (Attachment) it.next();
            attachmentNames += att.getName() + ";";
        }
        field = new Field(LUCENE_ATTACHMENTS, attachmentNames, Field.Store.YES, Field.Index.ANALYZED,
                Field.TermVector.NO);
        doc.add(field);

    } catch (ProviderException e) {
        // Unable to read attachments
        log.error("Failed to get attachments for page", e);
    }
    writer.addDocument(doc);

    return doc;
}

From source file:org.artifactory.util.layouts.token.OrganizationPathTokenFilter.java

@Override
public String forPath(String tokenValue) {
    return StringUtils.replaceChars(tokenValue, '.', '/');
}

From source file:org.artifactory.util.layouts.token.OrganizationPathTokenFilter.java

@Override
public String fromPath(String tokenValue) {
    return StringUtils.replaceChars(tokenValue, '/', '.');
}