public ITemplateResource relative(final String relativeLocation) { throw new TemplateInputException( String.format("Cannot create a relative resource for String resource \"%s\"", this.resource)); }
private static Properties readMessagesResource(final Reader propertiesReader) { if (propertiesReader == null) { return null; } final Properties properties = new Properties(); try { // Note Properties#load(Reader) this is JavaSE 6 specific, but Thymeleaf 3.0 does // not support Java 5 anymore... properties.load(propertiesReader); } catch (final Exception e) { throw new TemplateInputException("Exception loading messages file", e); } finally { try { propertiesReader.close(); } catch (final Throwable ignored) { // ignore errors closing } } return properties; }
public ITemplateResource relative(final String relativeLocation) { Validate.notEmpty(relativeLocation, "Relative Path cannot be null or empty"); // We will create a new URL using the current one as context, and the relative path as spec final URL relativeURL; try { relativeURL = new URL(this.url, (relativeLocation.charAt(0) == '/' ? relativeLocation.substring(1) : relativeLocation)); } catch (final MalformedURLException e) { throw new TemplateInputException( "Could not create relative URL resource for resource \"" + getDescription() + "\" and " + "relative location \"" + relativeLocation + "\"", e); } return new UrlTemplateResource(relativeURL, this.characterEncoding); }
@Override public void handleOpenElementEnd( final char[] buffer, final int nameOffset, final int nameLen, final int line, final int col) throws ParseException { if (!this.inLogicBody) { // A standalone element that is not inside a <logic> tag makes no sense return; } if (this.inAttrTag && this.selector.isLevelEmpty()) { throw new TemplateInputException( "Error while processing decoupled logic file: <attr> injection tag does not contain any " + "\"sel\" selector attributes.", this.templateName, line, col); } // Time to add the attributes to the decoupled logic. We do it here in order to allow the "sel" attribute to // be in any position inside the <attr> tag (even after the injected attributes themselves). final String currentSelector = this.selector.getCurrentSelector(); for (final DecoupledInjectedAttribute injectedAttribute : this.currentInjectedAttributes) { this.decoupledTemplateLogic.addInjectedAttribute(currentSelector, injectedAttribute); } this.currentInjectedAttributes.clear(); this.inAttrTag = false; }
private void parse( final IEngineConfiguration configuration, final String ownerTemplate, final String template, final Set<String> templateSelectors, final ITemplateResource resource, final int lineOffset, final int colOffset, final TemplateMode templateMode, final ITemplateHandler templateHandler) { // For a String template, we will use the ownerTemplate as templateName for its parsed events final String templateName = (resource != null? template : ownerTemplate); try { // The final step of the handler chain will be the adapter that will convert the raw parser's handler chain to thymeleaf's. final IRawHandler handler = new TemplateHandlerAdapterRawHandler( templateName, templateHandler, lineOffset, colOffset); // Obtain the resource reader final Reader templateReader = (resource != null? resource.reader() : new StringReader(template)); this.parser.parse(templateReader, handler); } catch (final IOException e) { final String message = "An error happened during template parsing"; throw new TemplateInputException(message, (resource != null? resource.getDescription() : template), e); } catch (final RawParseException e) { final String message = "An error happened during template parsing"; if (e.getLine() != null && e.getCol() != null) { throw new TemplateInputException(message, (resource != null? resource.getDescription() : template), e.getLine().intValue(), e.getCol().intValue(), e); } throw new TemplateInputException(message, (resource != null? resource.getDescription() : template), e); } }
@Override public void handleStandaloneElementEnd( final char[] buffer, final int nameOffset, final int nameLen, final boolean minimized, final int line, final int col) throws ParseException { if (!this.inLogicBody) { // A standalone element that is not inside a <logic> tag makes no sense return; } if (this.inAttrTag && this.selector.isLevelEmpty()) { throw new TemplateInputException( "Error while processing decoupled logic file: <attr> injection tag does not contain any " + "\"sel\" selector attributes.", this.templateName, line, col); } // Time to add the attributes to the decoupled logic. We do it here in order to allow the "sel" attribute to // be in any position inside the <attr> tag (even after the injected attributes themselves). final String currentSelector = this.selector.getCurrentSelector(); for (final DecoupledInjectedAttribute injectedAttribute : this.currentInjectedAttributes) { this.decoupledTemplateLogic.addInjectedAttribute(currentSelector, injectedAttribute); } this.currentInjectedAttributes.clear(); this.inAttrTag = false; this.selector.decreaseLevel(); }
throw new TemplateInputException( "Error while processing decoupled logic file: selector (\"sel\") attribute found more than " + "once in attr injection tag", this.templateName, nameLine, nameCol);
throw new TemplateInputException( "Error resolving template [" + template + "], " + "template might not exist or might not be accessible by " +
throw new TemplateInputException( "Error resolving fragment: \"" + executedFragmentExpression.fragmentExpression.getStringRepresentation() + "\": " + "template or fragment could not be resolved");
throw new TemplateInputException(message, (resource != null? resource.getDescription() : template), e); } catch (final TextParseException e) { final String message = "An error happened during template parsing"; if (e.getLine() != null && e.getCol() != null) { throw new TemplateInputException(message, (resource != null? resource.getDescription() : template), e.getLine().intValue(), e.getCol().intValue(), e); throw new TemplateInputException(message, (resource != null? resource.getDescription() : template), e);
throw new TemplateInputException(message, (resource != null? resource.getDescription() : template), e); } catch (final ParseException e) { final String message = "An error happened during template parsing"; if (e.getLine() != null && e.getCol() != null) { throw new TemplateInputException(message, (resource != null? resource.getDescription() : template), e.getLine().intValue(), e.getCol().intValue(), e); throw new TemplateInputException(message, (resource != null? resource.getDescription() : template), e);
throw new TemplateInputException( "Error resolving fragment: \"" + attributeValue + "\": " + "template or fragment could not be resolved");
private static Properties loadMessages(final InputStream propertiesIS) { if (propertiesIS == null) { return null; } final Properties properties = new Properties(); try { properties.load(propertiesIS); } catch (final Exception e) { throw new TemplateInputException("Exception loading messages file", e); } finally { try { propertiesIS.close(); } catch (final Exception e) { // ignored } } return properties; }
public ITemplateResource relative(final String relativeLocation) { throw new TemplateInputException(String.format("Cannot create relative resource for test resource \"%s\"", this.resource.getName())); }
public ITemplateResource relative(final String relativeLocation) { throw new TemplateInputException(String.format("Cannot create relative resource for test resource \"%s\"", this.resource.getName())); }
throw new TemplateInputException("DOCTYPE clause has bad format: \"" + docTypeClause + "\"");
throw new TemplateInputException("DOCTYPE clause has bad format: \"" + (new String(buffer, offset, len)) + "\"", e);
throw new TemplateInputException( SAXPARSEEXCEPTION_BAD_ELEMENT_CONTENT_EXPLANATION, e); throw new TemplateInputException("An exception happened during parsing", e); throw new TemplateInputException("Exception parsing document", e); throw new TemplateInputException("Exception parsing document", e);
throw new TemplateInputException("Exception parsing document", e); } catch (final TemplateProcessingException e) { throw e; String.format("Exception parsing document: template=\"%s\", line %d - column %d", documentName, Integer.valueOf(e.getLineNumber()), Integer.valueOf(e.getColumnNumber())); throw new TemplateInputException(message, e); } catch (final SAXException e) { throw new TemplateInputException("Exception parsing document", e); } finally {
/** * * @since 2.0.8 */ public static Document getDOMFor(final Configuration configuration, final Reader source, final ITemplateParser parser) { Validate.notNull(configuration, "Configuration cannot be null"); Validate.notNull(source, "Source cannot be null"); Validate.notNull(parser, "Template parser cannot be null"); try { return parser.parseTemplate(configuration, "input", source); } catch (final Exception e) { throw new TemplateInputException( "Exception during parsing of source", e); } }