In this example, functionality is added for inserting images in a custom framework. The images are represented by
the <image> element. The location of the image file is represented by the
value of the @href attribute. In the Java implementation, a dialog box will
be displayed with a text field where the user can enter a full URL or browse for a local
file.
A short description of these methods follows:
Example:
Here is the implementation of these three methods:
/**
* Performs the operation.
*/
public void doOperation(
AuthorAccess authorAccess,
ArgumentsMap arguments)
throws IllegalArgumentException,
AuthorOperationException {
JFrame oxygenFrame = (JFrame) authorAccess.getWorkspaceAccess().getParentFrame()
;
String href = displayURLDialog(oxygenFrame);
if (href.length() != 0) {
// Creates the image XML fragment.
String imageFragment =
"<image xmlns='http://www.oxygenxml.com/sample/documentation' href='"
+ href + "'/>";
// Inserts this fragment at the cursor position.
int caretPosition = authorAccess.getEditorAccess().getCaretOffset();
authorAccess.getDocumentController().insertXMLFragment
(imageFragment, caretPosition);
}
}
/**
* Has no arguments.
*
* @return null.
*/
public ArgumentDescriptor[] getArguments() {
return null;
}
/**
* @return A description of the operation.
*/
public String getDescription() {
return "Inserts an image element. Asks the user for a URL reference.";
}
Make sure you always specify the namespace of the inserted fragments.
<image xmlns='http://www.oxygenxml.com/sample/documentation'
href='path/to/image.png'/>
<?xml version="1.0" encoding="UTF-8"?>
<project name="project" default="dist">
<target name="dist">
<jar destfile="sdf.jar" basedir="classes">
<fileset dir="classes">
<include name="**/*"/>
</fileset>
</jar>
</target>
</project>
Add button. In the
displayed dialog box, enter the location of the JAR file, relative to the Oxygen XML Author Eclipse plugin
frameworks folder.
<section>, <book> or <article>.
local-name()='section' or local-name()='book'
or local-name()='article'
To test the action, open or create an XML file and place the cursor at a valid location. Then click the button associated with the action from the toolbar. In the dialog box, select an image URL and click OK. The image is inserted into the document.