Page 1 of 1
Changing Default Attribute Values
Posted: Wed Dec 14, 2011 8:56 pm
by rb_online
I'm currently running oXygen Author (version 12.2) and I was wondering if there is a way to change the default attribute values. Specifically, I'm looking to change the placement attribute (of the image element) from inline to break. Any help would be much appreciated.
Thank you,
Rob
Re: Changing Default Attribute Values
Posted: Wed Dec 14, 2011 9:33 pm
by adrian
Hello,
What type of document are you editing(DocBook, DITA, etc)?
The default attributes are specified in a schema or DTD, so a solution would be to customize the schema/DTD of that document type and adjust the default attribute values.
Regards,
Adrian
Re: Changing Default Attribute Values
Posted: Thu Dec 15, 2011 11:42 pm
by rb_online
We are editing DITA documents. Does anyone know the name and location of the file to modify?
Re: Changing Default Attribute Values
Posted: Fri Dec 16, 2011 4:10 pm
by mihaela
Hi Rob,
oXygen uses DITA Open Toolkit to process DITA documents. The DTDs and XSL stylesheets from the DITA Open Toolkit are packed in the oXygen distribution, and you can found them inside the [Oxygen-install-folder]/frameworks/dita/DITA-OT folder.
You can change the default value of the placement attribute in the commonElements.mod document (from DITA-OT/dtd/base/dtd folder) but we think that is better to make changes on the publishing side (DITA_OT XSLT stylesheets) than on the attribute declaration side.
Best regards,
Mihaela
Re: Changing Default Attribute Values
Posted: Wed Jan 04, 2012 9:39 pm
by craig_sandvik
If you change the DTD default for <image> @placement, you may have problems down the road if you need to mix your content with content from an implementation that follows the standard.
I think it's better to modify the image insertion code to set @placement.
I was able to get @placement set to "break" for new image insertion with a custom document filter using the code below. It might be nice if the image insertion code in Oxygen set @placement based on the intrinsic size of the image being inserted. (In our environment, images are inserted by a CMS action, so we need the custom code regardless.)
Code: Select all
protected class MyDITAAuthorListener extends AuthorListenerAdapter {
/**
* Filter inserted <image> to set @placement="break" if it is not
* explicitly set.
* Note this does affect paste of a single <image>: if @placement is
* not explicitly set in the pasted element, it will be set to "break".
*/
@Override
public void beforeContentInsert(DocumentContentInsertedEvent e) {
AuthorNode node = null;
if (e.getType() == DocumentContentChangedEvent.INSERT_NODE_EVENT) {
node = e.getInsertedNode();
} else if (e.getType() == DocumentContentChangedEvent.INSERT_FRAGMENT_EVENT) {
AuthorDocumentFragment frag = e.getInsertedFragment();
List<AuthorNode> nodeList = frag.getContentNodes();
if (nodeList != null && nodeList.size() == 1) {
node = nodeList.get(0);
}
}
if (node != null && (node.getType() == AuthorNode.NODE_TYPE_ELEMENT)) {
AuthorElement element = (AuthorElement) node;
if (element.getName().equals("image")) {
AttrValue placementAttr = element.getAttribute("placement");
if (placementAttr == null || !placementAttr.isSpecified()) {
element.setAttribute("placement", new AttrValue("break"));
}
}
}
super.beforeContentInsert(e);
}
}