Re: Auto detection of grammar
Olivier POTONNIEE <[email protected]> Tue, 06 Jan 2004 17:00:03 +0100
| Newsgroups | gmane.editors.pollo.devel |
|---|---|
| Message-ID | <[email protected]> |
I eventually did it this way: if a schemaLocation (or noNamespaceSchemaLocation) is detected in the document root element, then it is proposed as the default schema in the configuration panel. I also added the default selection of the "Ok" button, so that the user only has to type "Enter" on keyboard. However the config dialog is still proposed to allow any other configuration.
Modifications done to org.outerj.pollo.gui.ViewTypesDialog:
4a5
> import org.outerj.pollo.xmleditor.model.XmlModel;
6a8,11
> import org.w3c.dom.*;
>
> import com.sun.rsasign.t;
>
13a19
> import java.util.StringTokenizer;
52a59
> protected JButton okButton;
267c274
< polloTree.setSelected(true);
---
> polloTree.setSelected(false);
269a277
> classicTree.setSelected(true);
287c295
< JButton okButton = new JButton("Okay");
---
> okButton = new JButton("Okay");
438c446
< public boolean showDialog(Frame parent)
---
> public boolean showDialog(Frame parent, XmlModel xmlModel)
439a448,469
> // if document has a schema, select it by default
> boolean hasSchema = false;
> String schemaloc = null;
> Document doc = xmlModel.getDocument();
> NamedNodeMap attrs = doc.getDocumentElement().getAttributes();
> try {
> Node locattr = attrs.getNamedItem("xsi:noNamespaceSchemaLocation");
> schemaloc = locattr.getNodeValue();
> hasSchema = true;
> } catch (Exception e1) {
> try {
> Node locattr = attrs.getNamedItem("xsi:schemaLocation");
> String nslocpair = locattr.getNodeValue();
> StringTokenizer tokens = new StringTokenizer(nslocpair, " ");
> tokens.nextToken();
> schemaloc = tokens.nextToken();
> hasSchema = true;
> } catch (Exception e2) {
> // no schema, forget it
> }
> }
>
443a474,484
>
> if (hasSchema) {
> //predefinedViewTypeButton.setSelected(false);
> enableSelectPredefined(false);
> customViewTypeButton.setSelected(true);
> autodetectSchemaButton.setSelected(true);
> enableSelectCustom(true);
> schemaFileCombo.getEditor().setItem(schemaloc);
> getRootPane().setDefaultButton(okButton);
> }
>
I assume here that the schema instance namespace is always "xsi", which is the common usage (if it's not, schema location will be ignored).
Then, in Pollo.createEditorPanel() method:
if (viewTypesDialog.showDialog(polloFrame))
becomes:
if (viewTypesDialog.showDialog(polloFrame, xmlModel))
I guess this could be helpfull to other pollo users.
Regards,
--
Olivier
Olivier POTONNIEE wrote:
> Hello again
>
> I find it very cumbersome to have to specify the grammar of every XML
> document I open: my documents include the reference to the XML Schema
> there are based one (xsi:noNamespaceSchemaLocation). Has anybody patched
> pollo (or knows how to) so that this grammar is taken into account
> automatically ?
>
> Thanks
>
> --
> Olivier
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click