# com.bea.ide.document
DefaultDocumentHandler Class

public abstract class DefaultDocumentHandler
extends `Object`
implements `IDocumentHandler`

This class is a default implementation of a document handler. It is set up to handle a single file extension. It is able to create files of this type and derived classes may provide a template for the contents of the new file.

Hierarchy
  `Object`
  `DefaultDocumentHandler`

All Implemented Interfaces
  `IDocumentHandler`

Direct Known Subclasses
  `ControlDocumentFactory`, `JavaDocumentFactory`, `TextDocumentFactory`

## Constructor Summary

DefaultDocumentHandler(`String` sDefaultExtension) Constructor for the handler that accepts the default extension that this handler will provide information for.

## Method Summary

`protected abstract `IDocument`` | `createDocumentObject`(`URI` uriFile) This method must be implemented by derived classes to create the actual IDocument interface that this handler provides.
`public `URI`` | `createNewFile`(`URI` uriFile, `String` sTemplateId) Create a new document using the given URI.
`public `String`` | `getBaseName`(`String` sFile) Given a file name for this handler, strips off any leading or trailing characters that are particular to this file handler.
`public `String`` | `getDefaultExtension`() Returns the default extension for this handler.
`protected static `String`` | `getExtension`(`String` sFile) Helper method to retrieve the extension given a string.
`public `String`` | `getHandlerId`() Returns the handler ID for this document handler.
`protected `Reader`` | `getTemplate`(`URI` uriFile, `String` sTemplateId) This method may be overridden to return default content for a new file created using this handler.
`public `String`` | `invalidNameCheck`(`String` sFile) Examine the filename to determine if it is valid for this handler.
`public `IDocument`` | `openDocument`(`URI` uriFile) Opens an existing document with the given URI.
`public int` | `resolveUnknownPriority`(`IDocumentHandler.IHandlerContext` hc) A default implementation of the resolveUnknownPriority method.
`public `String`` | `suggestValidName`(`String` sFile) Examine the filename and suggest a valid version of the name.

Methods from class `java.lang.`Object``
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods from interface `com.bea.ide.document.`IDocumentHandler``
``createNewFile`, `getBaseName`, `getDefaultExtension`, `getHandlerId`, `invalidNameCheck`, `openDocument`, `resolveUnknownPriority`, `suggestValidName``

## Constructor Detail

### DefaultDocumentHandler

    protected DefaultDocumentHandler(String sDefaultExtension)

  Constructor for the handler that accepts the default extension that this handler will provide information for.

## Method Detail

### createDocumentObject(URI) Method

    protected abstract IDocument createDocumentObject(URI uriFile)
         throws IOException

This method must be implemented by derived classes to create the actual IDocument interface that this handler provides. It is expected that uriFile exists.

#### Parameters

uriFile
  Name of the existing file to create the IDocument interface for

#### Returns

An object implementing the IDocument interface that represents the contents of the given file

#### Exceptions

``IOException``

### createNewFile(URI, String) Method

    public URI createNewFile(URI uriFile,
                             String sTemplateId)

Create a new document using the given URI. The default implementation will try to obtain the initial contents for the new file by calling `DefaultDocumentHandler.getTemplate(URI, String)```. The template contents (or an empty file if getTemplate returns `null`) will be written into the file. NOTE: The canCreate attribute in the extension XML for this handler must be set to true; otherwise, this implementation will always return `null`. Any IO exception will be displayed in a dialog box.

#### Parameters

uriFile
  URI of the file to create

sTemplateId
  This value is used to hint to the handler what, if any, initial contents the file should have. These are typically values defined in the extension XML for the handler. A null value for sTemplateId is always valid and is considered the default template.

#### Returns

URI of the file created; `null` if an IO error occurs or the handler cannot create files.

### getBaseName(String) Method

    public String getBaseName(String sFile)

Given a file name for this handler, strips off any leading or trailing characters that are particular to this file handler. The default implementation simply removes the trailing .ext where ext is an extension understood by this handler. Derived classes should override this method if they add more than just an extension to the file name in suggestValidName().

#### Parameters

sFile
  Filename presumably generated by suggestValidName()

#### Returns

String containing the base name that was used to derive the filename for this handler

### getDefaultExtension() Method

    public String getDefaultExtension()

Returns the default extension for this handler. This is the extension used when creating new files. This implementation returns the extension given in the constructor. Derived classes should rarely need to override this method.

#### Returns

The default extension for this handler. This does NOT include the leading "."

### getExtension(String) Method

    protected static String getExtension(String sFile)

Helper method to retrieve the extension given a string. Finds the last '.' in the string and returns only the text following the '.' (exclusive)

### getHandlerId() Method

    public String getHandlerId()

Returns the handler ID for this document handler. The handler ID is always the class name of the handler. Derived classes should not need to override this method.

#### Returns

String representing the ID of this handler.

### getTemplate(URI, String) Method

    protected Reader getTemplate(URI uriFile,
                                 String sTemplateId)

This method may be overridden to return default content for a new file created using this handler. The default implementation returns null, resulting in a blank file.

#### Parameters

uriFile
  Name of the new file being created

#### Returns

A java.io.Reader object that will be used to write the contents of the new file

### invalidNameCheck(String) Method

    public String invalidNameCheck(String sFile)

Examine the filename to determine if it is valid for this handler. The return value is a string that contains information about what is invalid about the name. Note that this method does not validate the name for the operating system, only for this handler. For the default implementation, a name is only invalid if it does not end in an extension understood by this handler.

#### Parameters

sFile
  Filename to check

#### Returns

String containing information about why the name is invalid; `null` if the name is valid for this handler.

### openDocument(URI) Method

    public IDocument openDocument(URI uriFile)

Opens an existing document with the given URI. Delegates to the createDocument method. Any IO exception will be displayed in a dialog box.

#### Parameters

uriFile
  URI of the file to open

#### Returns

IDocument interface for the new file.

### resolveUnknownPriority(IDocumentHandler.IHandlerContext) Method

    public int resolveUnknownPriority(IDocumentHandler.IHandlerContext hc)

A default implementation of the resolveUnknownPriority method. This version simply returns Priority.IGNORE. If your handler registers as priority unknown for any extensions (including "*") this method will be invoked in order to give your handler an opportunity to determine a valid priority.

#### Parameters

hc
  Handler context containing relevant information about the file.

#### Returns

Priority value indicating the degree to which this handler understands the file.

### suggestValidName(String) Method

    public String suggestValidName(String sFile)

Examine the filename and suggest a valid version of the name. The default implementation checks to see if the file ends in an extension understood by this handler. If not, it replaces any existing extension with the default extension.

#### Parameters

sFile
  Filename to alter

#### Returns

String containing a valid filename for this handler