X

Geertjan's Blog

  • May 5, 2010

XML Editor in Source View of MultiView Component (Part 2)

Geertjan Wielenga
Product Manager
Let's extend the XML source editor in our multiview component to support XML checking and XML validation. The end result will be like this:

Thanks to Toni Epple and Enrico Scantamburlo, I came up with the following solution, which requires a dependency on the "XML Tools" module.

Note in particular the parts in bold below:

public class AbcDataObject extends XMLDataObject implements Lookup.Provider {
final InstanceContent ic;
private AbstractLookup lookup;
public AbcDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
super(pf, loader);
ic = new InstanceContent();
lookup = new AbstractLookup(ic);InputSource is = DataObjectAdapters.inputSource(this);
Source source = DataObjectAdapters.source(this);
ic.add(new CheckXMLSupport(is));
ic.add(new ValidateXMLSupport(is));
ic.add(new TransformableSupport(source));

ic.add(AbcEditorSupport.create(this));
}
@Override
protected Node createNodeDelegate() {
return new MyDataNode(this);
}
public class MyDataNode extends DataNode implements Node.Cookie {
public MyDataNode(AbcDataObject obj) {
super(obj, Children.LEAF, lookup);ic.add(this);
setIconBaseWithExtension("org/myorg/abcfiletype/Datasource.gif");
}
}
@Override
public Lookup getLookup() {
return lookup;
}
@Override
public Node.Cookie getCookie(Class type){
Object o = lookup.lookup(type);
return o instanceof Node.Cookie ? (Node.Cookie)o: null;
}
}

And now you should have XML checking and validation enabled in the XML editor of your multiview component!

In other news. Now continue to part 3 of this series!

Join the discussion

Comments ( 1 )
  • Eduardo Costa Wednesday, May 5, 2010

    Congratulations! Another great (and very useful) post!

    I have a question: have you tested NB's reaction when user changes the DOCTYPE or the root element?


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.