| Class | Line # | Actions | |||||
|---|---|---|---|---|---|---|---|
| XmlTools | 21 | 0 | - | 0 | 0 |
| 1 | package org.europa.together.business; | |
| 2 | ||
| 3 | import java.io.File; | |
| 4 | import java.io.IOException; | |
| 5 | import org.apiguardian.api.API; | |
| 6 | import static org.apiguardian.api.API.Status.STABLE; | |
| 7 | import org.springframework.stereotype.Component; | |
| 8 | ||
| 9 | /** | |
| 10 | * XML Tools are based on the event driven SAX concept. SAX = Simple API for | |
| 11 | * XML<br> | |
| 12 | * The implementation offers all necessary functions to deal with XML inside | |
| 13 | * Java Applications. | |
| 14 | * | |
| 15 | * @author elmar.dott@gmail.com | |
| 16 | * @version 1.2 | |
| 17 | * @since 1.0 | |
| 18 | */ | |
| 19 | @API(status = STABLE, since = "1.0", consumers = "SaxTools") | |
| 20 | @Component | |
| 21 | public interface XmlTools { | |
| 22 | ||
| 23 | /** | |
| 24 | * Identifier for the given feature. | |
| 25 | */ | |
| 26 | @API(status = STABLE, since = "1.2") | |
| 27 | String FEATURE_ID = "CM-10"; | |
| 28 | ||
| 29 | /** | |
| 30 | * Parse a given XML File to grab the content. | |
| 31 | * | |
| 32 | * @param xmlFile as File | |
| 33 | * @return content as String | |
| 34 | */ | |
| 35 | @API(status = STABLE, since = "1.0") | |
| 36 | String parseXmlFile(File xmlFile); | |
| 37 | ||
| 38 | /** | |
| 39 | * Parse a given XML String to grab the content. | |
| 40 | * | |
| 41 | * @param xml as String | |
| 42 | * @return content as String | |
| 43 | */ | |
| 44 | @API(status = STABLE, since = "1.1") | |
| 45 | String parseXmlString(String xml); | |
| 46 | ||
| 47 | /** | |
| 48 | * Before writeing a XML Document on a file, especially computer generated | |
| 49 | * XML Content, the content should formatted by a CodeBeautifier. This | |
| 50 | * function Beautifies the XML Sources with the following rules:<br> | |
| 51 | * - set content to UTF-8 without BOM (Byte Order Mark)<br> | |
| 52 | * - automated line breaks and indents<br> | |
| 53 | * - remove trailing space<br> | |
| 54 | * - replace TAB with 4 space characters | |
| 55 | * | |
| 56 | * @return content as String | |
| 57 | */ | |
| 58 | @API(status = STABLE, since = "1.0") | |
| 59 | String prettyPrintXml(); | |
| 60 | ||
| 61 | /** | |
| 62 | * Shrink the XML content to reduce the file size for a higher performance | |
| 63 | * in automated processing. The following option will be executed: - remove | |
| 64 | * XML comments<br> | |
| 65 | * - remove whitespace<br> | |
| 66 | * - remove linebreak<br> | |
| 67 | * The final result is an XML in one row without comments and whitespace in | |
| 68 | * one line. input and output is not parsed or checked for well formed. | |
| 69 | * | |
| 70 | * @param content as String | |
| 71 | * @return shrink content as String | |
| 72 | */ | |
| 73 | @API(status = STABLE, since = "1.1") | |
| 74 | String shrinkContent(String content); | |
| 75 | ||
| 76 | /** | |
| 77 | * Transform an XML File by a given XSLT to a new Output. | |
| 78 | * | |
| 79 | * @param xml as File | |
| 80 | * @param xslt as File | |
| 81 | * @return transformation as String | |
| 82 | */ | |
| 83 | @API(status = STABLE, since = "1.1") | |
| 84 | String transformXslt(File xml, File xslt); | |
| 85 | ||
| 86 | /** | |
| 87 | * Check if a external schema file s configured. | |
| 88 | * | |
| 89 | * @return true on success | |
| 90 | */ | |
| 91 | @API(status = STABLE, since = "1.1") | |
| 92 | boolean hasExternalSchemaFile(); | |
| 93 | ||
| 94 | /** | |
| 95 | * Validate well formed XML content (XML 1.0) against a given grammar. | |
| 96 | * Grammar files can be DTD or XML Schema. THe validation contains also a | |
| 97 | * well formed test for the XML file. | |
| 98 | * | |
| 99 | * @return true on success | |
| 100 | */ | |
| 101 | @API(status = STABLE, since = "1.0") | |
| 102 | boolean isValid(); | |
| 103 | ||
| 104 | /** | |
| 105 | * Check XML content (XML 1.0) if is well formed. the well formed rules for | |
| 106 | * XML are defined as:<br> | |
| 107 | * - the structure of a XML document is a tree and each node is defined as | |
| 108 | * TAG<br> | |
| 109 | * - each document contains exact one root tag<br> | |
| 110 | * - element tags are case-sensitive<br> | |
| 111 | * - content be delimited with a beginning and end tag<br> | |
| 112 | * - begin, end, and empty-element tags that delimit the elements are<br> | |
| 113 | * correctly nested, with none missing and none overlapping Detail<br> | |
| 114 | * - it contains only properly encoded legal Unicode characters<br> | |
| 115 | * - special characters like: > < & have to be encoded<br> | |
| 116 | * (StringUtils.escapeXmlCharacters()) Information: | |
| 117 | * https://en.wikipedia.org/wiki/Well-formed_document | |
| 118 | * | |
| 119 | * @return true on success | |
| 120 | */ | |
| 121 | @API(status = STABLE, since = "1.0") | |
| 122 | boolean isWellFormed(); | |
| 123 | ||
| 124 | /** | |
| 125 | * Reset the external schema file to NULL. | |
| 126 | */ | |
| 127 | @API(status = STABLE, since = "1.1") | |
| 128 | void resetExternalSchema(); | |
| 129 | ||
| 130 | /** | |
| 131 | * Set explicit the schema file for the validation option. This method | |
| 132 | * overwrites in the XML document declares Schemata. | |
| 133 | * | |
| 134 | * @param schema as File | |
| 135 | */ | |
| 136 | @API(status = STABLE, since = "1.0") | |
| 137 | void setSchemaFile(File schema); | |
| 138 | ||
| 139 | /** | |
| 140 | * Writes a XML String into a new file. | |
| 141 | * | |
| 142 | * @param content as string | |
| 143 | * @param destinationFile as String | |
| 144 | * @throws java.io.IOException | |
| 145 | */ | |
| 146 | @API(status = STABLE, since = "1.0") | |
| 147 | void writeXmlToFile(String content, String destinationFile) | |
| 148 | throws IOException; | |
| 149 | } |