All Downloads are FREE. Search and download functionalities are using the official Maven repository.

groovy.xml.MarkupBuilderHelper Maven / Gradle / Ivy

There is a newer version: 3.9
Show newest version
/*
 * Copyright 2003-2013 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: 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: 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: 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: 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.
     * 

* mkp.comment 'string' is equivalent to * mkp.yieldUnescaped '<!-- string -->'. * To create an element with the name 'comment', you need * to supply empty attributes, e.g.: *

     * comment('hello1')
     * 
* or *
     * mkp.comment('hello1')
     * 
* will produce: *
     * <!-- hello1 -->
     * 
* while: *
     * comment('hello2', [:])
     * 
* will produce: *
     * <comment>hello2</comment>
     * 
* * @param value the text within the comment. */ public void comment(String value) { yieldUnescaped(""); } /** * Produce an XML declaration in the output. * For example: *
     * mkp.xmlDeclaration(version:'1.0')
     * 
* * @param args the attributes for the declaration */ public void xmlDeclaration(Map args) { Map> map = new HashMap>(); map.put("xml", args); pi(map); } /** * Produce an XML processing instruction in the output. * For example: *
     * mkp.pi("xml-stylesheet":[href:"mystyle.css", type:"text/css"])
     * 
* * @param args a map with a single entry whose key is the name of the * processing instruction and whose value is the attributes * for the processing instruction. */ public void pi(Map> args) { builder.pi(args); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy