Example usage for org.apache.commons.lang.text StrTokenizer StrTokenizer

List of usage examples for org.apache.commons.lang.text StrTokenizer StrTokenizer

Introduction

In this page you can find the example usage for org.apache.commons.lang.text StrTokenizer StrTokenizer.

Prototype

public StrTokenizer(char[] input) 

Source Link

Document

Constructs a tokenizer splitting on space, tab, newline and formfeed as per StringTokenizer.

Usage

From source file:com.haulmont.cuba.core.app.prettytime.CubaPrettyTimeParser.java

@PostConstruct
public void init() {
    StrTokenizer tokenizer = new StrTokenizer(serverConfig.getPrettyTimeProperties());
    try {//ww  w  .j  av a 2 s .com
        for (String fileName : tokenizer.getTokenArray()) {
            InputStream stream = null;

            try {
                stream = resources.getResourceAsStream(fileName);
                if (stream == null) {
                    throw new IllegalStateException("Resource is not found: " + fileName);
                }
                InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8.name());
                Properties properties = new Properties() {
                    private Set orderedKeySet = new LinkedHashSet();

                    @Override
                    public Set<String> stringPropertyNames() {
                        return orderedKeySet;
                    }

                    @Override
                    public synchronized Object put(Object key, Object value) {
                        orderedKeySet.add(key);
                        return super.put(key, value);
                    }
                };
                properties.load(reader);
                for (String key : properties.stringPropertyNames()) {
                    String value = properties.getProperty(key);
                    replacements.put(key, value);
                }
            } finally {
                IOUtils.closeQuietly(stream);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.haulmont.cuba.gui.app.core.credits.CreditsLoader.java

public CreditsLoader load() {
    String configProperty = AppContext.getProperty("cuba.creditsConfig");
    if (StringUtils.isBlank(configProperty)) {
        log.info("Property cuba.creditsConfig is empty");
        return this;
    }//from w  w w .j  av a  2  s.  c om

    StrTokenizer tokenizer = new StrTokenizer(configProperty);
    String[] locations = tokenizer.getTokenArray();

    for (String location : locations) {
        Resources resources = AppBeans.get(Resources.NAME);
        String xml = resources.getResourceAsString(location);
        if (xml == null) {
            log.debug("Resource {} not found, ignore it", location);
            continue;
        }
        Element rootElement = Dom4j.readDocument(xml).getRootElement();
        loadLicenses(rootElement);
        loadConfig(rootElement);
    }

    Collections.sort(items);

    return this;
}

From source file:com.haulmont.cuba.core.sys.AbstractAppContextLoader.java

protected void initAppContext() {
    String configProperty = AppContext.getProperty(SPRING_CONTEXT_CONFIG);
    if (StringUtils.isBlank(configProperty)) {
        throw new IllegalStateException("Missing " + SPRING_CONTEXT_CONFIG + " application property");
    }/* ww  w .j a  va 2s .  co  m*/

    StrTokenizer tokenizer = new StrTokenizer(configProperty);
    String[] locations = tokenizer.getTokenArray();
    replaceLocationsFromConf(locations);

    ApplicationContext appContext = createApplicationContext(locations);
    AppContext.Internals.setApplicationContext(appContext);

    Events events = AppBeans.get(Events.NAME);
    events.publish(new AppContextInitializedEvent(appContext));

    log.debug("AppContext initialized");
}

From source file:com.haulmont.cuba.gui.theme.ThemeConstantsRepository.java

protected void init() {
    String configName = AppContext.getProperty("cuba.themeConfig");
    if (!StringUtils.isBlank(configName)) {
        Map<String, Map<String, String>> themeProperties = new HashMap<>();

        StrTokenizer tokenizer = new StrTokenizer(configName);
        for (String fileName : tokenizer.getTokenArray()) {
            String themeName = parseThemeName(fileName);
            if (StringUtils.isNotBlank(themeName)) {
                Map<String, String> themeMap = themeProperties.get(themeName);
                if (themeMap == null) {
                    themeMap = new HashMap<>();
                    themeProperties.put(themeName, themeMap);
                }//ww  w.j a  v a2 s .co m

                loadThemeProperties(fileName, themeMap);
            }
        }

        Map<String, ThemeConstants> themes = new LinkedHashMap<>();

        for (Map.Entry<String, Map<String, String>> entry : themeProperties.entrySet()) {
            themes.put(entry.getKey(), new ThemeConstants(entry.getValue()));
        }

        this.themeConstantsMap = Collections.unmodifiableMap(themes);
    } else {
        this.themeConstantsMap = Collections.emptyMap();
    }
}

From source file:it.drwolf.ridire.util.fixingpos.AsyncPosFixer.java

@SuppressWarnings("unchecked")
@Asynchronous//from w  ww  .j a  v  a2s .  c om
public void doAsyncFix(PosFixerData posFixerData) {
    StrTokenizer strTokenizer = new StrTokenizer("\t");
    File destDir = new File(posFixerData.getDestDir());
    File reverseDestDir = new File(posFixerData.getReverseDestDir());
    if (!destDir.exists() || !destDir.isDirectory() || !reverseDestDir.exists()
            || !reverseDestDir.isDirectory()) {
        System.err.println("Not valid destination folder.");
        return;
    }
    this.ridireReTagger = new RIDIREReTagger(null);
    try {
        this.entityManager = (EntityManager) Component.getInstance("entityManager");
        this.userTx = (UserTransaction) org.jboss.seam.Component
                .getInstance("org.jboss.seam.transaction.transaction");
        this.userTx.setTransactionTimeout(1000 * 10 * 60);
        if (!this.userTx.isActive()) {
            this.userTx.begin();
        }
        this.entityManager.joinTransaction();
        String treeTaggerBin = this.entityManager
                .find(CommandParameter.class, CommandParameter.TREETAGGER_EXECUTABLE_KEY).getCommandValue();
        this.ridireReTagger.setTreetaggerBin(treeTaggerBin);
        this.entityManager.flush();
        this.entityManager.clear();
        this.userTx.commit();
        List<String> lines = FileUtils.readLines(new File(posFixerData.getFile()));
        int count = 0;
        for (String l : lines) {
            if (l == null || l.trim().length() < 1) {
                continue;
            }
            String digest = l.replaceAll("\\./", "").replaceAll("\\.vrt", "");
            if (!this.userTx.isActive()) {
                this.userTx.begin();
            }
            this.entityManager.joinTransaction();
            List<CrawledResource> crs = this.entityManager
                    .createQuery("from CrawledResource cr where cr.digest=:digest")
                    .setParameter("digest", digest).getResultList();
            if (crs.size() != 1) {
                System.err.println("PosFixer: " + l + " resource not found.");
            } else {
                CrawledResource cr = crs.get(0);
                String origFile = FilenameUtils.getFullPath(cr.getArcFile())
                        .concat(JobMapperMonitor.RESOURCESDIR).concat(digest.concat(".txt"));
                File toBeRetagged = new File(origFile);
                if (toBeRetagged.exists() && toBeRetagged.canRead()) {
                    String retaggedFile = this.ridireReTagger.retagFile(toBeRetagged);
                    int wordsNumber = this.wordCounter.countWordsFromPoSTagResource(new File(retaggedFile));
                    cr.setWordsNumber(wordsNumber);
                    this.entityManager.persist(cr);
                    this.vrtFilesBuilder.createVRTFile(retaggedFile, strTokenizer, cr, destDir);
                    String vrtFileName = destDir + System.getProperty("file.separator") + digest + ".vrt";
                    File vrtFile = new File(vrtFileName);
                    this.vrtFilesBuilder.reverseFile(reverseDestDir, vrtFile);
                }
            }
            this.userTx.commit();
            System.out.println(" Processed " + (++count) + " of " + lines.size());
        }
    } catch (SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NotSupportedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (RollbackException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (HeuristicMixedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (HeuristicRollbackException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        try {
            if (this.userTx != null && this.userTx.isActive()) {
                this.userTx.rollback();
            }
        } catch (IllegalStateException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SecurityException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SystemException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}

From source file:com.haulmont.cuba.core.sys.remoting.RemotingServlet.java

@Override
public String getContextConfigLocation() {
    String configProperty = AppContext.getProperty(SPRING_CONTEXT_CONFIG);
    if (StringUtils.isBlank(configProperty)) {
        throw new IllegalStateException("Missing " + SPRING_CONTEXT_CONFIG + " application property");
    }/*from   w  w w  .  j  a  v a 2 s. c  om*/
    File baseDir = new File(AppContext.getProperty("cuba.confDir"));

    StrTokenizer tokenizer = new StrTokenizer(configProperty);
    String[] tokenArray = tokenizer.getTokenArray();
    StringBuilder locations = new StringBuilder();
    for (String token : tokenArray) {
        String location;
        if (ResourceUtils.isUrl(token)) {
            location = token;
        } else {
            if (token.startsWith("/"))
                token = token.substring(1);
            File file = new File(baseDir, token);
            if (file.exists()) {
                location = file.toURI().toString();
            } else {
                location = "classpath:" + token;
            }
        }
        locations.append(location).append(" ");
    }
    return locations.toString();
}

From source file:com.haulmont.cuba.desktop.theme.impl.DesktopThemeLoaderImpl.java

@Override
public DesktopTheme loadTheme(String themeName) {
    String themeLocations = config.getResourceLocations();
    StrTokenizer tokenizer = new StrTokenizer(themeLocations);
    String[] locationList = tokenizer.getTokenArray();

    List<String> resourceLocationList = new ArrayList<>();
    DesktopThemeImpl theme = createTheme(themeName, locationList);
    theme.setName(themeName);//from   ww  w.j a  v a  2 s  .  c o m
    for (String location : locationList) {
        resourceLocationList.add(getResourcesDir(themeName, location));

        String xmlLocation = getConfigFileName(themeName, location);
        Resource resource = resources.getResource(xmlLocation);
        if (resource.exists()) {
            try {
                loadThemeFromXml(theme, resource);
            } catch (IOException e) {
                log.error("Error", e);
            }
        } else {
            log.warn("Resource " + location + " not found, ignore it");
        }
    }

    DesktopResources desktopResources = new DesktopResources(resourceLocationList, resources);
    theme.setResources(desktopResources);

    return theme;
}

From source file:com.haulmont.cuba.core.sys.DefaultPermissionValuesConfig.java

protected void init() {
    permissionValues.clear();/*from  www .  j a v  a 2  s  . c  om*/

    String configName = AppContext.getProperty("cuba.defaultPermissionValuesConfig");
    if (!StringUtils.isBlank(configName)) {
        StrTokenizer tokenizer = new StrTokenizer(configName);
        for (String fileName : tokenizer.getTokenArray()) {
            parseConfigFile(fileName);
        }
    }
}

From source file:com.haulmont.cuba.core.sys.MetadataBuildSupport.java

public List<XmlFile> init() {
    List<XmlFile> metadataXmlList = new ArrayList<>();
    StrTokenizer metadataFilesTokenizer = new StrTokenizer(getMetadataConfig());
    for (String fileName : metadataFilesTokenizer.getTokenArray()) {
        metadataXmlList.add(new XmlFile(fileName, readXml(fileName)));
    }//from ww  w  . j a  va 2s  .com
    return metadataXmlList;
}

From source file:com.softlayer.objectstorage.Account.java

/**
 * list all containers on this account/*from  w w w  .ja  v a2  s.c  om*/
 * 
 * @return a list of container objects
 * @throws IOException
 */
public List<Container> listAllContainers() throws IOException {
    Hashtable<String, String> params = super.createAuthParams();
    ClientResource client = super.get(params, super.storageurl);
    Representation entity = client.getResponseEntity();
    String containers = entity.getText();
    StrTokenizer tokenize = new StrTokenizer(containers);
    tokenize.setDelimiterString("\n");
    String[] cont = tokenize.getTokenArray();
    ArrayList<Container> conts = new ArrayList<Container>();
    for (String token : cont) {

        conts.add(new Container(token, super.baseurl, this.username, this.password, false));

    }

    return conts;

}