Example usage for java.util StringTokenizer nextElement

List of usage examples for java.util StringTokenizer nextElement

Introduction

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

Prototype

public Object nextElement() 

Source Link

Document

Returns the same value as the nextToken method, except that its declared return value is Object rather than String .

Usage

From source file:com.ckfinder.connector.utils.FileUtils.java

/**
 * creates file and all above folders that doesn"t exists.
 * @param file file to create./*from w w w  .ja  v  a2  s. c o m*/
 * @param conf connector configuration
 * @param isFile if it is path to folder.
 * @throws IOException when io error occurs.
 */
public static void createPath(final File file, final IConfiguration conf, final boolean isFile)
        throws IOException {
    String path = file.getAbsolutePath();
    // on Linux first path char - "/" is removed by StringTokenizer
    StringTokenizer st = new StringTokenizer(path, File.separator);

    // if path include "/" as a first char of path we have to add it manually
    String checkPath = (path.indexOf(File.separator) == 0) ? File.separator : "";
    checkPath += (String) st.nextElement();
    while (st.hasMoreElements()) {
        String string = (String) st.nextElement();
        checkPath = checkPath.concat(File.separator + string);
        if (!(string.equals(file.getName()) && isFile)) {
            File dir = new File(checkPath);
            if (!dir.exists()) {
                mkdir(dir, conf);
            }
        } else {
            file.createNewFile();
        }
    }
}

From source file:org.wso2.carbon.andes.event.core.internal.subscription.registry.TopicManagerServiceImpl.java

/**
 * Admin user and user who had add topic permission create the hierarchy topic get permission to all level by default
 *
 * @param userRealm User's Realm//from  www.j  a  va  2s.  c om
 * @param topicId topic id
 * @param role admin role
 * @throws UserStoreException
 */
private static void grantPermissionToHierarchyLevel(UserRealm userRealm, String topicId, String role)
        throws UserStoreException {
    //tokenize resource path
    StringTokenizer tokenizer = new StringTokenizer(topicId, "/");
    StringBuilder resourcePathBuilder = new StringBuilder();
    //get token count
    int tokenCount = tokenizer.countTokens();
    int count = 0;
    Pattern pattern = Pattern.compile(PARENT_RESOURCE_PATH);

    while (tokenizer.hasMoreElements()) {
        //get each element in topicId resource path
        String resource = tokenizer.nextElement().toString();
        //build resource path again
        resourcePathBuilder.append(resource);
        //we want to give permission to any resource after event/topics/ in build resource path
        Matcher matcher = pattern.matcher(resourcePathBuilder.toString());
        if (matcher.find()) {
            // gives subscribe permissions to the internal role in the user store
            userRealm.getAuthorizationManager().authorizeRole(role, resourcePathBuilder.toString(),
                    EventBrokerConstants.EB_PERMISSION_SUBSCRIBE);
            // gives publish permissions to the internal role in the user store
            userRealm.getAuthorizationManager().authorizeRole(role, resourcePathBuilder.toString(),
                    EventBrokerConstants.EB_PERMISSION_PUBLISH);
            // gives change permissions to the internal role in the user store
            userRealm.getAuthorizationManager().authorizeRole(role, resourcePathBuilder.toString(),
                    EventBrokerConstants.EB_PERMISSION_CHANGE_PERMISSION);
        }
        count++;
        if (count < tokenCount) {
            resourcePathBuilder.append("/");
        }

    }
}

From source file:com.bskyb.cg.environments.message.MessageHandler.java

private Map<String, String> getFields(String key) {
    Map<String, String> map = new HashMap<String, String>();
    StringTokenizer tk = new StringTokenizer(key, "_");
    String datestring = (String) tk.nextElement();
    map.put("date", datestring);
    String hostname = (String) tk.nextElement();
    map.put("hostname", hostname);
    String msgtype = (String) tk.nextElement();
    map.put("msgtype", msgtype);
    String uuid = (String) tk.nextElement();
    map.put("uuid", uuid);
    String epochtime = (String) tk.nextElement();
    map.put("epochtime", epochtime);

    return map;//  w w  w.j a  v  a 2  s  .co  m

}

From source file:ait.ffma.service.preservation.riskmanagement.api.riskanalysis.risk.RiskUtils.java

/**
 * This method splits the source string by separator string.
 * @param source//from  w  w w.  j  a  v a2  s.c  o  m
 *        The initial string
 * @param separator
 *        The separator string between tokens
 * @return string list
 */
public static List<String> splitString(String source, String separator) {
    List<String> result = new ArrayList<String>();
    StringTokenizer st = new StringTokenizer(source, separator);
    while (st.hasMoreElements()) {
        String token = (String) st.nextElement();
        result.add(token);
    }
    return result;
}

From source file:org.jumpmind.symmetric.io.data.transform.ColumnsToRowsKeyColumnTransform.java

public List<String> transform(IDatabasePlatform platform, DataContext context, TransformColumn column,
        TransformedData data, Map<String, String> sourceValues, String newValue, String oldValue)
        throws IgnoreRowException {

    if (StringUtils.trimToNull(column.getTransformExpression()) == null) {
        throw new RuntimeException(
                "Transform configured incorrectly.  A map representing PK and column names must be defined as part of the transform expression");
    }/* ww w  .  j a va  2  s.com*/
    String mapAsString = StringUtils.trimToEmpty(column.getTransformExpression());

    // Build reverse map, while also building up array to return

    List<String> result = new ArrayList<String>();
    Map<String, String> reverseMap = new HashMap<String, String>();

    StringTokenizer tokens = new StringTokenizer(mapAsString);

    while (tokens.hasMoreElements()) {
        String keyValue = (String) tokens.nextElement();
        int equalIndex = keyValue.indexOf("=");
        if (equalIndex != -1) {
            reverseMap.put(keyValue.substring(equalIndex + 1), keyValue.substring(0, equalIndex));
            result.add(keyValue.substring(equalIndex + 1));
        } else {
            throw new RuntimeException(
                    "Map string for " + column.getTransformExpression() + " is invalid format: " + mapAsString);
        }
    }

    context.put(getContextBase(column.getTransformId()) + CONTEXT_MAP, reverseMap);
    context.put(getContextBase(column.getTransformId()) + CONTEXT_PK_COLUMN, column.getTargetColumnName());

    return result;
}

From source file:biblivre3.z3950.BiblivrePrefixString.java

@Override
public InternalModelRootNode toInternalQueryModel(ApplicationContext ctx) throws InvalidQueryException {
    if (StringUtils.isBlank(queryAttr) || StringUtils.isBlank(queryTerms)) {
        throw new InvalidQueryException("Null prefix string");
    }//from   w w w  . j  av  a2  s  .  c o  m
    try {
        if (internalModel == null) {
            internalModel = new InternalModelRootNode();
            InternalModelNamespaceNode node = new InternalModelNamespaceNode();
            node.setAttrset(DEFAULT_ATTRSET);
            internalModel.setChild(node);
            AttrPlusTermNode attrNode = new AttrPlusTermNode();
            final String attrValue = "1." + queryAttr;
            attrNode.setAttr(DEFAULT_ATTRTYPE, new AttrValue(null, attrValue));
            Vector terms = new Vector();
            StringTokenizer tokenizer = new StringTokenizer(queryTerms);
            while (tokenizer.hasMoreElements()) {
                terms.add(tokenizer.nextElement());
            }
            if (terms.size() > 1) {
                attrNode.setTerm(terms);
            } else if (terms.size() == 1) {
                attrNode.setTerm(terms.get(0));
            } else {
                throw new PrefixQueryException("No Terms");
            }
            node.setChild(attrNode);
        }
    } catch (Exception e) {
        throw new InvalidQueryException(e.getMessage());
    }
    return internalModel;
}

From source file:com.amalto.core.save.context.PartialDeleteSimulator.java

/**
 * "Source document" and "toDeleteDocument" may not be be able to share "toDeletePiovt". <br>
 * Like <b>"Kids/Kid[2]/Habits/Habit"</b> means to delete source document's <b>SECOND</b> kid's habits,<br> 
 * but "toDeleteDocument" should use <b>"Kids/Kid[1]/Habits/Habit"</b> to get the data to delete.
 * @return//from w w  w .j ava2 s. c om
 */
private String getPivotForToDeleteDocument() {
    if (toDeletePivot.contains("[") && toDeletePivot.contains("]")) { //$NON-NLS-1$ //$NON-NLS-2$
        StringBuilder pivot = new StringBuilder();
        StringTokenizer tokenizer = new StringTokenizer(toDeletePivot, "/"); //$NON-NLS-1$
        while (tokenizer.hasMoreElements()) {
            String element = (String) tokenizer.nextElement();
            pivot.append("/").append(StringUtils.substringBefore(element, "[")); //$NON-NLS-1$ //$NON-NLS-2$
            if (element.contains("[") && element.contains("]")) { //$NON-NLS-1$ //$NON-NLS-2$
                pivot.append("[1]"); //$NON-NLS-1$
            }
        }
        return pivot.toString().substring(1);
    } else {
        return toDeletePivot;
    }
}

From source file:org.openremote.modeler.utils.KnxImporter.java

@SuppressWarnings("unchecked")
public List<KnxGroupAddress> importETS4Configuration(InputStream inputStream) throws Exception {

    List<KnxGroupAddress> result = new ArrayList<KnxGroupAddress>();
    String xmlData = null;/*  w  w w.  j  a v a 2 s.co  m*/
    DecimalFormat df = new DecimalFormat("000");
    SAXBuilder builder = new SAXBuilder();
    Document document = null;

    ZipInputStream zin = new ZipInputStream(inputStream);
    ZipEntry zipEntry = zin.getNextEntry();
    while (zipEntry != null) {
        if (zipEntry.getName().endsWith("/0.xml")) {
            xmlData = convertStreamToString(zin);
            break;
        }
        zipEntry = zin.getNextEntry();
    }

    if (xmlData != null) {
        //Remove UTF-8 Byte-order mark from the beginning of the data
        xmlData = xmlData.trim().replaceFirst("^([\\W]+)<", "<");

        // parse the XML as a W3C Document
        StringReader in = new StringReader(xmlData);
        document = builder.build(in);

        // Query all GroupAddress elements
        XPath xpath = XPath.newInstance("//knx:GroupAddress");
        xpath.addNamespace("knx", document.getRootElement().getNamespaceURI());
        List<Element> xresult = xpath.selectNodes(document);
        for (Element element : xresult) {

            String id = element.getAttributeValue("Id");
            String name = element.getAttributeValue("Name");
            String address = element.getAttributeValue("Address");
            String dpt = null;
            // Query referenced ComObjectInstanceRef element which holds DPT
            xpath = XPath.newInstance("//knx:Send[@GroupAddressRefId='" + id + "']/../..");
            xpath.addNamespace("knx", "http://knx.org/xml/project/10");
            List<Element> result2 = xpath.selectNodes(document);
            if (result2.size() > 0) {
                dpt = result2.get(0).getAttributeValue("DatapointType");
                if (dpt != null && StringUtils.isNotEmpty(dpt)) {
                    StringTokenizer st = new StringTokenizer(dpt, "-");
                    st.nextElement();
                    try {
                        dpt = st.nextToken() + "." + df.format(Integer.parseInt(st.nextToken()));
                    } catch (Exception e) {
                        dpt = null;
                    }
                } else {
                    dpt = null;
                }
            }
            String levelAddress = getAddressFromInt(Integer.parseInt(address));
            result.add(new KnxGroupAddress(dpt, levelAddress, name));
            LOGGER.debug("Created GroupAddress: " + levelAddress + " - " + name + " - " + dpt);
        }
    }

    return result;
}

From source file:org.pdfgal.pdfgalweb.services.impl.WatermarkServiceImpl.java

/**
 * Gets the pages from a string with tokens.
 * //from   w w  w. j  ava  2 s.c  o  m
 * @param pages
 * @return
 */
private List<Integer> getPages(final String pages) {

    final List<Integer> result = new ArrayList<Integer>();

    final StringTokenizer st = new StringTokenizer(pages, ",");

    while (st.hasMoreElements()) {

        final String token = (String) st.nextElement();

        try {
            final Integer page = Integer.parseInt(token);
            result.add(page);

        } catch (final Exception e) {

            final StringTokenizer secondSt = new StringTokenizer(token, "-");
            if (secondSt.countTokens() != 2) {
                throw new IllegalArgumentException();
            }

            final String secondTokenFirst = (String) secondSt.nextElement();
            final String secondTokenLast = (String) secondSt.nextElement();
            try {
                final Integer firstPage = Integer.parseInt(secondTokenFirst);
                final Integer lastPage = Integer.parseInt(secondTokenLast);
                for (int i = firstPage; i <= lastPage; i++) {
                    result.add(i);
                }

            } catch (final Exception e2) {
                throw new IllegalArgumentException();
            }
        }
    }

    return result;
}

From source file:gtu._work.ui.StringArrayMakerUI.java

private void jButton1ActionPerformed(ActionEvent evt) {
    try {/*  ww w .  ja  va2  s.  com*/
        DefaultListModel model = JListUtil.createModel();
        String text = ClipboardUtil.getInstance().getContents();
        Validate.notEmpty(text, "");
        StringBuilder pattern = new StringBuilder();
        if (jCheckBox1.isSelected()) {
            pattern.append("\n");
        }
        if (jCheckBox2.isSelected()) {
            pattern.append("\t");
        }
        StringTokenizer tok = new StringTokenizer(text, pattern.toString());
        while (tok.hasMoreElements()) {
            String val = (String) tok.nextElement();
            model.addElement(val);
        }
        jList1.setModel(model);
    } catch (Exception ex) {
        JCommonUtil.handleException(ex);
    }
}