FileDocCategorySizeDatePackage
FormattingStyles.javaAPI DocExample15684Tue Dec 08 01:21:00 GMT 1998oisoft.togetherx.scripts.doc

FormattingStyles

public class FormattingStyles extends Object implements Styles

Fields Summary
private ResourceBundle
myBundle
private Hashtable
myAnchors
int
myLastAnchorIndex
private static final String
mySTARTMARK
private static final String
myENDMARK
private static final String
myANCHOR_PREFIX
private static final String
mySTYLE_NOT_DEFINED_MSG
private Hashtable
myFonts
private Hashtable
myStyles
private int
myListIndent
private int
myDeflistIndent
Constructors Summary
public FormattingStyles(String docType)

        // Try to open resources as class/property
        myBundle = ResourceBundleAccessor.getResourceBundle ("oisoft.togetherx.scripts.doc.Res" + docType, "Res" + docType);
    
Methods Summary
public java.lang.Stringanchor(java.lang.String anchor, java.lang.String displayText)
Start anchor

        String anchorDeclaration = style ("Anchor");
        Properties macros = new Properties ();
        macros.put ("name", normalizeAnchor (anchor));
        macros.put ("text", displayText);
        anchorDeclaration = Formatter.substituteMacros (anchorDeclaration, macros);
        return anchorDeclaration;
    
public java.lang.Stringbody()
Body start

        return style ("Body");
    
public java.lang.StringbodyEnd()
Body end

        return styleEnd ("Body");
    
public java.lang.Stringbold()
Start bold

        return style ("Bold");
    
public java.lang.StringboldEnd()
End bold

        return styleEnd ("Bold");
    
public java.lang.Stringbr()
Line separator

        return style ("new_line");
    
public java.lang.StringdefinitionList()
Start definition list

        myDeflistIndent++;
        return style ("DefinitionList");
    
public java.lang.StringdefinitionListDefinition()
Start Definition list Definition

        String indent = resource ("DefinitionListDefinition.indent");
        int numIndent;
        if (indent != null)
            numIndent = Integer.parseInt (indent, 10);
        else
            numIndent = 1;

        String text = style ("DefinitionListDefinition");

        Properties macros = new Properties ();
        macros.put ("indent", Integer.toString (numIndent * myDeflistIndent));

        text = Formatter.substituteMacros (text, macros);

        return text;
    
public java.lang.StringdefinitionListDefinitionEnd()
End Definition list Definition

        return styleEnd ("DefinitionListDefinition");
    
public java.lang.StringdefinitionListEnd()
End definition list

        myDeflistIndent--;
        return styleEnd ("DefinitionList");
    
public java.lang.StringdefinitionListTerm(java.lang.String text)
Definition list term

        String listItemDeclaration;
        String rightResource = resource ("DefinitionListTerm"+"."+ Integer.toString (myDeflistIndent));
        if (rightResource != null)
            listItemDeclaration = rightResource;
        else
            listItemDeclaration = style ("DefinitionListTerm");
        listItemDeclaration = Formatter.replaceTags (listItemDeclaration, "text", text);
        return listItemDeclaration;
    
public java.lang.Stringdocument()
Returns string, which should starts a new document (, for instance, for HTML document)

        String documentHeader = new String (style ("Document"));

        // Collect a font declarations, which should be written into header
        String fontDeclarationTable = new String ();

        String fontReference = resource ("Font.reference");

        if (fontReference != null) {
            int i = 1;
            String fontName;
            do {
                String resourceName = new String ("Font."+Integer.toString (i));
                fontName = resource (resourceName);
                if (fontName != null) {
                    String fontDeclaration = resource (resourceName + ".declaration");
                    if (fontDeclaration != null) {
                        Properties props = new Properties ();
                        props.put ("number", Integer.toString (i));
                        props.put ("name", fontName);
                        fontDeclaration = Formatter.substituteMacros (fontDeclaration, props);
                        fontDeclarationTable += fontDeclaration;
                        // Put the font with reference into internal vector
                        String theFontReference = new String (fontReference);
                        theFontReference = Formatter.substituteMacros (theFontReference, props);
                        myFonts.put (fontName, theFontReference);
                    }
                }
                ++i;
            } while (fontName != null);
        }
        Properties fontsAndStyles = new Properties ();
        fontsAndStyles.put ("fontDeclarations", fontDeclarationTable);
        documentHeader = Formatter.substituteMacros (documentHeader, fontsAndStyles);
        return documentHeader;
    
public java.lang.StringdocumentEnd()
Returns string, which should finish a document

        return styleEnd ("Document");
    
public java.lang.Stringfont(int size)
Selects a font size

        String fontDeclaration = style ("FontSize");
        fontDeclaration = Formatter.replaceTags (fontDeclaration, "size", Integer.toString (size));
        return fontDeclaration;
    
public java.lang.StringfontClass(java.lang.String name)
Selects a font class

        String fontReference = (String)myFonts.get (name);
        if (fontReference == null) {
            String fontDeclaration = style ("FontClass");
            fontDeclaration = Formatter.replaceTags (fontDeclaration, "fontName", name);
            return fontDeclaration;
        }
        return fontReference;
    
public java.lang.StringfontColor(java.lang.String color)
Selects a font color

        String fontDeclaration = style ("FontColor");
        fontDeclaration = Formatter.replaceTags (fontDeclaration, "color", color);
        return fontDeclaration;
    
public java.lang.StringfontEnd()
End font selection

        return styleEnd ("Font");
    
public java.lang.StringfontSizeClass(int size, java.lang.String name)
Selects a font class and size

        String fontDeclaration = style ("FontSizeClass");
        fontDeclaration = Formatter.replaceTags (fontDeclaration, "size", Integer.toString (size));
        fontDeclaration = Formatter.replaceTags (fontDeclaration, "fontName", name);
        return fontDeclaration;
    
public java.lang.Stringhr()
Returns a section separator

        return style ("new_section");
    
public java.lang.Stringhref(java.lang.String name)
Start href

        String hrefDeclaration = style ("Href");
        hrefDeclaration = Formatter.replaceTags (hrefDeclaration, "name", processBackSlashes (name));
        return hrefDeclaration;
    
public java.lang.StringhrefEnd()
End href

        return styleEnd ("Href");
    
public java.lang.StringhrefWithIndex(java.lang.String name, java.lang.String index)
Start href with index

        String hrefDeclaration = style ("HrefIndex");
        Properties macros = new Properties ();
        macros.put ("name", processBackSlashes (name));
        // For bookmark not all characters are acceptable, replace them by the same way as create anchor
        macros.put ("index", normalizeAnchor (index));
        hrefDeclaration = Formatter.substituteMacros (hrefDeclaration, macros);
        return hrefDeclaration;
    
public java.lang.Stringitalic()
Start italic

        return style ("Italic");
    
public java.lang.StringitalicEnd()
End italic

        return styleEnd ("Italic");
    
public java.lang.Stringlist()
Start list

        myListIndent++;
        String listDeclaration;
        String rightResource = resource ("List"+"."+ Integer.toString (myDeflistIndent));
        if (rightResource != null)
            listDeclaration = rightResource;
        else
            listDeclaration = style ("List");
        return listDeclaration;
    
public java.lang.Stringlist(java.lang.String style)
Start list with bullet type

        String listDeclaration = style ("ListType");
        listDeclaration = Formatter.replaceTags (listDeclaration, "style", style);
        return listDeclaration;
    
public java.lang.StringlistEnd()
End list

        myListIndent--;
        return styleEnd ("List");
    
public java.lang.StringlistItem(java.lang.String itemText)
List item

        String indent = resource ("ListItem.indent");
        int numIndent;
        if (indent != null)
            numIndent = Integer.parseInt (indent, 10);
        else
            numIndent = 1;

        String text = style ("ListItem");

        Properties macros = new Properties ();
        macros.put ("indent", Integer.toString (numIndent * myDeflistIndent));
        macros.put ("text", itemText);

        text = Formatter.substituteMacros (text, macros);

        return text;
    
public java.lang.StringnestedDocument(java.lang.String documentFileName)
Nested document

        String nestedDocumentDeclaration = style ("NestedDocument");
        String goodFileName = processBackSlashes (documentFileName);
        nestedDocumentDeclaration = Formatter.replaceTags (nestedDocumentDeclaration, "fileName", goodFileName);
        return nestedDocumentDeclaration;
    
private java.lang.StringnormalizeAnchor(java.lang.String source)
Create unique anchor string for the source string If the anchor already in table, return previous index, otherwise create new one

        String anchor = (String)myAnchors.get (source);
        if (anchor == null) {
            myLastAnchorIndex++;
            anchor = myANCHOR_PREFIX + Integer.toString (myLastAnchorIndex);
            myAnchors.put (source, anchor);
        }
        return anchor;
    
public java.lang.Stringpage()
Returns a page

        return style ("new_page");
    
public java.lang.Stringpar()
Returns a paragraph separator

        return style ("par");
    
public java.lang.StringparEnd()
Returns a paragraph separator end

        return styleEnd ("par");
    
public java.lang.Stringpicture(java.lang.String fileName)
Picture

        String pictureDeclaration = style ("Picture");
        String goodFileName = processBackSlashes (fileName);
        pictureDeclaration = Formatter.replaceTags (pictureDeclaration, "fileName", goodFileName);
        return pictureDeclaration;
    
public java.lang.StringpictureWithAlternativeText(java.lang.String fileName, java.lang.String message)
Picture with alternative text

        String pictureDeclaration = style ("PictureAltText");
        Properties macros = new Properties ();
        String goodFileName = processBackSlashes (fileName);
        macros.put ("fileName", goodFileName);
        macros.put ("message", message);
        pictureDeclaration = Formatter.substituteMacros (pictureDeclaration, macros);
        return pictureDeclaration;
    
public java.lang.Stringpre()
Starts of preformatted code

        return style ("preformatted");
    
public java.lang.StringpreEnd()
Finishs of preformatted code

        return styleEnd ("preformatted");
    
private java.lang.StringprocessBackSlashes(java.lang.String source)
Reverses all backslashes to right one to make file names compatible with all documentation format

        String result = new String (source);
        result = Formatter.replace (result, "\\", "/");
        return result;
    
private java.lang.StringpropertyKey(java.lang.String text)
Convert all blanks of text to underscores, because property keys do not support spaces

        return Formatter.replace (text, " ", "_");
    
public java.lang.Stringresource(java.lang.String resourceName)
Private method to access internal properties (unavailable from the script) Also it may be used to check resource availability

return
String if resource found, or null if not

        String value;
        try {
            value = myBundle.getString (propertyKey (resourceName));
        }
        catch (MissingResourceException e) {
            return null;
        }
        return value;
    
public java.lang.Stringstrikeout()
Start strikeout

        return style ("Strikeout");
    
public java.lang.StringstrikeoutEnd()
End strikeout

        return styleEnd ("Strikeout");
    
public java.lang.Stringstyle(java.lang.String styleName)
General method to access style beginning

        String stBegin = styleName + mySTARTMARK;
        String value;
        try {
            value = myBundle.getString (propertyKey (stBegin));
        }
        catch (MissingResourceException e) {
            value = new String (mySTYLE_NOT_DEFINED_MSG + styleName);
        }
        return value;
    
public java.lang.StringstyleEnd(java.lang.String styleName)
General method to access style end

        String stEnd = styleName + myENDMARK;
        String value;
        try {
            value = myBundle.getString (propertyKey (stEnd));
        }
        catch (MissingResourceException e) {
            value = new String (mySTYLE_NOT_DEFINED_MSG + stEnd);
        }
        return value;
    
public java.lang.Stringsubscript()
Start subscript

        return style ("Subscript");
    
public java.lang.StringsubscriptEnd()
End subscript

        return styleEnd ("Subscript");
    
public java.lang.Stringsuperscript()
Start superscript

        return style ("Superscript");
    
public java.lang.StringsuperscriptEnd()
End superscript

        return styleEnd ("Superscript");
    
public java.lang.Stringtitle()
Title start

        return style ("Title");
    
public java.lang.StringtitleEnd()
Title end

        return styleEnd ("Title");
    
public java.lang.Stringunderline()
Start Underline

        return style ("Underline");
    
public java.lang.StringunderlineEnd()
End Underline

        return styleEnd ("Underline");