List of usage examples for org.apache.wicket.util.string Strings isEmpty
public static boolean isEmpty(final CharSequence string)
string
is considered empty. From source file:org.rest.annotations.security.HttpBasicAuthRoleCheckingStrategy.java
License:Apache License
@Override public boolean hasAnyRole(Roles roles) { WebRequest currentWebRequest = AbstractRestResource.getCurrentWebRequest(); String authorization = currentWebRequest.getHeader("Authorization"); if (!Strings.isEmpty(authorization) && authorization.startsWith("Basic")) { String base64Credentials = authorization.substring("Basic".length()).trim(); String credentials = new String(Base64.decodeBase64(base64Credentials)); final String[] values = credentials.split(":", 2); return username.equals(values[0]) && password.equals(values[1]); }/* w w w. j a va2 s. c om*/ return false; }
From source file:org.sakaiproject.scorm.ui.ContentPackageResourceMountStrategy.java
License:Educational Community License
private void appendValue(AppendingStringBuffer url, String key, String value) { String escapedValue = urlEncode(value); if (key.equals("resourceName")) escapedValue = value;// w w w . j a va2s .co m if (!Strings.isEmpty(escapedValue)) { if (!url.endsWith("/")) { url.append("/"); } url.append(key).append("/").append(escapedValue).append("/"); } }
From source file:org.syncope.console.pages.SchemaModalPage.java
License:Apache License
@Override public void setSchemaModalPage(final PageReference callerPageRef, final ModalWindow window, AbstractBaseBean schemaTO, final boolean createFlag) { final SchemaTO schema = schemaTO == null ? new SchemaTO() : (SchemaTO) schemaTO; final Form schemaForm = new Form("form"); schemaForm.setModel(new CompoundPropertyModel(schema)); schemaForm.setOutputMarkupId(Boolean.TRUE); final AjaxTextFieldPanel name = new AjaxTextFieldPanel("name", getString("name"), new PropertyModel<String>(schema, "name"), true); name.addRequiredLabel();/* w w w . j a va 2 s .c o m*/ name.setEnabled(createFlag); final AjaxTextFieldPanel conversionPattern = new AjaxTextFieldPanel("conversionPattern", getString("conversionPattern"), new PropertyModel<String>(schema, "conversionPattern"), true); final IModel<List<String>> validatorsList = new LoadableDetachableModel<List<String>>() { private static final long serialVersionUID = 5275935387613157437L; @Override protected List<String> load() { return restClient.getAllValidatorClasses(); } }; final AjaxDropDownChoicePanel<String> validatorClass = new AjaxDropDownChoicePanel<String>("validatorClass", getString("validatorClass"), new PropertyModel(schema, "validatorClass"), true); ((DropDownChoice) validatorClass.getField()).setNullValid(true); validatorClass.setChoices(validatorsList.getObject()); final AjaxDropDownChoicePanel<SchemaType> type = new AjaxDropDownChoicePanel<SchemaType>("type", getString("type"), new PropertyModel(schema, "type"), false); type.setChoices(Arrays.asList(SchemaType.values())); type.addRequiredLabel(); final AjaxTextFieldPanel enumerationValues = new AjaxTextFieldPanel("enumerationValues", getString("enumerationValues"), new PropertyModel<String>(schema, "enumerationValues"), false); if (schema != null && SchemaType.Enum.equals(((SchemaTO) schema).getType())) { enumerationValues.addRequiredLabel(); enumerationValues.setEnabled(Boolean.TRUE); } else { enumerationValues.removeRequiredLabel(); enumerationValues.setEnabled(Boolean.FALSE); } type.getField().add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { if (SchemaType.Enum.ordinal() == Integer.parseInt(type.getField().getValue())) { enumerationValues.addRequiredLabel(); enumerationValues.setEnabled(Boolean.TRUE); enumerationValues.setModelObject(((SchemaTO) schema).getEnumerationValues()); } else { enumerationValues.removeRequiredLabel(); enumerationValues.setEnabled(Boolean.FALSE); enumerationValues.setModelObject(null); } target.add(schemaForm); } }); final AutoCompleteTextField mandatoryCondition = new AutoCompleteTextField("mandatoryCondition") { private static final long serialVersionUID = -2428903969518079100L; @Override protected Iterator getChoices(String input) { List<String> choices = new ArrayList<String>(); if (Strings.isEmpty(input)) { choices = Collections.emptyList(); return choices.iterator(); } if ("true".startsWith(input.toLowerCase())) { choices.add("true"); } else if ("false".startsWith(input.toLowerCase())) { choices.add("false"); } return choices.iterator(); } }; mandatoryCondition.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(AjaxRequestTarget art) { } }); final AjaxCheckBoxPanel multivalue = new AjaxCheckBoxPanel("multivalue", getString("multivalue"), new PropertyModel<Boolean>(schema, "multivalue"), true); final AjaxCheckBoxPanel readonly = new AjaxCheckBoxPanel("readonly", getString("readonly"), new PropertyModel<Boolean>(schema, "readonly"), true); final AjaxCheckBoxPanel uniqueConstraint = new AjaxCheckBoxPanel("uniqueConstraint", getString("uniqueConstraint"), new PropertyModel<Boolean>(schema, "uniqueConstraint"), true); final AjaxButton submit = new IndicatingAjaxButton("apply", new ResourceModel("submit")) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form form) { SchemaTO schemaTO = (SchemaTO) form.getDefaultModelObject(); if (schemaTO.isMultivalue() && schemaTO.isUniqueConstraint()) { error(getString("multivalueAndUniqueConstr.validation")); target.add(feedbackPanel); return; } try { if (createFlag) { restClient.createSchema(kind, schemaTO); } else { restClient.updateSchema(kind, schemaTO); } if (callerPageRef.getPage() instanceof BasePage) { ((BasePage) callerPageRef.getPage()).setModalResult(true); } window.close(target); } catch (SyncopeClientCompositeErrorException e) { error(getString("error") + ":" + e.getMessage()); target.add(feedbackPanel); } } @Override protected void onError(final AjaxRequestTarget target, final Form form) { target.add(feedbackPanel); } }; String allowedRoles; if (createFlag) { allowedRoles = xmlRolesReader.getAllAllowedRoles("Schema", "create"); } else { allowedRoles = xmlRolesReader.getAllAllowedRoles("Schema", "update"); } MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, allowedRoles); schemaForm.add(name); schemaForm.add(conversionPattern); schemaForm.add(validatorClass); schemaForm.add(type); schemaForm.add(enumerationValues); schemaForm.add(mandatoryCondition); schemaForm.add(multivalue); schemaForm.add(readonly); schemaForm.add(uniqueConstraint); schemaForm.add(submit); add(schemaForm); }
From source file:org.wicketopia.joda.util.format.JodaFormatSupport.java
License:Apache License
public T convertToObject(String value, Locale locale) { if (Strings.isEmpty(value)) { return null; }//from w ww. ja va 2 s. c o m DateTimeFormatter format = formatProvider.getFormatter(); if (format == null) { throw new IllegalStateException("format must be not null"); } format = format.withLocale(locale).withPivotYear(pivotYear); if (applyTimeZoneDifference) { TimeZone zone = getClientTimeZone(); // instantiate now/ current time MutableDateTime dt = new MutableDateTime(); if (zone != null) { // set time zone for client format = format.withZone(DateTimeZone.forTimeZone(zone)); dt.setZone(DateTimeZone.forTimeZone(zone)); } try { // parse date retaining the time of the submission int result = format.parseInto(dt, value, 0); if (result < 0) { throw new ConversionException(new ParseException("unable to parse date " + value, ~result)); } } catch (RuntimeException e) { throw new ConversionException(e); } // apply the server time zone to the parsed value dt.setZone(getServerTimeZone()); return translator.fromDateTime(dt.toDateTime()); } else { try { DateTime date = format.parseDateTime(value); return date == null ? null : translator.fromDateTime(date); } catch (RuntimeException e) { throw new ConversionException(e); } } }
From source file:org.wicketstuff.dashboard.web.util.AjaxConfirmLink.java
License:Apache License
@Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); if (!Strings.isEmpty(confirmMessage)) { attributes.getAjaxCallListeners().add(new ConfirmAjaxCallListener(confirmMessage)); }/*from ww w. ja v a 2 s. c o m*/ }
From source file:org.wicketstuff.datatables.columns.SpanHeadersToolbar.java
License:Apache License
/** * Constructor//from www . j a v a 2 s .co m * * @param table * data table this toolbar will be attached to * @param columns */ public <T> SpanHeadersToolbar(final DataTable<T, S> table, final IDataTablesColumn<T, S>... columns) { super(table); RefreshingView<IColumn<T, S>> headers = new RefreshingView<IColumn<T, S>>("headers") { private static final long serialVersionUID = 1L; @Override protected Iterator<IModel<IColumn<T, S>>> getItemModels() { List<IModel<IColumn<T, S>>> columnsModels = new LinkedList<>(); List<? extends IColumn<T, S>> tableColumns = (columns != null && columns.length > 0) ? Arrays.asList(columns) : table.getColumns(); for (IColumn<T, S> column : tableColumns) { columnsModels.add(Model.of(column)); } return columnsModels.iterator(); } @Override protected void populateItem(Item<IColumn<T, S>> item) { final IColumn<T, S> column = item.getModelObject(); WebMarkupContainer header = new WebMarkupContainer("header"); if (column instanceof IDataTablesColumn) { IDataTablesColumn<T, S> dtColumn = (IDataTablesColumn<T, S>) column; if (dtColumn.getColspan() > 0) { header.add(AttributeModifier.replace("colspan", dtColumn.getColspan())); } if (dtColumn.getRowspan() > 0) { header.add(AttributeModifier.replace("rowspan", dtColumn.getRowspan() - 1)); } } if (column instanceof IStyledColumn) { Behavior cssAttributeBehavior = new Behavior() { private static final long serialVersionUID = 1L; @Override public void onComponentTag(final Component component, final ComponentTag tag) { super.onComponentTag(component, tag); String cssClass = ((IStyledColumn<?, S>) column).getCssClass(); if (!Strings.isEmpty(cssClass)) { tag.append("class", cssClass, " "); } } }; header.add(cssAttributeBehavior); } item.add(header); item.setRenderBodyOnly(true); header.add(column.getHeader("label")); } }; add(headers); }
From source file:org.wicketstuff.datetime.DateConverter.java
License:Apache License
/** * @see org.apache.wicket.util.convert.IConverter#convertToObject(java.lang.String, * java.util.Locale)//w w w.ja va 2 s . c o m */ @Override public Date convertToObject(String value, Locale locale) { if (Strings.isEmpty(value)) { return null; } DateTimeFormatter format = getFormat(locale); if (format == null) { throw new IllegalStateException("format must be not null"); } if (applyTimeZoneDifference) { TimeZone zone = getClientTimeZone(); DateTime dateTime; // set time zone for client format = format.withZone(getTimeZone()); try { // parse date retaining the time of the submission dateTime = format.parseDateTime(value); } catch (RuntimeException e) { throw newConversionException(e, locale); } // apply the server time zone to the parsed value if (zone != null) { dateTime = dateTime.withZoneRetainFields(DateTimeZone.forTimeZone(zone)); } return dateTime.toDate(); } else { try { DateTime date = format.parseDateTime(value); return date.toDate(); } catch (RuntimeException e) { throw newConversionException(e, locale); } } }
From source file:org.wicketstuff.datetime.extensions.yui.calendar.DatePicker.java
License:Apache License
/** * Filter all empty elements (workaround for {@link DateFormatSymbols} returning arrays with * empty elements)./*from w w w . j a va 2 s. c o m*/ * * @param stringArray * array to filter * @return filtered array (without null or empty string elements) */ protected final String[] filterEmpty(String[] stringArray) { if (stringArray == null) { return null; } List<String> list = new ArrayList<>(stringArray.length); for (String string : stringArray) { if (!Strings.isEmpty(string)) { list.add(string); } } return list.toArray(new String[list.size()]); }
From source file:org.wicketstuff.dojo11.application.DojoSettings.java
License:Apache License
/** * configure defaults//from w ww. j a va 2s . c o m * @return this */ public DojoSettings configure() { try { _application.getSharedResources().add(AbstractDefaultDojoBehavior.class, "dojo", null); Properties dojoProperties = new Properties(); dojoProperties.load( ClassLoader.getSystemResourceAsStream("org/wicketstuff/dojo11/wicketstuff-dojo.properties")); _dojoRelease = dojoProperties.getProperty("org.wicketstuff.dojo.release"); if (Strings.isEmpty(_dojoRelease)) { throw new IllegalArgumentException("not a valid dojo release: " + _dojoRelease); } _dojoSkinManager = newDojoSkinManager(); _dojoBaseUrl = "/resources/dojo/" + getDojoPath() + "/dojo/"; return this; } catch (Throwable t) { throw new WicketRuntimeException(t); } }
From source file:org.wicketstuff.dojo11.dojodnd.DojoDraggableBehavior.java
License:Apache License
/** * @see org.apache.wicket.behavior.IBehavior#onComponentTag(org.apache.wicket.Component, * org.apache.wicket.markup.ComponentTag) *//*from www. ja v a2 s . c om*/ public final void onComponentTag(Component component, ComponentTag tag) { if (tag.getType() != XmlTag.CLOSE) { final IValueMap attributes = tag.getAttributes(); attributes.put("dndType", dndTypeModel.getObject()); String cls = (String) attributes.get("class"); if (Strings.isEmpty(cls)) { cls = DOJO_DND_ITEM_CLASS; } else { cls = cls + " " + DOJO_DND_ITEM_CLASS; } attributes.put("class", cls); } }