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

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

Introduction

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

Prototype

public static String trimToEmpty(String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null.

Usage

From source file:com.dattack.dbping.log.CSVFileLogWriter.java

private String format(final LogEntry entry) {

    String data = null;/* w w w .  j a va  2s.com*/
    synchronized (csvBuilder) {
        csvBuilder.append(new Date(entry.getEventTime())) //
                .append(StringUtils.trimToEmpty(entry.getTaskName())) //
                .append(StringUtils.trimToEmpty(entry.getThreadName())) //
                .append(entry.getIteration()) //
                .append(StringUtils.trimToEmpty(entry.getSqlLabel())) //
                .append(entry.getRows()) //
                .append(entry.getConnectionTime()) //
                .append(entry.getFirstRowTime()) //
                .append(entry.getTotalTime());

        if (entry.getException() != null) {
            csvBuilder.append(normalize(entry.getException().getMessage()));
        }
        csvBuilder.eol();
        addDataRowList(entry.getRowList());

        data = csvBuilder.toString();
        csvBuilder.clear();
    }
    return data;
}

From source file:com.bluexml.side.Integration.alfresco.xforms.webscript.XmlParser.java

public Map<String, Object> parse(Element element) throws Exception {
    Map<String, Object> objectModel = new HashMap<String, Object>();

    String qualifiedName = getQualifiedName(element);
    objectModel.put("dataType", qualifiedName);

    // collect attributes
    Element attributeContainer = DOMUtil.getChild(element, "attributes");
    Map<String, Object> attrs = new HashMap<String, Object>();
    if (attributeContainer != null) {
        List<Element> attributes = DOMUtil.getChildren(attributeContainer, "attribute");
        for (Element e : attributes) {
            // only legitimate attributes should find their way into the attributes map
            if (StringUtils.trimToNull(e.getAttribute("skipMe")) == null) {
                String attributeName = getQualifiedName(e);
                List<Element> value = DOMUtil.getChildren(e, "value");

                if (value.size() == 1) {
                    String stringValue = value.get(0).getTextContent();
                    attrs.put(attributeName, stringValue);
                } else if (value.size() > 1) {
                    List<String> values = new ArrayList<String>(value.size());
                    for (Element valueElement : value) {
                        String stringValue = StringUtils.trimToEmpty(valueElement.getTextContent());
                        values.add(stringValue);
                    }// ww w . jav  a 2 s .c o m
                    attrs.put(attributeName, values);
                }
            }
        }
    }
    objectModel.put("attributes", attrs);

    // collect associations
    Element associationsContener = DOMUtil.getChild(element, "associations");

    List<AssociationBean> assos = new ArrayList<AssociationBean>();
    if (associationsContener != null) {
        String associationsAction = associationsContener.getAttribute("action");
        if (StringUtils.trimToNull(associationsAction) != null) {
            objectModel.put("associationsAction", associationsAction);
        }
        List<Element> associations = DOMUtil.getChildren(associationsContener, "association");
        for (Element e : associations) {
            AssociationBean association = new AssociationBean();
            association.setAssociationName(getQualifiedName(e));
            Element target = DOMUtil.getChild(e, "target");
            String action = e.getAttribute("action");
            if (StringUtils.trimToNull(action) != null) {
                association.setAction(AssociationBean.Actions.valueOf(action));
            }
            if (target != null) {
                String targetRef = target.getTextContent();
                String targetQualifiedName = getQualifiedName(target);
                association.setTargetQualifiedName(targetQualifiedName);
                association.setTargetId(targetRef);
            }
            assos.add(association);
        }
    }
    objectModel.put("associations", assos);

    return objectModel;
}

From source file:mitm.common.net.NetUtils.java

/**
 * Parses the provided URL query and returns a map with all names to values. The values are URL decoded. If 
 * toLowercase is true the keys of the map will be converted to lowecase.
 * /*from  w  w  w.jav a2s .  c  o  m*/
 * Example:
 * test=123&value=%27test%27&value=abc maps to test -> [123] and value -> ["test", abc]
 * @throws IOException 
 */
public static Map<String, String[]> parseQuery(String query, boolean toLowercase) throws IOException {
    Map<String, String[]> map = new HashMap<String, String[]>();

    if (query == null) {
        return map;
    }

    String[] elements = StringUtils.split(query, '&');

    for (String element : elements) {
        element = element.trim();

        if (StringUtils.isEmpty(element)) {
            continue;
        }

        String name;
        String value;

        int i = element.indexOf('=');

        if (i > -1) {
            name = StringUtils.substring(element, 0, i);
            value = StringUtils.substring(element, i + 1);
        } else {
            name = element;
            value = "";
        }

        name = StringUtils.trimToEmpty(name);
        value = StringUtils.trimToEmpty(value);

        if (toLowercase) {
            name = name.toLowerCase();
        }

        value = URLDecoder.decode(value, CharacterEncoding.UTF_8);

        String[] updated = (String[]) ArrayUtils.add(map.get(name), value);

        map.put(name, updated);
    }

    return map;
}

From source file:de.xirp.profile.CommunicationProtocol.java

/**
 * Returns the main class' name of the communication plugin.
 * //ww w. j  a  v a 2s  . c o m
 * @return The class name.
 */
@XmlTransient
public String getClassName() {
    return StringUtils.trimToEmpty(className);
}

From source file:ips1ap101.lib.core.db.util.DBUtils.java

public static String[] getConstraintMessages(String message, String identifier) {
    String[] keys = getConstraintMessageKeys(message);
    if (keys != null && keys.length > 0) {
        String transaction = BundleWebui.getString("database.action.command");
        String[] messages = new String[keys.length];
        for (int i = 0; i < keys.length; i++) {
            messages[i] = StringUtils.trimToEmpty(Bitacora.getTextoMensaje(keys[i], transaction, identifier));
        }/*  w  w  w  . j  a v a  2 s  .  c  o  m*/
        return messages;
    }
    return null;
}

From source file:com.hangum.tadpole.util.tables.SQLResultFilter.java

@SuppressWarnings("unchecked")
@Override/*w  ww  . j  a  va 2 s.c  o  m*/
public boolean select(Viewer viewer, Object parentElement, Object element) {
    HashMap<Integer, String> model = (HashMap<Integer, String>) element;

    if (filter.equals("*") || filter.equals("")) //$NON-NLS-1$//$NON-NLS-2$
        return true;

    if (filter.indexOf("=") == -1) { //  ? . //$NON-NLS-1$
        for (int i = 0; i < model.size(); i++) {
            String tmp = model.get(i) == null ? "" : model.get(i);
            String key = (tmp).toLowerCase();

            if (!"".equals(key)) { //$NON-NLS-1$
                if (key.matches(".*" + filter.toLowerCase() + ".*")) //$NON-NLS-1$//$NON-NLS-2$
                    return true;
            }
        }

    } else { //  ? or .
        String[] baseArray = filter.split(","); //$NON-NLS-1$
        for (String baseTmp : baseArray) {
            try {
                String[] searchFillText = baseTmp.split("="); //$NON-NLS-1$
                String columnName = ("" + searchFillText[0]).toLowerCase(); //$NON-NLS-1$
                String searchText = searchFillText.length == 2 ? (StringUtils.trimToEmpty(searchFillText[1]))
                        : ""; //$NON-NLS-1$ //$NON-NLS-2$
                if ("".equals(searchText)) //$NON-NLS-1$
                    return false;

                int index = tableToHeaderInfo.get(columnName);
                String key = (model.get(index)).toLowerCase();

                if (!"".equals(key)) { //$NON-NLS-1$
                    if (key.matches(".*" + searchText.toLowerCase() + ".*")) //$NON-NLS-1$//$NON-NLS-2$
                        return true;
                }

            } catch (Exception e) {
                return false;
            }
        }
    }

    return false;
}

From source file:com.hangum.tadpole.engine.sql.util.tables.SQLResultFilter.java

@SuppressWarnings("unchecked")
@Override/*  w w  w .j a v a2s  .  c om*/
public boolean select(Viewer viewer, Object parentElement, Object element) {
    HashMap<Integer, Object> model = (HashMap<Integer, Object>) element;

    if (filter.equals("*") || filter.equals("")) //$NON-NLS-1$//$NON-NLS-2$
        return true;

    if (filter.indexOf("=") == -1) { //  ? . //$NON-NLS-1$
        for (int i = 0; i < model.size(); i++) {
            String tmp = model.get(i) == null ? "" : model.get(i).toString();
            String key = (tmp).toLowerCase();

            if (!"".equals(key)) { //$NON-NLS-1$
                if (key.matches(".*" + filter.toLowerCase() + ".*")) //$NON-NLS-1$//$NON-NLS-2$
                    return true;
            }
        }

    } else { //  ? or .
        String[] baseArray = filter.split(","); //$NON-NLS-1$
        for (String baseTmp : baseArray) {
            try {
                String[] searchFillText = baseTmp.split("="); //$NON-NLS-1$
                String columnName = ("" + searchFillText[0]).toLowerCase(); //$NON-NLS-1$
                String searchText = searchFillText.length == 2 ? (StringUtils.trimToEmpty(searchFillText[1]))
                        : ""; //$NON-NLS-1$ //$NON-NLS-2$
                if ("".equals(searchText)) //$NON-NLS-1$
                    return false;

                int index = tableToHeaderInfo.get(columnName);
                String key = (model.get(index) == null ? "" : model.get(index).toString()).toLowerCase();

                if (!"".equals(key)) { //$NON-NLS-1$
                    if (key.matches(".*" + searchText.toLowerCase() + ".*")) //$NON-NLS-1$//$NON-NLS-2$
                        return true;
                }

            } catch (Exception e) {
                return false;
            }
        }
    }

    return false;
}

From source file:de.xirp.profile.CommunicationInterface.java

/**
 * Sets the main class name of the communication interface plugin.
 * //  ww w  .jav  a2s  . c  om
 * @param clazz
 *            The class name to set.
 */
public void setClassName(String clazz) {
    this.clazz = StringUtils.trimToEmpty(clazz);
}

From source file:com.haulmont.cuba.desktop.sys.WindowBreadCrumbs.java

public void update() {
    removeAll();/*from  w  ww.j  a  v  a2  s  .  co  m*/
    btn2win.clear();
    for (Iterator<Window> it = windows.iterator(); it.hasNext();) {
        Window window = it.next();
        JButton button = new JXHyperlink();
        button.setFocusable(false);
        button.setText(StringUtils.trimToEmpty(window.getCaption()));
        button.addActionListener(new ValidationAwareActionListener() {
            @Override
            public void actionPerformedAfterValidation(ActionEvent e) {
                JButton btn = (JButton) e.getSource();
                Window win = btn2win.get(btn);
                if (win != null) {
                    fireListeners(win);
                }
            }
        });

        btn2win.put(button, window);

        if (it.hasNext()) {
            add(button);
            JLabel separatorLab = new JLabel(">");
            add(separatorLab);
        } else {
            add(new JLabel(window.getCaption()));
        }
    }
}

From source file:com.edgenius.wiki.render.impl.LinkRenderHelperImpl.java

public ObjectPosition appendCreateLink(StringBuffer buffer, String link, String view) {
    link = StringUtils.trimToEmpty(link);
    view = StringUtils.trimToEmpty(view);
    //check if link start by 0:link(always create) or 2:link (create home page)
    String type = String.valueOf(LinkModel.LINK_TO_CREATE_FLAG);
    if (link != null) {
        if (link.indexOf(':') == 1) {
            type = new String(new char[] { link.charAt(0) });
            link = link.substring(2);/*from w  w w.  j  a  va2 s .c  om*/
        }
    }

    ObjectPosition pos = new ObjectPosition("[" + view + "]");
    pos.serverHandler = LinkHandler.HANDLER;
    pos.uuid = context.createUniqueKey(false);
    pos.values.put(NameConstants.TYPE, String.valueOf(type));
    pos.values.put(NameConstants.NAME, link);
    pos.values.put(NameConstants.VIEW, view);
    pos.values.put(NameConstants.SPACE, spaceUname);
    context.getObjectList().add(pos);

    buffer.append(pos.uuid);

    return pos;
}