/************************Methods to convert wordlist to xml*************************/
private void parseElement(StringBuffer xhtml,int start, int end,boolean openStyle)
{//msn transport needs lettertype + color in 1 style to work
if(start>=end)return;
AttributeSet set = ((Word)wordList.get(start)).getAttributes();
int newEnd =0;
if(set==null);//remove empty set
else if (set.isDefined(StyleConstants.FontFamily))
{
String insert ="font-family: " + StyleConstants.getFontFamily(set);
newEnd = addStyle(xhtml, start, end, openStyle, set,insert,StyleConstants.FontFamily);
// xhtml.append("<span style=\"");
// xhtml.append();
// Object value = set.getAttribute(StyleConstants.FontFamily);
// newEnd = getStyleEnd(StyleConstants.FontFamily,value,start,end);
// parseElement(xhtml, start, newEnd,true);
// xhtml.append("</span>");
openStyle=false;
}
else if (set.isDefined(StyleConstants.FontSize))
{
String insert =" font-size: " + StyleConstants.getFontSize(set) + "pt";
newEnd = addStyle(xhtml, start, end, openStyle, set,insert,StyleConstants.FontSize);
openStyle=false;
}
else if (set.isDefined(StyleConstants.Foreground))
{
String hex = colorToHexString((Color)set.getAttribute(StyleConstants.Foreground));
String insert =" color: #" + hex;
newEnd = addStyle(xhtml, start, end, openStyle, set,insert,StyleConstants.Foreground);
openStyle=false;
// Object value = set.getAttribute(StyleConstants.Foreground);
// if(!set.isDefined(StyleConstants.Foreground+value.toString()))
// {
// newEnd = getStyleEnd(StyleConstants.Foreground,value,start,end);
// if(openStyle)
// {
// if(newEnd<end)xhtml.append("\"><span style=\"");
// else xhtml.append(';');
// }
// else if(!openStyle) xhtml.append("<span style=\"");
// String hex = colorToHexString((Color)value);
// xhtml.append(" color: #" + hex);
// if(newEnd != 0)
// {
// parseElement(xhtml, start, newEnd,true);
// }
// if(!openStyle)xhtml.append("</span>");
// openStyle=false;
// }
}
else if (set.isDefined(StyleConstants.Background))
{
String hex = colorToHexString((Color)set.getAttribute(StyleConstants.Background));
String insert =" background-color: #" + hex;
newEnd = addStyle(xhtml, start, end, openStyle, set,insert,StyleConstants.Background);
openStyle=false;
// Object value = set.getAttribute(StyleConstants.Background);
// if(!set.isDefined(StyleConstants.Background+value.toString()))
// {
// xhtml.append("<span style=\"");
// String hex = colorToHexString((Color)value);
// xhtml.append("background: #" + hex);
// newEnd = getStyleEnd(StyleConstants.Background,value,start,end);
// if(newEnd != 0)
// {
// parseElement(xhtml, start, newEnd,true);
// }
// xhtml.append("</span>");
// }
}
else if (set.isDefined(StyleConstants.StrikeThrough))
{
String insert =" text-decoration: line-through";
newEnd = addStyle(xhtml, start, end, openStyle, set,insert,StyleConstants.StrikeThrough);
openStyle=false;
// Object value = set.getAttribute(StyleConstants.StrikeThrough);
// if(!set.isDefined(StyleConstants.StrikeThrough+value.toString()))
// {
// xhtml.append("<span style=\"");
// xhtml.append("text-decoration: line-through");
// newEnd = getStyleEnd(StyleConstants.StrikeThrough,value,start,end);
// if(newEnd != 0)
// {
// parseElement(xhtml, start, newEnd,true);
// }
// xhtml.append("</span>");
// }
}
else if (set.containsAttribute(StyleConstants.Underline,Boolean.TRUE))
{
String insert =" text-decoration: underline";
newEnd = addStyle(xhtml, start, end, openStyle, set,insert,StyleConstants.Underline);
openStyle=false;
// Object value = set.getAttribute(StyleConstants.Underline);
// xhtml.append("<span style=\"");
// xhtml.append("text-decoration: underline");
// newEnd = getStyleEnd(StyleConstants.Underline,value,start,end);
// parseElement(xhtml, start, newEnd,true);
// xhtml.append("</span>");
}
else if (StyleConstants.isBold(set))
{
if(openStyle)xhtml.append("; margin:0 \">");
openStyle=false;
xhtml.append("<strong>");
Object value = set.getAttribute(StyleConstants.Bold);
newEnd = getStyleEnd(StyleConstants.Bold,value,start,end);
parseElement(xhtml, start, newEnd,false);
xhtml.append("</strong>");
}
else if (StyleConstants.isItalic(set))
{
if(openStyle)xhtml.append("; margin:0 \">");
openStyle=false;
xhtml.append("<em>");
Object value = set.getAttribute(StyleConstants.Italic);
newEnd = getStyleEnd(StyleConstants.Italic,value,start,end);
parseElement(xhtml, start, newEnd,false);
xhtml.append("</em>");
}