Java 类org.apache.commons.lang.text.StrTokenizer 实例源码

项目:DBus    文件:DBConfiguration.java   
/**
 * Converts a String back to connection parameters.
 * @param input String from configuration
 * @return JDBC connection parameters
 */
public static Properties propertiesFromString(String input) {
  if (input != null && !input.isEmpty()) {
    Properties result = new Properties();
    StrTokenizer propertyTokenizer = StrTokenizer.getCSVInstance(input);
    StrTokenizer valueTokenizer = StrTokenizer.getCSVInstance();
    valueTokenizer.setDelimiterChar('=');
    while (propertyTokenizer.hasNext()) {
      valueTokenizer.reset(propertyTokenizer.nextToken());
      String[] values = valueTokenizer.getTokenArray();
      if (values.length == 2) {
        result.put(values[0], values[1]);
      }
    }
    return result;
  } else {
    return null;
  }
}
项目:aliyun-maxcompute-data-collectors    文件:DBConfiguration.java   
/**
 * Converts a String back to connection parameters.
 * @param input String from configuration
 * @return JDBC connection parameters
 */
protected static Properties propertiesFromString(String input) {
  if (input != null && !input.isEmpty()) {
    Properties result = new Properties();
    StrTokenizer propertyTokenizer = StrTokenizer.getCSVInstance(input);
    StrTokenizer valueTokenizer = StrTokenizer.getCSVInstance();
    valueTokenizer.setDelimiterChar('=');
    while (propertyTokenizer.hasNext()){
      valueTokenizer.reset(propertyTokenizer.nextToken());
      String[] values = valueTokenizer.getTokenArray();
      if (values.length==2) {
        result.put(values[0], values[1]);
      }
    }
    return result;
  } else {
    return null;
  }
}
项目:http4e    文件:ProxyItem.java   
/**
 * @param proxysettings
 *           String to convert
 * @return
 * @throws Exception
 */
public static ProxyItem createFromString( String proxysettings) throws Exception{
   ProxyItem returnvalue = null;
   try {
      StrTokenizer tokenizer = new StrTokenizer(proxysettings, DELIMITER);
      String[] tokenArray = tokenizer.getTokenArray();
      String name = tokenArray[0];
      String host = tokenArray[1];
      int port = Integer.parseInt(tokenArray[2]);
      returnvalue = new ProxyItem(host, port, name, true);
   } catch (Exception e) {
      throw new Exception("Error while parsing proxysettings", e);
   }

   return returnvalue;
}
项目:sampler    文件:SamplesMenuConfig.java   
private void init() {
    rootItems.clear();

    String configName = AppContext.getProperty(MENU_CONFIG_XML_PROP);

    StrTokenizer tokenizer = new StrTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                Element rootElement = Dom4j.readDocument(stream).getRootElement();
                loadMenuItems(rootElement, null);
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage(), e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource " + location + " not found, ignore it");
        }
    }
}
项目:cuba    文件:WebExternalUIComponentsSource.java   
protected void _registerAppComponents() {
    String configName = AppContext.getProperty(WEB_COMPONENTS_CONFIG_XML_PROP);
    StrTokenizer tokenizer = new StrTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                _registerComponent(stream);
            } catch (ClassNotFoundException | IOException e) {
                throw new RuntimeException(e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource {} not found, ignore it", location);
        }
    }
}
项目:cuba    文件:AbstractViewRepository.java   
protected void init() {
    StopWatch initTiming = new Slf4JStopWatch("ViewRepository.init." + getClass().getSimpleName());

    storage.clear();
    readFileNames.clear();

    String configName = AppContext.getProperty("cuba.viewsConfig");
    if (!StringUtils.isBlank(configName)) {
        Element rootElem = DocumentHelper.createDocument().addElement("views");

        StrTokenizer tokenizer = new StrTokenizer(configName);
        for (String fileName : tokenizer.getTokenArray()) {
            addFile(rootElem, fileName);
        }

        checkDuplicates(rootElem);

        for (Element viewElem : Dom4j.elements(rootElem, "view")) {
            deployView(rootElem, viewElem, new HashSet<>());
        }
    }

    initTiming.stop();
}
项目:cuba    文件: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");
    }

    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");
}
项目:cuba    文件:DesktopExternalUIComponentsSource.java   
protected void _registerWindowLoaders() {
    String configName = AppContext.getProperty(DESKTOP_COMPONENTS_CONFIG_XML_PROP);
    StrTokenizer tokenizer = new StrTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                Element rootElement = Dom4j.readDocument(stream)
                        .getRootElement();
                _loadWindowLoaders(rootElement);
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource {} not found, ignore it", location);
        }
    }
}
项目:cuba    文件:RestJsonTransformations.java   
protected void init() {
    String configName = AppContext.getProperty(CUBA_REST_JSON_TRANSFORMATION_CONFIG_PROP_NAME);
    StrTokenizer tokenizer = new StrTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                loadConfig(Dom4j.readDocument(stream).getRootElement());
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource " + location + " not found, ignore it");
        }
    }
}
项目:cuba    文件:RestQueriesConfiguration.java   
protected void init() {
    String configName = AppContext.getProperty(CUBA_REST_QUERIES_CONFIG_PROP_NAME);
    StrTokenizer tokenizer = new StrTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                loadConfig(Dom4j.readDocument(stream).getRootElement());
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource " + location + " not found, ignore it");
        }
    }
}
项目:cuba    文件:RestServicesConfiguration.java   
protected void init() {
    String configName = AppContext.getProperty(CUBA_REST_SERVICES_CONFIG_PROP_NAME);
    StrTokenizer tokenizer = new StrTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                loadConfig(Dom4j.readDocument(stream).getRootElement());
            } catch (IOException e) {
                throw new RuntimeException("Error on parsing rest services config", e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource " + location + " not found, ignore it");
        }
    }
}
项目:cuba    文件:RestServicePermissions.java   
protected void init() {
    String configName = AppContext.getProperty(CUBA_REST_SERVICES_CONFIG_PROP_NAME);
    StrTokenizer tokenizer = new StrTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                loadConfig(Dom4j.readDocument(stream).getRootElement());
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource " + location + " not found, ignore it");
        }
    }
}
项目:cuba    文件:CreditsLoader.java   
public CreditsLoader load() {
    String configProperty = AppContext.getProperty("cuba.creditsConfig");
    if (StringUtils.isBlank(configProperty)) {
        log.info("Property cuba.creditsConfig is empty");
        return this;
    }

    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;
}
项目:cuba    文件:MenuConfig.java   
protected void init() {
    rootItems.clear();

    String configName = AppContext.getProperty(MENU_CONFIG_XML_PROP);

    StrTokenizer tokenizer = new StrTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                Element rootElement = Dom4j.readDocument(stream).getRootElement();
                loadMenuItems(rootElement, null);
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource " + location + " not found, ignore it");
        }
    }
}
项目:cuba    文件:PermissionConfig.java   
private void compileSpecific() {
    Node<BasicPermissionTarget> root = new Node<>(
            new BasicPermissionTarget("category:specific", getMessage("permissionConfig.specificRoot"), null));
    specific = new Tree<>(root);

    final String configName = AppContext.getProperty(PERMISSION_CONFIG_XML_PROP);
    StrTokenizer tokenizer = new StrTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                String xml = IOUtils.toString(stream, StandardCharsets.UTF_8);
                compileSpecific(xml, root);
            } catch (IOException e) {
                throw new RuntimeException("Unable to read permission config", e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource {} not found, ignore it", location);
        }
    }
}
项目:cuba    文件:UniqueNumbers.java   
protected Object executeScript(String domain, String sqlScript) {
    EntityManager em = persistence.getEntityManager(getDataStore(domain));
    StrTokenizer tokenizer = new StrTokenizer(sqlScript, SequenceSupport.SQL_DELIMITER);
    Object value = null;
    Connection connection = em.getConnection();
    while (tokenizer.hasNext()) {
        String sql = tokenizer.nextToken();
        try {
            PreparedStatement statement = connection.prepareStatement(sql);
            try {
                if (statement.execute()) {
                    ResultSet rs = statement.getResultSet();
                    if (rs.next())
                        value = rs.getLong(1);
                }
            } finally {
                DbUtils.closeQuietly(statement);
            }
        } catch (SQLException e) {
            throw new IllegalStateException("Error executing SQL for getting next number", e);
        }
    }
    return value;
}
项目:cuba    文件:NumberIdWorker.java   
protected Object executeScript(String entityName, String sqlScript) {
    EntityManager em = persistence.getEntityManager(getDataStore(entityName));
    StrTokenizer tokenizer = new StrTokenizer(sqlScript, SequenceSupport.SQL_DELIMITER);
    Object value = null;
    Connection connection = em.getConnection();
    while (tokenizer.hasNext()) {
        String sql = tokenizer.nextToken();
        try {
            PreparedStatement statement = connection.prepareStatement(sql);
            try {
                if (statement.execute()) {
                    ResultSet rs = statement.getResultSet();
                    if (rs.next())
                        value = rs.getLong(1);
                }
            } finally {
                DbUtils.closeQuietly(statement);
            }
        } catch (SQLException e) {
            throw new IllegalStateException("Error executing SQL for getting next number", e);
        }
    }
    return value;
}
项目:Cobol-to-Hive    文件:DBConfiguration.java   
/**
 * Converts a String back to connection parameters.
 * @param input String from configuration
 * @return JDBC connection parameters
 */
protected static Properties propertiesFromString(String input) {
  if (input != null && !input.isEmpty()) {
    Properties result = new Properties();
    StrTokenizer propertyTokenizer = StrTokenizer.getCSVInstance(input);
    StrTokenizer valueTokenizer = StrTokenizer.getCSVInstance();
    valueTokenizer.setDelimiterChar('=');
    while (propertyTokenizer.hasNext()){
      valueTokenizer.reset(propertyTokenizer.nextToken());
      String[] values = valueTokenizer.getTokenArray();
      if (values.length==2) {
        result.put(values[0], values[1]);
      }
    }
    return result;
  } else {
    return null;
  }
}
项目:jnrpe    文件:CommandExecutor.java   
public boolean executeCommand(String commandLine) throws Exception {
    StrTokenizer strtok = new StrTokenizer(commandLine, StrMatcher.charMatcher(' '), StrMatcher.quoteMatcher());
    String[] tokensAry = strtok.getTokenArray();
    String commandName = tokensAry[0];
    String[] params;
    if (tokensAry.length == 1) {
        params = new String[0];
    } else {
        params = new String[tokensAry.length - 1];
        System.arraycopy(tokensAry, 1, params, 0, params.length);
    }

    IConsoleCommand command = getCommand(commandName);
    if (command != null) {
        return command.execute(params);
    } else {
        throw new UnknownCommandException("Unknown command :'" + commandName + "'");
    }
}
项目:remoterun    文件:Server.java   
private void runCommand(String line) {
  StrTokenizer tokenizer = new StrTokenizer(line, ' ', '"');
  @SuppressWarnings("unchecked")
  List<String> tokens = tokenizer.getTokenList();
  tokens.remove(0); // first token is the run command
  String command = tokens.remove(0);

  Collection<IAgentConnection> connectedClients = remoteRunMaster.getConnectedClients();
  if(connectedClients.isEmpty()) {
    log.error("Unable to send command: no agent connections");
  } else {
    IAgentConnection connection = connectedClients.iterator().next();

    RemoteRun.MasterToAgent.Builder builder = RemoteRun.MasterToAgent.newBuilder()
      .setMessageType(RemoteRun.MasterToAgent.MessageType.RUN_COMMAND)
      .setRequestId(RemoteRunMaster.getNextRequestId());
    builder.getRunCommandBuilder().setCmd(command).addAllArgs(tokens);
    connection.write(builder.build());
  }
}
项目:remoterun    文件:Server.java   
private void sendInput(String line) {
  StrTokenizer tokenizer = new StrTokenizer(line, ' ', '"');
  @SuppressWarnings("unchecked")
  List<String> tokens = tokenizer.getTokenList();
  tokens.remove(0); // first token is the run command
  long id = Long.parseLong(tokens.remove(0));
  String input = StringUtils.join(tokens, ' ').replaceAll("\\\\n", "\n");

  Collection<IAgentConnection> connectedClients = remoteRunMaster.getConnectedClients();
  if(connectedClients.isEmpty()) {
    log.error("Unable to send command: no agent connections");
  } else {
    IAgentConnection connection = connectedClients.iterator().next();
    RemoteRun.MasterToAgent.Builder builder = RemoteRun.MasterToAgent.newBuilder()
      .setMessageType(RemoteRun.MasterToAgent.MessageType.STDIN_FRAGMENT)
      .setRequestId(id)
      .setFragment(ByteString.copyFromUtf8(input));
    connection.write(builder.build());
  }
}
项目:remoterun    文件:Server.java   
private void closeInput(String line) {
  StrTokenizer tokenizer = new StrTokenizer(line, ' ', '"');
  @SuppressWarnings("unchecked")
  List<String> tokens = tokenizer.getTokenList();
  tokens.remove(0); // first token is the run command
  long id = Long.parseLong(tokens.remove(0));

  Collection<IAgentConnection> connectedClients = remoteRunMaster.getConnectedClients();
  if(connectedClients.isEmpty()) {
    log.error("Unable to send command: no agent connections");
  } else {
    IAgentConnection connection = connectedClients.iterator().next();
    RemoteRun.MasterToAgent.Builder builder = RemoteRun.MasterToAgent.newBuilder().setMessageType(RemoteRun.MasterToAgent.MessageType.CLOSE_STDIN).setRequestId(id);
    connection.write(builder.build());
  }
}
项目:zSqoop    文件:DBConfiguration.java   
/**
 * Converts a String back to connection parameters.
 * @param input String from configuration
 * @return JDBC connection parameters
 */
protected static Properties propertiesFromString(String input) {
  if (input != null && !input.isEmpty()) {
    Properties result = new Properties();
    StrTokenizer propertyTokenizer = StrTokenizer.getCSVInstance(input);
    StrTokenizer valueTokenizer = StrTokenizer.getCSVInstance();
    valueTokenizer.setDelimiterChar('=');
    while (propertyTokenizer.hasNext()){
      valueTokenizer.reset(propertyTokenizer.nextToken());
      String[] values = valueTokenizer.getTokenArray();
      if (values.length==2) {
        result.put(values[0], values[1]);
      }
    }
    return result;
  } else {
    return null;
  }
}
项目:ridire-cpi    文件:JobManager.java   
public void retrievePoSText(CrawledResource cr) {
    File resourceDir = new File(FilenameUtils.getFullPath(cr.getArcFile()
            .replaceAll("__\\d+", "")) + JobManager.RESOURCESDIR);
    File posTextFile = new File(resourceDir, cr.getDigest() + ".txt.pos");
    List<PoSLine> posLines = new ArrayList<PoSLine>();
    try {
        List<String> lines = FileUtils.readLines(posTextFile);
        StrTokenizer tokenizer = StrTokenizer.getTSVInstance();
        for (String l : lines) {
            tokenizer.reset(l);
            String[] tokens = tokenizer.getTokenArray();
            if (tokens.length == 3) {
                PoSLine poSLine = new PoSLine();
                poSLine.setForm(tokens[0].trim());
                poSLine.setPosTag(tokens[1].trim());
                poSLine.setLemma(tokens[2].trim());
                posLines.add(poSLine);
            }
        }

    } catch (IOException e) {

    }
    this.setPosText(posLines);
}
项目:ridire-cpi    文件:WordCounter.java   
public Integer countWordsFromPoSTagResource(File posTagResourceFile)
        throws IOException {
    List<String> lines = FileUtils.readLines(posTagResourceFile);
    Integer count = 0;
    StrTokenizer tokenizer = StrTokenizer.getTSVInstance();
    for (String l : lines) {
        tokenizer.reset(l);
        String[] tokens = tokenizer.getTokenArray();
        if (tokens.length == 3) {
            if (this.isValidPos(tokens[1].trim())) {
                ++count;
            }
        }
    }
    return count;
}
项目:ridire-cpi    文件:Mapper.java   
@SuppressWarnings("unchecked")
public static Integer countWordsFromPoSTagResource(
        String posTagResourceFileName) throws IOException {
    List<String> lines = FileUtils.readLines(new File(
            posTagResourceFileName));
    Integer count = 0;
    StrTokenizer tokenizer = StrTokenizer.getTSVInstance();
    for (String l : lines) {
        tokenizer.reset(l);
        String[] tokens = tokenizer.getTokenArray();
        if (tokens.length == 3) {
            if (Mapper.isValidPos(tokens[1].trim())) {
                ++count;
            }
        }
    }
    return count;
}
项目:http4e    文件:FolderModel.java   
public FolderModel( String availableProxiesString, String availableKeystoresString) {
   this.availableProxies.add(ProxyItem.createDirectConnectionProxy());
   for (String proxysettings : new StrTokenizer(availableProxiesString, "#").getTokenArray()) {
      try {
         this.availableProxies.add(ProxyItem.createFromString(proxysettings));
      } catch (Exception e) {
         // TODO handle error
      }
   }
   this.availableKeystore = availableKeystoresString;
}
项目:cuba    文件:CubaDispatcherServlet.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");
    }
    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();
}
项目:cuba    文件:PortalDispatcherServlet.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");
    }
    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();
}
项目:cuba    文件: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)));
    }
    return metadataXmlList;
}
项目:cuba    文件:MetadataBuildSupport.java   
protected void loadFromPersistenceConfig(Map<String, List<EntityClassInfo>> packages, String db) {
    String persistenceConfig = getPersistenceConfig(db);
    if (persistenceConfig == null)
        return;
    StrTokenizer persistenceFilesTokenizer = new StrTokenizer(persistenceConfig);
    for (String fileName : persistenceFilesTokenizer.getTokenArray()) {
        Element root = readXml(fileName);
        Element puEl = root.element("persistence-unit");
        if (puEl == null)
            throw new IllegalStateException("File " + fileName + " has no persistence-unit element");

        for (Element classEl : Dom4j.elements(puEl, "class")) {
            String className = classEl.getText().trim();
            boolean included = false;
            for (String rootPackage : packages.keySet()) {
                if (className.startsWith(rootPackage + ".")) {
                    List<EntityClassInfo> classNames = packages.get(rootPackage);
                    if (classNames == null) {
                        classNames = new ArrayList<>();
                        packages.put(rootPackage, classNames);
                    }
                    classNames.add(new EntityClassInfo(db, className, true));
                    included = true;
                    break;
                }
            }
            if (!included)
                throw new IllegalStateException("Can not find a model for class " + className
                        + ". The class's package must be inside of some model's root package.");
        }
    }
}
项目:cuba    文件:AbstractMessages.java   
@Nullable
protected String searchMessage(String packs, String key, Locale locale, Locale truncatedLocale, Set<String> passedPacks) {
    StrTokenizer tokenizer = new StrTokenizer(packs);
    //noinspection unchecked
    List<String> list = tokenizer.getTokenList();
    Collections.reverse(list);
    for (String pack : list) {
        if (!enterPack(pack, locale, truncatedLocale, passedPacks))
            continue;

        String msg = searchOnePack(pack, key, locale, truncatedLocale, passedPacks);
        if (msg != null)
            return msg;

        Locale tmpLocale = truncatedLocale;
        while (tmpLocale != null) {
            tmpLocale = truncateLocale(tmpLocale);
            msg = searchOnePack(pack, key, locale, tmpLocale, passedPacks);
            if (msg != null)
                return msg;
        }
    }
    if (log.isTraceEnabled()) {
        String packName = new StrBuilder().appendWithSeparators(list, ",").toString();
        log.trace("Resource '" + makeCacheKey(packName, key, locale, locale) + "' not found");
    }
    return null;
}
项目:cuba    文件:AppPropertiesTest.java   
@Test
public void testEmptyStringSubstitution() {
    AppProperties appProperties = new AppProperties(new AppComponents("test"));
    appProperties.setProperty("refapp.myConfig", "1.xml ${ext.myConfig} 2.xml");
    appProperties.setProperty("ext.myConfig", "");

    String propValue = appProperties.getProperty("refapp.myConfig");
    log.debug("Property value: '" + propValue + "'");

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

    Assert.assertArrayEquals(new String[] {"1.xml", "2.xml"}, locations);
}
项目:cuba    文件:CubaIdpServlet.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");
    }
    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();
}
项目:cuba    文件: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);
    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;
}
项目:cuba    文件:DesktopThemeImpl.java   
@Override
public void applyStyle(Object component, String styleNameString, Set<String> state) {
    // split string into individual style names
    StrTokenizer tokenizer = new StrTokenizer(styleNameString);
    String[] styleNames = tokenizer.getTokenArray();
    for (String styleName : styleNames) {
        applyStyleName(component, state, styleName);
    }
}
项目:cuba    文件:CubaRestApiServlet.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");
    }
    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();
}
项目:cuba    文件:WindowConfig.java   
protected void init() {
    screens.clear();

    Map<String, ScreenAgent> agentMap = AppBeans.getAll(ScreenAgent.class);

    Map<String, ScreenAgent> screenAgents = new LinkedHashMap<>();
    List<ScreenAgent> availableAgents = new ArrayList<>(agentMap.values());

    AnnotationAwareOrderComparator.sort(availableAgents);

    for (ScreenAgent screenAgent : availableAgents) {
        screenAgents.put(screenAgent.getAlias(), screenAgent);
    }
    this.activeScreenAgents = screenAgents;

    String configName = AppContext.getProperty(WINDOW_CONFIG_XML_PROP);
    StrTokenizer tokenizer = new StrTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                loadConfig(Dom4j.readDocument(stream).getRootElement());
            } catch (IOException e) {
                throw new RuntimeException("Unable to read window config from " + location, e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource {} not found, ignore it", location);
        }
    }
}
项目:cuba    文件: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);
                }

                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();
    }
}
项目:cuba    文件:DefaultPermissionValuesConfig.java   
protected void init() {
    permissionValues.clear();

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