x:inlucde background color

Oxygen general issues.
guna@ebscohost.com
Posts: 27
Joined: Tue Nov 17, 2009 10:16 pm

x:inlucde background color

Post 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
Radu
Posts: 9508
Joined: Fri Jul 09, 2004 5:18 pm

Re: x:inlucde background color

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply