@Nonnull @Override public String getExportedType() { final FragmentData value = getData(); // Mimetype for text-based datatypes String type = value.getContentType(); // Datatype for non text-based datatypes if (type == null) { type = value.getDataType().getTypeString(); } return type; }
@Nullable @Override public Object getValue() { return getData().getValue(); }
@Nonnull @Override public String getDataType() { return getData().getDataType().getTypeString(); }
private String getContentType() { return getData().getContentType(); }
@Override public boolean isMultiLine() { String contentType = getContentType(); // a text element is defined as a single-valued element with a certain content type (e.g. "text/plain", // "text/html", "text/x-markdown", potentially others) return contentType != null && contentType.startsWith("text/") && !getData().getDataType().isMultiValue(); }
@Nonnull @Override protected List<ContentElement> getItems(@Nonnull ContentFragment fragment, @Nonnull SlingHttpServletRequest request) { Config config = getConfig(request); ValueMap map = getComponentValueMap(config, request); String textOnlyParam = request.getParameter(PARAM_AND_PN_DISPLAY_MODE); boolean textOnly = map != null && map.containsKey(PARAM_AND_PN_DISPLAY_MODE) && map.get(PARAM_AND_PN_DISPLAY_MODE, "multi").equals(SINGLE_TEXT); if (textOnlyParam != null) { textOnly = textOnlyParam.equals(SINGLE_TEXT); } if (textOnly) { Iterator<ContentElement> elementIterator = fragment.getElements(); List<ContentElement> elementList = new ArrayList<ContentElement>(); while (elementIterator.hasNext()) { ContentElement element = elementIterator.next(); String contentType = element.getValue().getContentType(); if (contentType != null && contentType.startsWith("text/") && !element.getValue().getDataType().isMultiValue()) { elementList.add(element); } } return elementList; } return IteratorUtils.toList(fragment.getElements()); }
@Nullable @Override public String getHtml() { // restrict this method to text elements if (!isMultiLine()) { return null; } String contentType = getContentType(); String [] values = getData().getValue(String[].class); String value = null; if (values != null) { value = StringUtils.join(values, ", "); } if ("text/html".equals(contentType)) { // return HTML as is return value; } else { try { if (htmlValue == null) { // convert element value to HTML htmlValue = converter.convertToHTML(value, contentType); } return htmlValue; } catch (ContentFragmentException e) { LOG.warn("Could not convert to HTML", e); return null; } } }