Example usage for org.apache.wicket.util.string Strings isEmpty

List of usage examples for org.apache.wicket.util.string Strings isEmpty

Introduction

In this page you can find the example usage for org.apache.wicket.util.string Strings isEmpty.

Prototype

public static boolean isEmpty(final CharSequence string) 

Source Link

Document

Checks whether the string is considered empty.

Usage

From source file:org.wicketstuff.mergedresources.util.MergedHeaderContributor.java

License:Apache License

public MergedHeaderContributor(List<ResourceReference> refs, String cssMediaType) {
    _refs = new ArrayList<ResourceReference>(refs);
    _cssMediaType = cssMediaType;//from  ww w . ja va  2  s  .c o  m
    _contributor = new IHeaderContributor() {

        private static final long serialVersionUID = 1L;

        public void renderHead(final IHeaderResponse response) {
            for (final ResourceReference ref : _refs) {
                final String name = ref.getName();
                if (name != null) {
                    if (name.endsWith(".js")) {
                        response.renderJavascriptReference(ref);
                    } else if (name.endsWith(".css")) {
                        if (Strings.isEmpty(_cssMediaType)) {
                            response.renderCSSReference(ref);
                        } else {
                            response.renderCSSReference(ref, _cssMediaType);
                        }
                    }
                }
            }
        }
    };
}

From source file:org.wicketstuff.minis.behavior.AttributeAppenderPlus.java

License:Apache License

/**
 * {@inheritDoc}/*from w  ww . j a  v  a 2  s  . com*/
 */
@Override
protected String newValue(final String currentValue, final String appendValue) {
    return super.newValue(currentValue,
            Strings.isEmpty(appendValue) ? appendValue : prefix_ + appendValue + suffix_);
}

From source file:org.wicketstuff.minis.behavior.HideWhenEmptyOrNullBehavior.java

License:Apache License

@Override
public void onConfigure(final Component component) {
    super.onConfigure(component);
    Object dependentValue = component.getDefaultModelObject();
    boolean visible;
    if (dependentValue instanceof Collection) {
        final Collection<?> c = (Collection<?>) dependentValue;
        visible = !c.isEmpty();//from  ww  w  .j a v a  2 s.  c o  m
    } else if (dependentValue instanceof CharSequence) {
        visible = !Strings.isEmpty((CharSequence) dependentValue);
    } else {
        visible = dependentValue != null;
    }
    component.setVisible(visible);
}

From source file:org.wicketstuff.minis.behavior.veil.Veil.java

License:Apache License

/**
 * Constructor// w  w  w .  jav a  2s. co m
 * 
 * @param cssClassName
 *            name of css class that will be used for the veil
 */
public Veil(final String cssClassName) {
    if (!Strings.isEmpty(cssClassName))
        this.cssClassName = cssClassName;

}

From source file:org.wicketstuff.minis.filter.ServerHostNameAndTimeFilter.java

License:Apache License

/**
 * Construct with an id.// w w  w  . j a  v a 2  s . c  om
 * 
 * @param hostId
 *            a unique id identifying this server instance
 */
public ServerHostNameAndTimeFilter(final String hostId) {
    try {
        final InetAddress localMachine = InetAddress.getLocalHost();
        host = localMachine.getHostName() + "/" + localMachine.getHostAddress() + "/"
                + (Strings.isEmpty(hostId) ? "<unknown>" : hostId);
    } catch (final UnknownHostException ex) {
        throw new WicketRuntimeException(ex);
    }
}

From source file:org.wicketstuff.minis.model.IsEmptyOrNullModel.java

License:Apache License

@Override
protected Boolean load() {
    boolean empty = true;
    W dependentValue = getDependentModel().getObject();
    if (dependentValue instanceof Collection) {
        empty = ((Collection<?>) dependentValue).isEmpty();
    } else if (dependentValue instanceof CharSequence) {
        empty = Strings.isEmpty((CharSequence) dependentValue);
    } else {/*from ww  w  .ja v a 2s  .c o m*/
        empty = dependentValue == null;
    }
    return empty;
}

From source file:org.wicketstuff.misc.behaviors.AttributeAppenderPlus.java

License:Apache License

@Override
protected String newValue(String currentValue, String appendValue) {
    if (!Strings.isEmpty(appendValue)) {
        appendValue = prefix_ + appendValue + suffix_;
    }//ww  w  .j  av  a  2s  .com
    return super.newValue(currentValue, appendValue);
}

From source file:org.wicketstuff.misc.behaviors.SimpleAttributeAppender.java

License:Apache License

/**
 * @see org.apache.wicket.behavior.AbstractBehavior#onComponentTag(org.apache.wicket.Component,
 *      org.apache.wicket.markup.ComponentTag)
 *///from  w w  w .j a  v  a2s. c o m
@Override
public void onComponentTag(final Component component, final ComponentTag tag) {
    if (isEnabled(component) && !Strings.isEmpty(getValue())) {
        CharSequence newValue = tag.getAttributes().getString(getAttribute());
        if (Strings.isEmpty(newValue)) {
            newValue = getValue();
        } else {
            newValue = new StringBuilder(getValue()).append(separator_).append(newValue);
        }
        tag.getAttributes().put(getAttribute(), newValue);
    }
}

From source file:org.wicketstuff.misc.filters.ServerHostNameAndTimeFilter.java

License:Apache License

/**
 * Construct with an id./*from   w  ww. ja  v a  2  s  . co  m*/
 *
 * @param hostId a unique id indentifying this server instance
 */
public ServerHostNameAndTimeFilter(String hostId) throws Exception {
    InetAddress localMachine = InetAddress.getLocalHost();
    String hostName = localMachine.getHostName();
    String address = localMachine.getHostAddress();
    host = ((!Strings.isEmpty(hostName)) ? hostName + "/" + address : address) + "/" + hostId;
    if (Strings.isEmpty(hostId)) {
        host = "<unknown>";
    }
}

From source file:org.wicketstuff.multitextinput.MultiTextInput.java

License:Apache License

@Override
public void renderHead(HtmlHeaderContainer container) {
    IHeaderResponse response = container.getHeaderResponse();

    // shouldn't be using MarkupAttributes as it's an internal method, but
    // have to, no other way to
    // find out if the user put an id attribute on the tag,
    // getMarkupId(false) should tell us, but it doens't
    // at this stage in rendering it seems
    String tmpId = getMarkupAttributes().getString("id");
    // if they haven't set the id on the component tag, we'll set one for
    // them//w  w w.ja  v  a2  s  . co m
    if (Strings.isEmpty(tmpId)) {
        setOutputMarkupId(true);
        tmpId = this.getMarkupId(true);
    }
    final String id = tmpId;

    // add prototype
    response.renderJavaScriptReference(PrototypeResourceReference.INSTANCE);
    // add this components javascript
    response.renderJavaScriptReference(new PackageResourceReference(this.getClass(), "res/scripts/tag.js"));
    // add component css
    if (properties.isBrowserInternetExplorer()) {
        response.renderCSSReference(
                new PackageResourceReference(this.getClass(), "res/stylesheets/tag-ie.css"));
    } else if (properties.isBrowserSafari()) {
        response.renderCSSReference(
                new PackageResourceReference(this.getClass(), "res/stylesheets/tag-webkit.css"));
    } else {
        response.renderCSSReference(
                new PackageResourceReference(this.getClass(), "res/stylesheets/tag-moz.css"));
    }

    // render the javascript to setup the component
    IModel<Map<String, CharSequence>> variablesModel = new AbstractReadOnlyModel<Map<String, CharSequence>>() {
        private static final long serialVersionUID = 1L;

        @Override
        public Map<String, CharSequence> getObject() {
            Map<String, CharSequence> variables = new HashMap<String, CharSequence>(2);
            variables.put("id", id);
            StringBuffer arr = new StringBuffer();
            // join our collection into a comma delimeted string
            Collection<T> model = (Collection<T>) MultiTextInput.this.getInnermostModel().getObject();
            if (model != null) {
                Iterator<?> iter = model.iterator();
                while (iter.hasNext()) {
                    arr.append('\'');
                    // looks like a weird substitution, but regexp in java
                    // ftl.
                    arr.append(iter.next().toString().replaceAll("'", "\\\\'").replaceAll("\"", "\\\\\""));
                    arr.append('\'');
                    if (iter.hasNext()) {
                        arr.append(',');
                    }
                }
            }
            variables.put("model", arr.toString());
            variables.put("length", String.valueOf(MultiTextInput.this.inputLength));
            return variables;
        }
    };
    // merge the javascript from the properties file with the properties we
    // set above
    String js = new StringBuffer().append(getString("javascript.tagEntry", variablesModel)).toString();
    response.renderOnDomReadyJavaScript(js.toString());

    super.renderHead(container);
}