当前位置: 首页>>代码示例>>Java>>正文


Java StringTemplate类代码示例

本文整理汇总了Java中org.antlr.stringtemplate.StringTemplate的典型用法代码示例。如果您正苦于以下问题:Java StringTemplate类的具体用法?Java StringTemplate怎么用?Java StringTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StringTemplate类属于org.antlr.stringtemplate包,在下文中一共展示了StringTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: restartmanager

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
public void restartmanager(HttpExchange exchange) throws IOException
{
	StringTemplate st = templates.getInstanceOf("templates/restartingmanager");
	HttpExchangeUtils.respondHtmlMessage(exchange, 200, st.toString());

	// Restart manager in a new thread after a 500ms wait to ensure that the
	// response has been sent and flushed properly.
	new Thread()
	{
		@Override
		public void run()
		{
			try
			{
				sleep(500);
			}
			catch( InterruptedException e )
			{
				e.printStackTrace();
			}
			new ServiceWrapper(config).restartmanager();
		}
	}.start();
}
 
开发者ID:equella,项目名称:Equella,代码行数:25,代码来源:PagesHandler.java

示例2: writeTemplate

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
/**
 * Writes the populated template to an output writer by providing a closure with access to
 * the unpopulated template object.
 *
 * @param out Template output writer.
 * @param parameterSetter Consumer to populate the template.
 * @throws TemplateException If an exception was encountered while populating the template.
 */
public void writeTemplate(
    Writer out,
    Consumer<StringTemplate> parameterSetter) throws TemplateException {

  Preconditions.checkNotNull(out);
  Preconditions.checkNotNull(parameterSetter);

  StringTemplate stringTemplate = group.getInstanceOf(templatePath);
  try {
    parameterSetter.accept(stringTemplate);
    stringTemplate.write(new AutoIndentWriter(out));
  } catch (IOException e) {
    throw new TemplateException("Failed to write template: " + e, e);
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:24,代码来源:StringTemplateHelper.java

示例3: generateClasses

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
public Map<String, StringTemplate> generateClasses(Class<? extends Storable> storableClass, StorableAttributes storableAttribute,
        Optional<Class<? extends StorableSerDeserHelper>> serDeserClass, Optional<Class<? extends Storable>> extendedClass) {
    Map<String, StringTemplate> map = new HashMap<>();

    PathAndTemplate indexInfo = generateIndexInfoClass(storableAttribute.getTypeName(), storableAttribute.getPackagePath(), storableAttribute.getSdkName(),
            storableAttribute.getPackageName(), storableAttribute.getIndices(), storableAttribute.getFieldNameToType());
    map.put(indexInfo.getPath(), indexInfo.getTemplate());

    PathAndTemplate storableInfo = generateStorableInfoClass(storableAttribute.getTypeName(), storableAttribute.getPackagePath(),
            storableAttribute.getSdkName(),
            storableAttribute.getPackageName(), storableAttribute.getCacheable());
    map.put(storableInfo.getPath(), storableInfo.getTemplate());

    PathAndTemplate storage = generateStorageClass(storableClass, storableAttribute, serDeserClass, extendedClass);
    map.put(storage.getPath(), storage.getTemplate());

    return map;
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:19,代码来源:StorableClassesFactory.java

示例4: generateStorageClass

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
private PathAndTemplate generateStorageClass(Class<? extends Storable> storableClass, StorableAttributes storableAttributes,
        Optional<Class<? extends StorableSerDeserHelper>> serDeserClass, Optional<Class<? extends Storable>> extendedClass) {
    String storageClassFullPath =
            AbstractTTree.GEN_PATH_PREFIX_JAVA + storableAttributes.getPackagePath() + "/" + storableAttributes.getTypeName() + "Storage.java";

    StringTemplate objectMapperTemplate;
    objectMapperTemplate = templateLib.getInstanceOf("beanStorage_objectMapper");

    ImmutableMap.Builder<String, Object> storageClassAttributes = storableAttributes.getStorageClassAttributes();
    if (serDeserClass.isPresent()) {
        if (extendedClass == null) {
            throw RaptureExceptionFactory.create(String
                    .format("Serializer/deserializer [%s] found for storable [%s], but no extended class found!", serDeserClass.get().getName(),
                            storableClass.getName()));
        }
    }
    storageClassAttributes.put("serDeserCode", createSerDeserTemplate(storableClass, storableAttributes.getTypeName(), serDeserClass));
    storageClassAttributes.put("serDeserImports", createImportsTemplate(serDeserClass, extendedClass, storableAttributes.getSdkName()));

    storageClassAttributes.put("objectMapper", objectMapperTemplate).build();
    StringTemplate storageClass = getTemplateLib().getInstanceOf("beanStorageClass", storageClassAttributes.build());

    return new PathAndTemplate(storageClassFullPath, storageClass);
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:25,代码来源:StorableClassesFactory.java

示例5: createImportsTemplate

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
private StringTemplate createImportsTemplate(Optional<Class<? extends StorableSerDeserHelper>> serDeserClass,
        Optional<Class<? extends Storable>> extendedClass,
        String sdkName) {
    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    if (serDeserClass.isPresent()) {
        builder.put("serDeserFullName", serDeserClass.get().getName());
    }
    if (extendedClass.isPresent()) {
        builder.put("extendedName", extendedClass.get().getName());
    }
    String apiVersionName;
    if (sdkName != null) {
        apiVersionName = String.format("rapture.%s.server.ServerApiVersion", sdkName);
    } else {
        apiVersionName = "rapture.server.ServerApiVersion";
    }
    builder.put("apiVersionName", apiVersionName);

    return getTemplateLib().getInstanceOf("beanStorage_serDeserImports", builder.build());
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:21,代码来源:StorableClassesFactory.java

示例6: generatePersistenceFiles

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
public Map<String, StringTemplate> generatePersistenceFiles(List<StorableAttributes> storableAttributes, StorableSerDeserRepo storableMappersRepo) {
    StorableClassesFactory factory = new StorableClassesFactory(templateLib);

    Map<String, StringTemplate> pathToTemplate = new HashMap<>();

    for (StorableAttributes storableAttribute : storableAttributes) {
        String typeName = storableAttribute.getTypeName();
        String packageName = storableAttribute.getPackageName();
        Class<? extends Storable> storableClass;
        try {
            //noinspection unchecked
            storableClass = (Class<? extends Storable>) Class.forName(String.format("%s.%s", packageName, typeName));
        } catch (ClassNotFoundException e) {
            throw RaptureExceptionFactory.create(ExceptionToString.format(e));
        }
        Class<? extends StorableSerDeserHelper> serDeserHelper = storableMappersRepo.getSerDeserHelper(storableClass);

        pathToTemplate.putAll(factory
                .generateClasses(storableClass, storableAttribute, Optional.<Class<? extends StorableSerDeserHelper>>fromNullable(serDeserHelper),
                        Optional.<Class<? extends Storable>>fromNullable(storableMappersRepo.getExtendedClass(storableClass))));

    }
    return pathToTemplate;
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:25,代码来源:Generator.java

示例7: writeTemplates

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
/**
 * Write templates to files. If you have files composed of multiple templates, look at {@link #writeMultiPartTemplates(String, Map)}
 *
 * @param rootFolder
 * @param pathToTemplate
 */
public static void writeTemplates(String rootFolder, Map<String, StringTemplate> pathToTemplate) {
    for (Map.Entry<String, StringTemplate> entry : pathToTemplate.entrySet()) {
        String filename = entry.getKey();

        File file = new File(rootFolder, filename);
        file.getParentFile().mkdirs();

        StringTemplate template = entry.getValue();
        try {
            FileUtils.write(file, template.toString());
        } catch (IOException e) {
            System.err.println("Error writing template: " + ExceptionToString.format(e));
        }

    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:23,代码来源:OutputWriter.java

示例8: createIndexTemplate

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
public static StringTemplate createIndexTemplate(String typeName, String sdkName, String packageName, List<IndexedAnnotation> indices,
        Map<String, String> fieldNameToType, StringTemplateGroup templateLib) {
    AbstractTTree.STAttrMap attrMap = new AbstractTTree.STAttrMap().put("name", typeName).put("sdkName", sdkName).put("package", packageName);

    List<StringTemplate> functionCalls = new LinkedList<StringTemplate>();
    List<StringTemplate> functionDefinitions = new LinkedList<StringTemplate>();
    for (IndexedAnnotation indexedAnnotation : indices) {
        StringTemplate createIndexDefinition = createIndexDefinitionTemplate(templateLib, packageName, typeName, indexedAnnotation, fieldNameToType);
        functionDefinitions.add(createIndexDefinition);

        StringTemplate indexCall = createIndexCallTemplate(templateLib, indexedAnnotation);
        functionCalls.add(indexCall);
    }

    if (indices.size() > 0) {
        attrMap.put("functionDefinitions", functionDefinitions);
        attrMap.put("functionCalls", functionCalls);
    }

    return templateLib.getInstanceOf("beanIndexInfoClass", attrMap);
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:22,代码来源:IndexTemplateFactory.java

示例9: createEntityEventType

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
private void createEntityEventType(ActionScriptType entityEventType,
        FlexScaffoldMetadata flexScaffoldMetadata) {
    ActionScriptType entityType = ActionScriptMappingUtils
            .toActionScriptType(flexScaffoldMetadata.getEntity());
    StringTemplate entityEventTemplate = this.templateGroup
            .getInstanceOf("org/gvnix/flex/roo/addon/ui/entity_event");
    entityEventTemplate.setAttribute("entityEventType", entityEventType);
    entityEventTemplate.setAttribute("entityType", entityType);
    entityEventTemplate.setAttribute("flexScaffoldMetadata",
            flexScaffoldMetadata);

    String relativePath = entityEventType.getFullyQualifiedTypeName()
            .replace('.', File.separatorChar) + ".as";
    String fileIdentifier = getPathResolver().getIdentifier(
            LogicalPath.getInstance(Path.ROOT, ""),
            "src/main/flex/" + relativePath);
    getFileManager().createOrUpdateTextFileIfRequired(fileIdentifier,
            entityEventTemplate.toString(), true);
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:20,代码来源:FlexUIMetadataProvider.java

示例10: buildListViewDocument

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
private Document buildListViewDocument(
        FlexScaffoldMetadata flexScaffoldMetadata,
        List<FieldMetadata> elegibleFields) {
    ActionScriptType entityType = ActionScriptMappingUtils
            .toActionScriptType(flexScaffoldMetadata.getEntity());
    StringTemplate listViewTemplate = this.templateGroup
            .getInstanceOf("org/gvnix/flex/roo/addon/ui/entity_list_view");
    listViewTemplate.setAttribute("entityType", entityType);
    listViewTemplate.setAttribute("flexScaffoldMetadata",
            flexScaffoldMetadata);
    listViewTemplate.setAttribute("fields", elegibleFields);

    try {
        ByteArrayInputStream stream = new ByteArrayInputStream(
                listViewTemplate.toString().getBytes("UTF-8"));
        return XmlUtils.getDocumentBuilder().parse(stream);
    }
    catch (Exception e) {
        throw new IllegalStateException(
                "Failed to build list view document", e);
    }
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:23,代码来源:FlexUIMetadataProvider.java

示例11: buildFormDocument

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
private Document buildFormDocument(
        FlexScaffoldMetadata flexScaffoldMetadata,
        List<FieldMetadata> elegibleFields) {
    ActionScriptType entityType = ActionScriptMappingUtils
            .toActionScriptType(flexScaffoldMetadata.getEntity());
    StringTemplate listViewTemplate = this.templateGroup
            .getInstanceOf("org/gvnix/flex/roo/addon/ui/entity_form");
    listViewTemplate.setAttribute("entityType", entityType);
    listViewTemplate.setAttribute("flexScaffoldMetadata",
            flexScaffoldMetadata);
    listViewTemplate.setAttribute("fields", wrapFields(elegibleFields));
    Set<RelatedTypeWrapper> relatedTypes = findRelatedTypes(
            flexScaffoldMetadata, elegibleFields);
    listViewTemplate.setAttribute("relatedTypes", relatedTypes);
    listViewTemplate.setAttribute("labelFields",
            calculateLabelFields(relatedTypes));
    try {
        ByteArrayInputStream stream = new ByteArrayInputStream(
                listViewTemplate.toString().getBytes("UTF-8"));
        return XmlUtils.getDocumentBuilder().parse(stream);
    }
    catch (Exception e) {
        throw new IllegalStateException(
                "Failed to build list view document", e);
    }
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:27,代码来源:FlexUIMetadataProvider.java

示例12: toString

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
/**
 * @return the text of a Type&lt;T&gt; object for the T class.
 */
@Override
public String toString() {
  StringTemplate t = template.getInstanceOf("type");
  HashMap<String, Object> map = new HashMap<String, Object>();
  map.put("typeName", this.typeName);
  map.put("package", this.typePackage);
  map.put("orders", this.typeOrders);
  map.put("fields", this.typeFields);

  boolean containsArray = false;
  for (Field f : typeFields) {
    containsArray = containsArray || f.isArray;
  }
  map.put("containsArray", containsArray);
  t.setAttributes(map);
  return t.toString();
}
 
开发者ID:teanalab,项目名称:demidovii,代码行数:21,代码来源:TemplateTypeBuilder.java

示例13: write

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
private void write(StringTemplate st, File output) throws IOException {
  output.getParentFile().mkdirs();
  BufferedWriter writer = new BufferedWriter(new FileWriter(output));
  try {
    writer.write(st.toString());
  } finally {
    try {
      writer.close();
    } catch (IOException e) {
      // If another exception is already propagating, we don't
      // want to throw a secondary one.
      // This means that exceptions on close() are ignored,
      // but what could usefully be done for a close()
      // exception anyway?
    }
  }
  styler.style(output, saveBackups);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:19,代码来源:Pst.java

示例14: getDOT

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
/** Return a String containing a DOT description that, when displayed,
   *  will show the incoming state machine visually.  All nodes reachable
   *  from startState will be included.
   */
  public String getDOT(State startState) {
      // The output DOT graph for visualization
StringTemplate dot = null;
markedStates = new HashSet();
      if ( startState instanceof DFAState ) {
          dot = stlib.getInstanceOf("org/antlr/tool/templates/dot/dfa");
	dot.setAttribute("startState",
			Utils.integer(startState.stateNumber));
	dot.setAttribute("useBox",
					 Boolean.valueOf(Tool.internalOption_ShowNFConfigsInDFA));
	walkCreatingDFADOT(dot, (DFAState)startState);
      }
      else {
          dot = stlib.getInstanceOf("org/antlr/tool/templates/dot/nfa");
	dot.setAttribute("startState",
			Utils.integer(startState.stateNumber));
	walkRuleNFACreatingDOT(dot, startState);
      }
dot.setAttribute("rankdir", rankdir);
      return dot.toString();
  }
 
开发者ID:Sable,项目名称:mclab-core,代码行数:26,代码来源:DOTGenerator.java

示例15: toString

import org.antlr.stringtemplate.StringTemplate; //导入依赖的package包/类
public String toString() {
	line = 0;
	column = 0;
	if ( offendingToken!=null ) {
		line = offendingToken.getLine();
		column = offendingToken.getColumn();
	}
	if ( g!=null ) {
		file = g.getFileName();
	}
	StringTemplate st = getMessageTemplate();
	if ( arg!=null ) {
		st.setAttribute("arg", arg);
	}
	if ( arg2!=null ) {
		st.setAttribute("arg2", arg2);
	}
	return super.toString(st);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:20,代码来源:GrammarSemanticsMessage.java


注:本文中的org.antlr.stringtemplate.StringTemplate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。