Search in sources :

Example 1 with PropCMSubProperty

use of org.eclipse.wst.css.core.internal.contentmodel.PropCMSubProperty in project webtools.sourceediting by eclipse.

the class CSSPropertyContext method set.

/**
 * This function sets the pair of 'prop'/'value'. If shorthand properties
 * related to 'prop' are already defined, they will be expanded to avoid
 * property confliction. If descendant properties of 'prop' are already
 * defined, they will be removed to avoid property confliction.
 */
public void set(org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty prop, java.lang.String value) throws org.w3c.dom.DOMException {
    if (prop instanceof PropCMSubProperty) {
        ISubPropertyAdapter adapter = (ISubPropertyAdapter) subPropertyAdapters.get(prop.getName());
        if (adapter != null) {
            adapter.set(this, value);
            return;
        }
    }
    if (prop.getShorthandContainerCount() > 0) {
        // expand shorthand property
        CSSPropertyContext context = new CSSPropertyContext();
        for (int i = 0; i < prop.getShorthandContainerCount(); i++) {
            recursiveExtract(prop.shorthandContainerAt(i), context);
        }
        Enumeration properties = context.properties();
        while (properties.hasMoreElements()) {
            String propForeign = properties.nextElement().toString();
            set(propForeign, context.get(propForeign));
        }
    }
    removeDescendants(prop);
    set(prop.getName(), value);
}
Also used : Enumeration(java.util.Enumeration) PropCMSubProperty(org.eclipse.wst.css.core.internal.contentmodel.PropCMSubProperty)

Example 2 with PropCMSubProperty

use of org.eclipse.wst.css.core.internal.contentmodel.PropCMSubProperty in project webtools.sourceediting by eclipse.

the class CSSPropertyContext method get.

/**
 * This function returns value of 'prop'. Querying value mechanism checks
 * short-hand properties.
 *
 * For example, given "background=fixed white" is set in this insatnce and
 * param "prop=background-color", the return value will be "white".
 */
public java.lang.String get(org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty prop) {
    if (prop instanceof PropCMSubProperty) {
        ISubPropertyAdapter adapter = (ISubPropertyAdapter) subPropertyAdapters.get(prop.getName());
        if (adapter != null)
            return adapter.get(this);
    }
    String str = get(prop.getName());
    if ((str == null || str.length() == 0) && prop.getShorthandContainerCount() > 0) {
        // get expanded property
        for (int i = 0; i < prop.getShorthandContainerCount(); i++) {
            PropCMProperty propParent = prop.shorthandContainerAt(i);
            String strParent = get(propParent);
            if (strParent != null && strParent.trim().length() > 0) {
                IShorthandAdapter adapter = (IShorthandAdapter) shorthandAdapters.get(propParent);
                if (adapter != null) {
                    String extractedValue = adapter.extract(strParent, prop);
                    // $NON-NLS-1$
                    return (extractedValue != null) ? extractedValue : "";
                }
            }
        }
    }
    return str;
}
Also used : PropCMProperty(org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty) PropCMSubProperty(org.eclipse.wst.css.core.internal.contentmodel.PropCMSubProperty)

Example 3 with PropCMSubProperty

use of org.eclipse.wst.css.core.internal.contentmodel.PropCMSubProperty in project webtools.sourceediting by eclipse.

the class CSSPropertyContext method expandToLeaf.

/**
 * This function expands a short-hand property's value to each leaf
 * property's value and set them to 'foreign'
 *
 * For example, given [prop=border-top, value="solid 1px yellow"] will be
 * expanded to [border-top-color=yellow, border-top-style=solid,
 * border-top-width=1px] and they are stored to 'foreign' context.
 *
 * Note that recursively shorthanded property like 'border' will be
 * expanded to all descendant leaf properties like
 * 'border-[top/right/bottom/left]-[color/style/width]'
 *
 * @param prop
 *            org.eclipse.wst.css.core.contentmodel.PropCMProperty
 * @param value
 *            java.lang.String
 * @param foreign
 *            org.eclipse.wst.css.core.util.declaration.CSSPropertyContext
 */
protected static void expandToLeaf(PropCMProperty prop, String value, CSSPropertyContext foreign) {
    // expand shorthand property
    if (value != null && value.trim().length() > 0) {
        IShorthandAdapter adapter = (IShorthandAdapter) shorthandAdapters.get(prop);
        if (adapter != null) {
            adapter.expand(value, foreign);
            // $NON-NLS-1$
            foreign.set(prop.getName(), "");
            for (int i = 0; i < prop.getNumChild(); i++) {
                Object obj = prop.getChildAt(i);
                if (obj instanceof PropCMProperty && !(obj instanceof PropCMSubProperty)) {
                    PropCMProperty expandedProp = (PropCMProperty) obj;
                    value = foreign.get(expandedProp.getName());
                    expandToLeaf(expandedProp, value, foreign);
                }
            }
        } else if (!value.equals(foreign.get(prop.getName()))) {
            foreign.set(prop.getName(), value);
        }
    }
}
Also used : PropCMProperty(org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty) PropCMSubProperty(org.eclipse.wst.css.core.internal.contentmodel.PropCMSubProperty)

Aggregations

PropCMSubProperty (org.eclipse.wst.css.core.internal.contentmodel.PropCMSubProperty)3 PropCMProperty (org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty)2 Enumeration (java.util.Enumeration)1