opendap/src/main/java/opendap/dap/DDS.java
public static Vector tokenizeAliasField(String field) throws MalformedAliasException
    {

        boolean Debug = false;

        // find the index of the last element in the field.
        int lastIndex = field.length() - 1;

        // make a place to put the tokens.
        Vector tokens = new Vector();

        //Coverity[DEADCODE]
        if (Debug) {
		DAPNode.log.debug("lastIndexOf(dot): " + field.lastIndexOf(dot) + "   lastIndex: " + lastIndex);
	    }

        // Does this thing start with a quote?
        if (field.charAt(0) == quote) {
            // find the closing quote.
            // Because this token starts with a quote, it must be normalized
            // (see method description). The closing quote must exist,
            // and it cannont be escaped.

            // The first character in the token is the one following the
            // leadin quote.
            int start = 1;

            // prepare to search for a closing quote.
            int end = -1;
            boolean done = false;
            boolean escaped = false;

            // search for the quote

            for (int i = 1; i <= lastIndex || !done; i++) {
                char c = field.charAt(i);
                //LogStream.out.println("Checking for clear quote on char: "+c+" escaped="+escaped+"  done="+done);

                // Was this character escaped (with a slash)?
                if (escaped) {
                    // then ignore it and unset the escaped flag
                    // since the escape has been consumed.
                    escaped = false;
                } else {
                    // otherwise, is it an escape (slash) character
                    if (c == slash) {
                        // the set the escaoed flag to true.
                        escaped = true;
                    } else if (c == quote) {  // if it's not an escape (slash) then is it a quote?

                        //LogStream.out.println("Found quote!");

                        end = i;
                        done = true;
                    }

                }
            }

            //LogStream.out.println("start="+start+"  end="+end+"  lastIndex="+lastIndex);

            // if the end is less than 0 then it didn't get set
            // during the search for the quote, and thus the closing quote wasn't
            // found. Throw an exception!
            if (end < 0)
                throw new MalformedAliasException("Alias fields that begin with the quote (\") sign " +
                        "must have a closing quote.");

            // If there is more stuff, and that stuff is not seperated from the
            // closing quote by a dot character, then it's bad syntax.
            if (lastIndex > end && field.charAt(end + 1) != dot)
                throw new MalformedAliasException("Alias fields must be seperated by the dot (.) character.");

            // The last caharcter in the field may not be an (unquoted) dot.
            if (field.charAt(lastIndex) == dot)
                throw new MalformedAliasException("Alias fields may not end with the dot (.) character.");

            // Looks like we found a complete token.
            // Get it.
            String firstToken = field.substring(start, end);

            // Add it to the tokens Vector.
            tokens.add(firstToken);

            // if there is more stuff, then tokenize it.
            if (end < lastIndex) {

                // get the rest of the stuff
                String theRest = field.substring(end + 2);

                // tokenize it and add each of the returned tokens to
                // this tokens Vector.
                // Recursive call.
                Enumeration tkns = tokenizeAliasField(theRest).elements();
                while (tkns.hasMoreElements())
                    tokens.add(tkns.nextElement());
            }

            return (tokens);


        }

        // Find the first dot. This simplistic search is appropriate because
        // if this field contained a dot as part of it's name it should have
        // been encased in quotes and handled by the previous logic.

        int firstDot = field.indexOf(dot);

        if (firstDot == 0) { // Does this thing start with dot?

            // Then it must be an absolute path.
            // NOTE: This should be true ONLY for the first token
            // in the list. By that I mean that a leading dot in
            // the field string should only occur when the
            // variable or alias field begins a dot. A secondary
            // token may only start with a dot if the dot is
            // actually part of the field, and thus it should be
            // encased in quotes.
            String thisToken = ".";
            tokens.add(thisToken);
            // Check to see if there are more characters in the field to be tokenized.
            // If there are, tokenize them.
            if (lastIndex > 0) {
                String theRest = field.substring(1);
                // Recursive call
                Enumeration tkns = tokenizeAliasField(theRest).elements();

                // Take the tokens from the rest of the fields and
                // add them to this token vector.
                while (tkns.hasMoreElements())
                    tokens.add(tkns.nextElement());
            }
            return (tokens);
        }


        if (firstDot > 0) {
            // A secondary token may only contain a dot if the dot is
            // actually part of the field, and thus the field should have been
            // encased in quotes. Since we already check for a leading quote,
            // the first dor MUST be the end of the token.
            String firstToken = field.substring(0, firstDot);
            tokens.add(firstToken);

            // A quick syntax check.
            if (lastIndex == firstDot)
                throw new MalformedAliasException("Alias fields may not end with the dot (.) character.");

            // Get the rest of the field string
            String theRest = field.substring(firstDot + 1);

            // tokenize it, and add it's tokens to this token Vector.
            Enumeration tkns = tokenizeAliasField(theRest).elements();
            while (tkns.hasMoreElements())
                tokens.add(tkns.nextElement());

            return (tokens);

        }

        // This field string might be the final token, if we
        // get here it must be so add it to the tokens vector
        tokens.add(field);

        return (tokens);


    }
public static Vector tokenizeAliasField(String field) throws MalformedAliasException
    {

        boolean Debug = false;

        // find the index of the last element in the field.
        int lastIndex = field.length() - 1;

        // make a place to put the tokens.
        Vector tokens = new Vector();

        //Coverity[DEADCODE]
        if (Debug) {
		DAPNode.log.debug("lastIndexOf(dot): " + field.lastIndexOf(dot) + "   lastIndex: " + lastIndex);
	    }

        // Does this thing start with a quote?
        if (field.charAt(0) == quote) {
            // find the closing quote.
            // Because this token starts with a quote, it must be normalized
            // (see method description). The closing quote must exist,
            // and it cannont be escaped.

            // The first character in the token is the one following the
            // leadin quote.
            int start = 1;

            // prepare to search for a closing quote.
            int end = -1;
            boolean done = false;
            boolean escaped = false;

            // search for the quote

            for (int i = 1; i <= lastIndex || !done; i++) {
                char c = field.charAt(i);
                //LogStream.out.println("Checking for clear quote on char: "+c+" escaped="+escaped+"  done="+done);

                // Was this character escaped (with a slash)?
                if (escaped) {
                    // then ignore it and unset the escaped flag
                    // since the escape has been consumed.
                    escaped = false;
                } else {
                    // otherwise, is it an escape (slash) character
                    if (c == slash) {
                        // the set the escaoed flag to true.
                        escaped = true;
                    } else if (c == quote) {  // if it's not an escape (slash) then is it a quote?

                        //LogStream.out.println("Found quote!");

                        end = i;
                        done = true;
                    }

                }
            }

            //LogStream.out.println("start="+start+"  end="+end+"  lastIndex="+lastIndex);

            // if the end is less than 0 then it didn't get set
            // during the search for the quote, and thus the closing quote wasn't
            // found. Throw an exception!
            if (end < 0)
                throw new MalformedAliasException("Alias fields that begin with the quote (\") sign " +
                        "must have a closing quote.");

            // If there is more stuff, and that stuff is not seperated from the
            // closing quote by a dot character, then it's bad syntax.
            if (lastIndex > end && field.charAt(end + 1) != dot)
                throw new MalformedAliasException("Alias fields must be seperated by the dot (.) character.");

            // The last caharcter in the field may not be an (unquoted) dot.
            if (field.charAt(lastIndex) == dot)
                throw new MalformedAliasException("Alias fields may not end with the dot (.) character.");

            // Looks like we found a complete token.
            // Get it.
            String firstToken = field.substring(start, end);

            // Add it to the tokens Vector.
            tokens.add(firstToken);

            // if there is more stuff, then tokenize it.
            if (end < lastIndex) {

                // get the rest of the stuff
                String theRest = field.substring(end + 2);

                // tokenize it and add each of the returned tokens to
                // this tokens Vector.
                // Recursive call.
                Enumeration tkns = tokenizeAliasField(theRest).elements();
                while (tkns.hasMoreElements())
                    tokens.add(tkns.nextElement());
            }

            return (tokens);


        }

        // Find the first dot. This simplistic search is appropriate because
        // if this field contained a dot as part of it's name it should have
        // been encased in quotes and handled by the previous logic.

        int firstDot = field.indexOf(dot);

        if (firstDot == 0) { // Does this thing start with dot?

            // Then it must be an absolute path.
            // NOTE: This should be true ONLY for the first token
            // in the list. By that I mean that a leading dot in
            // the field string should only occur when the
            // variable or alias field begins a dot. A secondary
            // token may only start with a dot if the dot is
            // actually part of the field, and thus it should be
            // encased in quotes.
            String thisToken = ".";
            tokens.add(thisToken);
            // Check to see if there are more characters in the field to be tokenized.
            // If there are, tokenize them.
            if (lastIndex > 0) {
                String theRest = field.substring(1);
                // Recursive call
                Enumeration tkns = tokenizeAliasField(theRest).elements();

                // Take the tokens from the rest of the fields and
                // add them to this token vector.
                while (tkns.hasMoreElements())
                    tokens.add(tkns.nextElement());
            }
            return (tokens);
        }


        if (firstDot > 0) {
            // A secondary token may only contain a dot if the dot is
            // actually part of the field, and thus the field should have been
            // encased in quotes. Since we already check for a leading quote,
            // the first dor MUST be the end of the token.
            String firstToken = field.substring(0, firstDot);
            tokens.add(firstToken);

            // A quick syntax check.
            if (lastIndex == firstDot)
                throw new MalformedAliasException("Alias fields may not end with the dot (.) character.");

            // Get the rest of the field string
            String theRest = field.substring(firstDot + 1);

            // tokenize it, and add it's tokens to this token Vector.
            Enumeration tkns = tokenizeAliasField(theRest).elements();
            while (tkns.hasMoreElements())
                tokens.add(tkns.nextElement());

            return (tokens);

        }

        // This field string might be the final token, if we
        // get here it must be so add it to the tokens vector
        tokens.add(field);

        return (tokens);


    }
public static Vector tokenizeAliasField ( String field ) throws MalformedAliasException { boolean Debug = false ; // find the index of the last element in the field. int lastIndex = field . length ( ) - 1 ; // make a place to put the tokens. Vector tokens = new Vector ( ) ; //Coverity[DEADCODE] if ( Debug ) { DAPNode . log . debug ( "lastIndexOf(dot): " + field . lastIndexOf ( dot ) + "   lastIndex: " + lastIndex ) ; } // Does this thing start with a quote? if ( field . charAt ( 0 ) == quote ) { // find the closing quote. // Because this token starts with a quote, it must be normalized // (see method description). The closing quote must exist, // and it cannont be escaped. // The first character in the token is the one following the // leadin quote. int start = 1 ; // prepare to search for a closing quote. int end = - 1 ; boolean done = false ; boolean escaped = false ; // search for the quote for ( int i = 1 ; i <= lastIndex || ! done ; i ++ ) { char c = field . charAt ( i ) ; //LogStream.out.println("Checking for clear quote on char: "+c+" escaped="+escaped+"  done="+done); // Was this character escaped (with a slash)? if ( escaped ) { // then ignore it and unset the escaped flag // since the escape has been consumed. escaped = false ; } else { // otherwise, is it an escape (slash) character if ( c == slash ) { // the set the escaoed flag to true. escaped = true ; } else if ( c == quote ) { // if it's not an escape (slash) then is it a quote? //LogStream.out.println("Found quote!"); end = i ; done = true ; } } } //LogStream.out.println("start="+start+"  end="+end+"  lastIndex="+lastIndex); // if the end is less than 0 then it didn't get set // during the search for the quote, and thus the closing quote wasn't // found. Throw an exception! if ( end < 0 ) throw new MalformedAliasException ( "Alias fields that begin with the quote (\") sign " + "must have a closing quote." ) ; // If there is more stuff, and that stuff is not seperated from the // closing quote by a dot character, then it's bad syntax. if ( lastIndex > end && field . charAt ( end + 1 ) != dot ) throw new MalformedAliasException ( "Alias fields must be seperated by the dot (.) character." ) ; // The last caharcter in the field may not be an (unquoted) dot. if ( field . charAt ( lastIndex ) == dot ) throw new MalformedAliasException ( "Alias fields may not end with the dot (.) character." ) ; // Looks like we found a complete token. // Get it. String firstToken = field . substring ( start , end ) ; // Add it to the tokens Vector. tokens . add ( firstToken ) ; // if there is more stuff, then tokenize it. if ( end < lastIndex ) { // get the rest of the stuff String theRest = field . substring ( end + 2 ) ; // tokenize it and add each of the returned tokens to // this tokens Vector. // Recursive call. Enumeration tkns = tokenizeAliasField ( theRest ) . elements ( ) ; while ( tkns . hasMoreElements ( ) ) tokens . add ( tkns . nextElement ( ) ) ; } return ( tokens ) ; } // Find the first dot. This simplistic search is appropriate because // if this field contained a dot as part of it's name it should have // been encased in quotes and handled by the previous logic. int firstDot = field . indexOf ( dot ) ; if ( firstDot == 0 ) { // Does this thing start with dot? // Then it must be an absolute path. // NOTE: This should be true ONLY for the first token // in the list. By that I mean that a leading dot in // the field string should only occur when the // variable or alias field begins a dot. A secondary // token may only start with a dot if the dot is // actually part of the field, and thus it should be // encased in quotes. String thisToken = "." ; tokens . add ( thisToken ) ; // Check to see if there are more characters in the field to be tokenized. // If there are, tokenize them. if ( lastIndex > 0 ) { String theRest = field . substring ( 1 ) ; // Recursive call Enumeration tkns = tokenizeAliasField ( theRest ) . elements ( ) ; // Take the tokens from the rest of the fields and // add them to this token vector. while ( tkns . hasMoreElements ( ) ) tokens . add ( tkns . nextElement ( ) ) ; } return ( tokens ) ; } if ( firstDot > 0 ) { // A secondary token may only contain a dot if the dot is // actually part of the field, and thus the field should have been // encased in quotes. Since we already check for a leading quote, // the first dor MUST be the end of the token. String firstToken = field . substring ( 0 , firstDot ) ; tokens . add ( firstToken ) ; // A quick syntax check. if ( lastIndex == firstDot ) throw new MalformedAliasException ( "Alias fields may not end with the dot (.) character." ) ; // Get the rest of the field string String theRest = field . substring ( firstDot + 1 ) ; // tokenize it, and add it's tokens to this token Vector. Enumeration tkns = tokenizeAliasField ( theRest ) . elements ( ) ; while ( tkns . hasMoreElements ( ) ) tokens . add ( tkns . nextElement ( ) ) ; return ( tokens ) ; } // This field string might be the final token, if we // get here it must be so add it to the tokens vector tokens . add ( field ) ; return ( tokens ) ; }
The <code>tokenizeAliasFiled()</code> method is used to tokenize
the <b>variable</b> and the <b>attribute</b> fields in the alias
declaration. It is required that these fields be <b>normalized</b>
in the XML instance document. The rules for this normalization
are as follows:
<ul>
<p/>
<li> The &quot; (double quote) and the \ (backslash, aka escape)
characters MUST be escaped (using the \ character) in the <b>variable</b>
and <b>attribute</b> fields.</li>
<p/>
<li> The <b>variable</b> and <b>attribute</b> fields must be enclosed
in double quotes if their values contain the dot (.) character.</li>
<p/>
<li> Fully qualified <b>variable</b> and <b>attribute</b> names always
begin with the dot (.) character.</li>
</ul>

@param field The string to be tokenized.
@return The tokenized string.
@throws MalformedAliasException
The <code > tokenizeAliasFiled () < / code > method is used to tokenize the <b > variable< / b > and the <b > attribute< / b > fields in the alias declaration . It is required that these fields be <b > normalized< / b > in the XML instance document . The rules for this normalization are as follows : <ul > <p / > <li > The &quot ; ( double quote ) and the \ ( backslash aka escape ) characters MUST be escaped ( using the \ character ) in the <b > variable< / b > and <b > attribute< / b > fields . < / li > <p / > <li > The <b > variable< / b > and <b > attribute< / b > fields must be enclosed in double quotes if their values contain the dot ( . ) character . < / li > <p / > <li > Fully qualified <b > variable< / b > and <b > attribute< / b > names always begin with the dot ( . ) character . < / li > < / ul >