Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.novell.nds.dirxml.util
Class DocumentTemplate

    java.lang.Object
      com.novell.nds.dirxml.util.DocumentTemplate

    public class DocumentTemplate

extends Object

This class takes a template string containing replacement tokens and generates strings with substitutions made for the tokens. The replacement values come from an XML document.

In particular:

A replacement token in the source string is specified by surrounding a token identifier with '$' (dollar) characters. The token identifier may be any legal XML name.

The replacement values are obtained from a passed XML document. If an XML attribute's name matches a replacement token identifier then the attribute's value is substituted for the replacement token. If the name of the parent element of a text node matches a replacement token identifier then the text node value replaces the token.

This class is designed primarily for templates that are serialized XML documents whose replacement token values should come from another XML document. E.g.,

Template string:

      static final String   SYNC_STRING =
      "<nds><input>" +
      "<sync src-dn='$src-dn$' qualified-src-dn='$qualified-src-dn$' class-name='$class-name$'>" +
      "<association>$association$</association>" +
      "</sync>" +
      "</input></nds>";

Replacement value document:

      <nds>
        <output>
          <instance class-name='User' src-dn='\\TREE\\novell\\jdoe' qualified-src-dn='O=novell\\CN=jdoe'>
            <association>1234</association>
          </instance>
        </output>
      </nds>

Result string:

      "<nds><input>" +
      "<sync src-dn='\\TREE\\novell\\jdoe' qualified-src-dn='O=novell\\CN=jdoe' class-name='User'>" +
      "<association>1234</association>" +
      "</sync>" +
      "</input></nds>";

Constructor Summary
`DocumentTemplate(String template)` Construct a `DocumentTemplate` instance from a template `String` containing zero or more replacement tokens.

Method Summary
`Document` | `getMappedDocument(Map replacementMap)` Get a DOM representation of the template `String` with all replacement tokens replaced.
`Document` | `getMappedDocument(Node replacementSource)` Get a DOM representation of the template `String` with all replacement tokens replaced.
`String` | `getMappedString(Map replacementMap)` Get the template `String` with all replacement tokens replaced.
`String` | `getMappedString(Node replacementSource)` Get the template `String` with all replacement tokens replaced.

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

Constructor Detail

### DocumentTemplate

    public DocumentTemplate(String template)

  Construct a `DocumentTemplate` instance from a template `String` containing zero or more replacement tokens.

  Parameters:
    `template` - the template `String`

Method Detail

### getMappedString

    public String getMappedString(Node replacementSource)

  Get the template `String` with all replacement tokens replaced.

  Parameters:
    `replacementSource` - DOM node that is the top of the subtree containing values for the replacement tokens
  Returns:
    mapped `String`

### getMappedString

    public String getMappedString(Map replacementMap)

  Get the template `String` with all replacement tokens replaced.

  Parameters:
    `replacementMap` - mapping between token identifiers and values
  Returns:
    mapped `String`

### getMappedDocument

    public Document getMappedDocument(Node replacementSource)

  Get a DOM representation of the template `String` with all replacement tokens replaced. If the template `String` is not a valid, serialized XML document then the return value will be `null`.

  Parameters:
    `replacementSource` - DOM node that is the top of the subtree containing values for the replacement tokens
  Returns:
    DOM document or `null`

### getMappedDocument

    public Document getMappedDocument(Map replacementMap)

  Get a DOM representation of the template `String` with all replacement tokens replaced. If the template `String` is not a valid, serialized XML document then the return value will be `null`.

  Parameters:
    `replacementMap` - mapping between token identifiers and values
  Returns:
    DOM document or `null`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD