@Override @SuppressWarnings("unchecked") public <Type> Type adaptTo(Class<Type> type) { if (type == ValueMap.class) { return (Type)this.properties; } else { return super.adaptTo(type); } }
/** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public final <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == ValueMap.class || type == ModifiableValueMap.class) { return (AdapterType) this.data; } return super.adaptTo(type); } }
@Override @SuppressWarnings("unchecked") public <Type> Type adaptTo(Class<Type> type) { if (type == String.class) { return (Type) ""; } return super.adaptTo(type); }
@SuppressWarnings("unchecked") @Override public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == ValueMap.class) { return (AdapterType) properties; } return super.adaptTo(type); }
@SuppressWarnings("unchecked") @Override public <Type> Type adaptTo(Class<Type> type) { if (ValueMap.class.equals(type)) { return (Type)props; } else { return super.adaptTo(type); } }
@SuppressWarnings("unchecked") @Override public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == InputStream.class) { return (AdapterType) new ByteArrayInputStream(data.getBytes(charset)); } else if (type == ValueMap.class) { return (AdapterType) ValueMapDecorator.EMPTY; } else { return super.adaptTo(type); } }
@Override @SuppressWarnings("unchecked") public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == ValueMap.class) { if (valueMap == null) { initValueMap(); } return (AdapterType) valueMap; } else { return super.adaptTo(type); } }
/** * @see org.apache.sling.api.adapter.Adaptable#adaptTo(java.lang.Class) */ @SuppressWarnings("unchecked") public <AdapterType> AdapterType adaptTo(final Class<AdapterType> type) { if (type == ValueMap.class) { return (AdapterType) new ValueMapDecorator(values); } else if (type == Map.class) { return (AdapterType) values; } return super.adaptTo(type); }
@Override @SuppressWarnings("unchecked") public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type.isAssignableFrom(ValueMap.class)) { return (AdapterType) getValueMap(); } return super.adaptTo(type); } }
@SuppressWarnings("unchecked") @Override public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == InputStream.class) { try { Map<String, List<Item>> out = new HashMap<>(); out.put("options", list.getItems()); Gson gson = new Gson(); String json = gson.toJson(out); return (AdapterType) new ByteArrayInputStream(json.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { log.warn("Unable to generate JSON object.", e); return null; } } else { return super.adaptTo(type); } } }
@SuppressWarnings("unchecked") @Override public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == InputStream.class) { StringWriter buffer = new StringWriter(); try { JSONWriter writer = new JSONWriter(buffer); writer.object(); writer.key("options"); writer.array(); for (Item item : list.getItems()) { writer.object(); writer.key("text").value(item.getTitle()); writer.key("value").value(item.getValue()); writer.endObject(); } writer.endArray(); writer.endObject(); return (AdapterType) new ByteArrayInputStream(buffer.toString().getBytes("UTF-8")); } catch (Exception e) { log.warn("Unable to generate JSON object.", e); return null; } } else { return super.adaptTo(type); } } }