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

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

Introduction

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

Prototype

public static String removeEnd(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

Usage

From source file:org.eclipse.wb.internal.swing.model.layout.LayoutJavaInfoParticipator.java

/**
 * Uses {@link IBindingProcessor} to attempt to perform binding by class of {@link LayoutInfo} and
 * any of its super classes. Trick is that sometimes artifact is bound not to the exact class of
 * {@link LayoutInfo}, but to some of its super classes, so we should check them too.
 *//*from w ww.  j  av a2 s.  c  o  m*/
private static void run(final LayoutInfo layout, final IBindingProcessor processor) {
    Class<?> layoutClass = layout.getClass();
    while (layoutClass != null) {
        final ClassLoader classLoader = ReflectionUtils.getClassLoader(layoutClass);
        // prepare name of Layout without "Info" suffix
        final String layoutName;
        {
            String layoutClassName = layoutClass.getName();
            layoutName = StringUtils.removeEnd(layoutClassName, "Info");
        }
        // bind safely
        final Class<?> finalLayoutClass = layoutClass;
        boolean success = ExecutionUtils.runObjectIgnore(new RunnableObjectEx<Boolean>() {
            public Boolean runObject() throws Exception {
                return processor.run(layout, classLoader, finalLayoutClass, layoutName);
            }
        }, false);
        if (success) {
            return;
        }
        // try super class
        layoutClass = layoutClass.getSuperclass();
    }
}

From source file:org.eclipse.wb.internal.swing.model.property.editor.font.DerivedFontInfo.java

private String getSource(String baseFontSource) throws Exception {
    // style/*  ww  w  .  j a  v  a 2  s.c o m*/
    boolean styleChanged = true;
    String styleSource = baseFontSource + ".getStyle()";
    {
        if (m_newBold == null && m_newItalic == null) {
            styleChanged = false;
        } else if (m_newBold != null && m_newBold.booleanValue() && m_newItalic == null) {
            styleSource += " | java.awt.Font.BOLD";
        } else if (m_newBold != null && !m_newBold.booleanValue() && m_newItalic == null) {
            styleSource += " & ~java.awt.Font.BOLD";
        } else if (m_newBold == null && m_newItalic != null && m_newItalic.booleanValue()) {
            styleSource += " | java.awt.Font.ITALIC";
        } else if (m_newBold == null && m_newItalic != null && !m_newItalic.booleanValue()) {
            styleSource += " & ~java.awt.Font.ITALIC";
        } else if (m_newBold != null && m_newItalic != null && m_newBold.booleanValue()
                && m_newItalic.booleanValue()) {
            styleSource += " | java.awt.Font.BOLD";
            styleSource += " | java.awt.Font.ITALIC";
        } else if (m_newBold != null && m_newItalic != null && !m_newBold.booleanValue()
                && m_newItalic.booleanValue()) {
            styleSource += " & ~java.awt.Font.BOLD";
            styleSource += " | java.awt.Font.ITALIC";
        } else if (m_newBold != null && m_newItalic != null && m_newBold.booleanValue()
                && !m_newItalic.booleanValue()) {
            styleSource += " & ~java.awt.Font.ITALIC";
            styleSource += " | java.awt.Font.BOLD";
        } else if (m_newBold != null && m_newItalic != null && !m_newBold.booleanValue()
                && !m_newItalic.booleanValue()) {
            styleSource += " & ~java.awt.Font.BOLD";
            styleSource += " & ~java.awt.Font.ITALIC";
        }
    }
    // size
    boolean sizeChanged = false;
    String sizeSource = baseFontSource + ".getSize()";
    {
        if (m_deltaSize != null) {
            int deltaSize = m_deltaSize.intValue();
            if (deltaSize > 0) {
                sizeSource += " + " + deltaSize + "f";
            } else {
                sizeSource += " - " + -deltaSize + "f";
            }
            sizeChanged = true;
        } else if (m_newSize != null) {
            sizeSource = "" + m_newSize.intValue() + "f";
            sizeChanged = true;
        }
    }
    // new family
    if (m_newFamily != null) {
        sizeSource = StringUtils.removeEnd(sizeSource, "f");
        return MessageFormat.format("new java.awt.Font({0}, {1}, {2})",
                StringConverter.INSTANCE.toJavaSource(null, m_newFamily), styleSource, sizeSource);
    }
    // style/size change
    if (styleChanged & sizeChanged) {
        return MessageFormat.format("{0}.deriveFont({1}, {2})", baseFontSource, styleSource, sizeSource);
    }
    if (styleChanged) {
        return MessageFormat.format("{0}.deriveFont({1})", baseFontSource, styleSource);
    }
    if (sizeChanged) {
        return MessageFormat.format("{0}.deriveFont({1})", baseFontSource, sizeSource);
    }
    // no changes
    return null;
}

From source file:org.eclipse.wb.internal.swt.model.layout.LayoutJavaInfoParticipator.java

private static void run(LayoutInfo layout, IBindingProcessor processor, Class<?> layoutClass) throws Exception {
    // prepare name of Layout without "Info" suffix
    final String layoutName;
    {/* ww  w  .  j a  v  a 2s  . com*/
        String layoutClassName = layoutClass.getName();
        layoutName = StringUtils.removeEnd(layoutClassName, "Info");
    }
    // try to bind
    ClassLoader classLoader = ReflectionUtils.getClassLoader(layoutClass);
    processor.run(layout, classLoader, layoutClass, layoutName);
}

From source file:org.eclipse.wb.internal.xwt.model.widgets.SashFormInfo.java

/**
 * Ensures that this {@link SashFormInfo} has "weights" attribute.
 *///from   ww w.  j a va2s . co m
private String ensureWeights() throws Exception {
    DocumentElement element = getCreationSupport().getElement();
    String weightsString = element.getAttribute("weights");
    if (weightsString == null) {
        weightsString = StringUtils.repeat("1, ", getChildrenControls().size());
        weightsString = StringUtils.removeEnd(weightsString, ", ");
        element.setAttribute("weights", weightsString);
    }
    return weightsString;
}

From source file:org.eclipse.wb.tests.designer.core.model.parser.AbstractJavaInfoRelatedTest.java

/**
 * Creates source for {@link String}'s array for hierarchy of {@link JavaInfo}'s starting from
 * given root.//  ww w.j  a v  a 2 s.co m
 */
private static void printHierarchySource(JavaInfo root) {
    final StringBuffer buffer = new StringBuffer();
    root.accept(new ObjectInfoVisitor() {
        private int m_level;

        @Override
        public boolean visit(ObjectInfo objectInfo) throws Exception {
            buffer.append('"');
            buffer.append(StringUtils.repeat("  ", m_level));
            {
                String line = objectInfo.toString();
                line = line.replace('"', '\'');
                buffer.append(StringUtilities.escapeJava(line));
            }
            buffer.append('"');
            buffer.append(",\n");
            m_level++;
            return true;
        }

        @Override
        public void endVisit(ObjectInfo objectInfo) throws Exception {
            m_level--;
        }
    });
    String result = buffer.toString();
    result = StringUtils.removeEnd(result, ",\n");
    System.out.println(result);
}

From source file:org.eclipse.wb.tests.designer.tests.DesignerTestCase.java

/**
 * Creates source for given lines, that can be used later in {@link #getSourceDQ(String...)}.
 *///from   w  ww . j av a2 s .com
protected static String getLinesForSourceDQ(String... lines) {
    StringBuffer buffer = new StringBuffer();
    // lines
    for (String line : lines) {
        buffer.append('"');
        line = StringUtils.replace(line, "\t", "  ");
        {
            line = line.replace('"', '\'');
            buffer.append(StringUtilities.escapeForJavaSource(line));
        }
        buffer.append('"');
        buffer.append(",\n");
    }
    // end
    String result = buffer.toString();
    result = StringUtils.removeEnd(result, ",\n");
    return result;
}

From source file:org.eclipse.wb.tests.designer.tests.Replacer.java

private static String replaceInString(String s) {
    int invocationLast = 0;
    Pattern patternBegin = Pattern
            .compile("createTypeDeclaration\\(\\s*\"test\",\\s*\"Test\\.java\", getSourceDQ\\(");
    Pattern patternEnd = Pattern.compile("\"\\)\\);");
    while (true) {
        // prepare begin of "invocation"
        int invocationBegin;
        String begin;/*from ww  w.  ja v a  2 s .co  m*/
        {
            Matcher matcher = patternBegin.matcher(s);
            if (!matcher.find(invocationLast)) {
                break;
            }
            invocationBegin = matcher.start();
            begin = matcher.group();
            //System.out.println(begin);
        }
        //
        //int invocationEnd = s.indexOf("\"}), m_lastEditor);\r\n", invocationBegin);
        int invocationEnd;
        String end;
        {
            Matcher matcher = patternEnd.matcher(s);
            if (!matcher.find(invocationBegin)) {
                System.out.println(s.substring(invocationBegin));
                System.out.println("!!!!!!!!!!!!!");
                System.exit(0);
            }
            invocationEnd = matcher.end();
            invocationEnd -= ");".length();
            end = s.substring(matcher.start(), invocationEnd);
            //System.out.println(end);
        }
        // process single "invocation"
        {
            String invocation = s.substring(invocationBegin, invocationEnd);
            if (invocation.contains(";\r\n")) {
                System.out.println(invocation);
                System.out.println("???????????");
                System.exit(0);
            }
            // begin/end
            invocation = StringUtils.removeStart(invocation, begin);
            invocation = StringUtils.removeEnd(invocation, end);
            //invocation = "createTypeDeclaration_Test0(" + invocation + "\")";
            invocation = "createTypeDeclaration_Test0(" + invocation;
            System.out.println(invocation);
            // replace " with '
            invocation = StringUtils.replace(invocation, "\\\"", "'");
            // apply updated "invocation"
            s = s.substring(0, invocationBegin) + invocation + s.substring(invocationEnd);
        }
        // next
        invocationLast = invocationBegin + 1;
    }
    return s;
}

From source file:org.eclipse.wb.tests.designer.XML.AbstractXmlObjectTest.java

/**
 * Prints XML in {@link #m_lastContext}, ready to paste {@link #assertXML(String...)} invocation.
 *//*  w w w  .jav  a2  s  .com*/
protected void printEditorLinesSource() {
    StringBuffer buffer = new StringBuffer();
    // lines
    String[] lines = StringUtils.split(m_lastContext.getContent(), "\r\n");
    for (String line : lines) {
        buffer.append('"');
        line = StringUtils.replace(line, "\t", "  ");
        {
            line = line.replace('"', '\'');
            buffer.append(StringUtilities.escapeForJavaSource(line));
        }
        buffer.append('"');
        buffer.append(",\n");
    }
    // end
    String result = buffer.toString();
    result = StringUtils.removeEnd(result, ",\n");
    {
        // remove name spaces
        result = result.replaceAll("\\s*xmlns:*\\w*=\\s*'[^']*'", "");
        // remove empty lines in root object (after name space in separate lines)
        {
            result = result.replaceAll("\"\",\n", "");
            result = result.replaceAll("\",\n\">\",\n", ">\",\n");
        }
        // add filler
        {
            String filler = "\"// filler filler filler filler filler\",\n";
            result = filler + result;
            result = filler + result;
        }
    }
    System.out.println(result);
}

From source file:org.eclipse.wb.tests.designer.XML.AbstractXmlObjectTest.java

/**
 * Creates source for {@link String}'s array for hierarchy of {@link ObjectInfo}'s starting from
 * given root.//  w w w. j a  v a 2s.c  om
 */
private static void printHierarchySource(ObjectInfo root) {
    final StringBuffer buffer = new StringBuffer();
    root.accept(new ObjectInfoVisitor() {
        private int m_level;

        @Override
        public boolean visit(ObjectInfo objectInfo) throws Exception {
            buffer.append('"');
            buffer.append(StringUtils.repeat("  ", m_level));
            {
                String line = objectInfo.toString();
                line = line.replace('"', '\'');
                buffer.append(StringUtilities.escapeJava(line));
            }
            buffer.append('"');
            buffer.append(",\n");
            m_level++;
            return true;
        }

        @Override
        public void endVisit(ObjectInfo objectInfo) throws Exception {
            m_level--;
        }
    });
    String result = buffer.toString();
    result = StringUtils.removeEnd(result, ",\n");
    {
        String filler = "\"// filler filler filler filler filler\",\n";
        result = filler + result;
        result = filler + result;
    }
    System.out.println(result);
}

From source file:org.eclipse.wb.tests.designer.XWT.model.property.StylePropertyEditorTest.java

private static String getStylePropertySource(String styles) {
    String source;/* w  ww.  j  a va  2s  .c o  m*/
    if (styles != null) {
        source = " x:Style='";
        for (String part : StringUtils.split(styles, " |")) {
            source += "(t:SWT)." + part;
            source += " | ";
        }
        source = StringUtils.removeEnd(source, " | ");
        source += "'";
    } else {
        source = "";
    }
    return source;
}