Package mgui.interfaces.xml
Class XMLFunctions
java.lang.Object
mgui.interfaces.Utility
mgui.interfaces.xml.XMLFunctions
public class XMLFunctions extends Utility
Utility class for XML-related functions.
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Andrew Reid
-
Constructor Summary
Constructors Constructor Description XMLFunctions() -
Method Summary
Modifier and Type Method Description static <V> Attribute<V>createAttribute(java.lang.Class<V> c, java.lang.String name, java.lang.Object value)Creates a newAttributewith a new instance of the given class.static java.awt.ColorgetColourForXML(org.xml.sax.Attributes attributes)static XMLObject.XMLEncodinggetEncodingForStr(java.lang.String encoding)Returns theXMLFormatcorresponding toformat.static java.lang.StringgetEncodingStr(XMLObject.XMLEncoding encoding)Returns the string corresponding toencoding.static java.lang.ObjectgetObjectForXML(java.lang.String localName, org.xml.sax.Attributes attributes, java.lang.String class_name)Returns a new instantiated Object corresponding to the "object_class" field ofattributes.static java.lang.ObjectgetObjectForXMLString(java.lang.Class<?> obj_class, java.lang.String string)Attempts to detect the data type ofsand return a newly instantiated Object of the correct Class.static org.jogamp.vecmath.Point2fgetPoint2f(java.lang.String s)static java.util.ArrayList<org.jogamp.vecmath.Point2f>getPoint2fList(java.lang.String s)Parsessfor '\t' and '\n' characters into a list of 2D pointsstatic org.jogamp.vecmath.Point3dgetPoint3d(java.lang.String s)static org.jogamp.vecmath.Point3fgetPoint3f(java.lang.String s)static java.lang.StringgetTab(int tab)Returns a string with the specified number of tabsstatic java.lang.StringgetTupleStr(org.jogamp.vecmath.Tuple3d t, int precision)static java.lang.StringgetTupleStr(org.jogamp.vecmath.Tuple3f t, int precision)static org.jogamp.vecmath.Vector2dgetVector2d(java.lang.String s)static org.jogamp.vecmath.Vector3dgetVector3d(java.lang.String s)static org.jogamp.vecmath.Vector3fgetVector3f(java.lang.String s)static java.lang.StringgetVectorStr(org.jogamp.vecmath.Tuple2d t, int precision)static java.lang.StringgetVectorStr(org.jogamp.vecmath.Tuple2f t, int precision)static java.lang.StringgetXMLCodedString(java.lang.String string)Encodes a string into an XML-friendly line by replacing angle brackets with their escape characters: < --> < > --> >static java.lang.StringgetXMLDecodedString(java.lang.String string)Decodes a string from an XML-friendly line by replacing angle brackets escape characters with their characters.static javax.swing.filechooser.FileFiltergetXMLFileFilter()static java.lang.StringgetXMLForAttributeObject(java.lang.Object obj, int tab)Returns a string representingobjin anAttribute.static java.lang.StringgetXMLForObject(java.lang.Object obj, int tab)static java.lang.StringgetXMLForPoint2f(org.jogamp.vecmath.Point2f p, int precision)static java.lang.StringgetXMLFriendlyString(java.lang.String string)Returns a string which is an XML-friendly version ofstring, for insertion into a tag value.static java.lang.StringgetXMLHeader()Returns the XML header from the current environmentstatic java.lang.StringgetXMLStrForType(XMLObject.XMLType type)Returns a String corresponding to the XMLObject.XMLType.static java.lang.StringgetXMLTabbedString(java.lang.String string, int tab)Prepends all newline characters with the appropriate tab character, for friendlier XML outputstatic XMLObject.XMLTypegetXMLTypeForStr(java.lang.String string)Returns the XMLObject.XMLType corresponding tostring.static java.lang.StringgetXMLUntabbedString(java.lang.String string, int tab)Removes all new-line tabs from an XML input stringstatic java.awt.ColorparseColor(java.lang.String fstr)Parses a color string (three space-delimited values) and returns the corresponding fontstatic java.awt.FontparseFont(java.lang.String fstr)Parses a font string (returned by Font.toString()) and returns the corresponding fontstatic java.awt.BasicStrokeparseStroke(java.lang.String fstr)Parses the string for a BasicStroke.static voidwriteToXML(java.io.File file, XMLObject xml)Writes an XML object to file.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
XMLFunctions
public XMLFunctions()
-
-
Method Details
-
getXMLFriendlyString
public static java.lang.String getXMLFriendlyString(java.lang.String string)Returns a string which is an XML-friendly version ofstring, for insertion into a tag value. That is, replaces special characters in tags such as '&', '<', or '>' with their XML equivalents. See this page for a list of codes.TODO: Either (1) complete this list; or (2) set policy such that tags cannot contain special characters
- Parameters:
string-- Returns:
-
getXMLHeader
public static java.lang.String getXMLHeader()Returns the XML header from the current environment- Returns:
-
getXMLTypeForStr
Returns the XMLObject.XMLType corresponding tostring.- Parameters:
string-- Returns:
-
getXMLStrForType
Returns a String corresponding to the XMLObject.XMLType.- Parameters:
string-- Returns:
-
getEncodingStr
Returns the string corresponding toencoding.- Parameters:
format-- Returns:
-
getEncodingForStr
Returns theXMLFormatcorresponding toformat.- Parameters:
format-- Returns:
-
getTab
public static java.lang.String getTab(int tab)Returns a string with the specified number of tabs- Parameters:
tab-- Returns:
-
getTupleStr
public static java.lang.String getTupleStr(org.jogamp.vecmath.Tuple3d t, int precision) -
getTupleStr
public static java.lang.String getTupleStr(org.jogamp.vecmath.Tuple3f t, int precision) -
getVectorStr
public static java.lang.String getVectorStr(org.jogamp.vecmath.Tuple2d t, int precision) -
getVectorStr
public static java.lang.String getVectorStr(org.jogamp.vecmath.Tuple2f t, int precision) -
getVector3d
public static org.jogamp.vecmath.Vector3d getVector3d(java.lang.String s) -
getVector2d
public static org.jogamp.vecmath.Vector2d getVector2d(java.lang.String s) -
getVector3f
public static org.jogamp.vecmath.Vector3f getVector3f(java.lang.String s) -
createAttribute
public static <V> Attribute<V> createAttribute(java.lang.Class<V> c, java.lang.String name, java.lang.Object value) throws org.xml.sax.SAXExceptionCreates a newAttributewith a new instance of the given class. Class must define an empty constructor.- Parameters:
c-name-- Returns:
- Throws:
org.xml.sax.SAXException
-
getXMLCodedString
public static java.lang.String getXMLCodedString(java.lang.String string)Encodes a string into an XML-friendly line by replacing angle brackets with their escape characters:- < --> <
- > --> >
- Parameters:
string-- Returns:
-
getXMLDecodedString
public static java.lang.String getXMLDecodedString(java.lang.String string)Decodes a string from an XML-friendly line by replacing angle brackets escape characters with their characters.- < --> <
- > --> >
- Parameters:
string-- Returns:
-
getXMLTabbedString
public static java.lang.String getXMLTabbedString(java.lang.String string, int tab)Prepends all newline characters with the appropriate tab character, for friendlier XML output- Parameters:
string-- Returns:
-
getXMLUntabbedString
public static java.lang.String getXMLUntabbedString(java.lang.String string, int tab)Removes all new-line tabs from an XML input string- Parameters:
string-tab-
-
getPoint2fList
public static java.util.ArrayList<org.jogamp.vecmath.Point2f> getPoint2fList(java.lang.String s)Parsessfor '\t' and '\n' characters into a list of 2D points- Parameters:
s-- Returns:
-
getPoint2f
public static org.jogamp.vecmath.Point2f getPoint2f(java.lang.String s) -
getPoint3f
public static org.jogamp.vecmath.Point3f getPoint3f(java.lang.String s) -
getPoint3d
public static org.jogamp.vecmath.Point3d getPoint3d(java.lang.String s) -
getXMLFileFilter
public static javax.swing.filechooser.FileFilter getXMLFileFilter() -
getXMLForPoint2f
public static java.lang.String getXMLForPoint2f(org.jogamp.vecmath.Point2f p, int precision) -
getXMLForObject
public static java.lang.String getXMLForObject(java.lang.Object obj, int tab) -
getXMLForAttributeObject
public static java.lang.String getXMLForAttributeObject(java.lang.Object obj, int tab)Returns a string representingobjin anAttribute.- Parameters:
obj-tab-- Returns:
-
getColourForXML
public static java.awt.Color getColourForXML(org.xml.sax.Attributes attributes) -
getObjectForXML
public static java.lang.Object getObjectForXML(java.lang.String localName, org.xml.sax.Attributes attributes, java.lang.String class_name)Returns a new instantiated Object corresponding to the "object_class" field ofattributes.- Parameters:
localName-attributes-- Returns:
- New object instance, or
nullif one could not be created TODO: Allow user-defined handlers in theInterfaceEnvironment
-
getObjectForXMLString
public static java.lang.Object getObjectForXMLString(java.lang.Class<?> obj_class, java.lang.String string) throws XMLExceptionAttempts to detect the data type ofsand return a newly instantiated Object of the correct Class.- Parameters:
string- String with which to instantiate object- Returns:
- The instantiated object
- Throws:
XMLException- If object could not be instantiated
-
parseFont
public static java.awt.Font parseFont(java.lang.String fstr) throws java.lang.ExceptionParses a font string (returned by Font.toString()) and returns the corresponding font- Parameters:
fstr-- Returns:
- Throws:
java.lang.Exception
-
parseColor
public static java.awt.Color parseColor(java.lang.String fstr) throws java.lang.ExceptionParses a color string (three space-delimited values) and returns the corresponding font- Parameters:
fstr-- Returns:
- Throws:
java.lang.Exception
-
parseStroke
public static java.awt.BasicStroke parseStroke(java.lang.String fstr) throws java.lang.ExceptionParses the string for a BasicStroke.- Parameters:
fstr-- Returns:
- Throws:
java.lang.Exception
-
writeToXML
Writes an XML object to file. Overwrites an existing file. To append to an existing file, use appendToXML.- Parameters:
file-xml-- Throws:
XMLException
-