本文整理汇总了Java中org.javalite.common.Inflector类的典型用法代码示例。如果您正苦于以下问题:Java Inflector类的具体用法?Java Inflector怎么用?Java Inflector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Inflector类属于org.javalite.common包,在下文中一共展示了Inflector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMethod
import org.javalite.common.Inflector; //导入依赖的package包/类
protected StringWriter createMethod(EntityNodePath path, boolean bulk, String method) throws Exception {
Template template = getMethodTemplate(path, bulk, method);
if (template == null) {
// TODO Can't get here. Handle if it still gets here
return new StringWriter();
}
VelocityContext context = new VelocityContext();
context.put("inflector", Inflector.class);
context.put("generator", this);
context.put("path", path);
if (bulk) {
context.put("param_names", new RoutePattern(path.getBulkPath()).getParameterNames());
} else {
context.put("param_names", new RoutePattern(path.getSinglePath()).getParameterNames());
}
StringWriter writer = new StringWriter();
template.merge(context, writer);
return writer;
}
示例2: createApplicationConfiguration
import org.javalite.common.Inflector; //导入依赖的package包/类
private ApplicationConfiguration createApplicationConfiguration() {
ApplicationConfiguration configuration = new ApplicationConfiguration(Inflector.tableize(applicationName));
DatabaseConfiguration databaseConfiguration = new DatabaseConfiguration();
databaseConfiguration.setDriverClass("org.h2.Driver");
databaseConfiguration.setIdleConnectionTestPeriod(300);
databaseConfiguration.setMinSize(5);
databaseConfiguration.setMaxSize(10);
databaseConfiguration.setPackagesToScan(Arrays.asList(getBasePackage()));
databaseConfiguration.setUrl("jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
databaseConfiguration.setUsername("sa");
Map<String, String> properties = new HashMap<String, String>();
properties.put("hibernate.ejb.naming_strategy", "org.hibernate.cfg.ImprovedNamingStrategy");
properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
properties.put("hibernate.current_session_context_class", "thread");
properties.put("hibernate.hbm2ddl.auto", "create-drop");
databaseConfiguration.setProviderProperties(properties);
configuration.setPackagesToScan(Arrays.asList(getBasePackage()));
configuration.setDatabaseConfiguration(databaseConfiguration);
configuration.setInstrumentationEnabled(enableInstrumentation);
return configuration;
}
示例3: toXml
import org.javalite.common.Inflector; //导入依赖的package包/类
/**
* Generates a XML document from content of this list.
*
* @param pretty pretty format (human readable), or one line text.
* @param declaration true to include XML declaration at the top
* @param attrs list of attributes to include. No arguments == include all attributes.
* @return generated XML.
*/
public String toXml(boolean pretty, boolean declaration, String... attrs) {
String topNode = Inflector.pluralize(Inflector.underscore(metaModel.getModelClass().getSimpleName()));
hydrate();
StringBuilder sb = new StringBuilder();
if(declaration) {
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
if (pretty) sb.append('\n');
}
sb.append('<').append(topNode).append('>');
if (pretty) { sb.append('\n'); }
for (T t : delegate) {
t.toXmlP(sb, pretty, pretty ? " " : "", attrs);
}
sb.append("</").append(topNode).append('>');
if (pretty) { sb.append('\n'); }
return sb.toString();
}
示例4: generate
import org.javalite.common.Inflector; //导入依赖的package包/类
@Override
public void generate() {
String packageName = entityClass.getPackage().getName() + ".generated";
String testClass = entityClass.getSimpleName() + "ResourceTest";
StringBuffer buffer = new StringBuffer();
for (EntityNodePath path : paths) {
createMethods(path, buffer);
}
VelocityContext context = new VelocityContext();
context.put("inflector", Inflector.class);
context.put("package_name", packageName);
context.put("methods", buffer.toString());
context.put("resource_class", testClass);
context.put("base_test_class", baseTestClass);
StringWriter writer = new StringWriter();
createResourceTestClassTemplate.merge(context, writer);
File folder = createPackage(packageName, TEST_JAVA_FOLDER);
String fileName = testClass + ".java";
File file = new File(folder, fileName);
if (file.exists()) {
File renamedFile = new File(folder, fileName + ".bk");
if (!file.renameTo(renamedFile)) {
throw new IllegalStateException("Failed while renaming the file " + file.getPath() + " to " + renamedFile.getPath());
}
file = new File(folder, fileName);
}
writeFile(CodeUtils.format(writer.toString()), file);
}
示例5: createApplicationClass
import org.javalite.common.Inflector; //导入依赖的package包/类
protected void createApplicationClass() {
String applicationClass = Inflector.shortName(getApplicationClassName());
String applicationConfigClass = Inflector.shortName(getApplicationConfigClassName());
VelocityContext context = new VelocityContext();
context.put("packageName", getBasePackage());
context.put("applicationClassName", applicationClass);
context.put("applicationConfigClassName", applicationConfigClass);
context.put("enableJpa", enableJpa);
writeFile(createApplicationTemplate, context, new File(createPackage(getBasePackage()), applicationClass + ".java"));
}
示例6: createApplicationConfigClass
import org.javalite.common.Inflector; //导入依赖的package包/类
protected void createApplicationConfigClass() {
String applicationConfigClass = Inflector.shortName(getApplicationConfigClassName());
VelocityContext context = new VelocityContext();
context.put("packageName", getBasePackage());
context.put("applicationConfigClassName", applicationConfigClass);
writeFile(createApplicationConfigTemplate, context, new File(createPackage(getBasePackage()), applicationConfigClass + ".java"));
}
示例7: generate
import org.javalite.common.Inflector; //导入依赖的package包/类
@Override
public void generate() {
logger.info("Generating the model class {} under the package {}", model.getName(), getDomainPackage());
VelocityContext context = new VelocityContext();
context.put("inflector", Inflector.class);
context.put("model", model);
context.put("packageName", getDomainPackage());
writeFile(createModelTemplate, context, new File(createPackage(getDomainPackage()), model.getName() + ".java"));
}
示例8: buildPath
import org.javalite.common.Inflector; //导入依赖的package包/类
private void buildPath(List<EntityNode> path) {
StringWriter writer = new StringWriter();
Iterator<EntityNode> iterator = iterator();
StringBuffer prefix = new StringBuffer();
EntityNode parent = null;
StringWriter pathName = new StringWriter();
while (iterator.hasNext()) {
EntityNode node = iterator.next();
String name = node.getResourceName();
pathName.append(node.getName());
writer.append("/").append(name);
if (iterator.hasNext()) {
writer.append("/{" + namingStrategy.getPathSegment(node.getName() + "Id") + "}");
pathName.append("_");
}
if (! iterator.hasNext()) {
if (parent != null) {
prefix = prefix.length() == 0 ? prefix.append(name) : prefix.append(".").append(name);
}
addSearchFields(prefix.toString(), node);
}
parent = node;
}
bulkPath = writer.toString();
singlePath = bulkPath + "/{id}";
name = Inflector.camelize(pathName.toString());
}
示例9: getFilter
import org.javalite.common.Inflector; //导入依赖的package包/类
public static Filter getFilter(MultivaluedMap<String, String> queryParams, final List<String> paramNames) {
Filter filter = getFilter(queryParams);
for (Entry<String, List<String>> entry : queryParams.entrySet()) {
if (! paramNames.contains(entry.getKey())) {
continue;
}
if (entry.getValue().size() == 1) {
filter.addCondition(Inflector.camelize(entry.getKey(), false), entry.getValue().get(0));
} else {
filter.addCondition(Inflector.camelize(entry.getKey(), false), Operator.in, entry.getValue());
}
}
return filter;
}
示例10: createMethodBody
import org.javalite.common.Inflector; //导入依赖的package包/类
/**
* Creates the method body
*
* @param context
* @return
*/
protected String createMethodBody(VelocityContext context) {
context.put("inflector", Inflector.class);
context.put("path", resourcePath.getNodePath());
context.put("param_names", getRoutePattern().getParameterNames());
Template template = getTemplate();
StringWriter writer = new StringWriter();
logger.debug("Creating the method body with context {} and template {} for the resource path {} and method {}", context, template.getName(), resourcePath, getHttpMethod());
template.merge(context, writer);
return writer.toString();
}
示例11: toResponse
import org.javalite.common.Inflector; //导入依赖的package包/类
@Override
public Response toResponse(ConstraintViolationException exception) {
ConstraintViolationException ex = (ConstraintViolationException) exception;
List<FieldError> errors = new ArrayList<FieldError>();
for (ConstraintViolation<?> violation : ex.getConstraintViolations()) {
errors.add(new FieldError(Inflector.underscore(violation.getPropertyPath().toString()), violation.getMessage(), violation.getInvalidValue()));
}
Map<String, List<FieldError>> message = new HashMap<String, List<FieldError>>();
message.put("fieldErrors", errors);
return Response.status(UnprocessableEntityStatusType.INSTANCE).entity(message).build();
}
示例12: init
import org.javalite.common.Inflector; //导入依赖的package包/类
@Override
public void init() {
applicationName = Inflector.camelize(baseDir.getName().toLowerCase().replace('-', '_'));
}
示例13: getBasePackage
import org.javalite.common.Inflector; //导入依赖的package包/类
protected String getBasePackage() {
return "com." + Inflector.underscore(applicationName).replace('_', '.');
}
示例14: getEntityName
import org.javalite.common.Inflector; //导入依赖的package包/类
@Override
public String getEntityName(Class<?> entityClass) {
return Inflector.camelize(Inflector.underscore(entityClass.getSimpleName()), false);
}
示例15: getResourceName
import org.javalite.common.Inflector; //导入依赖的package包/类
@Override
public String getResourceName(String entityName) {
return Inflector.tableize(entityName);
}