use of org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty in project webtools.sourceediting by eclipse.
the class BorderLeftShorthandAdapter 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_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();
}
}
dest.set(propColor.getName(), color);
dest.set(propStyle.getName(), style);
dest.set(propWidth.getName(), width);
return true;
}
use of org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty in project webtools.sourceediting by eclipse.
the class BorderShorthandAdapter 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_COLOR);
PropCMProperty propStyle = PropCMProperty.getInstanceOf(PropCMProperty.P_BORDER_STYLE);
PropCMProperty propWidth = PropCMProperty.getInstanceOf(PropCMProperty.P_BORDER_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;
}
use of org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty in project webtools.sourceediting by eclipse.
the class BorderTopShorthandAdapter 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_TOP_COLOR);
PropCMProperty propStyle = PropCMProperty.getInstanceOf(PropCMProperty.P_BORDER_TOP_STYLE);
PropCMProperty propWidth = PropCMProperty.getInstanceOf(PropCMProperty.P_BORDER_TOP_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;
}
use of org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty in project webtools.sourceediting by eclipse.
the class FontShorthandAdapter 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 style = null, variant = null, weight = null, size = null, height = null, family = null;
PropCMProperty propFont = PropCMProperty.getInstanceOf(PropCMProperty.P_FONT);
PropCMProperty propStyle = PropCMProperty.getInstanceOf(PropCMProperty.P_FONT_STYLE);
PropCMProperty propVariant = PropCMProperty.getInstanceOf(PropCMProperty.P_FONT_VARIANT);
PropCMProperty propWeight = PropCMProperty.getInstanceOf(PropCMProperty.P_FONT_WEIGHT);
PropCMProperty propSize = PropCMProperty.getInstanceOf(PropCMProperty.P_FONT_SIZE);
PropCMProperty propHeight = PropCMProperty.getInstanceOf(PropCMProperty.P_LINE_HEIGHT);
PropCMProperty propFamily = PropCMProperty.getInstanceOf(PropCMProperty.P_FONT_FAMILY);
boolean bNormalSpecified = false;
int i = 0;
for (; i < tokens.length; i++) {
if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT) {
// first of all, check font idents
if (i == 0) {
for (int j = 0; j < propFont.getNumChild(); j++) {
Object obj = propFont.getChildAt(i);
if (obj instanceof String && tokens[i].image.compareToIgnoreCase(obj.toString()) == 0)
return null;
}
}
// value "normal" is shared !!
if (tokens[i].image.equalsIgnoreCase(IValID.V_NORMAL)) {
bNormalSpecified = true;
} else {
if (propStyle.canHave(tokens[i].image))
style = tokens[i].image;
else if (propVariant.canHave(tokens[i].image))
variant = tokens[i].image;
else if (propWeight.canHave(tokens[i].image))
weight = tokens[i].image;
else if (propSize.canHave(tokens[i].image)) {
size = tokens[i].image;
// if size found, break loop
break;
}
}
} else if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_NUMBER && weight == null && propWeight.canHave(tokens[i].image)) {
weight = tokens[i].image;
} else if (org.eclipse.wst.css.core.internal.util.CSSUtil.isLength(tokens[i]) || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_NUMBER || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_PERCENTAGE) {
size = tokens[i].image;
// if size found, break loop
break;
}
}
if (bNormalSpecified) {
if (style == null)
style = IValID.V_NORMAL;
if (variant == null)
variant = IValID.V_NORMAL;
if (weight == null)
weight = IValID.V_NORMAL;
}
// skip whitespace
for (i++; i < tokens.length; i++) {
if (tokens[i].kind != CSSRegionContexts.CSS_S || tokens[i].kind != CSSRegionContexts.CSS_DECLARATION_VALUE_S)
break;
}
// line-height ?
if (i < tokens.length && tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR && tokens[i].image.equals("/")) {
// $NON-NLS-1$
for (i++; i < tokens.length; i++) {
if (org.eclipse.wst.css.core.internal.util.CSSUtil.isLength(tokens[i]) || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_PERCENTAGE || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_NUMBER || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT) {
height = tokens[i++].image;
break;
}
}
}
// font-family
StringBuffer buf = new StringBuffer();
for (; i < tokens.length; i++) {
if (tokens[i].kind == CSSRegionContexts.CSS_COMMENT)
// $NON-NLS-1$
buf.append(" ");
else
buf.append(tokens[i].image);
}
family = buf.toString().trim();
if (propStyle == propDest)
return style;
else if (propVariant == propDest)
return variant;
else if (propWeight == propDest)
return weight;
else if (propSize == propDest)
return size;
else if (propHeight == propDest)
return height;
else if (propFamily == propDest)
return family;
else
return null;
}
use of org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty in project webtools.sourceediting by eclipse.
the class FontShorthandAdapter 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;
}
String style = null, variant = null, weight = null, size = null, height = null, family = null;
PropCMProperty propFont = PropCMProperty.getInstanceOf(PropCMProperty.P_FONT);
PropCMProperty propStyle = PropCMProperty.getInstanceOf(PropCMProperty.P_FONT_STYLE);
PropCMProperty propVariant = PropCMProperty.getInstanceOf(PropCMProperty.P_FONT_VARIANT);
PropCMProperty propWeight = PropCMProperty.getInstanceOf(PropCMProperty.P_FONT_WEIGHT);
PropCMProperty propSize = PropCMProperty.getInstanceOf(PropCMProperty.P_FONT_SIZE);
boolean bNormalSpecified = false;
int i = 0;
for (; i < tokens.length; i++) {
if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT) {
// first of all, check font idents
if (i == 0) {
for (int j = 0; j < propFont.getNumChild(); j++) {
Object obj = propFont.getChildAt(i);
if (obj instanceof String && tokens[i].image.compareToIgnoreCase(obj.toString()) == 0)
return false;
}
}
// value "normal" is shared !!
if (tokens[i].image.equalsIgnoreCase(IValID.V_NORMAL)) {
bNormalSpecified = true;
} else {
if (propStyle.canHave(tokens[i].image))
style = tokens[i].image;
else if (propVariant.canHave(tokens[i].image))
variant = tokens[i].image;
else if (propWeight.canHave(tokens[i].image))
weight = tokens[i].image;
else if (propSize.canHave(tokens[i].image)) {
size = tokens[i].image;
// if size found, break loop
break;
}
}
} else if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_NUMBER && weight == null && propWeight.canHave(tokens[i].image)) {
weight = tokens[i].image;
} else if (org.eclipse.wst.css.core.internal.util.CSSUtil.isLength(tokens[i]) || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_NUMBER || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_PERCENTAGE) {
size = tokens[i].image;
// if size found, break loop
break;
}
}
if (bNormalSpecified) {
if (style == null)
style = IValID.V_NORMAL;
if (variant == null)
variant = IValID.V_NORMAL;
if (weight == null)
weight = IValID.V_NORMAL;
}
// skip whitespace
for (i++; i < tokens.length; i++) {
if (tokens[i].kind != CSSRegionContexts.CSS_S || tokens[i].kind != CSSRegionContexts.CSS_DECLARATION_VALUE_S)
break;
}
// line-height ?
if (i < tokens.length && tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR && tokens[i].image.equals("/")) {
// $NON-NLS-1$
for (i++; i < tokens.length; i++) {
if (org.eclipse.wst.css.core.internal.util.CSSUtil.isLength(tokens[i]) || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_PERCENTAGE || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_NUMBER || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT) {
height = tokens[i++].image;
break;
}
}
}
// font-family
StringBuffer buf = new StringBuffer();
for (; i < tokens.length; i++) {
if (tokens[i].kind == CSSRegionContexts.CSS_COMMENT)
// $NON-NLS-1$
buf.append(" ");
else
buf.append(tokens[i].image);
}
family = buf.toString().trim();
dest.set(PropCMProperty.P_FONT_STYLE, style);
dest.set(PropCMProperty.P_FONT_VARIANT, variant);
dest.set(PropCMProperty.P_FONT_WEIGHT, weight);
dest.set(PropCMProperty.P_FONT_SIZE, size);
dest.set(PropCMProperty.P_LINE_HEIGHT, height);
dest.set(PropCMProperty.P_FONT_FAMILY, family);
return true;
}
Aggregations