
org.thymeleaf.dom.Macro Maven / Gradle / Ivy
Show all versions of thymeleaf Show documentation
/*
* =============================================================================
*
* Copyright (c) 2011-2012, The THYMELEAF team (http://www.thymeleaf.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* =============================================================================
*/
package org.thymeleaf.dom;
import org.thymeleaf.Arguments;
import org.thymeleaf.Configuration;
import org.thymeleaf.util.Validate;
/**
*
* Node containing a piece of markup or text that should not be parsed or
* interpreted in any way. The content of a macro node should go straight to
* the template result writer.
*
*
* @author Daniel Fernández
*
* @since 2.0.9
*
*/
public final class Macro extends Node {
private static final long serialVersionUID = -3887347521552750092L;
private char[] content;
public Macro(final String content) {
this((content == null? null : content.toCharArray()), null, null);
}
public Macro(final char[] content) {
this(content, null, null);
}
public Macro(final String content, final String documentName, final Integer lineNumber) {
this((content == null? null : content.toCharArray()), documentName, lineNumber);
}
public Macro(final char[] content, final String documentName, final Integer lineNumber) {
super(documentName, lineNumber);
Validate.notNull(content, "Content cannot be null");
this.content = content;
}
/**
*
* Returns the textual content of this node, as a String.
*
*
* @return the textual content of this node.
*/
public String getContent() {
return new String(this.content);
}
/**
*
* Returns the unsafe inner char[] with the textual content of this
* code.
*
*
* Calling this method avoids the need to create a new String
* object (like {@link #getContent()} does, but requires to be extremely
* careful with the result, as any modification to the returned char array
* will actually modify the node's contents.
*
*
* @return the textual content of this node.
*/
public char[] unsafeGetContentCharArray() {
return this.content;
}
/**
*
* Modify the textual content of this node.
*
*
* @param content the new content
*/
public void setContent(final String content) {
this.content = content.toCharArray();
}
/**
*
* Modify the textual content of this node. This method
* is considered unsafe because it does not copy the
* specified array (instead, it is merely assigned to an internal variable).
*
*
* @param newContent the new content
*/
public void unsafeSetContent(final char[] newContent) {
this.content = newContent;
}
@Override
final void doAdditionalSkippableComputing(final boolean skippable) {
// Nothing to be done here!
}
@Override
final void doAdditionalPrecomputeNode(final Configuration configuration) {
// Nothing to be done here!
}
@Override
final void doAdditionalProcess(final Arguments arguments, final boolean processOnlyElementNodes) {
// Nothing to be done here
}
@Override
Node createClonedInstance(final NestableNode newParent, final boolean cloneProcessors) {
return new Macro(this.content);
}
@Override
void doCloneNodeInternals(final Node node, final NestableNode newParent,
final boolean cloneProcessors) {
// Nothing to be done here
}
@Override
public void visit(final DOMVisitor visitor) {
visitor.visit(this);
}
}