Search in sources :

Example 1 with ICSSValueList

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSValueList in project webtools.sourceediting by eclipse.

the class BackgroundPositionXSubStyleAdapter method get.

/**
 */
public String get(ICSS2Properties properties) {
    String str = null;
    Object obj = properties.get(PropCMProperty.getInstanceOf(PropCMProperty.P_BG_POSITION));
    if (obj != null) {
        PropCMProperty propX = PropCMSubProperty.getInstanceOf(PropCMSubProperty.PSUB_BG_POSITION_X);
        PropCMProperty propY = PropCMSubProperty.getInstanceOf(PropCMSubProperty.PSUB_BG_POSITION_Y);
        if (obj instanceof ICSSValueList) {
            ICSSValueList list = (ICSSValueList) obj;
            ICSSValue value = (ICSSValue) list.item(0);
            if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
                ICSSPrimitiveValue prim = (ICSSPrimitiveValue) value;
                if (prim.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
                    // check not top or bottom
                    if (!propX.canHave(prim.getStringValue()) && propY.canHave(prim.getStringValue())) {
                        // case order is vertical -> horizontal
                        value = (ICSSValue) list.item(1);
                    }
                }
            }
            str = value.getCSSValueText();
        } else if (obj instanceof ICSSValue) {
            str = ((ICSSValue) obj).getCSSValueText();
            if (str.equalsIgnoreCase(IValID.V_BOTTOM) || str.equalsIgnoreCase(IValID.V_TOP))
                // $NON-NLS-1$
                str = "";
        } else {
            str = obj.toString();
            CSSTextParser parser = new CSSTextParser(CSSTextParser.MODE_DECLARATION_VALUE, str);
            CSSTextToken[] tokens = parser.getTokens();
            tokens = correctMeaningToken(tokens);
            if (tokens.length == 0)
                // $NON-NLS-1$
                str = "";
            else if (tokens.length == 1 && (tokens[0].image.equalsIgnoreCase(IValID.V_BOTTOM) || tokens[0].image.equalsIgnoreCase(IValID.V_TOP)))
                // $NON-NLS-1$
                str = "";
            else
                str = tokens[0].image;
        }
    }
    // $NON-NLS-1$
    return (str != null) ? str : "";
}
Also used : PropCMProperty(org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty) ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) CSSTextParser(org.eclipse.wst.css.core.internal.parserz.CSSTextParser) ICSSValueList(org.eclipse.wst.css.core.internal.provisional.document.ICSSValueList)

Example 2 with ICSSValueList

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSValueList in project webtools.sourceediting by eclipse.

the class BackgroundPositionYSubStyleAdapter method get.

/**
 */
public String get(ICSS2Properties properties) {
    String str = null;
    Object obj = properties.get(PropCMProperty.getInstanceOf(PropCMProperty.P_BG_POSITION));
    if (obj != null) {
        PropCMProperty propX = PropCMSubProperty.getInstanceOf(PropCMSubProperty.PSUB_BG_POSITION_X);
        PropCMProperty propY = PropCMSubProperty.getInstanceOf(PropCMSubProperty.PSUB_BG_POSITION_Y);
        if (obj instanceof ICSSValueList) {
            ICSSValueList list = (ICSSValueList) obj;
            int index = 1;
            ICSSValue value = (ICSSValue) list.item(0);
            if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
                ICSSPrimitiveValue prim = (ICSSPrimitiveValue) value;
                if (prim.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
                    // check not top or bottom
                    if (!propX.canHave(prim.getStringValue()) && propY.canHave(prim.getStringValue())) {
                        // case order is vertical -> horizontal
                        index = 0;
                    }
                }
            }
            str = ((ICSSValue) list.item(index)).getCSSValueText();
        } else if (obj instanceof ICSSValue) {
            str = ((ICSSValue) obj).getCSSValueText();
            if (!str.equalsIgnoreCase(IValID.V_BOTTOM) && !str.equalsIgnoreCase(IValID.V_TOP))
                // $NON-NLS-1$
                str = "";
        } else {
            str = obj.toString();
            CSSTextParser parser = new CSSTextParser(CSSTextParser.MODE_DECLARATION_VALUE, str);
            CSSTextToken[] tokens = parser.getTokens();
            tokens = correctMeaningToken(tokens);
            if (tokens.length == 1 && (tokens[0].image.equalsIgnoreCase(IValID.V_BOTTOM) || tokens[0].image.equalsIgnoreCase(IValID.V_TOP)))
                str = tokens[0].image;
            else if (tokens.length > 1)
                str = tokens[1].image;
            else
                // $NON-NLS-1$
                str = "";
        }
    }
    // $NON-NLS-1$
    return (str != null) ? str : "";
}
Also used : PropCMProperty(org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty) ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) CSSTextParser(org.eclipse.wst.css.core.internal.parserz.CSSTextParser) ICSSValueList(org.eclipse.wst.css.core.internal.provisional.document.ICSSValueList)

Aggregations

PropCMProperty (org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty)2 CSSTextParser (org.eclipse.wst.css.core.internal.parserz.CSSTextParser)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