StandaloneElementTag( final TemplateMode templateMode, final ElementDefinition elementDefinition, final String elementCompleteName, final Attributes attributes, final boolean synthetic, final boolean minimized, final String templateName, final int line, final int col) { super(templateMode, elementDefinition, elementCompleteName, attributes, synthetic, templateName, line, col); Validate.isTrue(minimized || templateMode == TemplateMode.HTML, "Not-minimized standalone elements are only allowed in HTML template mode (is " + templateMode + ")"); this.minimized = minimized; }
public static String substring(final Object target, final int beginIndex, final int endIndex) { if (target == null) { return null; } Validate.isTrue(beginIndex >= 0, "Begin index must be >= 0"); // The String constructor is called on purpose to avoid problems from // creating substrings out of large amounts of long Strings (creating // a substring does not free the memory occupied by the original String). return new String(target.toString().substring(beginIndex, endIndex)); }
public static String abbreviate(final Object target, final int maxSize) { Validate.isTrue(maxSize >= 3, "Maximum size must be greater or equal to 3"); if (target == null) { return null; } final String str = target.toString(); if (str.length() <= maxSize) { return str; } final StringBuilder strBuilder = new StringBuilder(maxSize + 2); strBuilder.append(str, 0, maxSize - 3); strBuilder.append("..."); return strBuilder.toString(); }
public void decreaseLevel() { Validate.isTrue(this.level > 0, "Cannot decrease variable map level below 0"); if (this.levels[this.index] == this.level) { this.levels[this.index] = Integer.MAX_VALUE; if (this.maps[this.index] != null) { this.maps[this.index].clear(); } this.selectionTargets[this.index] = null; this.inliners[this.index] = null; this.templateDatas[this.index] = null; this.index--; // These might not belong to this level, but just in case... this.lastSelectionTarget = null; this.lastInliner = null; this.lastTemplateData = null; this.templateStack.clear(); } if (this.level < this.elementTags.length) { this.elementTags[this.level] = null; } this.level--; }
/** * <p> * copy a part of target start beginIndex to the end of target. * If non-String object, toString() will be called. * </p> * * @param target source of the copy. * @param beginIndex index where the copy start. * @return part of target, or {@code null} if target is null. * @since 1.1.2 */ public static String substring(final Object target, final int beginIndex) { if (target == null) { return null; } final String str = target.toString(); final int len = str.length(); Validate.isTrue(beginIndex >= 0 && beginIndex < len, "beginIndex must be >= 0 and < " + len); // Note this might not free the original string's char[] if using Java < Java7u6 return str.substring(beginIndex); }
TemplateModel( final IEngineConfiguration configuration, final TemplateData templateData, final IEngineTemplateEvent[] queue) { super(); Validate.notNull(configuration, "Engine Configuration cannot be null"); Validate.notNull(templateData, "Template Resolution cannot be null"); Validate.notNull(queue, "Event queue cannot be null"); Validate.isTrue(queue.length >= 2, "At least TemplateStart/TemplateEnd events must be added to a TemplateModel"); Validate.isTrue(queue[0] == TemplateStart.TEMPLATE_START_INSTANCE, "First event in queue is not TemplateStart"); Validate.isTrue(queue[queue.length - 1] == TemplateEnd.TEMPLATE_END_INSTANCE, "Last event in queue is not TemplateEnd"); this.configuration = configuration; this.templateData = templateData; this.queue = queue; }
public StandardInlineTextualTagProcessor(final TemplateMode templateMode, final String dialectPrefix) { super(templateMode, dialectPrefix, ATTR_NAME, PRECEDENCE); Validate.isTrue(templateMode.isText(), "Template mode must be a textual one"); }
public void decreaseLevel() { Validate.isTrue(this.level > 0, "Cannot decrease variable map level below 0");
public StandardCache(final String name, final boolean useSoftReferences, final int initialCapacity, final int maxSize, final ICacheEntryValidityChecker<? super K, ? super V> entryValidityChecker, final Logger logger, final boolean enableCounters) { super(); Validate.notEmpty(name, "Name cannot be null or empty"); Validate.isTrue(initialCapacity > 0, "Initial capacity must be > 0"); Validate.isTrue(maxSize != 0, "Cache max size must be either -1 (no limit) or > 0"); this.name = name; this.useSoftReferences = useSoftReferences; this.maxSize = maxSize; this.entryValidityChecker = entryValidityChecker; this.logger = logger; this.traceExecution = (logger != null && logger.isTraceEnabled()); this.enableCounters = (this.traceExecution || enableCounters); this.dataContainer = new CacheDataContainer<K,V>(this.name, initialCapacity, maxSize, this.traceExecution, this.logger); this.getCount = new AtomicLong(0); this.putCount = new AtomicLong(0); this.hitCount = new AtomicLong(0); this.missCount = new AtomicLong(0); if (this.logger != null) { if (this.maxSize < 0) { this.logger.trace("[THYMELEAF][CACHE_INITIALIZE] Initializing cache {}. Soft references {}.", this.name, (this.useSoftReferences? "are used" : "not used")); } else { this.logger.trace("[THYMELEAF][CACHE_INITIALIZE] Initializing cache {}. Max size: {}. Soft references {}.", new Object[] {this.name, Integer.valueOf(this.maxSize), (this.useSoftReferences? "are used" : "not used")}); } } }
public String multipleReplace(final Object target, final String[] before, final String[] after) { Validate.notNull(before, "Array of 'before' values cannot be null"); Validate.notNull(after, "Array of 'after' values cannot be null"); Validate.isTrue(before.length == after.length, "Arrays of 'before' and 'after' values must have the same length"); if (target == null) { return null; } String ret = target.toString(); for (int i = 0; i < before.length; i++) { ret = StringUtils.replace(ret, before[i], after[i]); } return ret; }
public void parseStandalone( final IEngineConfiguration configuration, final String ownerTemplate, final String template, final Set<String> templateSelectors, final ITemplateResource resource, final TemplateMode templateMode, final boolean useDecoupledLogic, final ITemplateHandler handler) { Validate.notNull(configuration, "Engine Configuration cannot be null"); // ownerTemplate CAN be null if this is a first-level template Validate.notNull(template, "Template cannot be null"); Validate.notNull(resource, "Template Resource cannot be null"); Validate.isTrue(templateSelectors == null || templateSelectors.isEmpty(), "Template selectors cannot be specified for a template using RAW template mode: template " + "insertion operations must be always performed on whole template files, not fragments"); Validate.notNull(templateMode, "Template Mode cannot be null"); Validate.isTrue(templateMode == TemplateMode.RAW, "Template Mode has to be RAW"); Validate.isTrue(!useDecoupledLogic, "Cannot use decoupled logic in template mode " + templateMode); Validate.notNull(handler, "Template Handler cannot be null"); parse(configuration, ownerTemplate, template, templateSelectors, resource, 0, 0, templateMode, handler); }
public void parseStandalone( final IEngineConfiguration configuration, final String ownerTemplate, final String template, final Set<String> templateSelectors, final ITemplateResource resource, final TemplateMode templateMode, final boolean useDecoupledLogic, final ITemplateHandler handler) { Validate.notNull(configuration, "Engine Configuration cannot be null"); // ownerTemplate CAN be null if this is a first-level template Validate.notNull(template, "Template cannot be null"); Validate.notNull(resource, "Template Resource cannot be null"); Validate.isTrue(templateSelectors == null || templateSelectors.isEmpty(), "Template selectors cannot be specified for a template using a TEXT template mode: template " + "insertion operations must be always performed on whole template files, not fragments"); Validate.notNull(templateMode, "Template Mode cannot be null"); Validate.isTrue(templateMode.isText(), "Template Mode has to be a text template mode"); Validate.isTrue(!useDecoupledLogic, "Cannot use decoupled logic in template mode " + templateMode); Validate.notNull(handler, "Template Handler cannot be null"); parse(configuration, ownerTemplate, template, templateSelectors, resource, 0, 0, templateMode, handler); }
Validate.isTrue(templateResolvers.size() > 0, "Template Resolver set cannot be empty"); Validate.containsNoNulls(templateResolvers, "Template Resolver set cannot contain any nulls"); Validate.notNull(messageResolvers, "Message Resolver set cannot be null");
Validate.isTrue(templateMode == null || outputContentType == null, "If template mode or output content type are specified, the other one cannot");
public void parseString( final IEngineConfiguration configuration, final String ownerTemplate, final String template, final int lineOffset, final int colOffset, final TemplateMode templateMode, final ITemplateHandler handler) { Validate.notNull(configuration, "Engine Configuration cannot be null"); Validate.notNull(ownerTemplate, "Owner template cannot be null"); Validate.notNull(template, "Template cannot be null"); // NOTE selectors cannot be specified when parsing a nested template Validate.notNull(templateMode, "Template mode cannot be null"); Validate.isTrue(templateMode == TemplateMode.RAW, "Template Mode has to be RAW"); Validate.notNull(handler, "Template Handler cannot be null"); parse(configuration, ownerTemplate, template, null, null, lineOffset, colOffset, templateMode, handler); }
public void parseString( final IEngineConfiguration configuration, final String ownerTemplate, final String template, final int lineOffset, final int colOffset, final TemplateMode templateMode, final ITemplateHandler handler) { Validate.notNull(configuration, "Engine Configuration cannot be null"); Validate.notNull(ownerTemplate, "Owner template cannot be null"); Validate.notNull(template, "Template cannot be null"); // NOTE selectors cannot be specified when parsing a nested template Validate.notNull(templateMode, "Template mode cannot be null"); Validate.isTrue(templateMode.isMarkup(), "Template Mode has to be a markup template mode"); Validate.notNull(handler, "Template Handler cannot be null"); parse(configuration, ownerTemplate, template, null, null, lineOffset, colOffset, templateMode, false, handler); }
public void parseString( final IEngineConfiguration configuration, final String ownerTemplate, final String template, final int lineOffset, final int colOffset, final TemplateMode templateMode, final ITemplateHandler handler) { Validate.notNull(configuration, "Engine Configuration cannot be null"); Validate.notNull(ownerTemplate, "Owner template cannot be null"); Validate.notNull(template, "Template cannot be null"); // NOTE selectors cannot be specified when parsing a nested template Validate.notNull(templateMode, "Template mode cannot be null"); Validate.isTrue(templateMode.isText(), "Template Mode has to be a text template mode"); Validate.notNull(handler, "Template Handler cannot be null"); parse(configuration, ownerTemplate, template, null, null, lineOffset, colOffset, templateMode, handler); }
public void parseStandalone( final IEngineConfiguration configuration, final String ownerTemplate, final String template, final Set<String> templateSelectors, final ITemplateResource resource, final TemplateMode templateMode, final boolean useDecoupledLogic, final ITemplateHandler handler) { Validate.notNull(configuration, "Engine Configuration cannot be null"); // ownerTemplate CAN be null if this is a first-level template Validate.notNull(template, "Template cannot be null"); Validate.notNull(resource, "Template Resource cannot be null"); // templateSelectors CAN be null if we are going to render the entire template Validate.notNull(templateMode, "Template Mode cannot be null"); Validate.isTrue(templateMode.isMarkup(), "Template Mode has to be a markup template mode"); Validate.notNull(handler, "Template Handler cannot be null"); parse(configuration, ownerTemplate, template, templateSelectors, resource, 0, 0, templateMode, useDecoupledLogic, handler); }
final Writer writer) { Validate.isTrue( this.configuration == template.getConfiguration(), "Specified template was built by a different Template Engine instance");