|
Groovy example source code file (MarkupBuilderHelper.java)
The Groovy MarkupBuilderHelper.java source code/* * Copyright 2003-2009 the original author or authors. * * 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 groovy.xml; import java.util.HashMap; import java.util.Map; /** * A helper class for MarkupBuilder. * * @author Paul King */ public class MarkupBuilderHelper { private MarkupBuilder builder; /** * @param builder the builder to delegate to */ public MarkupBuilderHelper(MarkupBuilder builder) { this.builder = builder; } /** * Prints data in the body of the current tag, escaping XML entities. * For example: <code>mkp.yield('5 < 7') * * @param value an Object whose toString() representation is to be printed */ public void yield(Object value) { yield(value.toString()); } /** * Prints data in the body of the current tag, escaping XML entities. * For example: <code>mkp.yield('5 < 7') * * @param value text to print */ public void yield(String value) { builder.yield(value, true); } /** * Print data in the body of the current tag. Does not escape XML entities. * For example: <code>mkp.yieldUnescaped('I am <i>happy</i>!'). * * @param value an Object whose toString() representation is to be printed */ public void yieldUnescaped(Object value) { yieldUnescaped(value.toString()); } /** * Print data in the body of the current tag. Does not escape XML entities. * For example: <code>mkp.yieldUnescaped('I am <i>happy</i>!'). * * @param value the text or markup to print. */ public void yieldUnescaped(String value) { builder.yield(value, false); } /** * Produce a comment in the output. * <p/> * <code>mkp.comment 'string' is equivalent to * <code>mkp.yieldUnescaped '<!-- string -->'. * To create an element with the name 'comment', you need * to supply empty attributes, e.g.: * <pre> * comment('hello1') * </pre> * or * <pre> * mkp.comment('hello1') * </pre> * will produce: * <pre> * <!-- hello1 --> * </pre> * while: * <pre> * comment('hello2', [:]) * </pre> * will produce: * <pre> * <comment>hello2</comment> * </pre> * * @param value the text within the comment. */ public void comment(String value) { yieldUnescaped("<!-- " + value + " -->"); } /** * Produce an XML declaration in the output. * For example: * <pre> * mkp.xmlDeclaration(version:'1.0') * </pre> * * @param args the attributes for the declaration */ public void xmlDeclaration(Map<String, Object> args) { Map<String, Map Other Groovy examples (source code examples)Here is a short list of links related to this Groovy MarkupBuilderHelper.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.