Java XML Element to String getStringOptionsList(final Element configuration, final String optionPrefix, final String option)

Here you can find the source of getStringOptionsList(final Element configuration, final String optionPrefix, final String option)

Description

get String Options List

License

Open Source License

Declaration

public static String[] getStringOptionsList(final Element configuration, final String optionPrefix,
            final String option) 

Method Source Code


//package com.java2s;
/*//from   ww w.  j a v  a2s .co m
 * Copyright 2001-2008 Aqris Software AS. All rights reserved.
 * 
 * This program is dual-licensed under both the Common Development
 * and Distribution License ("CDDL") and the GNU General Public
 * License ("GPL"). You may elect to use one or the other of these
 * licenses.
 */

import org.w3c.dom.Element;
import java.util.Arrays;

public class Main {
    public static String[] getStringOptionsList(final Element configuration, final String optionPrefix,
            final String option) {
        String[] optionsList = new String[0];

        Element optionsElement = null;
        try {
            optionsElement = (Element) configuration.getElementsByTagName(optionPrefix).item(0);
        } catch (NullPointerException e) {
            return optionsList;
        }

        String[] skiped = null;
        try {
            skiped = optionsElement.getAttribute(option).split(";");
        } catch (NullPointerException e) {
        }

        int badValues = 0;
        if (skiped != null) {
            for (int i = 0; i < skiped.length; i++) {
                if (skiped[i].trim().length() == 0) {
                    skiped[i] = null;
                    badValues++;
                }
            }

            optionsList = new String[skiped.length - badValues];
            for (int i = 0, j = 0; i < skiped.length; i++) {
                if (skiped[i] != null) {
                    optionsList[j++] = skiped[i];
                }
            }
        }

        Arrays.sort(optionsList);

        return optionsList;
    }
}

Related

  1. getString(Element root, String name)
  2. getString(Element xmlElement)
  3. getString(final Element element)
  4. getStringByTagName(Element element, String tag)
  5. getStringFromParagraphElement(Element element)
  6. getStringProperty(Element properties, String name)
  7. getStringRepresentation(Element element)
  8. getStringValue(Element el)
  9. getStringValue(Element ele, String tagName)