public class DoxiaUtils extends Object
Modifier and Type | Method and Description |
---|---|
static String |
encodeId(String text)
Construct a valid Doxia id.
|
static MutableAttributeSet |
getImageAttributes(String logo)
Determine width and height of an image.
|
static boolean |
isExternalLink(String link)
Checks if the given string corresponds to an external URI,
ie is not a link within the same document nor a relative link
to another document (a local link) of the same site.
|
static boolean |
isInternalLink(String link)
Checks if the given string corresponds to an internal link,
ie it is a link to an anchor within the same document.
|
static boolean |
isLocalLink(String link)
|
static boolean |
isValidId(String text)
Determines if the specified text is a valid id according to the rules
laid out in
encodeId(String) . |
static Date |
parseDate(String str)
Parses a string representing a date by trying different date patterns.
|
public static boolean isInternalLink(String link)
isInternalLink(java.lang.String)
, isExternalLink(java.lang.String)
and
isLocalLink(java.lang.String)
will return true.link
- The link to check. Not null.NullPointerException
- if link is null.isExternalLink(String)
,
isLocalLink(String)
public static boolean isExternalLink(String link)
isInternalLink(java.lang.String)
, isExternalLink(java.lang.String)
and
isLocalLink(java.lang.String)
will return true.link
- The link to check. Not null.NullPointerException
- if link is null.isInternalLink(String)
,
isLocalLink(String)
public static boolean isLocalLink(String link)
internal
nor an external
link.
If link is not null, then exactly one of the three methods
isInternalLink(java.lang.String)
, isExternalLink(java.lang.String)
and
isLocalLink(java.lang.String)
will return true.link
- The link to check. Not null.NullPointerException
- if link is null.isExternalLink(String)
,
isInternalLink(String)
public static String encodeId(String text)
A valid Doxia id corresponds to an XML id which is a {code NCName} which is in turn identical
to a Name
, but without a colon
and without any character above 0x7F
.
To achieve this we need to convert the id String. Two conversions are necessary and one is done to get prettier ids:
String.trim()
before starting to process,NameStartChar
prepend the letter 'a',0x20
) is replaced with an underscore,Here are some examples:
DoxiaUtils.encodeId(null) = null DoxiaUtils.encodeId("") = null DoxiaUtils.encodeId(" ") = null DoxiaUtils.encodeId(" _ ") = "_" DoxiaUtils.encodeId("1") = "a1" DoxiaUtils.encodeId("1anchor") = "a1anchor" DoxiaUtils.encodeId("_anchor") = "_anchor" DoxiaUtils.encodeId("a b-c123 ") = "a_b-c123" DoxiaUtils.encodeId(" anchor") = "anchor" DoxiaUtils.encodeId("myAnchor") = "myAnchor" DoxiaUtils.encodeId("€") = "a.E2.82.AC"
text
- The text to be encoded.
May be null, empty or blank in which case null is returned.isValidId(java.lang.String)
public static boolean isValidId(String text)
encodeId(String)
.text
- The id to be tested.
May be null or empty in which case false is returned.true
if the text is a valid id, otherwise false
.encodeId(String)
public static Date parseDate(String str) throws ParseException
Parses a string representing a date by trying different date patterns.
The following date patterns are tried (in the given order):
"yyyy-MM-dd", "yyyy/MM/dd", "yyyyMMdd", "yyyy", "dd.MM.yyyy", "dd MMM yyyy", "dd MMM. yyyy", "MMMM yyyy", "MMM. dd, yyyy", "MMM. yyyy", "MMMM dd, yyyy", "MMM d, ''yy", "MMM. ''yy", "MMMM ''yy"
A parse is only sucessful if it parses the whole of the input string. If no parse patterns match, a ParseException is thrown.
As a special case, the strings "today"
and "now"
(ignoring case) return the current date.
str
- the date to parse, not null."today"
or "now"
.ParseException
- if no pattern matches.NullPointerException
- if str is null.public static MutableAttributeSet getImageAttributes(String logo) throws IOException
logo
- a String containing either a URL or a path to an image file. Not null.IOException
- if an error occurs during reading.NullPointerException
- if logo is null.Copyright © 2005–2024 The Apache Software Foundation. All rights reserved.