Search in sources :

Example 11 with PropCMProperty

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

the class ListStyleShorthandAdapter method expand.

/**
 */
public boolean expand(String source, CSSPropertyContext dest) {
    CSSTextParser parser = new CSSTextParser(CSSTextParser.MODE_DECLARATION_VALUE, source);
    CSSTextToken[] tokens = parser.getTokens();
    if (tokens.length <= 0) {
        return false;
    }
    // $NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
    String image = "", pos = "", type = "";
    PropCMProperty propPos = PropCMProperty.getInstanceOf(PropCMProperty.P_LIST_STYLE_POSITION);
    PropCMProperty propType = PropCMProperty.getInstanceOf(PropCMProperty.P_LIST_STYLE_TYPE);
    PropCMProperty propImage = PropCMProperty.getInstanceOf(PropCMProperty.P_LIST_STYLE_IMAGE);
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT) {
            if (propPos.canHave(tokens[i].image))
                pos = tokens[i].image;
            else {
                // value="none" is shared !!
                if (propType.canHave(tokens[i].image))
                    type = tokens[i].image;
                if (propImage.canHave(tokens[i].image))
                    image = tokens[i].image;
            }
        } else if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_URI) {
            image = tokens[i].image;
        }
    }
    dest.set(propPos.getName(), pos);
    dest.set(propType.getName(), type);
    dest.set(propImage.getName(), image);
    return true;
}
Also used : PropCMProperty(org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty) CSSTextToken(org.eclipse.wst.css.core.internal.parserz.CSSTextToken) CSSTextParser(org.eclipse.wst.css.core.internal.parserz.CSSTextParser)

Example 12 with PropCMProperty

use of org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty 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 13 with PropCMProperty

use of org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty 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)

Example 14 with PropCMProperty

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

the class BorderBottomShorthandAdapter method expand.

/**
 */
public boolean expand(String source, CSSPropertyContext dest) {
    CSSTextParser parser = new CSSTextParser(CSSTextParser.MODE_DECLARATION_VALUE, source);
    CSSTextToken[] tokens = parser.getTokens();
    if (tokens.length <= 0) {
        return false;
    }
    // $NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
    String color = "", style = "", width = "";
    PropCMProperty propColor = PropCMProperty.getInstanceOf(PropCMProperty.P_BORDER_BOTTOM_COLOR);
    PropCMProperty propStyle = PropCMProperty.getInstanceOf(PropCMProperty.P_BORDER_BOTTOM_STYLE);
    PropCMProperty propWidth = PropCMProperty.getInstanceOf(PropCMProperty.P_BORDER_BOTTOM_WIDTH);
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT) {
            if (propStyle.canHave(tokens[i].image))
                style = tokens[i].image;
            else if (propWidth.canHave(tokens[i].image))
                width = tokens[i].image;
            else if (propColor.canHave(tokens[i].image))
                color = tokens[i].image;
        } else if (org.eclipse.wst.css.core.internal.util.CSSUtil.isLength(tokens[i]) || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_NUMBER) {
            width = tokens[i].image;
        } else if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_HASH) {
            color = tokens[i].image;
        } else if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION) {
            StringBuffer buf = new StringBuffer();
            while (i < tokens.length) {
                if (tokens[i].kind == CSSRegionContexts.CSS_COMMENT) {
                    i++;
                    continue;
                }
                buf.append(tokens[i].image);
                if (tokens[i++].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_PARENTHESIS_CLOSE)
                    break;
            }
            i--;
            color = buf.toString();
        }
    }
    dest.set(propColor.getName(), color);
    dest.set(propStyle.getName(), style);
    dest.set(propWidth.getName(), width);
    return true;
}
Also used : PropCMProperty(org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty) CSSTextToken(org.eclipse.wst.css.core.internal.parserz.CSSTextToken) CSSTextParser(org.eclipse.wst.css.core.internal.parserz.CSSTextParser)

Example 15 with PropCMProperty

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

the class BorderLeftShorthandAdapter method extract.

/**
 */
public String extract(String source, PropCMProperty propDest) {
    CSSTextParser parser = new CSSTextParser(CSSTextParser.MODE_DECLARATION_VALUE, source);
    CSSTextToken[] tokens = parser.getTokens();
    if (tokens.length <= 0) {
        return null;
    }
    String color = null, style = null, width = null;
    PropCMProperty propColor = PropCMProperty.getInstanceOf(PropCMProperty.P_BORDER_LEFT_COLOR);
    PropCMProperty propStyle = PropCMProperty.getInstanceOf(PropCMProperty.P_BORDER_LEFT_STYLE);
    PropCMProperty propWidth = PropCMProperty.getInstanceOf(PropCMProperty.P_BORDER_LEFT_WIDTH);
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT) {
            if (propStyle.canHave(tokens[i].image))
                style = tokens[i].image;
            else if (propWidth.canHave(tokens[i].image))
                width = tokens[i].image;
            else if (propColor.canHave(tokens[i].image))
                color = tokens[i].image;
        } else if (org.eclipse.wst.css.core.internal.util.CSSUtil.isLength(tokens[i]) || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_NUMBER) {
            width = tokens[i].image;
        } else if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_HASH) {
            color = tokens[i].image;
        } else if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION) {
            StringBuffer buf = new StringBuffer();
            while (i < tokens.length) {
                if (tokens[i].kind == CSSRegionContexts.CSS_COMMENT) {
                    i++;
                    continue;
                }
                buf.append(tokens[i].image);
                if (tokens[i++].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_PARENTHESIS_CLOSE)
                    break;
            }
            i--;
            color = buf.toString();
        }
    }
    if (propColor == propDest)
        return color;
    else if (propStyle == propDest)
        return style;
    else if (propWidth == propDest)
        return width;
    else
        return null;
}
Also used : PropCMProperty(org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty) CSSTextToken(org.eclipse.wst.css.core.internal.parserz.CSSTextToken) CSSTextParser(org.eclipse.wst.css.core.internal.parserz.CSSTextParser)

Aggregations

PropCMProperty (org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty)21 CSSTextParser (org.eclipse.wst.css.core.internal.parserz.CSSTextParser)18 CSSTextToken (org.eclipse.wst.css.core.internal.parserz.CSSTextToken)16 PropCMSubProperty (org.eclipse.wst.css.core.internal.contentmodel.PropCMSubProperty)2 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)2 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)2 ICSSValueList (org.eclipse.wst.css.core.internal.provisional.document.ICSSValueList)2 Enumeration (java.util.Enumeration)1 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)1 CSSLinkConverter (org.eclipse.wst.css.core.internal.util.CSSLinkConverter)1