Framework Content Association extension
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 57
- Joined: Tue Jul 21, 2009 1:48 am
Framework Content Association extension
Hi, I'm working on a framework that ideally can look at both an attribute of the root element and a child element of the root to determine the correct Document Type to associate with the document. For example:
Currently I use the Doc Association dialog to look at @schemaVer, but I need a way to look at element status to know if I use a Doc Type that uses a production Schematron validation which uses different rules and external resources than used for test data.
What I gather from this post is that I'll need an extension of type ro.sync.ecss.extensions.api.DocumentTypeCustomRuleMatcher to do the second part. I'm more of a Java hack than developer - do I need to just create a piece of code with like the second code snippet in the above post and zip it up in a jar file, add it on the Classpath tab and point to it in the Document Association dialog? It would parse out the status element value (assuming that's possible) and return a boolean as required by logic. Also, would that code need to do both pieces (looking at both @schemaVer and status) or is the result of the extension combined with what is set up in the dialog?
Thanks Scott
Code: Select all
<doc schemaVer="3.2">
<status>production</status>
....
</doc>
What I gather from this post is that I'll need an extension of type ro.sync.ecss.extensions.api.DocumentTypeCustomRuleMatcher to do the second part. I'm more of a Java hack than developer - do I need to just create a piece of code with like the second code snippet in the above post and zip it up in a jar file, add it on the Classpath tab and point to it in the Document Association dialog? It would parse out the status element value (assuming that's possible) and return a boolean as required by logic. Also, would that code need to do both pieces (looking at both @schemaVer and status) or is the result of the extension combined with what is set up in the dialog?
Thanks Scott
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Framework Content Association extension
Hi Scott,
Please see some remarks below:
https://www.oxygenxml.com/InstData/Edit ... tcher.html
I see someone gave an example for this in an older post, the matcher has a method which receives a Reader which can be used to read content from the entire XML document and make decisions based on it:
post61947.html#p61947
In the Java project you create a class which extends ro.sync.ecss.extensions.api.DocumentTypeAdvancedCustomRuleMatcher and uses that method which is passes the Reader to make decisions based on the entire content.
The Java class is compiled and compressed to a JAR library, library which you copy inside your framework folder and which is then referenced in the document type association "Classpath" list.
Then you create an association rule for your framework based on that extension class.
https://www.oxygenxml.com/doc/ug-editor ... s-tab.html
All the fields need to match the XML content so if you are already looking for the @schemaVer in the association rules dialog, the Java code does not need to check for that again.
Regards,
Radu
Please see some remarks below:
Maybe if you can modify the XML structure and schema you could promote the <status> as an attribute on the root element instead of a separate element but I understand this might not be possible.I'm working on a framework that ideally can look at both an attribute of the root element and a child element of the root to determine the correct Document Type to associate with the document.
Maybe as an alternative you can have one framework with one Schematron schema which in in its rules context can use XPath to look at the value of that element.[/quote]Currently I use the Doc Association dialog to look at @schemaVer, but I need a way to look at element status to know if I use a Doc Type that uses a production Schematron validation which uses different rules and external resources than used for test data.
Actually you would need to extend this base class:What I gather from this post is that I'll need an extension of type ro.sync.ecss.extensions.api.DocumentTypeCustomRuleMatcher to do the second part.
https://www.oxygenxml.com/InstData/Edit ... tcher.html
I see someone gave an example for this in an older post, the matcher has a method which receives a Reader which can be used to read content from the entire XML document and make decisions based on it:
post61947.html#p61947
You would need to create a Java project either Maven-based using our SDK (https://www.oxygenxml.com/oxygen_sdk.html) or having in its classpath a reference to all the Java JAR libraries in the "OXYGEN_INSTALL_DIR\lib" folder.I'm more of a Java hack than developer - do I need to just create a piece of code with like the second code snippet in the above post and zip it up in a jar file, add it on the Classpath tab and point to it in the Document Association dialog? It would parse out the status element value (assuming that's possible) and return a boolean as required by logic.
In the Java project you create a class which extends ro.sync.ecss.extensions.api.DocumentTypeAdvancedCustomRuleMatcher and uses that method which is passes the Reader to make decisions based on the entire content.
The Java class is compiled and compressed to a JAR library, library which you copy inside your framework folder and which is then referenced in the document type association "Classpath" list.
Then you create an association rule for your framework based on that extension class.
The "Document Type Rule" dialog box has various fields inside it:Also, would that code need to do both pieces (looking at both @schemaVer and status) or is the result of the extension combined with what is set up in the dialog
https://www.oxygenxml.com/doc/ug-editor ... s-tab.html
All the fields need to match the XML content so if you are already looking for the @schemaVer in the association rules dialog, the Java code does not need to check for that again.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 57
- Joined: Tue Jul 21, 2009 1:48 am
Re: Framework Content Association extension
Thank you for your response Radu. I wish I could change this XML structure! LOL... oh well sometimes you just have to live with things. Your other alternative with the Schematron won't work for other reasons I won't go into. I tried with the extension but it it doesn't seem to work - I created a jar containing the following code but it always returns false (it was detected and is clearly being used by the association rules). If you see anything obvious I'd appreciate your thoughts but no worries if not, my guess is I have it packaged wrong somehow... but I wasn't sure how to configure to run the extension in Eclipse so it could be the code too. I may just stick with having to manually select from various validation scenarios. Thanks again.
Scott
Scott
Code: Select all
package ro.sync.ecss.extensions.api;
import java.io.IOException;
import java.io.Reader;
import java.util.Map;
import org.xml.sax.Attributes;
import ro.sync.ecss.extensions.api.DocumentTypeAdvancedCustomRuleMatcher;
public class DdmfProdStatusCustomRulesMatcher extends DocumentTypeAdvancedCustomRuleMatcher {
public boolean matches(final String systemID, final String rootNamespace, final String rootLocalName,
final String doctypePublicID, final String doctypeSystemID, final Attributes rootAttributes,
final Map<String, String> queryParameters, final Reader contentReader) {
boolean valuesMatch = false;
int bufferSize = 1024;
char[] buffer = new char[bufferSize];
StringBuilder out = new StringBuilder();
try {
for (int numRead; (numRead = contentReader.read(buffer, 0, buffer.length)) > 0;) {
out.append(buffer, 0, numRead);
}
} catch (IOException e) {
return valuesMatch; // if no content then false
}
String doc = out.toString();
if (doc.matches("<status>\\s*production")) {
valuesMatch = true;
}
return valuesMatch;
}
@Override
public String getDescription() {
// TODO Auto-generated method stub
return null;
}
}
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Framework Content Association extension
Hi Scott,
When in doubt you can create a small class to test just part of the code like:
This returns "false" because "matches" returns true only if the entire string matches that regexp, but in your case you want to check if the string contains the regular expression. So in your specific case I think you can create a regexp pattern and try to find the pattern in the text, something like:
Also if you write messages to the console output using for example "System.err.println("---");" and start Oxygen from the Oxygen installation folder using the "oxygen.bat" script, you will see those messages in the console output and they might help you debug your code while being used by Oxygen.
Regards,
Radu
When in doubt you can create a small class to test just part of the code like:
Code: Select all
public class ABC {
public static void main(String[] args) {
String str = "<doc schemaVer=\"3.2\">\n"
+ " <status>production</status>\n"
+ " ....\n"
+ "</doc>";
System.err.println(str.matches("<status>\\s*production"));
}
}
Code: Select all
public static void main(String[] args) {
String str = "<doc schemaVer=\"3.2\">\n"
+ " <status>production</status>\n"
+ " ....\n"
+ "</doc>";
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("<status>\\s*production");
java.util.regex.Matcher matcher = pattern.matcher(str);
System.err.println(matcher.find());
}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service