Page 1 of 1

x:inlucde background color

Posted: Sat Mar 13, 2010 2:37 pm
by guna@ebscohost.com
Hi,
we are including x:include inside the document, we want to change the background color of x:include content

say if href starts with s, then use x color
if href starts with r, the use y color
if href starts with any other color, then use z color


can you guide us how to implement this

Re: x:inlucde background color

Posted: Mon Mar 15, 2010 10:14 am
by Radu
Hi,

This is too complex to do with CSS selectors. In the ExtensionsBundle you have to overwrite the createAuthorStylesFilter() method and assign styles on the xi:include content nodes. Here is some code, I made some comments.

Code: Select all


  /**
* @see ro.sync.ecss.extensions.api.ExtensionsBundle#createAuthorStylesFilter()
*/
@Override
public StylesFilter createAuthorStylesFilter() {

return new StylesFilter() {
public String getDescription() {
return "Custom reference colors";
}

public Styles filter(Styles styles, AuthorNode authorNode) {
if(authorNode.getName().equals("#reference")){
//This is an artificial node which represents the referenced content.
//Its parent is the xi:include
//Its href value is the "href" of the xi:include made absolute
//If you want the original value of the "href" you take this node's parent and get its href.
AttrValue attribute = ((AuthorElement)authorNode).getAttribute("href");
if(attribute != null) {
String hrefVal = attribute.getValue();
if(hrefVal.endsWith("section1.xml")) {
styles.setProperty(Styles.KEY_BACKGROUND_COLOR, new ro.sync.exml.view.graphics.Color(40, 40, 40));
return styles;
} else if(hrefVal.endsWith("section2.xml")) {
styles.setProperty(Styles.KEY_BACKGROUND_COLOR, new ro.sync.exml.view.graphics.Color(100, 100, 100));
return styles;
} else {
styles.setProperty(Styles.KEY_BACKGROUND_COLOR, new ro.sync.exml.view.graphics.Color(150, 150, 150));
return styles;
}
}
}
return null;
}
};
}
Regards,
Radu