List of usage examples for org.apache.commons.lang3 EnumUtils getEnum
public static <E extends Enum<E>> E getEnum(final Class<E> enumClass, final String enumName)
Gets the enum for the class, returning null if not found.
This method differs from Enum#valueOf in that it does not throw an exception for an invalid enum name.
From source file:org.jbb.system.impl.install.auto.DatabaseAutoInstallDataReader.java
private DatabaseInstallationData buildDatabaseData(FileBasedConfiguration configuration) { DatabaseType databaseType = EnumUtils.getEnum(DatabaseType.class, configuration.getString(DB_TYPE, null)); if (databaseType == null) { databaseType = DatabaseType.H2_EMBEDDED; }//w w w . j a v a 2s . com return DatabaseInstallationData.builder().databaseType(databaseType) .h2EmbeddedInstallationData(H2EmbeddedInstallationData.builder() .username(configuration.getString(DB_H2_EMBEDDED_USERNAME, null)) .databaseFileName(configuration.getString(DB_H2_EMBEDDED_FILENAME, null)) .usernamePassword(configuration.getString(DB_H2_EMBEDDED_PSWD, null)).build()) .h2ManagedServerInstallationData(H2ManagedServerInstallationData.builder() .username(configuration.getString(DB_H2_MANAGED_USERNAME, null)) .databaseFileName(configuration.getString(DB_H2_MANAGED_FILENAME, null)) .port(configuration.getInt(DB_H2_MANAGED_PORT, 0)) .usernamePassword(configuration.getString(DB_H2_MANAGED_PSWD, null)).build()) .h2RemoteServerInstallationData(H2RemoteServerInstallationData.builder() .username(configuration.getString(DB_H2_REMOTE_USERNAME, null)) .url(configuration.getString(DB_H2_REMOTE_URL, null)) .usernamePassword(configuration.getString(DB_H2_REMOTE_PSWD, null)).build()) .postgresqlInstallationData(PostgresqlInstallationData.builder() .hostName(configuration.getString(DB_POSTGRES_HOSTNAME, null)) .port(configuration.getInt(DB_POSTGRES_PORT, 0)) .databaseName(configuration.getString(DB_POSTGRES_DATABASE_NAME, null)) .username(configuration.getString(DB_POSTGRES_USERNAME, null)) .password(configuration.getString(DB_POSTGRES_PSWD, null)).build()) .build(); }
From source file:org.jbb.system.impl.metrics.MetricSettingsProvider.java
private MetricType mapToType(MetricPrefix prefix) { return EnumUtils.getEnum(MetricType.class, prefix.name()); }
From source file:org.jbb.system.web.install.InstallationDataTranslator.java
private DatabaseInstallationData buildDatabaseInstallationData(InstallForm form) { H2EmbeddedForm h2embeddedForm = form.getH2embeddedForm(); H2ManagedServerForm h2managedServerForm = form.getH2managedServerForm(); H2RemoteServerForm h2remoteServerForm = form.getH2remoteServerForm(); PostgresqlForm postgresqlForm = form.getPostgresqlForm(); return DatabaseInstallationData.builder() .databaseType(EnumUtils.getEnum(DatabaseType.class, form.getDatabaseProviderName())) .h2EmbeddedInstallationData( H2EmbeddedInstallationData.builder().databaseFileName(h2embeddedForm.getDatabaseFileName()) .username(h2embeddedForm.getUsername()) .usernamePassword(h2embeddedForm.getUsernamePassword()).build()) .h2ManagedServerInstallationData(H2ManagedServerInstallationData.builder() .databaseFileName(h2managedServerForm.getDatabaseFileName()) .port(h2managedServerForm.getPort()).username(h2managedServerForm.getUsername()) .usernamePassword(h2managedServerForm.getUsernamePassword()).build()) .h2RemoteServerInstallationData(H2RemoteServerInstallationData.builder() .url(h2remoteServerForm.getUrl()).username(h2remoteServerForm.getUsername()) .usernamePassword(h2remoteServerForm.getUsernamePassword()).build()) .postgresqlInstallationData(PostgresqlInstallationData.builder() .hostName(postgresqlForm.getHostName()).port(postgresqlForm.getPort()) .databaseName(postgresqlForm.getDatabaseName()).username(postgresqlForm.getUsername()) .password(postgresqlForm.getPassword()).build()) .build();/*from w ww. j av a 2 s. c om*/ }
From source file:org.jbb.system.web.logging.logic.FilterUtils.java
public static LogFilter getFilterFromString(String logFilterString) { if (logFilterString == null) { return null; }// w ww . j av a2s . co m if (StringUtils.isEmpty(logFilterString) || "None".equalsIgnoreCase(logFilterString)) { return null; } if (logFilterString.startsWith("Level: ")) { return new LogLevelFilter( EnumUtils.getEnum(LogLevel.class, logFilterString.substring(7).toUpperCase())); } else if (logFilterString.startsWith("Threshold: ")) { return new LogThresholdFilter( EnumUtils.getEnum(LogLevel.class, logFilterString.substring(11).toUpperCase())); } return null; }
From source file:org.jbb.system.web.metrics.logic.MetricsSettingsFormTranslator.java
private Set<MetricType> mapToTypes(Map<String, Boolean> metricTypes) { return metricTypes.entrySet().stream().filter(entry -> entry.getValue() != null && entry.getValue()) .map(entry -> EnumUtils.getEnum(MetricType.class, entry.getKey())).collect(Collectors.toSet()); }
From source file:org.sbs.goodcrawler.extractor.selector.action.string.ActionFactory.java
public static SelectorAction create(Element element, String c) { if ("string".equals(c)) { StringActionType $type = EnumUtils.getEnum(StringActionType.class, element.attr("operation")); if (null == $type) { try { throw new Exception( "?" + element.tagName() + "operation"); } catch (Exception e) { e.printStackTrace();/*from ww w . ja v a 2 s . c om*/ } } switch ($type) { case after: return new StringAfterAction(element.attr("split")); case afterLast: return new StringAfterLastAction(element.attr("split")); case before: return new StringBeforeAction(element.attr("split")); case beforeLast: return new StringBeforeLastAction(element.attr("split")); case between: return new StringBetweenAction(element.attr("exp")); case filter: return new StringFilterAction(element.attr("filter"), element.attr("charType")); case replace: return new StringReplaceAction(element.attr("search"), element.attr("replacement")); case split: return new StringSplitAction(element.attr("split"), element.attr("index")); case sub: return new StringSubAction(element.attr("exp")); case suffix: return new StringSuffixAction(element.attr("suffix")); case perfix: return new StringPerfixAction(element.attr("perfix")); default: break; } } else if ("integer".equals(c) || "int".equals(c)) { IntegerActionType $type = EnumUtils.getEnum(IntegerActionType.class, element.attr("operation")); switch ($type) { case abs: return new IntegerAbsAction(); case between: try { return new IntegerBetweenAction(element.attr("exp"), element.attr("default")); } catch (IntegerBetweenExpressionException e) { e.printStackTrace(); } default: break; } } else if ("date".equals(c)) { } else if ("numerica".equals(c)) { IntegerActionType $type = EnumUtils.getEnum(IntegerActionType.class, element.attr("operation")); switch ($type) { case abs: return new IntegerAbsAction(); case between: try { return new IntegerBetweenAction(element.attr("exp"), element.attr("default")); } catch (IntegerBetweenExpressionException e) { e.printStackTrace(); } default: break; } } else if ("file".equals(c)) { FileActionType $type = EnumUtils.getEnum(FileActionType.class, element.attr("operation")); switch ($type) { case download: String dir = element.attr("dir"); String temp = element.attr("fileName"); boolean md5File = false, asyn; if (StringUtils.isNotBlank(temp)) { if ("{md5}".equals(temp)) { md5File = true; } } else md5File = true; temp = element.attr("asyn"); if (StringUtils.isNotBlank(temp)) { asyn = Boolean.parseBoolean(temp); } else { asyn = true; } return new DownLoadFileAction(dir, md5File, asyn); case download_resize: String dir2 = element.attr("dir"); String temp2 = element.attr("fileName"); boolean md5File2 = false, asyn2; if (StringUtils.isNotBlank(temp2)) { if ("{md5}".equals(temp2)) { md5File2 = true; } } else md5File2 = true; temp2 = element.attr("asyn"); if (StringUtils.isNotBlank(temp2)) { asyn2 = Boolean.parseBoolean(temp2); } else { asyn2 = true; } DownLoadImageResizeAction resizeAction = new DownLoadImageResizeAction(dir2, md5File2, asyn2); temp2 = element.attr("width"); if (StringUtils.isNotBlank(temp2)) { resizeAction.setW(Integer.parseInt(temp2)); } temp2 = element.attr("height"); if (StringUtils.isNotBlank(temp2)) { resizeAction.setH(Integer.parseInt(temp2)); } temp2 = element.attr("quality"); if (StringUtils.isNotBlank(temp2)) { resizeAction.setQuality(Float.parseFloat(temp2)); } temp2 = element.attr("del"); if (StringUtils.isNotBlank(temp2)) { resizeAction.setDeleteOldFile(Boolean.parseBoolean(temp2)); } return resizeAction; default: break; } } else { StringActionType $type = EnumUtils.getEnum(StringActionType.class, element.attr("operation")); if (null == $type) { try { throw new Exception( "?" + element.tagName() + "operation"); } catch (Exception e) { e.printStackTrace(); } } switch ($type) { case after: return new StringAfterAction(element.attr("split")); case afterLast: return new StringAfterLastAction(element.attr("split")); case before: return new StringBeforeAction(element.attr("split")); case beforeLast: return new StringBeforeLastAction(element.attr("split")); case between: return new StringBetweenAction(element.attr("exp")); case filter: return new StringFilterAction(element.attr("filter"), element.attr("charType")); case replace: return new StringReplaceAction(element.attr("search"), element.attr("replacement")); case split: return new StringSplitAction(element.attr("split"), element.attr("index")); case sub: return new StringSubAction(element.attr("exp")); case suffix: return new StringSuffixAction(element.attr("suffix")); case perfix: return new StringPerfixAction(element.attr("perfix")); default: break; } } return null; }
From source file:org.sbs.goodcrawler.jobconf.StoreConfig.java
public StoreConfig loadConfig(Document confDoc) { Document doc = confDoc;/* ww w . j a v a2 s . c o m*/ jobName = doc.select("job").attr("name"); indexName = doc.select("job").attr("indexName"); Elements e = doc.select("store"); this.type = e.select("type").text(); if (StringUtils.isNotBlank(e.select("threadNum").text())) { this.threadNum = Integer.parseInt(e.select("threadNum").text()); } String className = e.select("plugin").text(); if (StringUtils.isNotBlank(className)) { this.pluginClass = className; } // id? String idPolicy = e.select("idPolicy").text(); if (StringUtils.isNotBlank(idPolicy)) { id = EnumUtils.getEnum(IDPolicy.class, idPolicy); if (!IDPolicy.auto.equals(id)) { String pref = e.select("ref").text(); if (StringUtils.isNotBlank(pref)) { this.policyRef = pref; } if (StringUtils.isBlank(this.policyRef)) { try { throw new ConfigurationException("ID??"); } catch (Exception e2) { e2.printStackTrace(); } } } } return this; }
From source file:org.xlrnet.tibaija.memory.Variables.java
private static <E extends Enum<E>> E internalResolveVariableName(final Class<E> clazz, String variableName) { E result = EnumUtils.getEnum(clazz, variableName); if (result == null) throw new UndefinedVariableException(-1, -1, "Unknown variable name", variableName); return result; }
From source file:org.xlrnet.tibaija.processor.FullTIBasicVisitor.java
private int internalHandleSkipFlowLogic(int currentCommandCounter, List<TIBasicParser.CommandContext> commandList, Stack<ControlFlowElement.ControlFlowToken> skipCommandsStack, TIBasicParser.CommandContext nextCommand) { int commandListSize = commandList.size(); final String enumName = nextCommand.controlFlowStatement().flowType; ControlFlowElement.ControlFlowToken currentFlowToken = EnumUtils .getEnum(ControlFlowElement.ControlFlowToken.class, enumName); ControlFlowElement.ControlFlowToken topToken = skipCommandsStack.peek(); if (currentFlowToken == null) { throw new IllegalStateException( "Internal error: control flow token is null at command " + currentCommandCounter); }/*from www . j av a 2 s . c om*/ switch (currentFlowToken) { case IF: // Look ahead if the next command might be a "Then" i.e. if it is a controlflow statement if (commandListSize <= currentCommandCounter + 1) { throw new IllegalControlFlowException(-1, -1, "Illegal 'If' at the end of the program"); } else if (commandList.get(currentCommandCounter + 1).isControlFlowStatement) { skipCommandsStack.push(currentFlowToken); LOGGER.debug("Predicted multiline IF while skipping over command {}", currentCommandCounter); } else { LOGGER.debug("Skipping over single line IF at command {}", currentCommandCounter); currentCommandCounter++; } break; case THEN: if (topToken != ControlFlowElement.ControlFlowToken.IF) throw new IllegalControlFlowException(-1, -1, "Illegal 'Then' Statement without preceding 'If'"); skipCommandsStack.pop(); skipCommandsStack.push(currentFlowToken); break; case ELSE: if (skipCommandsStack.size() > 1 && topToken != ControlFlowElement.ControlFlowToken.THEN) throw new IllegalControlFlowException(-1, -1, "Illegal 'Else' Statement without preceding 'Then' "); skipCommandsStack.pop(); if (!skipCommandsStack.empty()) skipCommandsStack.push(topToken); break; case FOR: case WHILE: case REPEAT: skipCommandsStack.push(currentFlowToken); break; case END: skipCommandsStack.pop(); break; case GOTO: case LABEL: break; default: throw new IllegalStateException("Illegal flow token: " + currentFlowToken); } if (skipCommandsStack.empty()) { LOGGER.debug("Skip stack is now empty - continuing execution at command {}", currentCommandCounter + 1); } return currentCommandCounter; }
From source file:org.xwiki.extension.internal.validator.AbstractExtensionValidator.java
protected void checkAccess(Right entityRight, String namespaceString, Request request) throws AccessDeniedException { Namespace namespace = NamespaceUtils.toNamespace(namespaceString); // Root namespace if (namespace == null) { checkRootRight(entityRight, request); return;/*from w w w. j av a 2s .c o m*/ } if (namespace.getType() != null) { // User if (namespace.getType().equals("user")) { EntityReference reference = this.resolver.resolve(namespace.getValue(), EntityType.DOCUMENT); checkUserRight(reference, request); return; } // Entity EntityType entityType = EnumUtils.getEnum(EntityType.class, namespace.getType().toUpperCase()); if (entityType != null) { EntityReference reference = this.resolver.resolve(namespace.getValue(), entityType); checkAccess(reference, entityRight, request); return; } } // Unknown namespace checkNamespaceRight(namespace, Right.PROGRAM, request); }