Attributes attribute = design.attributes();
DesignAttributeHandler.writeAttribute("color", attribute,
- color.getCSS(), Color.WHITE.getCSS(), String.class);
+ color.getCSS(), Color.WHITE.getCSS(), String.class,
+ designContext);
DesignAttributeHandler.writeAttribute("popup-style", attribute,
popupStyle == PopupStyle.POPUP_NORMAL ? "normal" : "simple",
- "normal", String.class);
+ "normal", String.class, designContext);
DesignAttributeHandler.writeAttribute("position", attribute,
- positionX + "," + positionY, "0,0", String.class);
+ positionX + "," + positionY, "0,0", String.class,
+ designContext);
}
@Override
Attributes attr = design.attributes();
// handle readonly
DesignAttributeHandler.writeAttribute("readonly", attr,
- super.isReadOnly(), def.isReadOnly(), Boolean.class);
+ super.isReadOnly(), def.isReadOnly(), Boolean.class,
+ designContext);
}
private static final Logger getLogger() {
// handle immediate
if (explicitImmediateValue != null) {
DesignAttributeHandler.writeAttribute("immediate", attr,
- explicitImmediateValue, def.isImmediate(), Boolean.class);
+ explicitImmediateValue, def.isImmediate(), Boolean.class,
+ designContext);
}
}
Resource icon = getItemIcon(itemId);
if (icon != null) {
DesignAttributeHandler.writeAttribute("icon", element.attributes(),
- icon, null, Resource.class);
+ icon, null, Resource.class, context);
}
if (isSelected(itemId)) {
.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("maxlength", attr, getMaxLength(),
- def.getMaxLength(), Integer.class);
+ def.getMaxLength(), Integer.class, designContext);
}
}
CheckBox def = (CheckBox) designContext.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("checked", attr, getValue(),
- def.getValue(), Boolean.class);
+ def.getValue(), Boolean.class, designContext);
}
@Override
if (section.grid.getDefaultHeaderRow() == this) {
DesignAttributeHandler.writeAttribute("default",
- trElement.attributes(), true, null, boolean.class);
+ trElement.attributes(), true, null, boolean.class,
+ designContext);
}
}
GridColumnState def = new GridColumnState();
DesignAttributeHandler.writeAttribute("property-id", attributes,
- getPropertyId(), null, Object.class);
+ getPropertyId(), null, Object.class, designContext);
// Sortable is a special attribute that depends on the container.
DesignAttributeHandler.writeAttribute("sortable", attributes,
- isSortable(), null, boolean.class);
+ isSortable(), null, boolean.class, designContext);
DesignAttributeHandler.writeAttribute("editable", attributes,
- isEditable(), def.editable, boolean.class);
+ isEditable(), def.editable, boolean.class, designContext);
DesignAttributeHandler.writeAttribute("resizable", attributes,
- isResizable(), def.resizable, boolean.class);
+ isResizable(), def.resizable, boolean.class, designContext);
DesignAttributeHandler.writeAttribute("hidable", attributes,
- isHidable(), def.hidable, boolean.class);
+ isHidable(), def.hidable, boolean.class, designContext);
DesignAttributeHandler.writeAttribute("hidden", attributes,
- isHidden(), def.hidden, boolean.class);
+ isHidden(), def.hidden, boolean.class, designContext);
DesignAttributeHandler.writeAttribute("hiding-toggle-caption",
- attributes, getHidingToggleCaption(), null, String.class);
+ attributes, getHidingToggleCaption(), null, String.class,
+ designContext);
DesignAttributeHandler.writeAttribute("width", attributes,
- getWidth(), def.width, Double.class);
+ getWidth(), def.width, Double.class, designContext);
DesignAttributeHandler.writeAttribute("min-width", attributes,
- getMinimumWidth(), def.minWidth, Double.class);
+ getMinimumWidth(), def.minWidth, Double.class,
+ designContext);
DesignAttributeHandler.writeAttribute("max-width", attributes,
- getMaximumWidth(), def.maxWidth, Double.class);
+ getMaximumWidth(), def.maxWidth, Double.class,
+ designContext);
DesignAttributeHandler.writeAttribute("expand", attributes,
- getExpandRatio(), def.expandRatio, Integer.class);
+ getExpandRatio(), def.expandRatio, Integer.class,
+ designContext);
}
/**
Grid def = context.getDefaultInstance(this);
DesignAttributeHandler.writeAttribute("editable", attrs,
- isEditorEnabled(), def.isEditorEnabled(), boolean.class);
+ isEditorEnabled(), def.isEditorEnabled(), boolean.class,
+ context);
DesignAttributeHandler.writeAttribute("frozen-columns", attrs,
- getFrozenColumnCount(), def.getFrozenColumnCount(), int.class);
+ getFrozenColumnCount(), def.getFrozenColumnCount(), int.class,
+ context);
if (getHeightMode() == HeightMode.ROW) {
DesignAttributeHandler.writeAttribute("rows", attrs,
- getHeightByRows(), def.getHeightByRows(), double.class);
+ getHeightByRows(), def.getHeightByRows(), double.class,
+ context);
}
SelectionMode selectionMode = null;
+ selectionModel.getClass().getName();
DesignAttributeHandler.writeAttribute("selection-mode", attrs,
- selectionMode, getDefaultSelectionMode(), SelectionMode.class);
+ selectionMode, getDefaultSelectionMode(), SelectionMode.class,
+ context);
if (columns.isEmpty()) {
// Empty grid. Structure not needed.
.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("value", attr, getValue(),
- def.getValue(), String.class);
+ def.getValue(), String.class, designContext);
}
@Override
Float defaultValue = ((ProgressBar) designContext
.getDefaultInstance(this)).getValue();
DesignAttributeHandler.writeAttribute("value", design.attributes(),
- getValue(), defaultValue, Float.class);
+ getValue(), defaultValue, Float.class, designContext);
}
@Override
}
Slider defaultSlider = context.getDefaultInstance(this);
DesignAttributeHandler.writeAttribute(this, "value",
- design.attributes(), defaultSlider);
+ design.attributes(), defaultSlider, context);
}
@Override
Table def = context.getDefaultInstance(this);
DesignAttributeHandler.writeAttribute("sortable", design.attributes(),
- isSortEnabled(), def.isSortEnabled(), boolean.class);
+ isSortEnabled(), def.isSortEnabled(), boolean.class, context);
Element table = null;
boolean hasColumns = getVisibleColumns().length != 0;
if (hasColumns) {
table = design.appendElement("table");
- writeColumns(table, def);
- writeHeader(table, def);
+ writeColumns(table, def, context);
+ writeHeader(table, def, context);
}
super.writeDesign(design, context);
if (hasColumns) {
}
}
- private void writeColumns(Element table, Table def) {
+ private void writeColumns(Element table, Table def, DesignContext context) {
Object[] columns = getVisibleColumns();
if (columns.length == 0) {
return;
}
DesignAttributeHandler.writeAttribute("width", col.attributes(),
- getColumnWidth(id), def.getColumnWidth(null), int.class);
+ getColumnWidth(id), def.getColumnWidth(null), int.class,
+ context);
DesignAttributeHandler.writeAttribute("expand", col.attributes(),
getColumnExpandRatio(id), def.getColumnExpandRatio(null),
- float.class);
+ float.class, context);
DesignAttributeHandler.writeAttribute("collapsible",
col.attributes(), isColumnCollapsible(id),
- def.isColumnCollapsible(null), boolean.class);
+ def.isColumnCollapsible(null), boolean.class, context);
DesignAttributeHandler.writeAttribute("collapsed", col.attributes(),
isColumnCollapsed(id), def.isColumnCollapsed(null),
- boolean.class);
+ boolean.class, context);
}
}
- private void writeHeader(Element table, Table def) {
+ private void writeHeader(Element table, Table def, DesignContext context) {
Object[] columns = getVisibleColumns();
if (columns.length == 0
|| (columnIcons.isEmpty() && columnHeaders.isEmpty())) {
Element th = header.appendElement("th");
th.html(getColumnHeader(id));
DesignAttributeHandler.writeAttribute("icon", th.attributes(),
- getColumnIcon(id), def.getColumnIcon(null), Resource.class);
+ getColumnIcon(id), def.getColumnIcon(null), Resource.class,
+ context);
}
}
.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("value", attr, getValue(),
- def.getValue(), String.class);
+ def.getValue(), String.class, designContext);
}
/*
Resource icon = getItemIcon(itemId);
if (icon != null) {
DesignAttributeHandler.writeAttribute("icon", element.attributes(),
- icon, null, Resource.class);
+ icon, null, Resource.class, context);
}
if (isSelected(itemId)) {
for (Object itemId : itemIds) {
Element tr = writeItem(tbody, itemId, context);
DesignAttributeHandler.writeAttribute("depth", tr.attributes(),
- depth, 0, int.class);
+ depth, 0, int.class, context);
if (getChildren(itemId) != null) {
writeItems(tbody, getChildren(itemId), depth + 1, context);
DesignContext context) {
Element tr = super.writeItem(tbody, itemId, context);
DesignAttributeHandler.writeAttribute("collapsed", tr.attributes(),
- isCollapsed(itemId), true, boolean.class);
+ isCollapsed(itemId), true, boolean.class, context);
return tr;
}
import com.vaadin.ui.components.colorpicker.ColorPickerPreview;
import com.vaadin.ui.components.colorpicker.ColorPickerSelect;
import com.vaadin.ui.declarative.Design;
-import com.vaadin.ui.declarative.DesignAttributeHandler;
import com.vaadin.ui.declarative.DesignContext;
/**
public class ComponentDesignWriterUtility {
private static final Set<String> WHITE_LIST_FQNS = new HashSet<>();
+ private static final Document document = new Document("");
+ private static final DesignContext designContext = new DesignContext(
+ document);
+
static {
WHITE_LIST_FQNS.add(DragAndDropWrapper.class.getName());
WHITE_LIST_FQNS.add(Navigator.EmptyView.class.getName());
"com.vaadin.server.VaadinPortlet$VaadinWebSpherePortalRequest");
WHITE_LIST_FQNS.add("com.vaadin.server.VaadinPortlet");
WHITE_LIST_FQNS.add("com.vaadin.server.VaadinPortletRequest");
- }
- private static final Document document = new Document("");
- private static final DesignContext designContext = new DesignContext(
- document);
+ designContext.setShouldWriteDefaultValues(true);
+ }
@SafeVarargs
public static List<String> getDeclarativeSyntax(
public static List<String> getDeclarativeSyntax(
List<Class<? extends Component>> components) {
- DesignAttributeHandler.setWriteDefaultValues(true);
-
List<String> declarativeStrings = components.stream()
.map(ComponentDesignWriterUtility::getDeclarativeSyntax)
.collect(Collectors.toList());
- DesignAttributeHandler.setWriteDefaultValues(false);
return declarativeStrings;
}
private static void printFullDeclarativeSyntax(
List<Class<? extends Component>> components) {
- DesignAttributeHandler.setWriteDefaultValues(true);
components.stream().forEach(component -> System.out
.println(getDeclarativeSyntax(component)));
- DesignAttributeHandler.setWriteDefaultValues(false);
}
private static List<Class<? extends Component>> getVaadin8Components()
Attributes attribute = design.attributes();
DesignAttributeHandler.writeAttribute("color", attribute,
- getValue().getCSS(), Color.WHITE.getCSS(), String.class);
+ getValue().getCSS(), Color.WHITE.getCSS(), String.class,
+ designContext);
DesignAttributeHandler.writeAttribute("popup-style", attribute,
popupStyle == PopupStyle.POPUP_NORMAL ? "normal" : "simple",
- "normal", String.class);
+ "normal", String.class, designContext);
DesignAttributeHandler.writeAttribute("position", attribute,
- positionX + "," + positionY, "0,0", String.class);
+ positionX + "," + positionY, "0,0", String.class,
+ designContext);
}
@Override
Attributes attr = design.attributes();
// handle default attributes
for (String attribute : getDefaultAttributes()) {
- DesignAttributeHandler.writeAttribute(this, attribute, attr, def);
+ DesignAttributeHandler.writeAttribute(this, attribute, attr, def,
+ designContext);
}
// handle locale
if (getLocale() != null && (getParent() == null
if (this instanceof Focusable) {
DesignAttributeHandler.writeAttribute("tabindex", attr,
((Focusable) this).getTabIndex(),
- ((Focusable) def).getTabIndex(), Integer.class);
+ ((Focusable) def).getTabIndex(), Integer.class,
+ designContext);
}
// handle custom attributes
Map<String, String> customAttributes = designContext
super.writeDesign(design, designContext);
AbstractEmbedded def = designContext.getDefaultInstance(this);
DesignAttributeHandler.writeAttribute("alt", design.attributes(),
- getAlternateText(), def.getAlternateText(), String.class);
+ getAlternateText(), def.getAlternateText(), String.class,
+ designContext);
}
@Override
AbstractField<T> def = designContext.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("readonly", attr,
- super.isReadOnly(), def.isReadOnly(), Boolean.class);
+ super.isReadOnly(), def.isReadOnly(), Boolean.class,
+ designContext);
}
@Override
MarginInfo defMargin, DesignContext context) {
if (margin.hasAll()) {
DesignAttributeHandler.writeAttribute("margin", design.attributes(),
- margin.hasAll(), defMargin.hasAll(), boolean.class);
+ margin.hasAll(), defMargin.hasAll(), boolean.class,
+ context);
} else {
DesignAttributeHandler.writeAttribute("margin-left",
design.attributes(), margin.hasLeft(), defMargin.hasLeft(),
- boolean.class);
+ boolean.class, context);
DesignAttributeHandler.writeAttribute("margin-right",
design.attributes(), margin.hasRight(),
- defMargin.hasRight(), boolean.class);
+ defMargin.hasRight(), boolean.class, context);
DesignAttributeHandler.writeAttribute("margin-top",
design.attributes(), margin.hasTop(), defMargin.hasTop(),
- boolean.class);
+ boolean.class, context);
DesignAttributeHandler.writeAttribute("margin-bottom",
design.attributes(), margin.hasBottom(),
- defMargin.hasBottom(), boolean.class);
+ defMargin.hasBottom(), boolean.class, context);
}
}
}
for (Resource r : getSources()) {
Attributes attr = design.appendElement("source").attributes();
DesignAttributeHandler.writeAttribute("href", attr, r, null,
- Resource.class);
+ Resource.class, designContext);
}
}
.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("maxlength", attr, getMaxLength(),
- def.getMaxLength(), Integer.class);
+ def.getMaxLength(), Integer.class, designContext);
}
@Override
// icon-alt
DesignAttributeHandler.writeAttribute("icon-alt", attr,
getIconAlternateText(), def.getIconAlternateText(),
- String.class);
+ String.class, designContext);
// click-shortcut
if (clickShortcut != null) {
DesignAttributeHandler.writeAttribute("click-shortcut", attr,
- clickShortcut, null, ShortcutAction.class);
+ clickShortcut, null, ShortcutAction.class, designContext);
}
}
}
CheckBox def = (CheckBox) designContext.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("checked", attr, getValue(),
- def.getValue(), Boolean.class);
+ def.getValue(), Boolean.class, designContext);
}
}
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Objects;
import java.util.Set;
import org.jsoup.nodes.Attributes;
// Row Expand
DesignAttributeHandler.writeAttribute("expand", row.attributes(),
- (int) getRowExpandRatio(i), 0, int.class);
+ (int) getRowExpandRatio(i), 0, int.class, designContext);
int colspan = 1;
Element col;
super.writeDesign(design, designContext);
Link def = designContext.getDefaultInstance(this);
DesignAttributeHandler.writeAttribute("target", design.attributes(),
- getTargetName(), def.getTargetName(), String.class);
+ getTargetName(), def.getTargetName(), String.class,
+ designContext);
DesignAttributeHandler.writeAttribute("href", design.attributes(),
- getResource(), def.getResource(), Resource.class);
+ getResource(), def.getResource(), Resource.class,
+ designContext);
}
@Override
public void writeDesign(Element design, DesignContext designContext) {
super.writeDesign(design, designContext);
for (MenuItem item : getItems()) {
- design.appendChild(createMenuElement(item));
+ design.appendChild(createMenuElement(item, designContext));
}
// in many cases there seems to be an empty more menu item
if (getMoreMenuItem() != null
&& !getMoreMenuItem().getText().isEmpty()) {
- Element moreMenu = createMenuElement(getMoreMenuItem());
+ Element moreMenu = createMenuElement(getMoreMenuItem(),
+ designContext);
moreMenu.attr("more", true);
design.appendChild(moreMenu);
}
}
}
- protected Element createMenuElement(MenuItem item) {
+ protected Element createMenuElement(MenuItem item, DesignContext context) {
Element menuElement = new Element(Tag.valueOf("menu"), "");
// Defaults
MenuItem def = new MenuItem("", null, null);
Attributes attr = menuElement.attributes();
DesignAttributeHandler.writeAttribute("icon", attr, item.getIcon(),
- def.getIcon(), Resource.class);
+ def.getIcon(), Resource.class, context);
DesignAttributeHandler.writeAttribute("disabled", attr,
- !item.isEnabled(), !def.isEnabled(), boolean.class);
+ !item.isEnabled(), !def.isEnabled(), boolean.class, context);
DesignAttributeHandler.writeAttribute("visible", attr, item.isVisible(),
- def.isVisible(), boolean.class);
+ def.isVisible(), boolean.class, context);
DesignAttributeHandler.writeAttribute("separator", attr,
- item.isSeparator(), def.isSeparator(), boolean.class);
+ item.isSeparator(), def.isSeparator(), boolean.class, context);
DesignAttributeHandler.writeAttribute("checkable", attr,
- item.isCheckable(), def.isCheckable(), boolean.class);
+ item.isCheckable(), def.isCheckable(), boolean.class, context);
DesignAttributeHandler.writeAttribute("checked", attr, item.isChecked(),
- def.isChecked(), boolean.class);
+ def.isChecked(), boolean.class, context);
DesignAttributeHandler.writeAttribute("description", attr,
- item.getDescription(), def.getDescription(), String.class);
+ item.getDescription(), def.getDescription(), String.class,
+ context);
DesignAttributeHandler.writeAttribute("style-name", attr,
- item.getStyleName(), def.getStyleName(), String.class);
+ item.getStyleName(), def.getStyleName(), String.class, context);
menuElement.append(item.getText());
if (item.hasChildren()) {
for (MenuItem subMenu : item.getChildren()) {
- menuElement.appendChild(createMenuElement(subMenu));
+ menuElement.appendChild(createMenuElement(subMenu, context));
}
}
.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("value", attr, getValue(),
- def.getValue(), String.class);
+ def.getValue(), String.class, designContext);
}
}
Float defaultValue = ((ProgressBar) designContext
.getDefaultInstance(this)).getValue();
DesignAttributeHandler.writeAttribute("value", design.attributes(),
- getValue(), defaultValue, Float.class);
+ getValue(), defaultValue, Float.class, designContext);
}
/**
}
Slider defaultSlider = context.getDefaultInstance(this);
DesignAttributeHandler.writeAttribute(this, "value",
- design.attributes(), defaultSlider);
+ design.attributes(), defaultSlider, context);
}
@Override
Attributes attr = tabElement.attributes();
// write attributes
DesignAttributeHandler.writeAttribute("visible", attr, tab.isVisible(),
- def.isVisible(), Boolean.class);
+ def.isVisible(), Boolean.class, designContext);
DesignAttributeHandler.writeAttribute("closable", attr,
- tab.isClosable(), def.isClosable(), Boolean.class);
+ tab.isClosable(), def.isClosable(), Boolean.class,
+ designContext);
DesignAttributeHandler.writeAttribute("caption", attr, tab.getCaption(),
- def.getCaption(), String.class);
+ def.getCaption(), String.class, designContext);
DesignAttributeHandler.writeAttribute("enabled", attr, tab.isEnabled(),
- def.isEnabled(), Boolean.class);
+ def.isEnabled(), Boolean.class, designContext);
DesignAttributeHandler.writeAttribute("icon", attr, tab.getIcon(),
- def.getIcon(), Resource.class);
+ def.getIcon(), Resource.class, designContext);
DesignAttributeHandler.writeAttribute("icon-alt", attr,
tab.getIconAlternateText(), def.getIconAlternateText(),
- String.class);
+ String.class, designContext);
DesignAttributeHandler.writeAttribute("description", attr,
- tab.getDescription(), def.getDescription(), String.class);
+ tab.getDescription(), def.getDescription(), String.class,
+ designContext);
DesignAttributeHandler.writeAttribute("style-name", attr,
- tab.getStyleName(), def.getStyleName(), String.class);
+ tab.getStyleName(), def.getStyleName(), String.class,
+ designContext);
DesignAttributeHandler.writeAttribute("id", attr, tab.getId(),
- def.getId(), String.class);
+ def.getId(), String.class, designContext);
if (getSelectedTab() != null
&& getSelectedTab().equals(tab.getComponent())) {
// use write attribute to get consistent handling for boolean
DesignAttributeHandler.writeAttribute("selected", attr, true, false,
- boolean.class);
+ boolean.class, designContext);
}
}
.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("value", attr, getValue(),
- def.getValue(), String.class);
+ def.getValue(), String.class, designContext);
}
}
if (getPoster() != null) {
Attributes attr = design.appendElement("poster").attributes();
DesignAttributeHandler.writeAttribute("href", attr, getPoster(),
- null, Resource.class);
+ null, Resource.class, designContext);
}
}
}
DesignAttributeHandler.writeAttribute("position", design.attributes(),
- getPosition(), def.getPosition(), String.class);
+ getPosition(), def.getPosition(), String.class, context);
// Process keyboard shortcuts
if (closeShortcuts.size() == 1 && hasCloseShortcut(KeyCode.ESCAPE)) {
// Write everything except the last "," to the design
DesignAttributeHandler.writeAttribute("close-shortcut",
- design.attributes(), attrString.trim(), null, String.class);
+ design.attributes(), attrString.trim(), null, String.class,
+ context);
}
for (Component c : getAssistiveDescription()) {
return Logger.getLogger(DesignAttributeHandler.class.getName());
}
- private static Map<Class<?>, AttributeCacheEntry> cache = new ConcurrentHashMap<>();
+ private final static Map<Class<?>, AttributeCacheEntry> cache = new ConcurrentHashMap<>();
// translates string <-> object
- private static DesignFormatter FORMATTER = new DesignFormatter();
-
- private static boolean writeDefaultValues = false;
-
- /**
- * Set whether default attribute values should be written by the
- * {@code DesignAttributeHandler#writeAttribute(String, Attributes, Object, Object, Class)}
- * method. Default is {@code false}.
- *
- * @param value
- * {@code true} to write default values of attributes,
- * {@code false} to disable writing of default values
- */
- public static void setWriteDefaultValues(boolean value) {
- writeDefaultValues = value;
- }
+ private final static DesignFormatter FORMATTER = new DesignFormatter();
/**
* Returns the currently used formatter. All primitive types and all types
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void writeAttribute(Object component, String attribute,
- Attributes attr, Object defaultInstance) {
+ Attributes attr, Object defaultInstance, DesignContext context) {
Method getter = findGetterForAttribute(component.getClass(), attribute);
if (getter == null) {
getLogger().warning(
Object value = getter.invoke(component);
Object defaultValue = getter.invoke(defaultInstance);
writeAttribute(attribute, attr, value, defaultValue,
- (Class) getter.getReturnType());
+ (Class) getter.getReturnType(), context);
} catch (Exception e) {
getLogger().log(Level.SEVERE,
"Failed to invoke getter for attribute " + attribute,
* the type of the input value
*/
public static <T> void writeAttribute(String attribute,
- Attributes attributes, T value, T defaultValue,
- Class<T> inputType) {
+ Attributes attributes, T value, T defaultValue, Class<T> inputType,
+ DesignContext context) {
if (!getFormatter().canConvert(inputType)) {
throw new IllegalArgumentException(
"input type: " + inputType.getName() + " not supported");
}
- if (writeDefaultValues || !SharedUtil.equals(value, defaultValue)) {
+ if (context.shouldWriteDefaultValues()
+ || !SharedUtil.equals(value, defaultValue)) {
String attributeValue = toAttributeValue(inputType, value);
if ("".equals(attributeValue) && (inputType == boolean.class
|| inputType == Boolean.class)) {
// this cannot be static because of testability issues
private Boolean legacyDesignPrefix = null;
+ private boolean shouldWriteDefaultValues = false;
+
public DesignContext(Document doc) {
this.doc = doc;
// Initialize the mapping between prefixes and package names.
}
map.put(attribute, value);
}
+
+ /**
+ * Set whether default attribute values should be written by the
+ * {@code DesignAttributeHandler#writeAttribute(String, Attributes, Object, Object, Class, DesignContext)}
+ * method. Default is {@code false}.
+ *
+ * @since 8.0
+ * @param value
+ * {@code true} to write default values of attributes,
+ * {@code false} to disable writing of default values
+ */
+ public void setShouldWriteDefaultValues(boolean value) {
+ shouldWriteDefaultValues = value;
+ }
+
+ /**
+ * Determines whether default attribute values should be written by the
+ * {@code DesignAttributeHandler#writeAttribute(String, Attributes, Object, Object, Class, DesignContext)}
+ * method. Default is {@code false}.
+ *
+ * @since 8.0
+ * @return {@code true} if default values of attributes should be written,
+ * otherwise {@code false}
+ */
+ public boolean shouldWriteDefaultValues() {
+ return shouldWriteDefaultValues;
+ }
}