Changeset 6565


Ignore:
Timestamp:
2004-01-21T11:18:33+13:00 (20 years ago)
Author:
jmt12
Message:

HelpFrame now looks in the appropriate language code named folder for help files. It also wants help_index.xml rather than the full help.xml.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/help/HelpFrame.java

    r5597 r6565  
    4747import org.apache.xerces.parsers.DOMParser;
    4848import org.greenstone.gatherer.Dictionary;
     49import org.greenstone.gatherer.util.StaticStrings;
    4950import org.greenstone.gatherer.util.Utility;
    5051import org.w3c.dom.*;
     
    5859    extends JFrame {
    5960
     61    static private final String NULL_STRING = "<null>";
     62    /** The size of the frame */
     63    static private final Dimension SIZE = new Dimension(760, 560);
     64
    6065    /** The HTML rendering pane */
    6166    private CalHTMLPane view = null;
     
    6772    private JSplitPane split_pane = null;
    6873
    69     /** The size of the frame */
    70     static final Dimension SIZE = new Dimension(760, 560);
    7174
    7275
     
    7982    view = new CalHTMLPane(new CalHTMLPreferences(), new Observer(), "Help Pages");
    8083
    81     HelpItem rootNode = new HelpItem(Dictionary.get("Help.Contents"), "<null>");
     84    HelpItem rootNode = new HelpItem(Dictionary.get("Help.Contents"), NULL_STRING);
    8285    model = new ContentsModel(rootNode);
    8386    contents = new JTree((DefaultTreeModel) model);
     
    141144        try {
    142145        DOMParser parser = new DOMParser();
    143         parser.parse(Utility.HELP_DIR + "help.xml");
     146        parser.parse(Utility.getHelpIndex());
    144147        Document document = parser.getDocument();
    145148
     
    151154        for (int i = 0; i < children.getLength(); i++) {
    152155            Node child = children.item(i);
    153             if (child.getNodeName().equals("Section")) {
     156            if (child.getNodeName().equals(StaticStrings.SECTION_ELEMENT)) {
    154157            sectionNum++;
    155             buildContentsHierarchy(rootNode, sectionNum + "", child);
     158            buildContentsHierarchy(rootNode, sectionNum + StaticStrings.EMPTY_STR, child);
    156159            }
    157160        }
     
    166169    {
    167170        // Determine the section name
    168         String sectionName = ((Element) node).getAttribute("name");
     171        String sectionName = ((Element) node).getAttribute(StaticStrings.NAME_ATTRIBUTE);
    169172
    170173        // Determine the section title
    171         String sectionTitle = "";
     174        String sectionTitle = StaticStrings.EMPTY_STR;
    172175        NodeList children = node.getChildNodes();
    173176        for (int i = 0; i < children.getLength(); i++) {
    174177        Node child = children.item(i);
    175         if (child.getNodeName().equals("Title")) {
    176             sectionTitle = pos + ": " + child.getFirstChild().getNodeValue();
     178        if (child.getNodeName().equals(StaticStrings.TITLE_ELEMENT)) {
     179            sectionTitle = pos + StaticStrings.COLON_CHARACTER + StaticStrings.SPACE_CHARACTER + child.getFirstChild().getNodeValue();
    177180        }
    178181        }
     
    186189        for (int i = 0; i < children.getLength(); i++) {
    187190        Node child = children.item(i);
    188         if (child.getNodeName().equals("Section")) {
     191        if (child.getNodeName().equals(StaticStrings.SECTION_ELEMENT)) {
    189192            sectionNum++;
    190             buildContentsHierarchy(item, pos + "." + sectionNum, child);
     193            buildContentsHierarchy(item, pos + StaticStrings.STOP_CHARACTER + sectionNum, child);
    191194        }
    192195        }
     
    260263    public URL getURL()
    261264    {
    262         if (name != null && !name.equals("<null>")) {
     265        if (name != null && !name.equals(NULL_STRING)) {
    263266        try {
    264             File file = new File(Utility.HELP_DIR + name + ".htm");
     267            File file = new File(Utility.HELP_DIR + name + StaticStrings.HTM_FILE_EXTENSION);
    265268            return file.toURL();
    266269        }
  • trunk/gli/src/org/greenstone/gatherer/util/StaticStrings.java

    r6549 r6565  
    119119    static final public String HTTP_PROTOCOL_STR                          = "http://";
    120120    static final public String HELP_ARGUMENT                              = "-help";
     121    static final public String HELP_INDEX_FILENAME                        = "help_index.xml";
     122    static final public String HTM_FILE_EXTENSION                         = ".htm";
    121123    static final public String IDENTIFIER_VALUE                           = "identifier";
    122124    static final public String IMAGES_FOLDER                              = "images";
     
    152154    static final public String MAPPING_ELEMENT                            = "Mapping";
    153155    static final public String MARC_EXTENSION                             = ".marc";
     156    static final public String MDS_ATTRIBUTE                              = "mds";
    154157    static final public String METADATA_ARGUMENT                          = "-metadata";
    155158    static final public String METADATA_BAK                               = "~metadata.xml";
     
    190193    static final public String SEARCHTYPE_ELEMENT                         = "SearchType";
    191194    static final public String SEARCHTYPE_STR                             = "searchtype";
     195    static final public String SECTION_ELEMENT                            = "Section";
    192196    static final public String SECTION_STR                                = "section";
    193197    static final public String SEPARATOR_ATTRIBUTE                        = "separator";
     
    216220    static final public String TEXT_STR                                   = "text";
    217221    static final public String TIMESTAMP_ARGUMENT                         = "&uq=";
     222    static final public String TITLE_ELEMENT                              = "Title";
    218223    static final public String TRUE_STR                                   = "true";
    219     static final public String TRUNCATED_STRING                            = "...";
     224    static final public String TRUNCATED_STRING                           = "...";
    220225    static final public String TYPE_ATTRIBUTE                             = "type";
    221226    static final public String UNDERSCORE_CHARACTER                       = "_";
  • trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r6539 r6565  
    370370            // If the token is bigger than two thirds width, before we've even started break it down.
    371371            if(current_width + 1 + token.length() > width && token.length() > threshold) {
    372             String prefix = token.substring(0, width - 1 - current_width);
    373             token = token.substring(prefix.length());
    374             if(current_width == 0) {
    375                 line = line + prefix;
     372            if(width == current_width) {
     373                lines.push(line);
     374                line = token;
     375                current_width = token.length();
    376376            }
    377377            else {
    378                 line = line + " " + prefix;
     378                String prefix = token.substring(0, width - 1 - current_width);
     379                token = token.substring(prefix.length());
     380                if(current_width == 0) {
     381                line = line + prefix;
     382                }
     383                else {
     384                line = line + " " + prefix;
     385                }
     386                lines.push(line);
     387                line = "";
     388                current_width = 0;
    379389            }
    380             lines.push(line);
    381             line = "";
    382             current_width = 0;
    383390            }
    384391            // If adding the next token would push us over the maximum line width.
     
    547554    return col_dir + ETC_DIR;
    548555    }
     556
     557    /** Retrieve the full file path to the help index xml file.
     558     * @return the full path as a String
     559     */
     560    static public String getHelpIndex() {
     561    String help_index = HELP_DIR + Gatherer.config.getLanguage() + File.separator + StaticStrings.HELP_INDEX_FILENAME;
     562    File help_index_file = new File(help_index);
     563    // If that file can't be found, default to english
     564    if(!help_index_file.exists()) {
     565        help_index = HELP_DIR + StaticStrings.ENGLISH_LANGUAGE_STR  + File.separator + StaticStrings.HELP_INDEX_FILENAME;
     566    }
     567    return help_index;
     568    }
     569
     570
    549571    /** Method to retrieve an image icon with the given filename found in classpath or the resouces directory.
    550572     *  @return The specified <strong>ImageIcon</strong>, or an error image replacement if no such images exists.
Note: See TracChangeset for help on using the changeset viewer.