Package nl.dedicon.pipeline.braille.step
Class Utils
- java.lang.Object
-
- nl.dedicon.pipeline.braille.step.Utils
-
public class Utils extends Object
Utilities for Java XProc steps- Author:
- Paul Rambags
-
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ElementaddChild(Node parent, String name)Add a new child node to a parent node The new child node will inherit the parent's namespacestatic ElementaddChildBefore(Node parent, Node child, String name)Add a new child node to a parent node before a child node The new child node will inherit the parent's namespace If the child node is null, the new child node will be added at the end of the list of childrenstatic charconvertBraille(char braille)Convert a character from braille to lowercase text Braille control characters are not changed For characters with more than one text representation, the most common one is chosen e.g.static charconvertBrailleNumeric(char braille)Convert a numeric character from braille to lowercase textstatic DocumentconvertToDocument(String xml)Convert an XML string to a Document nodestatic DocumentconvertToDocument(net.sf.saxon.s9api.XdmNode node)Convert an XdmNode to a Document node TODO this produces unwanted white space (it is converted with indent="true")static net.sf.saxon.s9api.XdmNodeconvertToXdmNode(Document document, net.sf.saxon.s9api.Processor processor, boolean useFile)Convert a Document node to an XdmNodestatic StringconvertXmlEndtagsToHtmlEndtags(String xml)Converts XML end tags to a HTML end tags Each "/>" is replaced by ">" for the correct tagstatic NodegetChild(Node node, String name)Get the first child in the same namespace with a given namestatic net.sf.saxon.s9api.XdmNodegetChildNode(net.sf.saxon.s9api.XdmNode node, net.sf.saxon.s9api.QName childName)Get the first child nodestatic NodegetFirstChildWithAttribute(Node node, String name, String attributeName, String attributeValue)Get the first child in the same namespace with a given name and a given attribute valuestatic NodegetNextSiblingWithAttribute(Node node, String name, String attributeName, String attributeValue)Get the first sibling in the same namespace with a given name and a given attribute valuestatic StringgetValue(net.sf.saxon.s9api.XdmNode node, net.sf.saxon.s9api.QName childName)Get the string value of a child nodestatic booleanisBraille(char c)Determine whether a unicode character is in the braille rangestatic booleanisBrailleDecimalSeparator(char braille)Determine whether a braille character is a decimal separatorstatic booleanisBrailleDigit(char braille)Determine whether a braille character is a digitstatic booleanisBrailleMinus(char braille)Determine whether a character is the minus signstatic booleanisBrailleMoneyZeros(char braille)Determine whether a braille character can be used as a shorthand for 00 at the end of a price E.g.static booleanisDecimalSeparator(char c)Determine whether a character is a decimal separatorstatic booleanisDigit(char c)Determine whether a character is a digitstatic booleanisMoneyZeros(char c)Determine whether a character can be used as a shorthand for 00 at the end of a price E.g.static voidremoveNodes(Set<Node> nodes)Remove nodesstatic NoderenameNode(Node node, String newNodeName)Rename a node and maintain the namespacestatic StringtoString(net.sf.saxon.s9api.XdmNode node)Convert an XdmNode to an XML stringstatic StringtoString(Document document, net.sf.saxon.s9api.DocumentBuilder documentBuilder)Convert a Document node to an XML string
-
-
-
Method Detail
-
convertToDocument
public static Document convertToDocument(net.sf.saxon.s9api.XdmNode node) throws ParserConfigurationException, SAXException, IOException, net.sf.saxon.s9api.SaxonApiException
Convert an XdmNode to a Document node TODO this produces unwanted white space (it is converted with indent="true")- Parameters:
node- XdmNode- Returns:
- Document node
- Throws:
ParserConfigurationException- thrown on parse exceptionsSAXException- thrown on a SAX exceptionIOException- thrown on an IO exceptionnet.sf.saxon.s9api.SaxonApiException
-
convertToXdmNode
public static net.sf.saxon.s9api.XdmNode convertToXdmNode(Document document, net.sf.saxon.s9api.Processor processor, boolean useFile) throws IOException, net.sf.saxon.s9api.SaxonApiException
Convert a Document node to an XdmNode- Parameters:
document- Document nodedocumentBuilder- document builderuseFile- if true, the resulting XdmNode will be saved in a temporary file so that it has an URI- Returns:
- XdmNode
- Throws:
IOException- thrown on an IO exceptionnet.sf.saxon.s9api.SaxonApiException- thrown on a Saxon API exception
-
toString
public static String toString(net.sf.saxon.s9api.XdmNode node) throws net.sf.saxon.s9api.SaxonApiException
Convert an XdmNode to an XML string- Parameters:
node- XdmNode- Returns:
- XML string
- Throws:
net.sf.saxon.s9api.SaxonApiException- thrown on a Saxon API exception
-
toString
public static String toString(Document document, net.sf.saxon.s9api.DocumentBuilder documentBuilder) throws net.sf.saxon.s9api.SaxonApiException
Convert a Document node to an XML string- Parameters:
document- Document nodedocumentBuilder- document builder- Returns:
- XML string
- Throws:
net.sf.saxon.s9api.SaxonApiException
-
convertToDocument
public static Document convertToDocument(String xml) throws ParserConfigurationException, SAXException, IOException
Convert an XML string to a Document node- Parameters:
xml- XML string- Returns:
- Document node
- Throws:
ParserConfigurationException- thrown on parse exceptionsSAXException- thrown on a SAX exceptionIOException- thrown on an IO exception
-
getChild
public static Node getChild(Node node, String name)
Get the first child in the same namespace with a given name- Parameters:
node- nodename- child node name- Returns:
- the first child in the same namespace with the given name, or null if it doesn't exist
-
getFirstChildWithAttribute
public static Node getFirstChildWithAttribute(Node node, String name, String attributeName, String attributeValue)
Get the first child in the same namespace with a given name and a given attribute value- Parameters:
node- nodename- child node nameattributeName- attribute nameattributeValue- attribute value- Returns:
- the first child in the same namespace with the given name and with the given attribute value, or null if it doesn't exist
-
getNextSiblingWithAttribute
public static Node getNextSiblingWithAttribute(Node node, String name, String attributeName, String attributeValue)
Get the first sibling in the same namespace with a given name and a given attribute value- Parameters:
node- nodename- sibling node nameattributeName- attribute nameattributeValue- attribute value- Returns:
- the first sibling in the same namespace with the given name and with the given attribute value, or null if it doesn't exist
-
addChild
public static Element addChild(Node parent, String name)
Add a new child node to a parent node The new child node will inherit the parent's namespace- Parameters:
parent- parent nodename- name of the child node- Returns:
- the new child node
-
addChildBefore
public static Element addChildBefore(Node parent, Node child, String name)
Add a new child node to a parent node before a child node The new child node will inherit the parent's namespace If the child node is null, the new child node will be added at the end of the list of children- Parameters:
parent- parent nodechild- child node, can be nullname- name of the child node- Returns:
- the new child node
-
renameNode
public static Node renameNode(Node node, String newNodeName)
Rename a node and maintain the namespace- Parameters:
node- the node that will get a new node namenewNodeName- the new node name- Returns:
- the renamed node
-
removeNodes
public static void removeNodes(Set<Node> nodes)
Remove nodes- Parameters:
nodes- the nodes that must be removed
-
getChildNode
public static net.sf.saxon.s9api.XdmNode getChildNode(net.sf.saxon.s9api.XdmNode node, net.sf.saxon.s9api.QName childName)Get the first child node- Parameters:
node- XdmNodechildName- child name- Returns:
- XdmNode the first child node, or null if it doesn't exist
-
getValue
public static String getValue(net.sf.saxon.s9api.XdmNode node, net.sf.saxon.s9api.QName childName)
Get the string value of a child node- Parameters:
node- XdmNodechildName- child name- Returns:
- String value of the child, or null if it doesn't exist
-
convertXmlEndtagsToHtmlEndtags
public static String convertXmlEndtagsToHtmlEndtags(String xml)
Converts XML end tags to a HTML end tags Each "/>" is replaced by ">" for the correct tag- Parameters:
xml- XML string- Returns:
- HTML string
-
isBraille
public static boolean isBraille(char c)
Determine whether a unicode character is in the braille range- Parameters:
c- unicode character- Returns:
- true if it is in the braile range, false otherwise
-
convertBraille
public static char convertBraille(char braille)
Convert a character from braille to lowercase text Braille control characters are not changed For characters with more than one text representation, the most common one is chosen e.g. (123456) is displayed as é but can also be %- Parameters:
braille- Braille character- Returns:
- text character
-
isBrailleDigit
public static boolean isBrailleDigit(char braille)
Determine whether a braille character is a digit- Parameters:
braille- braille character- Returns:
- true if it is a digit in the braille range
-
isDigit
public static boolean isDigit(char c)
Determine whether a character is a digit- Parameters:
c- character- Returns:
- true if it is a digit
-
convertBrailleNumeric
public static char convertBrailleNumeric(char braille)
Convert a numeric character from braille to lowercase text- Parameters:
braille- Braille character- Returns:
- numeric text character
-
isBrailleMinus
public static boolean isBrailleMinus(char braille)
Determine whether a character is the minus sign- Parameters:
braille- braille character- Returns:
- true when the character is '-'
-
isBrailleDecimalSeparator
public static boolean isBrailleDecimalSeparator(char braille)
Determine whether a braille character is a decimal separator- Parameters:
braille- braille character- Returns:
- true when the braille character is a comma or period
-
isDecimalSeparator
public static boolean isDecimalSeparator(char c)
Determine whether a character is a decimal separator- Parameters:
c- character- Returns:
- true when the character is a comma or period
-
isBrailleMoneyZeros
public static boolean isBrailleMoneyZeros(char braille)
Determine whether a braille character can be used as a shorthand for 00 at the end of a price E.g. the = sign in this price: € 6,=- Parameters:
braille- braille character- Returns:
- true when the character is a - or a =
-
isMoneyZeros
public static boolean isMoneyZeros(char c)
Determine whether a character can be used as a shorthand for 00 at the end of a price E.g. the = sign in this price: € 6,=- Parameters:
c- character- Returns:
- true when the character is a - or a =
-
-