1 /**
2 * Copyright 2006-2016 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.mybatis.generator.api.dom.xml;
17
18 import org.mybatis.generator.api.dom.OutputUtilities;
19
20 /**
21 * The Class Document.
22 *
23 * @author Jeff Butler
24 */
25 public class Document {
26
27 /** The public id. */
28 private String publicId;
29
30 /** The system id. */
31 private String systemId;
32
33 /** The root element. */
34 private XmlElement rootElement;
35
36 /**
37 * Instantiates a new document.
38 *
39 * @param publicId
40 * the public id
41 * @param systemId
42 * the system id
43 */
44 public Document(String publicId, String systemId) {
45 super();
46 this.publicId = publicId;
47 this.systemId = systemId;
48 }
49
50 /**
51 * Instantiates a new document.
52 */
53 public Document() {
54 super();
55 }
56
57 /**
58 * Gets the root element.
59 *
60 * @return Returns the rootElement.
61 */
62 public XmlElement getRootElement() {
63 return rootElement;
64 }
65
66 /**
67 * Sets the root element.
68 *
69 * @param rootElement
70 * The rootElement to set.
71 */
72 public void setRootElement(XmlElement rootElement) {
73 this.rootElement = rootElement;
74 }
75
76 /**
77 * Gets the public id.
78 *
79 * @return Returns the publicId.
80 */
81 public String getPublicId() {
82 return publicId;
83 }
84
85 /**
86 * Gets the system id.
87 *
88 * @return Returns the systemId.
89 */
90 public String getSystemId() {
91 return systemId;
92 }
93
94 /**
95 * Gets the formatted content.
96 *
97 * @return the formatted content
98 */
99 public String getFormattedContent() {
100 StringBuilder sb = new StringBuilder();
101
102 sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$
103
104 if (publicId != null && systemId != null) {
105 OutputUtilities.newLine(sb);
106 sb.append("<!DOCTYPE "); //$NON-NLS-1$
107 sb.append(rootElement.getName());
108 sb.append(" PUBLIC \""); //$NON-NLS-1$
109 sb.append(publicId);
110 sb.append("\" \""); //$NON-NLS-1$
111 sb.append(systemId);
112 sb.append("\">"); //$NON-NLS-1$
113 }
114
115 OutputUtilities.newLine(sb);
116 sb.append(rootElement.getFormattedContent(0));
117
118 return sb.toString();
119 }
120 }