org.openide.loaders
Class XMLDataObject

java.lang.Object
  |
  +--org.openide.loaders.DataObject
        |
        +--org.openide.loaders.MultiDataObject
              |
              +--org.openide.loaders.XMLDataObject
All Implemented Interfaces:
Node.Cookie, Serializable

public class XMLDataObject
extends MultiDataObject

Object that provides main functionality for xml documents. These object are recognized by xml extension and by text/xml MIME type. After recognizing is a Info @see Info created. The Info is constructed from sibling xmlInfo file or registered info. The infos are registered for whole class of XML documents by DTD public ID.

See Also:
Serialized Form

Inner Class Summary
static class XMLDataObject.Info
          Representation of xmlinfo file holding container of Processors.
static interface XMLDataObject.Processor
          This class has to be implemented by all processors in the xmlinfo file.
static class XMLDataObject.Util
          Utility class collecting library methods related to XML processing not to XMLDataObject directly.
 
Inner classes inherited from class org.openide.loaders.MultiDataObject
MultiDataObject.Entry
 
Inner classes inherited from class org.openide.loaders.DataObject
DataObject.Registry
 
Field Summary
static String MIME
          Mime type of XML documents.
static String PROP_DOCUMENT
          property name of document property
static String PROP_INFO
          property name of info property
static int STATUS_ERROR
          Parsed with errors.
static int STATUS_NOT
          Not parsed yet.
static int STATUS_OK
          Parsed ok.
static int STATUS_WARNING
          Parsed with warnings.
static String XMLINFO_DTD_PUBLIC_ID
           
static String XMLINFO_DTD_PUBLIC_ID_FORTE
          Public ID of xmlinfo dtd.
 
Fields inherited from class org.openide.loaders.DataObject
PROP_COOKIE, PROP_FILES, PROP_HELP, PROP_MODIFIED, PROP_NAME, PROP_PRIMARY_FILE, PROP_TEMPLATE, PROP_VALID
 
Constructor Summary
XMLDataObject(FileObject fo, MultiFileLoader loader)
          Create new XMLDataObject
 
Method Summary
static boolean addEntityResolver(org.xml.sax.EntityResolver resolver)
          Add a given entity resolver to IDE resolver chain.
static org.w3c.dom.Document createDocument()
          Deprecated. Moved to Util
protected  EditorCookie createEditorCookie()
          Allows subclasses to provide their own editor cookie.
static org.xml.sax.InputSource createInputSource(URL url)
          Deprecated. Deprecated as it was a workaround method. Replace with new InputSource(url.toExternalForm()).
protected  Node createNodeDelegate()
          If the Info associated with this data object (if any) provides a subclass of Node, then this object is created to represent the XML data object, otherwise DataNode is created.
static org.xml.sax.Parser createParser()
          Deprecated. Use Util instead. It will create a SAX XMLReader that is SAX Parser replacement. You will have to replace DocumentHandler by ContentHandler besause XMLReader accepts just ContentHandler.

Alternatively if not interested in new callbacks defined by SAX 2.0 you can wrap returned XMLReader into XMLReaderAdapter that implements Parser.

static org.xml.sax.Parser createParser(boolean validate)
          Deprecated. Use Util instead setting ns to false. For more details see createParser
 Node.Cookie getCookie(Class cls)
          Cookies from info are not placed into cookie set and can be obtained only by invoking this method.
 org.w3c.dom.Document getDocument()
          Creates w3c's document for the xml file.
 HelpCtx getHelpCtx()
          Get help context for this object.
 XMLDataObject.Info getInfo()
           
static XMLDataObject.Info getRegisteredInfo(String publicId)
          Obtain registered Info for particular DTD public ID.
 int getStatus()
           
static org.w3c.dom.Document parse(URL url)
          Deprecated. Use Util instead setting null error handler and validation to false.
static org.w3c.dom.Document parse(URL url, boolean validate)
          Deprecated. Use Util instead setting null handler.
static org.w3c.dom.Document parse(URL url, org.xml.sax.ErrorHandler eh)
          Deprecated. Use Util instead setting validation to false.
static org.w3c.dom.Document parse(URL url, org.xml.sax.ErrorHandler eh, boolean validate)
          Deprecated. Use Util instead.
static void registerCatalogEntry(String publicId, String uri)
          Registers the given public ID as corresponding to a particular URI, typically a local copy.
static void registerCatalogEntry(String publicId, String resourceName, ClassLoader loader)
          Registers a given public ID as corresponding to a particular Java resource in a given class loader, typically distributed with a software package.
static void registerInfo(String publicId, XMLDataObject.Info info)
          Registers new Info to particular XML document content type as recognized by DTD public id.
static org.xml.sax.EntityResolver removeEntityResolver(org.xml.sax.EntityResolver resolver)
          Remove a given entity resolver from IDE resolver chain.
 void setInfo(XMLDataObject.Info ii)
           
protected  void updateIconBase(String res)
          Called when the info file is parsed and the icon should change.
static void write(org.w3c.dom.Document doc, OutputStream out, String enc)
          Deprecated. Moved to Util.
static void write(org.w3c.dom.Document doc, Writer writer)
          Deprecated. Encoding used by Writer may be in direct conflict with encoding declared in document. Replaced with Util.
 
Methods inherited from class org.openide.loaders.MultiDataObject
addSecondaryEntry, files, findSecondaryEntry, getCookieSet, getMultiFileLoader, getPrimaryEntry, handleCopy, handleCreateFromTemplate, handleDelete, handleMove, handleRename, isCopyAllowed, isDeleteAllowed, isMoveAllowed, isRenameAllowed, registerEntry, removeSecondaryEntry, secondaryEntries, setCookieSet, takePrimaryFileLock
 
Methods inherited from class org.openide.loaders.DataObject
addPropertyChangeListener, addVetoableChangeListener, copy, createFromTemplate, createFromTemplate, createShadow, delete, dispose, find, firePropertyChange, fireVetoableChange, getFolder, getLoader, getName, getNodeDelegate, getPrimaryFile, getRegistry, handleCreateShadow, isModified, isShadowAllowed, isTemplate, isValid, markFiles, move, removePropertyChangeListener, removeVetoableChangeListener, rename, setModified, setTemplate, setValid, toString, writeReplace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

XMLINFO_DTD_PUBLIC_ID_FORTE

public static final String XMLINFO_DTD_PUBLIC_ID_FORTE
Public ID of xmlinfo dtd.

XMLINFO_DTD_PUBLIC_ID

public static final String XMLINFO_DTD_PUBLIC_ID

MIME

public static final String MIME
Mime type of XML documents.

STATUS_NOT

public static final int STATUS_NOT
Not parsed yet. Constant for getStatus method.

STATUS_OK

public static final int STATUS_OK
Parsed ok. Constant for getStatus method.

STATUS_WARNING

public static final int STATUS_WARNING
Parsed with warnings. Constant for getStatus method.

STATUS_ERROR

public static final int STATUS_ERROR
Parsed with errors. Constant for getStatus method.

PROP_DOCUMENT

public static final String PROP_DOCUMENT
property name of document property

PROP_INFO

public static final String PROP_INFO
property name of info property
Constructor Detail

XMLDataObject

public XMLDataObject(FileObject fo,
                     MultiFileLoader loader)
              throws DataObjectExistsException
Create new XMLDataObject
Parameters:
fo - the primary file object
loader - loader of this data object
Method Detail

createNodeDelegate

protected Node createNodeDelegate()
If the Info associated with this data object (if any) provides a subclass of Node, then this object is created to represent the XML data object, otherwise DataNode is created.
Overrides:
createNodeDelegate in class MultiDataObject
Returns:
the node representation for this data object
See Also:
DataNode

updateIconBase

protected void updateIconBase(String res)
Called when the info file is parsed and the icon should change.
Parameters:
res - resource for the icon

getHelpCtx

public HelpCtx getHelpCtx()
Description copied from class: DataObject
Get help context for this object.
Overrides:
getHelpCtx in class MultiDataObject
Following copied from class: org.openide.loaders.DataObject
Returns:
the help context

getCookie

public Node.Cookie getCookie(Class cls)
Cookies from info are not placed into cookie set and can be obtained only by invoking this method. Cookie order in info is handled consistently with CookieSet i.e. FIFO.
Overrides:
getCookie in class MultiDataObject
Returns:
a cookie (instanceof cls) that has been found in info or super.getCookie(cls).

createEditorCookie

protected EditorCookie createEditorCookie()
Allows subclasses to provide their own editor cookie.
Returns:
an editor cookie to use

getDocument

public final org.w3c.dom.Document getDocument()
                                       throws IOException,
                                              org.xml.sax.SAXException
Creates w3c's document for the xml file. Either returns cached reference or parses the file and creates new document.
Returns:
the parsed document
Throws:
org.xml.sax.SAXException - if there is a parsing error
IOException - if there is an I/O error

getStatus

public final int getStatus()
Returns:
one of STATUS_XXX constants

getInfo

public final XMLDataObject.Info getInfo()

setInfo

public final void setInfo(XMLDataObject.Info ii)
                   throws IOException

parse

public static org.w3c.dom.Document parse(URL url)
                                  throws IOException,
                                         org.xml.sax.SAXException
Deprecated. Use Util instead setting null error handler and validation to false.

Provides access to internal XML parser. This method takes URL. After successful finish the document tree is returned. Used non validating parser.
Parameters:
url - the url to read the file from

parse

public static org.w3c.dom.Document parse(URL url,
                                         boolean validate)
                                  throws IOException,
                                         org.xml.sax.SAXException
Deprecated. Use Util instead setting null handler.

Provides access to internal XML parser. This method takes URL. After successful finish the document tree is returned. Used non validating parser.
Parameters:
url - the url to read the file from
validate - if true validating parser is used

parse

public static org.w3c.dom.Document parse(URL url,
                                         org.xml.sax.ErrorHandler eh)
                                  throws IOException,
                                         org.xml.sax.SAXException
Deprecated. Use Util instead setting validation to false.

Provides access to internal XML parser. This method takes URL. After successful finish the document tree is returned.
Parameters:
url - the url to read the file from
eh - error handler to notify about exception

parse

public static org.w3c.dom.Document parse(URL url,
                                         org.xml.sax.ErrorHandler eh,
                                         boolean validate)
                                  throws IOException,
                                         org.xml.sax.SAXException
Deprecated. Use Util instead.

Factory a DocumentBuilder and let it create a org.w3c.dom.Document This method takes URL. After successful finish the document tree is returned. A parser producing the Document has set entity resolver to system entity resolver chain.
Parameters:
url - the url to read the file from
eh - error handler to notify about exception
validate - if true validating parser is used
Returns:
org.w3c.dom.Document

createParser

public static org.xml.sax.Parser createParser()
Deprecated. Use Util instead. It will create a SAX XMLReader that is SAX Parser replacement. You will have to replace DocumentHandler by ContentHandler besause XMLReader accepts just ContentHandler.

Alternatively if not interested in new callbacks defined by SAX 2.0 you can wrap returned XMLReader into XMLReaderAdapter that implements Parser.

Creates SAX parse that can be used to parse XML files.
Returns:
sax parser

createParser

public static org.xml.sax.Parser createParser(boolean validate)
Deprecated. Use Util instead setting ns to false. For more details see createParser

Factory SAX parser that can be used to parse XML files. The factory is created according to javax.xml.parsers.SAXParserFactory property. The parser has set entity resolver to system entity resolver chain.
Parameters:
validate - if true validating parser is returned
Returns:
sax parser or null if no parser can be created

createDocument

public static org.w3c.dom.Document createDocument()
Deprecated. Moved to Util

Creates empty DOM Document using JAXP factoring.
Returns:
Document or null on problems with JAXP factoring

write

public static void write(org.w3c.dom.Document doc,
                         Writer writer)
                  throws IOException
Deprecated. Encoding used by Writer may be in direct conflict with encoding declared in document. Replaced with Util.

Writes DOM Document to writer.
Parameters:
doc - DOM Document to be written
writer - OutoutStreamWriter preffered otherwise encoding will be left for implementation specific autodection

write

public static void write(org.w3c.dom.Document doc,
                         OutputStream out,
                         String enc)
                  throws IOException
Deprecated. Moved to Util.

Write Document into OutputStream using given encoding. It is a shortcut for writing configurations etc. It guarantee just that data will be written. Structure and indentation may change.
Parameters:
doc - DOM Document to be written
out - data sink
enc - - XML defined encoding name (i.e. IANA defined, one of UTF-8, UNICODE, ASCII).

createInputSource

public static org.xml.sax.InputSource createInputSource(URL url)
                                                 throws IOException
Deprecated. Deprecated as it was a workaround method. Replace with new InputSource(url.toExternalForm()).

Creates SAX InputSource for specified URL

registerCatalogEntry

public static void registerCatalogEntry(String publicId,
                                        String uri)
Registers the given public ID as corresponding to a particular URI, typically a local copy. This URI will be used in preference to ones provided as system IDs in XML entity declarations. This mechanism would most typically be used for Document Type Definitions (DTDs), where the public IDs are formally managed and versioned.

Any created parser use global entity resolver and you can register its catalog entry.

Parameters:
publicId - The managed public ID being mapped
uri - The URI of the preferred copy of that entity

registerCatalogEntry

public static void registerCatalogEntry(String publicId,
                                        String resourceName,
                                        ClassLoader loader)
Registers a given public ID as corresponding to a particular Java resource in a given class loader, typically distributed with a software package. This resource will be preferred over system IDs included in XML documents. This mechanism should most typically be used for Document Type Definitions (DTDs), where the public IDs are formally managed and versioned.

If a mapping to a URI has been provided, that mapping takes precedence over this one.

Any created parser use global entity resolver and you can register its catalog entry.

Parameters:
publicId - The managed public ID being mapped
resourceName - The name of the Java resource
loader - The class loader holding the resource, or null if it is a system resource.

addEntityResolver

public static final boolean addEntityResolver(org.xml.sax.EntityResolver resolver)
Add a given entity resolver to IDE resolver chain. The resolver chain is searched by private chaining resolver until some registered resolver succed.

Every created parser use global entity resolver and then chain.

Parameters:
resolver - non null resolver to be added
Returns:
true if successfully added

removeEntityResolver

public static final org.xml.sax.EntityResolver removeEntityResolver(org.xml.sax.EntityResolver resolver)
Remove a given entity resolver from IDE resolver chain.

Every created parser use global entity resolver and then chain.

Parameters:
resolver - non null resolver to be removed
Returns:
removed resolver instance or null if not present

registerInfo

public static void registerInfo(String publicId,
                                XMLDataObject.Info info)
Registers new Info to particular XML document content type as recognized by DTD public id. The registration is valid until end.
Parameters:
publicId - used as key
info - associated value or null to unregister

getRegisteredInfo

public static XMLDataObject.Info getRegisteredInfo(String publicId)
Obtain registered Info for particular DTD public ID.
Parameters:
publicId - key which value is required
Returns:
Info clone that is used for given publicId or null


Built on February 22 2001.  |  Portions Copyright 1997-2000 Sun Microsystems, Inc. All rights reserved.