Java ListIterator Usage parsePath(String sPath)

Here you can find the source of parsePath(String sPath)

Description

Parses the XPath expression in a string array containing the XPath elements.

License

Apache License

Parameter

Parameter Description
sPath Path to be parsed.

Exception

Parameter Description
IllegalArgumentException Thrown if the parsing failed.

Return

The XPath expression in a string array.

Declaration

public static String[] parsePath(String sPath) throws IllegalArgumentException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class Main {
    /**/*from   w  ww.jav a 2s .c  om*/
     * Parses the XPath expression in a string array containing the XPath elements. The expressiong must be a simple /a/b/c for
     * and it cannot contain any wild-cards or attributes.
     * 
     * @param sPath Path to be parsed.
     * @return The XPath expression in a string array.
     * @throws IllegalArgumentException Thrown if the parsing failed.
     */
    public static String[] parsePath(String sPath) throws IllegalArgumentException {
        if (sPath.indexOf("//") >= 0) {
            throw new IllegalArgumentException("Destination path cannot have wild-cards.");
        }

        List<String> lElemList = new LinkedList<String>(Arrays.asList(sPath.split("/")));

        for (ListIterator<String> iIter = lElemList.listIterator(); iIter.hasNext();) {
            String sElem = iIter.next();

            if (sElem.equals(".")) {
                throw new IllegalArgumentException("Destination path cannot have wild-cards.");
            }

            int iIndex = sElem.indexOf("@");

            if (iIndex >= 0) {
                sElem = ((iIndex > 0) ? sElem.substring(0, iIndex) : "");
            }

            if (sElem.length() == 0) {
                iIter.remove();
            }
        }

        return lElemList.toArray(new String[lElemList.size()]);
    }
}

Related

  1. listToStringArray(java.util.List list)
  2. makeSortFieldFallbackExpr(List fieldNames)
  3. normalizeVersion(String version, int length)
  4. numberToDigits(int num)
  5. overlap(List> lists, int before, int after)
  6. partialSort(List list, int numTop, Comparator c)
  7. peekNext(ListIterator it)
  8. peekNext(ListIterator iterator)
  9. print(final List concatenatables)