use of org.eclipse.wst.css.core.internal.parserz.CSSTextParser in project webtools.sourceediting by eclipse.
the class BackgroundShorthandAdapter 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-5$//$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
String color = "", image = "", repeat = "", attach = "", pos = "";
PropCMProperty propColor = PropCMProperty.getInstanceOf(PropCMProperty.P_BG_COLOR);
PropCMProperty propImage = PropCMProperty.getInstanceOf(PropCMProperty.P_BG_IMAGE);
PropCMProperty propRepeat = PropCMProperty.getInstanceOf(PropCMProperty.P_BG_REPEAT);
PropCMProperty propAttach = PropCMProperty.getInstanceOf(PropCMProperty.P_BG_ATTACHMENT);
PropCMProperty propPos = PropCMProperty.getInstanceOf(PropCMProperty.P_BG_POSITION);
for (int i = 0; i < tokens.length; i++) {
if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT) {
if (propColor.canHave(tokens[i].image))
color = tokens[i].image;
else if (propImage.canHave(tokens[i].image))
image = tokens[i].image;
else if (propRepeat.canHave(tokens[i].image))
repeat = tokens[i].image;
else if (propAttach.canHave(tokens[i].image))
attach = tokens[i].image;
else if (propPos.canHave(tokens[i].image)) {
if (pos == null || pos.length() <= 0)
pos = tokens[i].image;
else
// $NON-NLS-1$
pos = pos + " " + 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) {
if (pos == null || pos.length() <= 0)
pos = tokens[i].image;
else
// $NON-NLS-1$
pos = pos + " " + tokens[i].image;
} else if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_URI) {
image = 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(propImage.getName(), image);
dest.set(propRepeat.getName(), repeat);
dest.set(propAttach.getName(), attach);
dest.set(propPos.getName(), pos);
return true;
}
use of org.eclipse.wst.css.core.internal.parserz.CSSTextParser in project webtools.sourceediting by eclipse.
the class BackgroundShorthandAdapter 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, image = null, repeat = null, attach = null, pos = null;
PropCMProperty propColor = PropCMProperty.getInstanceOf(PropCMProperty.P_BG_COLOR);
PropCMProperty propImage = PropCMProperty.getInstanceOf(PropCMProperty.P_BG_IMAGE);
PropCMProperty propRepeat = PropCMProperty.getInstanceOf(PropCMProperty.P_BG_REPEAT);
PropCMProperty propAttach = PropCMProperty.getInstanceOf(PropCMProperty.P_BG_ATTACHMENT);
PropCMProperty propPos = PropCMProperty.getInstanceOf(PropCMProperty.P_BG_POSITION);
for (int i = 0; i < tokens.length; i++) {
if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT) {
if (propColor.canHave(tokens[i].image))
color = tokens[i].image;
else if (propImage.canHave(tokens[i].image))
image = tokens[i].image;
else if (propRepeat.canHave(tokens[i].image))
repeat = tokens[i].image;
else if (propAttach.canHave(tokens[i].image))
attach = tokens[i].image;
else if (propPos.canHave(tokens[i].image)) {
if (pos == null)
pos = tokens[i].image;
else
// $NON-NLS-1$
pos = pos + " " + 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) {
if (pos == null)
pos = tokens[i].image;
else
// $NON-NLS-1$
pos = pos + " " + tokens[i].image;
} else if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_URI) {
image = 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 (propImage == propDest)
return image;
else if (propRepeat == propDest)
return repeat;
else if (propAttach == propDest)
return attach;
else if (propPos == propDest)
return pos;
else
return null;
}
use of org.eclipse.wst.css.core.internal.parserz.CSSTextParser in project webtools.sourceediting by eclipse.
the class BorderColorShorthandAdapter 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[] idents = new String[4];
int j = 0;
for (int i = 0; i < tokens.length; i++) {
if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_HASH)
idents[j++] = 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--;
idents[j++] = buf.toString();
}
if (j == 4)
break;
}
String[] dests = new String[4];
if (j == 0)
return true;
else if (j == 1) {
dests[0] = dests[1] = dests[2] = dests[3] = idents[0];
} else if (j == 2) {
dests[0] = dests[2] = idents[0];
dests[1] = dests[3] = idents[1];
} else if (j == 3) {
dests[0] = idents[0];
dests[1] = dests[3] = idents[1];
dests[2] = idents[2];
} else {
for (int k = 0; k < 4; k++) dests[k] = idents[k];
}
dest.set(PropCMProperty.P_BORDER_TOP_COLOR, dests[0]);
dest.set(PropCMProperty.P_BORDER_RIGHT_COLOR, dests[1]);
dest.set(PropCMProperty.P_BORDER_BOTTOM_COLOR, dests[2]);
dest.set(PropCMProperty.P_BORDER_LEFT_COLOR, dests[3]);
return true;
}
use of org.eclipse.wst.css.core.internal.parserz.CSSTextParser in project webtools.sourceediting by eclipse.
the class BorderColorShorthandAdapter 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[] idents = new String[4];
int j = 0;
for (int i = 0; i < tokens.length; i++) {
if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT || tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_HASH)
idents[j++] = 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--;
idents[j++] = buf.toString();
}
if (j == 4)
break;
}
if (j == 0)
return null;
else if (j == 1)
return idents[0];
else if (j == 2) {
if (propDest.getName() == PropCMProperty.P_BORDER_TOP_COLOR || propDest.getName() == PropCMProperty.P_BORDER_BOTTOM_COLOR)
return idents[0];
else
return idents[1];
} else if (j == 3) {
if (propDest.getName() == PropCMProperty.P_BORDER_TOP_COLOR)
return idents[0];
else if (propDest.getName() == PropCMProperty.P_BORDER_BOTTOM_COLOR)
return idents[2];
else
return idents[1];
} else {
if (propDest.getName() == PropCMProperty.P_BORDER_TOP_COLOR)
return idents[0];
else if (propDest.getName() == PropCMProperty.P_BORDER_RIGHT_COLOR)
return idents[1];
else if (propDest.getName() == PropCMProperty.P_BORDER_BOTTOM_COLOR)
return idents[2];
else if (propDest.getName() == PropCMProperty.P_BORDER_LEFT_COLOR)
return idents[3];
else
return null;
}
}
use of org.eclipse.wst.css.core.internal.parserz.CSSTextParser in project webtools.sourceediting by eclipse.
the class BorderStyleShorthandAdapter 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[] idents = new String[4];
int j = 0;
for (int i = 0; i < tokens.length; i++) {
if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT)
idents[j++] = tokens[i].image;
if (j == 4)
break;
}
String[] dests = new String[4];
if (j == 0)
return true;
else if (j == 1) {
dests[0] = dests[1] = dests[2] = dests[3] = idents[0];
} else if (j == 2) {
dests[0] = dests[2] = idents[0];
dests[1] = dests[3] = idents[1];
} else if (j == 3) {
dests[0] = idents[0];
dests[1] = dests[3] = idents[1];
dests[2] = idents[2];
} else {
for (int k = 0; k < 4; k++) dests[k] = idents[k];
}
dest.set(PropCMProperty.P_BORDER_TOP_STYLE, dests[0]);
dest.set(PropCMProperty.P_BORDER_RIGHT_STYLE, dests[1]);
dest.set(PropCMProperty.P_BORDER_BOTTOM_STYLE, dests[2]);
dest.set(PropCMProperty.P_BORDER_LEFT_STYLE, dests[3]);
return true;
}
Aggregations