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 being 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 * @param name The name of the tag.
52 * @throws IOException if starting the element fails.
53 */
54 void startElement( String name ) throws IOException;
55
56
57 /**
58 * Add a XML attribute to the current XML Element.
59 * This method must get called immediately after {@link #startElement(String)}
60 * @param key The key of the attribute.
61 * @param value The value of the attribute.
62 * @throws IllegalStateException if no element tag is currently in process
63 * @throws IOException if adding the attribute fails.
64 */
65 void addAttribute( String key, String value ) throws IOException;
66
67 /**
68 * Add a value text to the current element tag
69 * This will perform XML escaping to guarantee valid content
70 * @param text The text which should be written.
71 * @throws IllegalStateException if no element tag got started yet
72 * @throws IOException if writing the text fails.
73 */
74 void writeText( String text ) throws IOException;
75
76 /**
77 * Add a preformatted markup to the current element tag
78 * @param text The text which should be written.
79 * @throws IllegalStateException if no element tag got started yet
80 * @throws IOException if writing the markup fails.
81 */
82 void writeMarkup( String text ) throws IOException;
83
84 /**
85 * End the previously opened element.
86 * @see #startElement(String)
87 * @throws IOException if ending the element fails.
88 */
89 void endElement() throws IOException;
90 }