@MinDoc(copyright="Copyright 2003 - 2007, 2009, 2016 A. Weinert", author="Albrecht Weinert", version="V.65", lastModified="3.06.2024", usage="use in XML / HTML applications", purpose="provide helper methods and values") public abstract class MLHelper extends Object
TextHelper
.Modifier and Type | Field and Description |
---|---|
static String |
JAXP_SCHEMA_LANGUAGE
Scheme for JAXP.
|
static String |
JAXP_SCHEMA_SOURCE
Scheme source for JAXP.
|
static String[] |
MIME_TYPES
List MIME type: file extension(s).
|
static String |
W3C_XML_SCHEMA
Scheme of W3C.
|
Modifier and Type | Method and Description |
---|---|
static int |
clearHTMLdefAtts(Element root)
Shorten a HTML document by not necessary default attributes.
|
static String |
guessContentType(byte[] start)
Determine (MIME-) content type from the first (4-11) bytes.
|
static String |
guessContentType(String ext)
Determine (MIME-) content type from file type (extension).
|
static boolean |
isDocNode(Node node)
Is the node a (part of) a document.
|
static void |
listNode(Node node,
PrintWriter log,
int recurs)
List a node and all attributes to a PrintWriter.
|
static StringBuilder |
unEscapePercent(CharSequence request)
"Un-percent" a text (a Http request).
|
static Object |
xmlDecode(InputStream in)
Generate an object (bean) from a XML description.
|
static Object |
xmlDecode(String fileName)
Generate an object from a XML file.
|
static void |
xmlEncode(Object mb,
String file)
XML encode an object and write to a file.
|
static int |
zifValue(char c)
Transform digit (hexadecimal) to number (0-15).
|
public static final String JAXP_SCHEMA_LANGUAGE
"http://java.sun.com/xml/jaxp/properties/schemaLanguage"
public static final String W3C_XML_SCHEMA
JAXP_SCHEMA_LANGUAGE
.JAXP_SCHEMA_LANGUAGE
.
"http://www.w3.org/2001/XMLSchema"
public static final String JAXP_SCHEMA_SOURCE
JAXP_SCHEMA_LANGUAGE
.
"http://java.sun.com/xml/jaxp/properties/schemaSource"
public static final String[] MIME_TYPES
"image/jpeg: .jfif,.jfif-tbnl,.jpe,.jpg,.jpeg,"
guessContentType(String)
public static StringBuilder unEscapePercent(CharSequence request)
request
- the original textzifValue(char)
public static int zifValue(char c)
c
- the digit characterpublic static void xmlEncode(Object mb, String file) throws IllegalArgumentException, ClassNotFoundException, IOException
mb
and all objects associated to
it have to be Java beans. Otherwise a senseless XML file (empty except
start and end tag) will be generated.mb
will be XML encoded and the result will be written
into a file named file
.mb
- the (bean) object to encodefile
- the file for encoded outputIllegalArgumentException
- wrong parameter valuesClassNotFoundException
- JDK problems in getting a XML encoderIOException
- problems with streams or filespublic static Object xmlDecode(String fileName) throws IllegalArgumentException, ClassNotFoundException, IOException
fileName
has to denote a file containing a XML
document. This must describe an object / bean. This will be constructed
and returned.fileName
not end with .xml,
.xml is appended and the trial repeated.xmlDecode(InputStream
.fileName
- the file for input to be decodedIllegalArgumentException
- wrong parameter valuesClassNotFoundException
- JDK problems in getting a XML encoderIOException
- problems with streams or filespublic static Object xmlDecode(InputStream in) throws IllegalArgumentException, ClassNotFoundException, IOException, ClassCastException
in
must be an input stream delivering a XML
document. This must describe an object / bean. This will be constructed
and returned.in
- the XML input streamIllegalArgumentException
- wrong parameter valueClassNotFoundException
- problems in getting a XML decoderIOException
- stream problemsClassCastException
- forwarded from ? (obsolete?)public static void listNode(Node node, PrintWriter log, int recurs)
node
- a Node with attributes to be listedlog
- the destination writerrecurs
- if > 0 descend recurs levels to list sub-Nodes toopublic static String guessContentType(byte[] start)
URLConnection.guessContentTypeFromStream(java.io.InputStream)
is used here
a bit "tuned".start
- the start of the content (minimum) 4 or 6, 8 or 11 byte!guessContentType(java.lang.String)
public static String guessContentType(String ext)
ext
- the file extensionguessContentType(byte[])
,
MIME_TYPES
public static boolean isDocNode(Node node)
node
is not null and is of type
DocumentFragment
or Element
. These types may have
children and hence may be start of a (document) structure.public static int clearHTMLdefAtts(Element root)
dom.Attr
ibutes from
a dom.Element
and (recursively) from all its
children.root
- start element of the (HTLM) document or a part, to be cleaned.