1 package org.apache.maven.shared.utils.xml; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.io.IOException; 23 24 /** 25 * Interface for tools writing XML files. 26 * XMLWriters are not thread safe and must not be accessed concurrently. 27 */ 28 public interface XMLWriter 29 { 30 31 /** 32 * Sets the encoding of the document. 33 * If not set, UTF-8 is used. 34 * 35 * @param encoding the encoding 36 * @throws IllegalStateException if the generation of the document has already started 37 */ 38 void setEncoding( String encoding ); 39 40 /** 41 * Sets the DOCTYPE of the document. 42 * 43 * @param docType the docType 44 * @throws IllegalStateException if the generation of the document has already started 45 */ 46 void setDocType( String docType ); 47 48 49 /** 50 * Start an XML Element tag. 51 * 52 * @param name the name of the tag 53 * @throws IOException if starting the element fails 54 */ 55 void startElement( String name ) throws IOException; 56 57 58 /** 59 * Add a XML attribute to the current XML Element. 60 * This method must get called immediately after {@link #startElement(String)}. 61 * 62 * @param key The key of the attribute. 63 * @param value The value of the attribute. 64 * @throws IllegalStateException if no element tag is currently in process 65 * @throws IOException if adding the attribute fails. 66 */ 67 void addAttribute( String key, String value ) throws IOException; 68 69 /** 70 * Add text to the current element tag. 71 * This performs XML escaping to guarantee well-formed content. 72 * 73 * @param text The text which should be written. 74 * @throws IllegalStateException if no element tag got started yet 75 * @throws IOException if writing the text fails. 76 */ 77 void writeText( String text ) throws IOException; 78 79 /** 80 * Add preformatted markup to the current element tag. 81 * 82 * @param text the text which should be written 83 * @throws IllegalStateException if no element tag is started yet 84 * @throws IOException if writing the markup fails 85 */ 86 void writeMarkup( String text ) throws IOException; 87 88 /** 89 * End the previously opened element. 90 * @see #startElement(String) 91 * @throws IOException if ending the element fails. 92 */ 93 void endElement() throws IOException; 94 }