Java 类org.apache.velocity.runtime.parser.ParseException 实例源码

项目:PackageTemplates    文件:AttributesHelper.java   
public static String[] getUnsetAttributes(FileTemplate fileTemplate, PackageTemplateWrapper ptWrapper) {
    HashSet<String> defaultAttributeNames = getDefaultAttributeNames(ptWrapper.getProject());

    // Add globals vars
    for (GlobalVariable variable : ptWrapper.getPackageTemplate().getListGlobalVariable()) {
        defaultAttributeNames.add(variable.getName());
    }

    Properties properties = new Properties();
    for (String item : defaultAttributeNames) {
        properties.put(item, "fakeValue");
    }

    //parse
    try {
        return fileTemplate.getUnsetAttributes(properties, ptWrapper.getProject());
    } catch (ParseException e) {
        Logger.log("getUnsetAttributes ex: " + e.getMessage());
        Logger.printStack(e);
        return new String[0];
    }
}
项目:motech    文件:VelocityTemplateParser.java   
public String mergeTemplateIntoString(String templateFilename, Map<String, Object> params)
        throws VelocityTemplateParsingException {
    try (InputStream is = settingsFacade.getRawConfig(templateFilename)) {
        StringReader reader = new StringReader(IOUtils.toString(is));
        SimpleNode node = rs.parse(reader, templateFilename);

        Template template = new Template();
        template.setRuntimeServices(rs);
        template.setData(node);
        template.initDocument();

        StringWriter writer = new StringWriter();
        template.merge(new VelocityContext(params), writer);
        return writer.toString();
    } catch (ParseException|IOException e) {
        throw new VelocityTemplateParsingException("Couldn't merge template into string", e);
    }
}
项目:connector-certification-tools    文件:DirectoryStructureRule.java   
private void initTemplate(@NonNull final String verifyExpression) throws ParseException {

        // Init pattern ...
        final RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();

        final StringReader reader = new StringReader(verifyExpression);
        SimpleNode node = runtimeServices.parse(reader, this.getDocumentation().getId());

        final Template template = new Template();
        template.setRuntimeServices(runtimeServices);
        template.setData(node);
        template.initDocument();
        this.template = template;

        // Parse expression looking for variable ...
        final Pattern pattern = Pattern.compile(VELOCITY_VARIABLE);
        final Matcher matcher = pattern.matcher(verifyExpression);

        while (matcher.find()) {
            final String key = matcher.group(1);
            final ClassProperty property = ClassProperty.to(key);
            this.templateProperties.add(property);
        }

    }
项目:FileTemplatesVariable    文件:PerProjectTemplateManager.java   
public Set<String> getAllFileTemplatesVariables() {
    Set<String> result = new TreeSet<String>();
    List<FileTemplate> allTemplates = new ArrayList<FileTemplate>();
    FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance();
    FileTemplate[] templates = fileTemplateManager.getAllTemplates();
    FileTemplate[] patterns = fileTemplateManager.getAllPatterns();
    FileTemplate[] codeTemplates = fileTemplateManager.getAllCodeTemplates();
    FileTemplate[] j2eeTemplates = fileTemplateManager.getAllJ2eeTemplates();
    allTemplates.addAll(Arrays.asList(templates));
    allTemplates.addAll(Arrays.asList(codeTemplates));
    allTemplates.addAll(Arrays.asList(j2eeTemplates));
    allTemplates.addAll(Arrays.asList(patterns));

    for (FileTemplate template : allTemplates) {
        try {
            String[] variables = FileTemplateUtil.calculateAttributes(template.getText(), new Properties(), true, myProject);
            result.addAll(Arrays.asList(variables));
        } catch (ParseException e) {
            logger.warn("Parsing exception", e);
        }
    }
    return result;
}
项目:idea-php-class-templates    文件:PhpNewTemplateClassDialog.java   
private void updateTemplateAttributes() {
    FileTemplate template = (FileTemplate) ((Trinity) this.myKindComboBox.getSelectedItem()).getThird();

    if (template.equals(this.myCurrentTemplate)) {
        return;
    }

    this.myCurrentTemplate = template;
    this.myTemplateAttributes.getPanel().removeAll();
    this.myTemplateAttributesFields.clear();

    String[] attrs = new String[0];
    try {
        attrs = template.getUnsetAttributes(this.getProperties(this.getDirectory()), this.myProject);
    } catch (ParseException e1) {
        e1.printStackTrace();
    }

    List<String> ignoredAttributes = Arrays.asList("PROJECT_NAME", "FILE_NAME", "NAME", "USER", "DATE", "TIME", "YEAR", "MONTH", "DAY", "HOUR", "MINUTE", "PRODUCT_NAME", "MONTH_NAME_SHORT", "MONTH_NAME_FULL", "NAME", "NAMESPACE", "CLASS_NAME", "STATIC", "TYPE_HINT", "PARAM_DOC", "THROWS_DOC", "DS", "CARET");
    for (String attribute : attrs) {

        if (ignoredAttributes.contains(attribute)) {
            continue;
        }

        EditorTextField field = new EditorTextField();

        this.myTemplateAttributesFields.put(attribute, field);
        this.myTemplateAttributes.addLabeledComponent(attribute.concat(":"), field);
    }

    this.myTemplateAttributes.getPanel().revalidate();
    this.myTemplateAttributes.getPanel().repaint();
}
项目:iotplatform    文件:VelocityUtils.java   
public static Template create(String source, String templateName) throws ParseException {
  RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
  StringReader reader = new StringReader(source);
  SimpleNode node = runtimeServices.parse(reader, templateName);
  Template template = new Template();
  template.setRuntimeServices(runtimeServices);
  template.setData(node);
  template.initDocument();
  return template;
}
项目:iotplatform    文件:AlarmDeduplicationProcessor.java   
@Override
public void init(AlarmDeduplicationProcessorConfiguration configuration) {
  this.configuration = configuration;
  try {
    this.alarmIdTemplate = VelocityUtils.create(configuration.getAlarmIdTemplate(), "Alarm Id Template");
    this.alarmBodyTemplate = VelocityUtils.create(configuration.getAlarmBodyTemplate(), "Alarm Body Template");
  } catch (ParseException e) {
    log.error("Failed to create templates based on provided configuration!", e);
    throw new RuntimeException("Failed to create templates based on provided configuration!", e);
  }
}
项目:iotplatform    文件:SendMailAction.java   
@Override
public void init(SendMailActionConfiguration configuration) {
  this.configuration = configuration;
  try {
    fromTemplate = toTemplate(configuration.getFromTemplate(), "From Template");
    toTemplate = toTemplate(configuration.getToTemplate(), "To Template");
    ccTemplate = toTemplate(configuration.getCcTemplate(), "Cc Template");
    bccTemplate = toTemplate(configuration.getBccTemplate(), "Bcc Template");
    subjectTemplate = toTemplate(configuration.getSubjectTemplate(), "Subject Template");
    bodyTemplate = toTemplate(configuration.getBodyTemplate(), "Body Template");
  } catch (ParseException e) {
    log.error("Failed to create templates based on provided configuration!", e);
    throw new RuntimeException("Failed to create templates based on provided configuration!", e);
  }
}
项目:iotplatform    文件:SendMailAction.java   
private Optional<Template> toTemplate(String source, String name) throws ParseException {
  if (!StringUtils.isEmpty(source)) {
    return Optional.of(VelocityUtils.create(source, name));
  } else {
    return Optional.empty();
  }
}
项目:iotplatform    文件:AbstractTemplatePluginAction.java   
@Override
public void init(T configuration) {
  this.configuration = configuration;
  try {
    this.template = VelocityUtils.create(configuration.getTemplate(), "Template");
  } catch (ParseException e) {
    throw new RuntimeException(e.getMessage(), e);
  }
}
项目:thingsboard    文件:VelocityUtils.java   
public static Template create(String source, String templateName) throws ParseException {
    RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
    StringReader reader = new StringReader(source);
    SimpleNode node = runtimeServices.parse(reader, templateName);
    Template template = new Template();
    template.setRuntimeServices(runtimeServices);
    template.setData(node);
    template.initDocument();
    return template;
}
项目:thingsboard    文件:AlarmDeduplicationProcessor.java   
@Override
public void init(AlarmDeduplicationProcessorConfiguration configuration) {
    this.configuration = configuration;
    try {
        this.alarmIdTemplate = VelocityUtils.create(configuration.getAlarmIdTemplate(), "Alarm Id Template");
        this.alarmBodyTemplate = VelocityUtils.create(configuration.getAlarmBodyTemplate(), "Alarm Body Template");
    } catch (ParseException e) {
        log.error("Failed to create templates based on provided configuration!", e);
        throw new RuntimeException("Failed to create templates based on provided configuration!", e);
    }
}
项目:thingsboard    文件:ServerSideRpcCallAction.java   
@Override
public void init(ServerSideRpcCallActionConfiguration configuration) {
    this.configuration = configuration;
    try {
        deviceIdTemplate = toTemplate(configuration.getDeviceIdTemplate(), "Device Id Template");
        fromDeviceRelationTemplate = toTemplate(configuration.getFromDeviceRelationTemplate(), "From Device Relation Template");
        toDeviceRelationTemplate = toTemplate(configuration.getToDeviceRelationTemplate(), "To Device Relation Template");
        rpcCallMethodTemplate = toTemplate(configuration.getRpcCallMethodTemplate(), "RPC Call Method Template");
        rpcCallBodyTemplate = toTemplate(configuration.getRpcCallBodyTemplate(), "RPC Call Body Template");
    } catch (ParseException e) {
        log.error("Failed to create templates based on provided configuration!", e);
        throw new RuntimeException("Failed to create templates based on provided configuration!", e);
    }
}
项目:thingsboard    文件:ServerSideRpcCallAction.java   
private Optional<Template> toTemplate(String source, String name) throws ParseException {
    if (!StringUtils.isEmpty(source)) {
        return Optional.of(VelocityUtils.create(source, name));
    } else {
        return Optional.empty();
    }
}
项目:thingsboard    文件:SendMailAction.java   
@Override
public void init(SendMailActionConfiguration configuration) {
    this.configuration = configuration;
    try {
        fromTemplate = toTemplate(configuration.getFromTemplate(), "From Template");
        toTemplate = toTemplate(configuration.getToTemplate(), "To Template");
        ccTemplate = toTemplate(configuration.getCcTemplate(), "Cc Template");
        bccTemplate = toTemplate(configuration.getBccTemplate(), "Bcc Template");
        subjectTemplate = toTemplate(configuration.getSubjectTemplate(), "Subject Template");
        bodyTemplate = toTemplate(configuration.getBodyTemplate(), "Body Template");
    } catch (ParseException e) {
        log.error("Failed to create templates based on provided configuration!", e);
        throw new RuntimeException("Failed to create templates based on provided configuration!", e);
    }
}
项目:thingsboard    文件:SendMailAction.java   
private Optional<Template> toTemplate(String source, String name) throws ParseException {
    if (!StringUtils.isEmpty(source)) {
        return Optional.of(VelocityUtils.create(source, name));
    } else {
        return Optional.empty();
    }
}
项目:thingsboard    文件:AbstractTemplatePluginAction.java   
@Override
public void init(T configuration) {
    this.configuration = configuration;
    try {
        this.template = VelocityUtils.create(configuration.getTemplate(), "Template");
    } catch (ParseException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
项目:intellij-ce-playground    文件:CreateFromTemplateDialog.java   
public CreateFromTemplateDialog(@NotNull Project project,
                                @NotNull PsiDirectory directory,
                                @NotNull FileTemplate template,
                                @Nullable final AttributesDefaults attributesDefaults,
                                @Nullable final Properties defaultProperties) {
  super(project, true);
  myDirectory = directory;
  myProject = project;
  myTemplate = template;
  setTitle(IdeBundle.message("title.new.from.template", template.getName()));

  myDefaultProperties = defaultProperties == null ? FileTemplateManager.getInstance(project).getDefaultProperties() : defaultProperties;
  FileTemplateUtil.fillDefaultProperties(myDefaultProperties, directory);
  boolean mustEnterName = FileTemplateUtil.findHandler(template).isNameRequired();
  if (attributesDefaults != null && attributesDefaults.isFixedName()) {
    myDefaultProperties.setProperty(FileTemplate.ATTRIBUTE_NAME, attributesDefaults.getDefaultFileName());
    mustEnterName = false;
  }

  String[] unsetAttributes = null;
  try {
    unsetAttributes = myTemplate.getUnsetAttributes(myDefaultProperties, project);
  }
  catch (ParseException e) {
    showErrorDialog(e);
  }

  if (unsetAttributes != null) {
    myAttrPanel = new CreateFromTemplatePanel(unsetAttributes, mustEnterName, attributesDefaults);
    myAttrComponent = myAttrPanel.getComponent();
    init();
  }
  else {
    myAttrPanel = null;
    myAttrComponent = null;
  }
}
项目:intellij-ce-playground    文件:FileTemplateUtil.java   
public static String[] calculateAttributes(String templateContent, Properties properties, boolean includeDummies, Project project) throws ParseException {
  Set<String> propertiesNames = new HashSet<String>();
  for (Enumeration e = properties.propertyNames(); e.hasMoreElements(); ) {
    propertiesNames.add((String)e.nextElement());
  }
  return calculateAttributes(templateContent, propertiesNames, includeDummies, project);
}
项目:intellij-ce-playground    文件:FileTemplateUtil.java   
private static String[] calculateAttributes(String templateContent, Set<String> propertiesNames, boolean includeDummies, Project project) throws ParseException {
  final Set<String> unsetAttributes = new LinkedHashSet<String>();
  final Set<String> definedAttributes = new HashSet<String>();
  //noinspection HardCodedStringLiteral
  SimpleNode template = RuntimeSingleton.parse(new StringReader(templateContent), "MyTemplate");
  collectAttributes(unsetAttributes, definedAttributes, template, propertiesNames, includeDummies, new HashSet<String>(), project);
  for (String definedAttribute : definedAttributes) {
    unsetAttributes.remove(definedAttribute);
  }
  return ArrayUtil.toStringArray(unsetAttributes);
}
项目:RetroFacebook    文件:TemplateVars.java   
static SimpleNode parsedTemplateForResource(String templateStr, String resourceName) {
  try {
    return velocityRuntimeInstance.parse(templateStr, resourceName);
  } catch (ParseException e) {
    throw new AssertionError(e);
  }
}
项目:RetroFacebook    文件:TemplateVarsTest.java   
static SimpleNode parsedTemplateForString(String string) {
  try {
    Reader reader = new StringReader(string);
    return RuntimeSingleton.parse(reader, string);
  } catch (ParseException e) {
    throw new AssertionError(e);
  }
}
项目:RetroFacebook    文件:TemplateVars.java   
static SimpleNode parsedTemplateForResource(String templateStr, String resourceName) {
  try {
    return velocityRuntimeInstance.parse(templateStr, resourceName);
  } catch (ParseException e) {
    throw new AssertionError(e);
  }
}
项目:RetroFacebook    文件:TemplateVarsTest.java   
static SimpleNode parsedTemplateForString(String string) {
  try {
    Reader reader = new StringReader(string);
    return RuntimeSingleton.parse(reader, string);
  } catch (ParseException e) {
    throw new AssertionError(e);
  }
}
项目:AutoCursor    文件:TemplateVars.java   
static SimpleNode parsedTemplateForResource(String templateStr, String resourceName) {
  try {
    return velocityRuntimeInstance.parse(templateStr, resourceName);
  } catch (ParseException e) {
    throw new AssertionError(e);
  }
}
项目:AutoCursor    文件:TemplateVarsTest.java   
static SimpleNode parsedTemplateForString(String string) {
  try {
    Reader reader = new StringReader(string);
    return RuntimeSingleton.parse(reader, string);
  } catch (ParseException e) {
    throw new AssertionError(e);
  }
}
项目:velocity-edit    文件:VelocityMacroParser.java   
public static VelocityMacro[] parse (String content) {
    try {
        instance.content = content;
        return instance._parse(content);
    }
    catch (ParseException e) {
        return new VelocityMacro[0];
    }
}
项目:retrofit2.bak    文件:TemplateVars.java   
static SimpleNode parsedTemplateForResource(String templateStr, String resourceName) {
  try {
    return velocityRuntimeInstance.parse(templateStr, resourceName);
  } catch (ParseException e) {
    throw new AssertionError(e);
  }
}
项目:retrofit2.bak    文件:TemplateVarsTest.java   
static SimpleNode parsedTemplateForString(String string) {
  try {
    Reader reader = new StringReader(string);
    return RuntimeSingleton.parse(reader, string);
  } catch (ParseException e) {
    throw new AssertionError(e);
  }
}
项目:SimpleWeibo    文件:TemplateVars.java   
static SimpleNode parsedTemplateForResource(String templateStr, String resourceName) {
  try {
    return velocityRuntimeInstance.parse(templateStr, resourceName);
  } catch (ParseException e) {
    throw new AssertionError(e);
  }
}
项目:SimpleWeibo    文件:TemplateVarsTest.java   
static SimpleNode parsedTemplateForString(String string) {
  try {
    Reader reader = new StringReader(string);
    return RuntimeSingleton.parse(reader, string);
  } catch (ParseException e) {
    throw new AssertionError(e);
  }
}
项目:connector-certification-tools    文件:DirectoryStructureRule.java   
public DirectoryStructureRule(@NonNull final Documentation documentation, @NonNull String accept, @NonNull final String assertExp) {
    super(documentation, "pom.xml$");
    this.templateProperties = new LinkedHashSet<>();

    try {
        this.initTemplate(assertExp);
    } catch (ParseException e) {
        throw new DevKitSonarRuntimeException(e);
    }
}
项目:AutoJson    文件:TemplateVars.java   
static SimpleNode parsedTemplateForResource(String templateStr, String resourceName) {
  try {
    return velocityRuntimeInstance.parse(templateStr, resourceName);
  } catch (ParseException e) {
    throw new AssertionError(e);
  }
}
项目:AutoJson    文件:TemplateVarsTest.java   
static SimpleNode parsedTemplateForString(String string) {
  try {
    Reader reader = new StringReader(string);
    return RuntimeSingleton.parse(reader, string);
  } catch (ParseException e) {
    throw new AssertionError(e);
  }
}
项目:tools-idea    文件:CreateFromTemplateDialog.java   
public CreateFromTemplateDialog(@NotNull Project project,
                                @NotNull PsiDirectory directory,
                                @NotNull FileTemplate template,
                                @Nullable final AttributesDefaults attributesDefaults,
                                @Nullable final Properties defaultProperties) {
  super(project, true);
  myDirectory = directory;
  myProject = project;
  myTemplate = template;
  setTitle(IdeBundle.message("title.new.from.template", template.getName()));

  myDefaultProperties = defaultProperties == null ? FileTemplateManager.getInstance().getDefaultProperties(project) : defaultProperties;
  FileTemplateUtil.fillDefaultProperties(myDefaultProperties, directory);
  boolean mustEnterName = FileTemplateUtil.findHandler(template).isNameRequired();
  if (attributesDefaults != null && attributesDefaults.isFixedName()) {
    myDefaultProperties.setProperty(FileTemplate.ATTRIBUTE_NAME, attributesDefaults.getDefaultFileName());
    mustEnterName = false;
  }

  String[] unsetAttributes = null;
  try {
    unsetAttributes = myTemplate.getUnsetAttributes(myDefaultProperties);
  }
  catch (ParseException e) {
    showErrorDialog(e);
  }

  if (unsetAttributes != null) {
    myAttrPanel = new CreateFromTemplatePanel(unsetAttributes, mustEnterName, attributesDefaults);
    myAttrComponent = myAttrPanel.getComponent();
    init();
  }
  else {
    myAttrPanel = null;
    myAttrComponent = null;
  }
}
项目:tools-idea    文件:FileTemplateUtil.java   
public static String[] calculateAttributes(String templateContent, Properties properties, boolean includeDummies) throws ParseException {
  Set<String> propertiesNames = new HashSet<String>();
  for (Enumeration e = properties.propertyNames(); e.hasMoreElements(); ) {
    propertiesNames.add((String)e.nextElement());
  }
  return calculateAttributes(templateContent, propertiesNames, includeDummies);
}
项目:tools-idea    文件:FileTemplateUtil.java   
public static String[] calculateAttributes(String templateContent, Set<String> propertiesNames, boolean includeDummies) throws ParseException {
  final Set<String> unsetAttributes = new LinkedHashSet<String>();
  final Set<String> definedAttributes = new HashSet<String>();
  //noinspection HardCodedStringLiteral
  SimpleNode template = RuntimeSingleton.parse(new StringReader(templateContent), "MyTemplate");
  collectAttributes(unsetAttributes, definedAttributes, template, propertiesNames, includeDummies, new HashSet<String>());
  for (String definedAttribute : definedAttributes) {
    unsetAttributes.remove(definedAttribute);
  }
  return ArrayUtil.toStringArray(unsetAttributes);
}
项目:easyjweb    文件:BasePageVender.java   
@Override
public boolean process() throws ResourceNotFoundException,
        ParseErrorException, Exception {
        super.rsvc=RuntimeSingleton.getRuntimeServices();
        if(content==null) throw new ResourceNotFoundException("Unknown resource error for resource " + super.name);
        super.data = null;               
        InputStream is = new java.io.ByteArrayInputStream(content);
        if(is != null)
        {
            try
            {
                BufferedReader br = new BufferedReader(new InputStreamReader(is, super.encoding));
                super.data = super.rsvc.parse(br, super.name);
                initDocument();
                boolean flag = true;
                return flag;
            }
            catch(UnsupportedEncodingException uce)
            {
                String msg = "Template.process : Unsupported input encoding : " + super.encoding + " for template " + super.name;
                throw new ParseErrorException(msg);
            }
            catch(ParseException pex)
            {
               throw new ParseErrorException(pex.getMessage());
            }
            catch(Exception e)
            {   
                throw e;
            }
            finally
            {
                is.close();
            }
        } else
        {
            throw new ResourceNotFoundException("Unknown resource error for resource " + super.name);
        }
}
项目:consulo    文件:CreateFromTemplateDialog.java   
public CreateFromTemplateDialog(@Nonnull PsiDirectory directory,
                                @Nonnull FileTemplate template,
                                @Nullable final AttributesDefaults attributesDefaults,
                                @Nullable final Map<String, Object> defaultProperties) {
  super(directory.getProject(), true);
  myDirectory = directory;
  myProject = directory.getProject();
  myTemplate = template;
  setTitle(IdeBundle.message("title.new.from.template", template.getName()));

  myDefaultProperties = defaultProperties == null ? FileTemplateManager.getInstance(myProject).getDefaultVariables() : defaultProperties;
  FileTemplateUtil.fillDefaultProperties(myDefaultProperties, directory);
  boolean mustEnterName = FileTemplateUtil.findHandler(template).isNameRequired();
  if (attributesDefaults != null && attributesDefaults.isFixedName()) {
    myDefaultProperties.put(FileTemplate.ATTRIBUTE_NAME, attributesDefaults.getDefaultFileName());
    mustEnterName = false;
  }

  String[] unsetAttributes = null;
  try {
    unsetAttributes = myTemplate.getUnsetAttributes(myDefaultProperties, myProject);
  }
  catch (ParseException e) {
    showErrorDialog(e);
  }

  if (unsetAttributes != null) {
    myAttrPanel = new CreateFromTemplatePanel(unsetAttributes, mustEnterName, attributesDefaults);
    myAttrComponent = myAttrPanel.getComponent();
    init();
  }
  else {
    myAttrPanel = null;
    myAttrComponent = null;
  }
}
项目:consulo    文件:FileTemplateUtil.java   
@Deprecated
@DeprecationInfo("Use #calculateAttributes with Map parameter")
public static String[] calculateAttributes(String templateContent, Properties properties, boolean includeDummies, Project project) throws ParseException {
  Set<String> propertiesNames = new HashSet<>();
  for (Enumeration e = properties.propertyNames(); e.hasMoreElements(); ) {
    propertiesNames.add((String)e.nextElement());
  }
  return calculateAttributes(templateContent, propertiesNames, includeDummies, project);
}