Example usage for java.util StringTokenizer hasMoreTokens

List of usage examples for java.util StringTokenizer hasMoreTokens

Introduction

In this page you can find the example usage for java.util StringTokenizer hasMoreTokens.

Prototype

public boolean hasMoreTokens() 

Source Link

Document

Tests if there are more tokens available from this tokenizer's string.

Usage

From source file:com.adito.input.tags.VariablesTag.java

/**
 * Method to generate the Replacement Variable Chooser Fragment.
 * /* ww  w  .j a  v a  2s.com*/
 * @param titleKey
 * @param pageContext
 * @param bundle
 * @param locale
 * @param inputId
 * @param variables
 * @param includeSession
 * @param includeUserAttributes
 * @param includeRequest
 * @return String
 * @throws JspException
 */
public static String generateReplacementVariableChooserFragment(String titleKey, PageContext pageContext,
        String bundle, String locale, String inputId, String variables, boolean includeSession,
        boolean includeUserAttributes, boolean includeRequest) throws JspException {
    StringBuffer buf = new StringBuffer();

    String title = null;
    if (titleKey != null) {
        title = TagUtils.getInstance().message(pageContext, bundle, locale, titleKey, new String[] {});
    }
    if (title == null) {
        title = TagUtils.getInstance().message(pageContext, bundle, locale, "replacementVariablesChooser.title",
                new String[] {});
        if (title == null) {
            title = "Replacement Variables";
        }
    }
    buf.append("<div class=\"component_replacementVariablesToggle\">");

    // buf.append("<input type=\"button\"
    // onclick=\"toggleAndPositionBelow(document.getElementById('replacementVariablesChooser");
    // buf.append(inputId);
    // buf.append("'), document.getElementById('");
    // buf.append(inputId);
    // buf.append("'))\" ");
    // buf.append("value=\"${}\"/>");

    buf.append("<img onclick=\"togglePopupBelowLeft(document.getElementById('replacementVariablesChooser");
    buf.append(inputId);
    buf.append("'), document.getElementById('");
    buf.append(inputId);
    buf.append("'))\" ");
    buf.append("src=\"");
    buf.append(CoreUtil.getThemePath(pageContext.getSession()));
    buf.append("/images/variables.gif\"/>");

    buf.append("</div>");
    buf.append("<div id=\"replacementVariablesChooser");
    buf.append(inputId);
    buf.append("\" style=\"position:absolute;display: none;overflow:visible;top:4px;left:4px;z-index:900;\">");
    buf.append("<div class=\"replacementVariablesMain\">");
    buf.append("<div class=\"replacementVariablesTitleBar\">");
    buf.append("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
    buf.append("<tr><td class=\"title\">");
    buf.append(title);
    buf.append("</td><td class=\"close\"><img src=\"");
    buf.append(CoreUtil.getThemePath(pageContext.getSession()));
    buf.append("/images/actions/erase.gif\" ");
    buf.append("onclick=\"document.getElementById('");
    buf.append(inputId);
    buf.append("').value = ''\"/><img src=\"");
    buf.append(CoreUtil.getThemePath(pageContext.getSession()));
    buf.append("/images/actions/closeReplacementVariables.gif\" ");
    buf.append("onclick=\"togglePopup(document.getElementById('replacementVariablesChooser");
    buf.append(inputId);
    buf.append("'))\"/>");
    buf.append("</td></tr></table></div><div class=\"replacementVariablesContent\">");
    buf.append("<ul>");
    if (variables != null) {
        StringTokenizer t = new StringTokenizer(variables, ",");
        while (t.hasMoreTokens()) {
            String n = t.nextToken();
            addVariable(n, n, buf, pageContext, bundle, locale, inputId);
        }
    }
    if (includeSession) {
        addVariable("session:username", null, buf, pageContext, bundle, locale, inputId);
        addVariable("session:password", null, buf, pageContext, bundle, locale, inputId);
        addVariable("session:email", null, buf, pageContext, bundle, locale, inputId);
        addVariable("session:fullname", null, buf, pageContext, bundle, locale, inputId);
        addVariable("session:clientProxyURL", null, buf, pageContext, bundle, locale, inputId);
        addVariable("session:clientReverseProxyURL", null, buf, pageContext, bundle, locale, inputId);
    }

    if (includeRequest) {
        addVariable("request:serverName", null, buf, pageContext, bundle, locale, inputId);
        addVariable("request:serverPort", null, buf, pageContext, bundle, locale, inputId);
        addVariable("request:userAgent", null, buf, pageContext, bundle, locale, inputId);
    }

    if (includeUserAttributes) {
        Collection<PropertyDefinition> l;
        try {
            for (PropertyClass propertyClass : PropertyClassManager.getInstance().getPropertyClasses()) {
                if (propertyClass instanceof AttributesPropertyClass
                        && !propertyClass.getName().equals(ResourceAttributes.NAME)) {
                    l = propertyClass.getDefinitions();
                    for (PropertyDefinition d : l) {
                        AttributeDefinition def = (AttributeDefinition) d;
                        if (def.isReplaceable()) {
                            addVariable(def.getPropertyClass().getName() + ":" + def.getName(),
                                    def.getDescription(), buf, pageContext, bundle, locale, inputId);
                        }
                    }
                }
            }
        } catch (Exception e) {
            log.error("Failed to get user attribute definitions.");
        }
    }
    buf.append("</ul>");
    buf.append("</div>");
    buf.append("</div>");
    return buf.toString();
}

From source file:com.persistent.cloudninja.controller.AuthFilterUtils.java

/**
 * /*  w  w w  . j a  va 2 s  .  co  m*/
 * @param fieldName
 * @param cookieValue
 * @return
 */
public static String getFieldValueFromCookieString(String fieldName, String cookieValue) {
    String retVal = null;
    String fieldNameAndSeparatorString = fieldName + CloudNinjaConstants.COOKIE_FIELD_AND_VALUE_SEPARATOR;
    StringTokenizer tokenizer = new StringTokenizer(cookieValue, CloudNinjaConstants.COOKIE_FIELDS_SEPARATOR);
    while (tokenizer.hasMoreTokens()) {
        String nextToken = tokenizer.nextToken();
        if (nextToken.startsWith(fieldNameAndSeparatorString)) {
            retVal = nextToken.substring(fieldNameAndSeparatorString.length());
        }
    }
    return retVal;
}

From source file:com.concursive.connect.web.webdav.WebdavManager.java

protected static HashMap getAuthenticationParams(String argHeader) {
    HashMap params = new HashMap();
    StringTokenizer st = new StringTokenizer(argHeader, ",");
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if (token.startsWith("Digest")) {
            token = token.substring("Digest".length());
        }// w  ww  . j a v  a 2 s.  c o  m
        if (token.contains("=") && token.contains("\"")) {
            String param = token.substring(0, token.indexOf("=")).trim();
            String value = token.substring(token.indexOf("\"") + 1, token.lastIndexOf("\""));
            params.put(param, value);
        }
    }
    return params;
}

From source file:fit.Fixture.java

public static String camel(String name) {
    StringBuilder b = new StringBuilder(name.length());
    StringTokenizer t = new StringTokenizer(name);
    b.append(t.nextToken());//from w w w.ja v  a2s.  c  o m
    while (t.hasMoreTokens()) {
        String token = t.nextToken();
        b.append(token.substring(0, 1).toUpperCase()); // replace spaces with
        // camelCase
        b.append(token.substring(1));
    }
    return b.toString();
}

From source file:com.adaptris.core.http.jetty.HttpsConnection.java

private static String[] asArray(String s) {
    if (s == null) {
        return new String[0];
    }//www.  j  a v a  2s . c  o  m
    StringTokenizer st = new StringTokenizer(s, ",");
    List<String> l = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        String tok = st.nextToken().trim();
        if (!isEmpty(tok))
            l.add(tok);
    }
    return l.toArray(new String[0]);
}

From source file:com.adsapient.shared.service.TimeService.java

public static final long parseDateDDMMYYYY(String str, boolean checkPast) throws IncorrectDateException {
    int year;/*from   w w  w  .ja  v  a2 s .c  o  m*/
    int month;
    int day;

    if (StringUtils.isEmpty(str)) {
        throw new IncorrectDateException("Date string is empty.");
    }

    StringTokenizer st = new StringTokenizer(str, ".");

    if (!st.hasMoreTokens()) {
        throw new IncorrectDateException("Day was not specified.");
    }

    String tempEl = st.nextToken();

    try {
        day = Integer.parseInt(tempEl);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Day parameter should be numeric.");
    }

    if ((day < MIN_DAY_VALUE) || (day > MAX_DAY_VALUE)) {
        throw new IncorrectDateException("Incorrect ranges for day (day should be >= " + MIN_DAY_VALUE
                + " and <= " + MAX_DAY_VALUE + ")");
    }

    if (!st.hasMoreTokens()) {
        throw new IncorrectDateException("Month was not specified.");
    }

    tempEl = st.nextToken();

    try {
        month = Integer.parseInt(tempEl);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Month parameter should be numeric.");
    }

    if ((month < MIN_MONTH_VALUE) || (month > MAX_MONTH_VALUE)) {
        throw new IncorrectDateException("Incorrect ranges for month (month should be >= " + MIN_MONTH_VALUE
                + " and <= " + MAX_MONTH_VALUE + ")");
    }

    if (!st.hasMoreTokens()) {
        throw new IncorrectDateException("Year was not specified.");
    }

    tempEl = st.nextToken();

    try {
        year = Integer.parseInt(tempEl);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Year parameter should be numeric.");
    }

    if ((year < MIN_YEAR_VALUE) || (year > MAX_YEAR_VALUE)) {
        throw new IncorrectDateException("Incorrect ranges for year (year should be >= " + MIN_YEAR_VALUE
                + " and <= " + MAX_YEAR_VALUE + ")");
    }

    Calendar cal = Calendar.getInstance();

    if (checkPast) {
        if (year < cal.get(Calendar.YEAR)) {
            throw new IncorrectDateException("Date should not refer to the past.");
        } else if (year == cal.get(Calendar.YEAR)) {
            if (month < (cal.get(Calendar.MONTH) + 1)) {
                throw new IncorrectDateException("Date should not refer to the past.");
            } else if (month == (cal.get(Calendar.MONTH) + 1)) {
                if (day < cal.get(Calendar.DAY_OF_MONTH)) {
                    throw new IncorrectDateException("Date should not refer to the past.");
                }
            }
        }
    }

    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DAY_OF_MONTH, day);

    return cal.getTime().getTime();
}

From source file:com.adsapient.shared.service.TimeService.java

public static final long parseDateYYYYMMDD(String str, boolean checkPast) throws IncorrectDateException {
    int year;/*from   ww w  .  ja  v a  2 s . co  m*/
    int month;
    int day;

    if (StringUtils.isEmpty(str)) {
        throw new IncorrectDateException("Date string is empty.");
    }

    StringTokenizer st = new StringTokenizer(str, " -");

    if (!st.hasMoreTokens()) {
        throw new IncorrectDateException("Year was not specified.");
    }

    String tempEl = st.nextToken();

    try {
        year = Integer.parseInt(tempEl);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Year parameter should be numeric.");
    }

    if ((year < MIN_YEAR_VALUE) || (year > MAX_YEAR_VALUE)) {
        throw new IncorrectDateException("Incorrect ranges for year (year should be >= " + MIN_YEAR_VALUE
                + " and <= " + MAX_YEAR_VALUE + ")");
    }

    if (!st.hasMoreTokens()) {
        throw new IncorrectDateException("Month was not specified.");
    }

    tempEl = st.nextToken();

    try {
        month = Integer.parseInt(tempEl);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Month parameter should be numeric.");
    }

    if ((month < MIN_MONTH_VALUE) || (month > MAX_MONTH_VALUE)) {
        throw new IncorrectDateException("Incorrect ranges for month (month should be >= " + MIN_MONTH_VALUE
                + " and <= " + MAX_MONTH_VALUE + ")");
    }

    if (!st.hasMoreTokens()) {
        throw new IncorrectDateException("Day was not specified.");
    }

    tempEl = st.nextToken();

    try {
        day = Integer.parseInt(tempEl);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Day parameter should be numeric.");
    }

    if ((day < MIN_DAY_VALUE) || (day > MAX_DAY_VALUE)) {
        throw new IncorrectDateException("Incorrect ranges for day (day should be >= " + MIN_DAY_VALUE
                + " and <= " + MAX_DAY_VALUE + ")");
    }

    Calendar cal = Calendar.getInstance();

    if (checkPast) {
        if (year < cal.get(Calendar.YEAR)) {
            throw new IncorrectDateException("Date should not refer to the past.");
        } else if (year == cal.get(Calendar.YEAR)) {
            if (month < (cal.get(Calendar.MONTH) + 1)) {
                throw new IncorrectDateException("Date should not refer to the past.");
            } else if (month == (cal.get(Calendar.MONTH) + 1)) {
                if (day < cal.get(Calendar.DAY_OF_MONTH)) {
                    throw new IncorrectDateException("Date should not refer to the past.");
                }
            }
        }
    }

    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DAY_OF_MONTH, day);

    return cal.getTime().getTime();
}

From source file:com.netspective.sparx.panel.editor.ReportPanelEditorContentElement.java

public static String getPkValueFromState(PanelEditorState state) {
    if (state.getActiveElementInfo() != null) {
        StringTokenizer st = new StringTokenizer(state.getActiveElementInfo());
        if (st.hasMoreTokens())
            return st.nextToken();
    }//from  w w  w.  ja  v  a2 s .c o  m
    return null;
}

From source file:com.concursive.connect.web.modules.search.utils.SearchUtils.java

/**
 * Description of the Method/*from   w  w w .  j a v  a2 s  . c om*/
 *
 * @param searchText Description of the Parameter
 * @return Description of the Return Value
 */
public static ArrayList<String> parseSearchTerms(String searchText) {
    ArrayList<String> terms = new ArrayList<String>();
    StringBuffer sb = new StringBuffer();
    boolean returnTokens = true;
    String currentDelims = WHITESPACE_AND_QUOTES;
    StringTokenizer parser = new StringTokenizer(searchText, currentDelims, returnTokens);
    String token = null;
    while (parser.hasMoreTokens()) {
        token = parser.nextToken(currentDelims);
        if (!isDoubleQuote(token)) {
            if (hasText(token)) {
                String gotToken = token.trim().toLowerCase();
                if ("and".equals(gotToken) || "or".equals(gotToken) || "not".equals(gotToken)) {
                } else {
                    if (sb.length() > 0) {
                        sb.append(" ");
                    }
                    sb.append(gotToken);
                    terms.add(sb.toString());
                    sb.setLength(0);
                }
            }
        } else {
            currentDelims = flipDelimiters(currentDelims);
        }
    }
    return terms;
}

From source file:com.cisco.dvbu.ps.common.scriptutil.ScriptUtil.java

/**
 * Create a command file for UNIX or Windows from name value pairs strings constructed based on passed in xml content
 * @param xmlFilePath xml File Path//from  w  ww. j a  va2 s  . co m
 * @param nodeName String return name values for passed in node name and node value. * is treated as all nodes
 * @param nodeValue String return name values for passed in node name and node value. * is treated as all node values
 * @param options additional options to return the node name or attributes such as "-noid -noattributes"
 * @param commandOutputFile The fully qualifed path of the command output file
 * @param commandHeader The command file header such as #!/bin/bash
 * @param commandType The type of command file [UNIX|WINDOWS] {use export for UNIX, use set for WINDOWS)
 *           UNIX: export name="value"
 *        WINDOWS: set name=value
 * usage createCommandFileFromXML xmlFilePath * * "-noid -noattributes" /Users/rthummal/mywork/clients/ps/CisDeployTool/resources/abc.sh #!/bin/bash UNIX
 * usage createCommandFileFromXML xmlFilePath hostname localhost "" C:\opt\pdtool/abc.bat "echo off"    WINDOWS
 * usage createCommandFileFromXML xmlFilePath hostname * "-noid" /opt/pdtool/abc.sh #!/bin/bash UNIX
 */
public static void createCommandFileFromXML(String xmlFilePath, String nodeName, String nodeValue,
        String options, String commandOutputFile, String commandHeader, String commandType) {
    boolean win = false;
    String cmdPrefix = "export ";
    if (commandType != null && commandType.equals("WINDOWS")) {
        win = true;
        cmdPrefix = "set ";
    }

    String nameValuePairs = XMLUtils.getNameValuePairsFromXML(xmlFilePath, null, null, nodeName, nodeValue,
            options);
    if (nameValuePairs != null) {
        StringBuffer sb = new StringBuffer();
        sb.append(commandHeader + "\n");
        StringTokenizer st = new StringTokenizer(nameValuePairs, "|");
        while (st.hasMoreTokens()) {
            sb.append(cmdPrefix);

            String nameValuePair = st.nextToken();

            if (!win) {
                nameValuePair = nameValuePair.replace("=", "=\"");
                nameValuePair += "\"";
            }
            sb.append(nameValuePair + "\n");
        }

        try {
            Writer out = new OutputStreamWriter(new FileOutputStream(commandOutputFile));
            out.write(sb.toString());
            out.flush();
        } catch (FileNotFoundException e) {
            logger.error("Could not wirte to command file " + commandOutputFile, e);
            throw new ValidationException(e.getMessage(), e);

        } catch (IOException e) {
            logger.error("Could not wirte to command file " + commandOutputFile, e);
            throw new ValidationException(e.getMessage(), e);
        }

    }

}