|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.maven.doxia.util.DoxiaUtils
public class DoxiaUtils
General Doxia utility methods. The methods in this class should not assume any specific Doxia module or document format.
| Method Summary | |
|---|---|
static String |
byteToHex(byte b)
Convert a byte to it's hexadecimal equivalent. |
static String |
encodeId(String id)
Construct a valid Doxia id. |
static String |
encodeId(String id,
boolean chop)
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)
Checks if the given string corresponds to a relative link to another document within the same site, ie it is neither an internal
nor an external 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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static boolean isInternalLink(String link)
link - The link to check.
isExternalLink(String),
isLocalLink(String)public static boolean isExternalLink(String link)
link - The link to check.
isInternalLink(String),
isLocalLink(String)public static boolean isLocalLink(String link)
internal
nor an external link.
link - The link to check.
isExternalLink(String),
isInternalLink(String)public static String encodeId(String id)
This method is equivalent to encodeId( id, false ).
id - The id to be encoded.
encodeId(java.lang.String, boolean)
public static String encodeId(String id,
boolean chop)
A valid Doxia id obeys the same constraints as an HTML ID or NAME token. According to the HTML 4.01 specification section 6.2 SGML basic types:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
According to XHTML 1.0 section C.8. Fragment Identifiers:
When defining fragment identifiers to be backward-compatible, only strings matching the pattern [A-Za-z][A-Za-z0-9:_.-]* should be used.
To achieve this we need to convert the id String. Two conversions are necessary and one is done to get prettier ids:
For letters, the case is preserved in the conversion.
Here are some examples:
DoxiaUtils.encodeId( null ) = null DoxiaUtils.encodeId( "" ) = "a" DoxiaUtils.encodeId( " " ) = "a" DoxiaUtils.encodeId( " _ " ) = "a_" DoxiaUtils.encodeId( "1" ) = "a1" DoxiaUtils.encodeId( "1anchor" ) = "a1anchor" DoxiaUtils.encodeId( "_anchor" ) = "a_anchor" DoxiaUtils.encodeId( "a b-c123 " ) = "a_b-c123" DoxiaUtils.encodeId( " anchor" ) = "anchor" DoxiaUtils.encodeId( "myAnchor" ) = "myAnchor"
id - The id to be encoded.chop - true if non-ASCII characters should be ignored.
If false, any non-ASCII characters will be replaced as specified above.
public static String byteToHex(byte b)
b - the byte value.
public static boolean isValidId(String text)
encodeId(String).
text - The text to be tested.
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.
public static MutableAttributeSet getImageAttributes(String logo)
throws IOException
logo - a String containing either a URL or a path to an image file.
IOException - if an error occurs during reading.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||