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

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

Introduction

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

Prototype

public static String removeStart(String str, String remove) 

Source Link

Document

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

Usage

From source file:org.eclipse.wb.internal.core.model.generic.SimpleContainerFactory.java

private static AssociationObjectFactory getAssociation_invocationChild(String associationString) {
    associationString = StringUtils.removeStart(associationString, "invocationChild ");
    Assert.isTrue(associationString.startsWith("%parent%."),
            "Association 'invocationChild' should start with '%%parent%%.', but '%s' found.",
            associationString);// w  ww.  jav a  2 s  .c o m
    return AssociationObjectFactories.invocationChild(associationString, false);
}

From source file:org.eclipse.wb.internal.core.model.property.category.PropertyCategory.java

/**
 * Parses {@link PropertyCategory} from strings. Supported strings are:
 * /*from   w  w w.  j  a  va 2  s .  c om*/
 * <ul>
 * <li><b>normal</b></li>
 * <li><b>preferred</b></li>
 * <li><b>advanced</b></li>
 * <li><b>advanced-really</b></li>
 * <li><b>hidden</b></li>
 * <li><b>system(number)</b></li>
 * </ul>
 * 
 * @param defaultCategory
 *          the {@link PropertyCategory} to use if given string can not be parsed, or
 *          <code>null</code> if exception should be thrown.
 * 
 * @return the parsed {@link PropertyCategory}.
 */
public static PropertyCategory get(String text, PropertyCategory defaultCategory) {
    // simple
    if (StringUtils.equals(text, "normal")) {
        return NORMAL;
    }
    if (StringUtils.equals(text, "preferred")) {
        return PREFERRED;
    }
    if (StringUtils.equals(text, "advanced")) {
        return ADVANCED;
    }
    if (StringUtils.equals(text, "advanced-really")) {
        return ADVANCED_REALLY;
    }
    if (StringUtils.equals(text, "hidden")) {
        return HIDDEN;
    }
    // system
    if (StringUtils.startsWith(text, "system(")) {
        String systemText = text;
        systemText = StringUtils.removeStart(systemText, "system(");
        systemText = StringUtils.removeEnd(systemText, ")");
        try {
            int priority = Integer.parseInt(systemText);
            return system(priority);
        } catch (NumberFormatException e) {
        }
    }
    // can not parse
    if (defaultCategory != null) {
        return defaultCategory;
    }
    throw new IllegalArgumentException("Unknown category " + text);
}

From source file:org.eclipse.wb.internal.core.model.property.event.ListenerInfo.java

/**
 * @return the name of listener method, to display for user. For example <code>key</code> for
 *         <code>addKeyListener()</code>.
 *///from w w  w  .  j ava  2  s . c om
private static String _getListenerSimpleName(Method addListenerMethod) {
    String name = addListenerMethod.getName();
    // convert into simple name
    name = StringUtils.removeStart(name, "add");
    name = StringUtils.removeEnd(name, "Listener");
    name = StringUtils.removeEnd(name, "Handler");
    name = StringUtils.uncapitalize(name);
    // if become empty, use full name
    if (name.length() == 0) {
        name = addListenerMethod.getName();
    }
    return name;
}

From source file:org.eclipse.wb.internal.core.model.util.generic.CopyPropertyTopAbstractSupport.java

/**
 * Configures given {@link JavaInfo} to copy properties according parameters in description.
 */// w  w  w . j  av  a2s  . c o  m
protected final void install(JavaInfo javaInfo, String prefix) {
    for (String parameter : javaInfo.getDescription().getParameters().keySet()) {
        String sourcePath = null;
        String copyTitle = null;
        PropertyCategory category = PropertyCategory.NORMAL;
        if (parameter.startsWith(prefix)) {
            String[] parts = StringUtils.split(parameter);
            for (String part : parts) {
                if (part.startsWith("from=")) {
                    sourcePath = StringUtils.removeStart(part, "from=");
                }
                if (part.startsWith("to=")) {
                    copyTitle = StringUtils.removeStart(part, "to=");
                }
                if (part.startsWith("category=")) {
                    String categoryText = StringUtils.removeStart(part, "category=");
                    category = PropertyCategory.get(categoryText, category);
                }
            }
            // validate
            if (sourcePath == null || copyTitle == null) {
                String message = "No 'from' or 'to' attributes: " + parameter;
                JavaInfoUtils.getState(javaInfo).addWarning(new EditorWarning(message, null));
                continue;
            }
            // OK, create copy processor
            Predicate<JavaInfo> targetPredicate = createTargetPredicate(javaInfo);
            new CopyProcessor(javaInfo, targetPredicate, sourcePath, copyTitle, category);
        }
    }
}

From source file:org.eclipse.wb.internal.core.model.util.generic.ModelMethodPropertyChildSupport.java

@Override
protected ParameterProcessor createParameterProcessor() {
    return new ParameterProcessor() {
        private String m_childTypeName;

        @Override/*from ww w .j av a 2 s.  c  o m*/
        protected void processParameterPart(String part) throws Exception {
            super.processParameterPart(part);
            if (part.startsWith("child=")) {
                m_childTypeName = StringUtils.removeStart(part, "child=");
            }
        }

        @Override
        protected void processGetterSignature() {
            getterSignature += "(" + m_childTypeName + ")";
        }

        @Override
        protected void processSetterSignature() {
            setterSignature += "(" + m_childTypeName + ",java.lang.Object)";
        }

        @Override
        protected void configureProperty() {
            new PropertyProcessor() {
                @Override
                protected boolean isPropertyTarget(ObjectInfo target) {
                    return target.getParent() == object
                            && getter.getParameterTypes()[0].isAssignableFrom(target.getClass());
                }

                @Override
                protected Object getValue(ObjectInfo target) throws Exception {
                    return getter.invoke(object, target);
                }

                @Override
                protected void setValue(ObjectInfo target, Object value) throws Exception {
                    setter.invoke(object, target, value);
                }
            };
        }
    };
}

From source file:org.eclipse.wb.internal.core.utils.jdt.core.CodeUtils.java

private static String clearHiddenCode_getTag(String name) {
    IPreferenceStore preferences = DesignerPlugin.getPreferences();
    String tag = preferences.getString(name);
    tag = tag.trim();//w  w  w  . j  a va  2  s.  c  o  m
    // remove leading "//" prefix to search even "// $hide" - formatted line comments
    tag = StringUtils.removeStart(tag, "//");
    return tag;
}

From source file:org.eclipse.wb.internal.core.xml.model.generic.FlowContainerFactory.java

private Association getAssociation(String prefix) {
    String associationString = getParameter(prefix + ".x-association");
    if (StringUtils.isEmpty(associationString)) {
        return Associations.direct();
    } else if (associationString.startsWith("inter ")) {
        associationString = StringUtils.removeStart(associationString, "inter ");
        // extract tag
        String tag = StringUtils.substringBefore(associationString, " ");
        associationString = StringUtils.substringAfter(associationString, " ");
        // extract attributes
        Map<String, String> attributes = parseAttributes(associationString);
        return Associations.intermediate(tag, attributes);
    } else {/*  w ww  . j a  v  a 2 s  .  co m*/
        Assert.isTrue(associationString.startsWith("property "));
        String property = StringUtils.removeStart(associationString, "property ");
        return Associations.property(property);
    }
}

From source file:org.eclipse.wb.internal.core.xml.model.generic.SimpleContainerFactory.java

private Association getAssociation(String prefix) {
    String associationString = getParameter(prefix + ".x-association");
    if (associationString == null) {
        return Associations.direct();
    } else if (associationString.startsWith("inter ")) {
        associationString = StringUtils.removeStart(associationString, "inter ");
        // extract tag
        String tag = StringUtils.substringBefore(associationString, " ");
        associationString = StringUtils.substringAfter(associationString, " ");
        // extract attributes
        Map<String, String> attributes = parseAttributes(associationString);
        return Associations.intermediate(tag, attributes);
    } else {/*  w w  w .jav a2 s.c  om*/
        Assert.isTrue(associationString.startsWith("property "));
        String property = StringUtils.removeStart(associationString, "property ");
        return Associations.property(property);
    }
}

From source file:org.eclipse.wb.internal.core.xml.model.utils.CopyPropertyTopAbstractSupport.java

private List<CopyProcessor> createProcessors(XmlObjectInfo object) {
    List<CopyProcessor> processors = Lists.newArrayList();
    Predicate<XmlObjectInfo> targetPredicate = createTargetPredicate(object);
    for (String parameter : object.getDescription().getParameters().keySet()) {
        String sourcePath = null;
        String copyTitle = null;//from   w w  w  . ja v a 2 s.  co  m
        PropertyCategory category = PropertyCategory.NORMAL;
        if (parameter.startsWith(m_prefix)) {
            String[] parts = StringUtils.split(parameter);
            for (String part : parts) {
                if (part.startsWith("from=")) {
                    sourcePath = StringUtils.removeStart(part, "from=");
                }
                if (part.startsWith("to=")) {
                    copyTitle = StringUtils.removeStart(part, "to=");
                }
                if (part.startsWith("category=")) {
                    String categoryText = StringUtils.removeStart(part, "category=");
                    category = PropertyCategory.get(categoryText, category);
                }
            }
            // validate
            if (sourcePath == null || copyTitle == null) {
                continue;
            }
            // OK, create copy processor
            processors.add(new CopyProcessor(object, targetPredicate, sourcePath, copyTitle, category));
        }
    }
    return processors;
}

From source file:org.eclipse.wb.internal.core.xml.model.utils.NamespacesHelper.java

/**
 * Prepares information about existing namespaces.
 *///from   ww  w  . j  a va 2 s .co  m
public void prepareNamespaces() {
    m_names.clear();
    m_nameForURI.clear();
    for (DocumentAttribute attribute : m_rootElement.getDocumentAttributes()) {
        String name = attribute.getName();
        if (name.startsWith("xmlns")) {
            name = StringUtils.removeStart(name, "xmlns");
            name = StringUtils.removeStart(name, ":");
            m_nameForURI.put(attribute.getValue(), name);
            m_uriForName.put(name, attribute.getValue());
            m_names.add(name);
        }
    }
}