Changeset 9005


Ignore:
Timestamp:
2005-02-10T16:47:46+13:00 (19 years ago)
Author:
kjdon
Message:

added insertIntoOrderedList and createParameterDescription2 (takes arraylist instead of string[]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r8961 r9005  
    1313import java.util.Vector;
    1414import java.util.Iterator;
     15import java.util.ArrayList;
     16
    1517//import java.util.Locale;
    1618
     
    106108    public static final String NODE_NAME_ATT = "nodeName";
    107109    public static final String NODE_TYPE_ATT = "nodeType";
    108 
     110    public static final String NODE_RANK_ATT = "rank";
    109111    public static final String NODE_TYPE_ROOT = "root";
    110112    public static final String NODE_TYPE_INTERNAL = "internal";
     
    514516    return p;
    515517    }
     518    public static Element createParameterDescription2(Document owner,
     519                             String id,
     520                             String display_name,
     521                             String type,
     522                             String default_value,
     523                             ArrayList option_ids,
     524                             ArrayList option_names) {
     525
     526   
     527    Element p = owner.createElement(PARAM_ELEM);
     528    p.setAttribute(NAME_ATT, id);
     529    p.setAttribute(TYPE_ATT, type);
     530    p.appendChild(createDisplayTextElement(owner, GSXML.DISPLAY_TEXT_NAME, display_name));
     531    if (default_value != null) {
     532        p.setAttribute(DEFAULT_ATT, default_value);
     533    }
     534    if (option_ids!=null && option_names!=null) {
     535        for (int i=0; i<option_ids.size(); i++) {
     536        Element e = owner.createElement(PARAM_OPTION_ELEM);
     537        e.setAttribute(NAME_ATT, (String)option_ids.get(i));
     538        e.appendChild(createDisplayTextElement(owner, GSXML.DISPLAY_TEXT_NAME, (String)option_names.get(i)));
     539        p.appendChild(e);
     540        }
     541    }
     542    return p;
     543    }
    516544
    517545
     
    535563    }
    536564
    537    
     565    public static int SORT_TYPE_STRING = 0;
     566    public static int SORT_TYPE_INT = 1;
     567    public static int SORT_TYPE_FLOAT = 2;
     568   
     569    // sort type:
     570    public static Element insertIntoOrderedList(Element parent_node,
     571                        String node_name,
     572                        Element start_from_elem,
     573                        Element new_elem, String sort_att,
     574                        boolean descending)
     575    {
     576    if (new_elem == null) return null;
     577    System.err.println("+");
     578    Element cloned_elem = (Element)parent_node.getOwnerDocument().importNode(new_elem, true);
     579    if (start_from_elem == null) {
     580        parent_node.appendChild(cloned_elem);
     581        return cloned_elem;
     582    }
     583    System.err.println("++");
     584   
     585    Node current_node = start_from_elem;
     586    String insert_att = cloned_elem.getAttribute(sort_att);
     587    String list_att = start_from_elem.getAttribute(sort_att);
     588    while ((!descending && list_att.compareTo(insert_att)<0) || (descending && list_att.compareTo(insert_att)>0)) {
     589        System.err.println("+++");
     590        current_node = current_node.getNextSibling();
     591        if (current_node == null) break; // end of the list
     592        if (!current_node.getNodeName().equals(node_name)) {
     593        continue; // not a valid node
     594        }
     595        list_att = ((Element)current_node).getAttribute(sort_att);
     596    }
     597    System.err.println("++++");
     598
     599    parent_node.insertBefore(cloned_elem, current_node);
     600    return cloned_elem;
     601    }
     602
    538603
    539604    /** Returns the appropriate language element from a display elem,
     
    542607     lang if neither lang is found, will return the first one it finds*/
    543608    public static String getDisplayText(Element display, String name,
    544                        String lang, String lang_default) {
     609                    String lang, String lang_default) {
    545610   
    546611    String def = null;
Note: See TracChangeset for help on using the changeset viewer.