Page 1 of 1

CSS, Selecting nodes preceeded by processing instructions

Posted: Tue Feb 02, 2010 3:12 pm
by sijomon
Hi,

Couple of questions, thanks for any assistance you might be able to provide:

1) I am experimenting with Oxygen 11.1; is there somewhere I can go to get a list of all the API changes from one version of the API to the next?

2) I am attempting to build a CSS which will apply a style to any element which is immediately preceeded by a specific processing isntruction, e.g.

Code: Select all


<?AthenaChunk_Start?>
<taxonomy>
<taxonomy-keywords>
<keyword>Community trade marks</keyword>
<keyword>Trade marks</keyword>
</taxonomy-keywords>
</taxonomy>
<taxonomy>
<taxonomy-keywords>
<keyword>Similarity</keyword>
</taxonomy-keywords>
</taxonomy>
<?SomeotherProcessingInstruction?>
<taxonomy>
<taxonomy-keywords>
<keyword>Confusion</keyword>
</taxonomy-keywords>
</taxonomy>
In this example I want to build a CSS selector which will select the first taxonomy node only. Is this possible, and if so can you given an example? The best quess I have so far is:

Code: Select all

oxy|processing-instruction + *{
background-color: #ff0000;
}
But this doesn't work, and even if it did it would select all nodes proceeded by *any* PI.

Many Thanks,

Simon.

Re: CSS, Selecting nodes preceeded by processing instructions

Posted: Tue Feb 02, 2010 4:57 pm
by Radu
Hi Simon,

We will try to maintain on site a list of API changes starting with Oxygen 11.2.
Here is a compiled list of changes which occurred between Oxygen 10.3 and 11.1:

Code: Select all


For the Author SDK API, the following major changes have appeared from Oxygen 10.3 to Oxygen 11.1:

1) Introduced the "AttributesValueEditor", "EditedAttribute" as a way for the developer to control editing attributes in the Attributes view

2) The possibility to insert an XML fragment as the last child of the current context (by adding a new relative position constant).
See the:
AuthorDocumentController.insertXMLFragment(String xmlFragment, AuthorNode relativeTo, String relativePosition) throws AuthorOperationException;

3) Added the following new methods to the AuthorDocumentController (see the Javadoc for more details):
void replaceRoot(AuthorDocumentFragment fragment);
AuthorDocumentFragment createNewDocumentTextFragment(String textFragment) throws AuthorOperationException;
void insertXMLFragment(String xmlFragment, AuthorNode relativeTo, String relativePosition) throws AuthorOperationException;
public void getChars(int where, int len, Segment chars) throws BadLocationException;
public AuthorSchemaManager getAuthorSchemaManager();

4) Added the possibility to implement a AuthorSchemaAwareEditingHandler (in the ExtensionsBundle) which can be used by developers to decide better paste, delete, insert strategies.
For example if some text is pasted the developer can choose to insert a new element and then insert the text in it. The developer also has access to the schema information associated with the XML document to make better editing decisions.
See the newly added methods from AuthorDocumentController.

5) Added an AuthorSchemaManager which can be used to get information from the schema associated to the edited XML file.

6) The following new methods can now be implemented for the ExtensionsBundle (see Javadoc for more details):
public AttributesValueEditor createAttributesValueEditor(boolean forEclipsePlugin)
public URL resolveCustomHref(String linkHref)
public AuthorSchemaAwareEditingHandler getAuthorSchemaAwareEditingHandler()
As for the second problem, you have no way to specify what you want from the CSS. Processing instructions are not elements. Indeed we made some extensions like the oxy|processing-instruction you were using so that styles can be set to all processing instructions but the extension can not be used in complex CSS selectors.

What you can do is implement a StylesFilter. You can find an implementation example in the SimpleDocumentationFramework available in the AuthorSDK.

The StylesFilter implementation should be something like:

Code: Select all


  /**
* Set background color to element preceded by processing instruction.
*/
public Styles filter(Styles styles, AuthorNode authorNode) {
//Use background color red for "taxonomy" preceded by special processing instruction
if(authorNode.getName().equals("taxonomy")) {
AuthorNode parent = authorNode.getParent();
if(parent.getType() == AuthorNode.NODE_TYPE_ELEMENT) {
AuthorElement parentElem = (AuthorElement) parent;
List<AuthorNode> contentNodes = parentElem.getContentNodes();
int childIndex = contentNodes.indexOf(authorNode);
if(childIndex > 0) {
AuthorNode previousSibling = contentNodes.get(childIndex - 1);
if(previousSibling.getType() == AuthorNode.NODE_TYPE_PI) {
try {
//Found the processing instruction
if("SomeotherProcessingInstruction".equals(previousSibling.getTextContent())) {
ro.sync.exml.view.graphics.Color red = ro.sync.exml.view.graphics.Color.COLOR_RED;
styles.setProperty(Styles.KEY_BACKGROUND_COLOR, red);
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
}
}

return styles;
}
Regards,
Radu

Re: CSS, Selecting nodes preceeded by processing instructions

Posted: Wed Feb 03, 2010 2:53 pm
by sijomon
Thanks for the answers.

My actual requirement is a little more complex than I first described. I will be using two processing instructions, one at the start of a document which identifies that the document should be treated as readonly. The second identifes a subsection of the document which should be read/write. The enforcing of the readonly or read/write is done in a custom DocumentFilter.

When a document contains the first processing instruction (which will allways be found immediately before the root element oif the document) all of the document content should have its default text colour style overridden (in a custom StyleFilter) so it displays as a light-grey, appart from the subsection preceeded by the second processing instruction, which should display in the CSS defined style.

My problem is that inside the style filter we have no access to the AuthorAccess object. The AuthorExtensionsBundle which instantiates the filter doesn't have access to the AuthorAccess instance, and it cannot be retrieved from the AuthorNode instances passed to the filter() method on the StyleFilter. Without access to the AuthorAccess instnace we cannot retrieve siblings of the root node, as the only method to rerieveing a sibling is to access the parent node and gets its children. The root node has no parent and therefore I cannot access the siblings of the root node, i.e. the PIs at the start of the document. I had been using XPath to retieve the Processing isntructions, however inside a StylerFilter, without access to the AuthorAccess instnace I cannot use the XPath methods.

What this boiuld down to is that it seesm there is now way to style a node on the basis of what PIs appear prior to the root node of the document; is this correct? Have you any suggestions?

Simon.

Re: CSS, Selecting nodes preceeded by processing instructions

Posted: Wed Feb 03, 2010 3:18 pm
by Radu
Hi Simon,

Above the root element there is the parent document which contains both the root element and all comments, processing instructions which are its siblings.
So you do not need the AuthorAccess to determine if before the root element there is a sibling processing instruction.
The code is like:

Code: Select all


    /**
* @see ro.sync.ecss.extensions.api.StylesFilter#filter(ro.sync.ecss.css.Styles, ro.sync.ecss.extensions.api.node.AuthorNode)
*/
public Styles filter(Styles styles, AuthorNode authorNode) {
AuthorDocument ownerDocument = authorNode.getOwnerDocument();
AuthorElement rootElement = ownerDocument.getRootElement();
List<AuthorNode> allDocumentNodes = ownerDocument.getContentNodes();
int rootIndex = allDocumentNodes.indexOf(rootElement);
if(rootIndex > 0) {
AuthorNode nodeBeforeRoot = allDocumentNodes.get(rootIndex - 1);
if(nodeBeforeRoot.getType() == AuthorNode.NODE_TYPE_PI) {
try {
String piContent = nodeBeforeRoot.getTextContent();
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
return null;
}
You can still get the AuthorAccess in the ExtensionsBundle by overwriting a method called createAuthorExtensionStateListener() which is notified when the page is activated and is given the AuthorAccess. There might be problems sharing the received AuthorAccess with the StylesFilter in Oxygen 10.3 one ExtensionsBundle object is shared between multiple opened files of the same type. This was fixed in Oxygen 11.1 which creates a new ExtensionsBundle for each Author page so that the objects created in the bundle can share different information fields.

Regards,
Radu

Re: CSS, Selecting nodes preceeded by processing instructions

Posted: Wed Feb 03, 2010 3:31 pm
by sijomon
Many thanks for the fast and clear response, this is exactly what I needed.

Simon.