-
Notifications
You must be signed in to change notification settings - Fork 0
Class JSX
JSX is the principal class to manage the XML file.
This is a simple construct.
Example:
JSX jsx = new JSX();
throws JSXLockException
This construct set the file path of XML document to be load.
Parameters:
- filePath, path to XML file
Exceptions:
- JSXLockException, exception thrown if JSX-Lock failed
Example:
JSX jsx = new JSX("path/to/file.xml");
This construct set the XML document to work on.
Parameters:
-
document, XML document. Class
org.w3c.dom.Document
Example:
Document doc = JSX.createDocument("path/to/file.xml"); JSX jsx = new JSX(doc);
-
- String getFilePath()
- void setFilePath(String filePath)
- Document getDocument()
- void setDocument(Document document)
- boolean isLock()
- void setLock(boolean lock)
- int getIndentAmount()
- void setIndentAmount(int indentAmount)
- boolean isAutoFlush()
- void setAutoFlush(boolean autoFlush)
- boolean isValidating()
- void setValidating(boolean validating)
- boolean isNamespaceAware()
- void setNamespaceAware(boolean namespaceAware)
- boolean isFeatValidation()
- void setFeatValidation(boolean featValidation)
- boolean isLock()
- void setLock(boolean lock)
- boolean isFeatNamespaces()
- void setFeatNamespaces(boolean featNamespaces)
- boolean isFeatLoadDTDGramm()
- void setFeatLoadDTDGramm(boolean featLoadDTDGramm)
- boolean isFeatLoadExtDTD()
- void setFeatLoadExtDTD(boolean featLoadExtDTD)
- ReentrantLock getReentrantLock()
-
- void addElement(String nameElement)
- void addElement(String nameElement, String textContent)
- void addElement(String nameElement, Map<String, String> attributesMap)
- void addElementWithId(String nameElement, String idElement)
- void addElementWithChild(String nameElement, String idElement, Map<String, String> mapChildNode)
- void addElementWithChild(String nameElement, Map<String, String> attributesMap, Map<String, String> mapChildNode)
- void addElementWithChild(String nameElement, String idElement, Map<String, String> mapChildNode, Map<String, String> mapIdChild)
- void addElementWithChild(String nameElement, Map<String, String> attributesMap, Map<String, String> mapChildNode, Map<String, Map<String, String>> attributesMapChild)
- void appendElement(Node parentNode, String nameElement, String textContext)
- void appendElement(Node parentNode, String nameElement, String idElement, String textContext)
- void appendElement(Node parentNode, String nameElement, Map<String, String> attributesMap, String textContext)
- void appendElementWithChild(Node parentNode, String nameElement, Map<String, String> mapChildNode)
- void deleteNode(String nameElement, String id)
- void deleteNode(Node node)
- void removeBlankLines()
throws XMLException
This method write a log.
Return:
Return an object org.w3c.dom.Document
that rapresents the XML file.
Parameters:
- pathFile, path to XML file
Exceptions:
- XMLException, exception thrown the document creation return a error.
Example:
Document doc = JSX.createDocument("path/to/file.xml");
Document createDocument(String pathFile, boolean validating, boolean namespaceAware, boolean featValidation, boolean featNamespaces, boolean featLoadDTDGramm, boolean featLoadExtDTD)
throws XMLException
This method write a log.
Return:
Return an object org.w3c.dom.Document
that rapresents the XML file.
Parameters:
- pathFile, path to XML file
- validating, activate validating
- namespaceAware, activate namespace aware
- featValidation, activate feature validation
- featNamespaces, activate feature namespaces
- featLoadDTDGramm, activate feature load DTD gramm
- featLoadExtDTD, activate feature load ext DTD
Exceptions:
- XMLException, exception thrown the document creation return a error.
Example:
Document doc = JSX.createDocument("path/to/file.xml", false, false, false, false, false, false);
throws XMLException
This method get the great Integer id.
Return:
Return the great Integer id
Parameters:
- idSet, set of id
Example:
JSX jsx = new JSX("path/to/file.xml"); HashMap<String, Node> mapElement = jsx.getMapIdElement("my-element"); Set<String> idSet = mapElement.keySet(); int greatId = Jogger.getGreatId(idSet);
throws JSXException
This method remove the blank lines on XML document.
Parameters:
-
document, XML document. Class
org.w3c.dom.Document
Exceptions:
- JSXException, exception thrown if the operation return a error.
Example:
Document doc = JSX.createDocument("path/to/file.xml"); JSX.removeBlankLines(doc);
This method get the path of XML file.
Default null
Return:
Return the path of XML file.
Example:
JSX jsx = new JSX("path/to/file.xml"); String path = jsx.getFilePath();
This method set the path of XML file.
Parameters:
- filePath, path of XML file
Example:
JSX jsx = new JSX(); jsx.setFilePath("path/to/file.xml");
This method get the XML document.
Default null
Return:
Return the XML document. Class org.w3c.dom.Document
Example:
JSX jsx = new JSX("path/to/file.xml"); String path = jsx.getFilePath();
This method set the the XML document.
Parameters:
-
document, XML document. Class
org.w3c.dom.Document
Example:
JSX jsx = new JSX(); Document doc = JSX.getDocument("path/to/file.xml"); jsx.setDocument(doc);
This method check if the JSX-Lock is active. Read JSX-Lock.
Default false
Return:
Return true if JSX-Lock is active, false otherwise.
Example:
JSX jsx = new JSX("path/to/file.xml"); if (jsx.isLock()) { //your code }
This method can enable or disable JSX-Lock.
Read JSX-Lock.
Parameters:
- lock, true for active it, false otherwise
Example:
JSX jsx = new JSX("path/to/file.xml"); jsx.setLock(true);
This method get the number of sapces for the indent.
Default 4
Return:
Return the number of sapces for the indent.
Example:
JSX jogger = new JSX("path/to/file.xml"); int indAmnt = jsx.getIndentAmount();
This method set the number of sapces for the indent.
Parameters:
- indentAmount, number of sapces for the indent
Example:
JSX jsx = new JSX("path/to/file.xml"); jsx.setIndentAmount(8);
This method check if the autoflush is active.
Default false
Return:
Return true if autoflush is active, false otherwise.
Example:
JSX jsx = new JSX("path/to/file.xml"); if (jsx.isAutoFlush()) { //your code }
This method can enable or disable autoflush.
Parameters:
- autoFlush, true for active it, false otherwise
Example:
JSX jsx = new JSX("path/to/file.xml"); jsx.setAutoFlush(true);
This method check if the validating is active.
For javax.xml.parsers.DocumentBuilderFactory
object.
Default false
Return:
Return true if the validating is active, false otherwise.
Example:
JSX jogger = new JSX("path/to/file.xml"); if (jsx.isValidating()) { //your code }
This method can enable or disable the validation of XML file.
It passed at setValidating(validating)
method of javax.xml.parsers.DocumentBuilderFactory
object.
Parameters:
- validating, true for active it, false otherwise
Example:
JSX jsx = new JSX("path/to/file.xml"); jsx.setValidating(true);
This method check if the namespace aware is active.
For javax.xml.parsers.DocumentBuilderFactory
object.
Default false
Return:
Return true if namespace aware is active, false otherwise.
Example:
JSX jogger = new JSX("path/to/file.xml"); if (jsx.isNamespaceAware()) { //your code }
This method can enable or disable the namespace aware.
It passed at setNamespaceAware(namespaceAware)
method of javax.xml.parsers.DocumentBuilderFactory
object.
Parameters:
- namespaceAware, true for active it, false otherwise
Example:
JSX jsx = new JSX("path/to/file.xml"); jsx.setNamespaceAware(true);
This method check if the feature validation is active.
For javax.xml.parsers.DocumentBuilderFactory
object.
Default false
Return:
Return true if the feature validation is active, false otherwise.
Example:
JSX jsx = new JSX("path/to/file.xml"); if (jsx.isFeatValidation()) { //your code }
This method can enable or disable the feature validation.
Feature http://xml.org/sax/features/validation
used for javax.xml.parsers.DocumentBuilderFactory
object.
Parameters:
- featValidation, true for active it, false otherwise
Example:
JSX jsx = new JSX("path/to/file.xml"); jsx.setFeatValidation(true);
This method check if the feature namespaces is active.
Default false
Return:
Return true if feature namespaces is active, false otherwise.
Example:
JSX jogger = new JSX("path/to/file.xml"); if (jsx.isFeatNamespaces()) { //your code }
This method can enable or disable the feature namespaces.
Feature http://xml.org/sax/features/namespaces
used for javax.xml.parsers.DocumentBuilderFactory
object.
Parameters:
- featNamespaces, true for active it, false otherwise
Example:
JSX jsx = new JSX("path/to/file.xml"); jsx.setFeatNamespaces(true);
This method check if the feature load DTD gramm is active.
Default false
Return:
Return true if the feature load DTD gramm is active, false otherwise.
Example:
JSX jsx = new JSX("path/to/file.xml"); if (jsx.isFeatLoadDTDGramm()) { //your code }
This method can enable or disable the feature load DTD gramm.
Feature http://apache.org/xml/features/nonvalidating/load-dtd-grammar
used for javax.xml.parsers.DocumentBuilderFactory
object.
Parameters:
- featLoadDTDGramm, true for active it, false otherwise
Example:
JSX jsx = new JSX("path/to/file.xml"); jsx.setFeatLoadDTDGramm(true);
This method check if the feature load ext DTD is active.
Default false
Return:
Return true if the feature load ext DTD is active, false otherwise.
Example:
JSX jsx = new JSX("path/to/file.xml"); if (jsx.isFeatLoadExtDTD()) { //your code }
This method can enable or disable the feature load ext DTD.
Feature http://apache.org/xml/features/nonvalidating/load-external-dtd
used for javax.xml.parsers.DocumentBuilderFactory
object.
Parameters:
- validating, true for active it, false otherwise
Example:
JSX jsx = new JSX("path/to/file.xml"); jsx.setFeatLoadExtDTD(true);
This method get the reentrant lock used for XML file.
Return:
Return the java.util.concurrent.locks.ReentrantLock
object used for the lock.
Example:
JSX jsx = new JSX("path/to/file.xml"); if (jsx.getReentrantLock().tryLock()) { // your code }
throws JSXLockException
This method add a element on document.
Implement JSX-Lock. For more info JSX-Lock.
Parameters:
- nameElement, name of element to be added
Exceptions:
- JSXLockException, exception thrown if JSX-Lock_ failed
Example:
JSX jsx = new JSX("path/to/file.xml"); jsx.addElement("new-element");
throws JSXLockException
This method add a element with text on document.
Implement JSX-Lock. For more info JSX-Lock.
Parameters:
- nameElement, name of element to be added
- textContent, text body of the the new element
Exceptions:
- JSXLockException, exception thrown if JSX-Lock_ failed
Example:
JSX jsx = new JSX("path/to/file.xml"); jsx.addElement("jsx", "Awesome!!!");
throws JSXLockException
This method add a element with attributes on document.
Implement JSX-Lock. For more info JSX-Lock.
Parameters:
- nameElement, name of element to be added
- attributesMap, map of attributes
Exceptions:
- JSXLockException, exception thrown if JSX-Lock_ failed
Example:
JSX jsx = new JSX("path/to/file.xml"); HashMap<String, String> attrMap = new HashMap<String, String>(); attrMap.put("attribute", "value"); jsx.addElement("new-element", attrMap);
throws JSXLockException
This method add a element with the id attribute on document.
Implement JSX-Lock. For more info JSX-Lock.
Parameters:
- nameElement, name of element to be added
- idElement, id for element
Exceptions:
- JSXLockException, exception thrown if JSX-Lock_ failed
Example:
JSX jsx = new JSX("path/to/file.xml"); jsx.addElementWithId("new-element", "jsx-element");
throws JSXLockException
This method add a element with the id attribute and child elements on document.
Implement JSX-Lock. For more info JSX-Lock.
Parameters:
- nameElement, name of element to be added
- idElement, id for element
- mapChildNode, map of child node for new element. The key is the name of child element, the value is the text body
Exceptions:
- JSXLockException, exception thrown if JSX-Lock_ failed
Example:
JSX jsx = new JSX("path/to/file.xml"); HashMap<String, String> childs = new HashMap<String, String>(); childs.put("jsx", "cool"); jsx.addElementWithChild("new-element", "jsx-element", childs);
void addElementWithChild(String nameElement, Map<String, String> attributesMap, Map<String, String> mapChildNode)
throws JSXLockException
This method add a element with attributes and child elements on document.
Implement JSX-Lock. For more info JSX-Lock.
Parameters:
- nameElement, name of element to be added
- attributesMap, map of attributes
- mapChildNode, map of child node for new element. The key is the name of child element, the value is the text body
Exceptions:
- JSXLockException, exception thrown if JSX-Lock_ failed
Example:
JSX jsx = new JSX("path/to/file.xml"); HashMap<String, String> attrMap = new HashMap<String, String>(); HashMap<String, String> childs = new HashMap<String, String>(); attrMap.put("attr", "val"); childs.put("jsx", "cool"); jsx.addElementWithChild("new-element", attrMap, childs);
void addElementWithChild(String nameElement, String idElement, Map<String, String> mapChildNode, Map<String, String> mapIdChild)
throws JSXLockException
This method add a element with the id attribute and child elements with id on document.
Implement JSX-Lock. For more info JSX-Lock.
Parameters:
- nameElement, name of element to be added
- idElement, id for element
- mapChildNode, map of child node for new element. The key is name of child element, the value is the text body
- mapIdChild, map of id for child. The key is the name of child element, the value is the id
Exceptions:
- JSXLockException, exception thrown if JSX-Lock_ failed
Example:
JSX jsx = new JSX("path/to/file.xml"); HashMap<String, String> childs = new HashMap<String, String>(); HashMap<String, String> idChilds = new HashMap<String, String>(); childs.put("jsx", "cool"); idChilds.put("jsx", "jsx-id"); jsx.addElementWithChild("new-element", "jsx-element", childs, idChilds);
void addElementWithChild(String nameElement, Map<String, String> attributesMap, Map<String, String> mapChildNode, Map<String, Map<String, String>> attributesMapChild)
throws JSXLockException
This method add a element and child elements, with attributes, on document.
Implement JSX-Lock. For more info JSX-Lock.
Parameters:
- nameElement, name of element to be added
- attributesMap, map of attributes
- mapChildNode, map of child node for new element. The key is name of child element, the value is the text body
- attributesMapChild, bidimensional map for attributes of childs. The key is name of child element, the value is the map with the attributes
Exceptions:
- JSXLockException, exception thrown if JSX-Lock_ failed
Example:
JSX jsx = new JSX("path/to/file.xml"); HashMap<String, String> attrMap = new HashMap<String, String>(); HashMap<String, String> childs = new HashMap<String, String>(); HashMap<String, HashMap<String, String>> attrChildsMap = new HashMap<String, HashMap<String, String>>(); HashMap<String, String> attr = new HashMap<String, String>(); attrMap.put("attr-element", "val"); childs.put("jsx", "cool"); attr.put("attr-child", "val"); attrChildsMap.put("jsx", attr); jsx.addElementWithChild("new-element", attrMap, childs, attrChildsMap);
throws JSXLockException
This method append new element on parent node.
Implement JSX-Lock. For more info JSX-Lock.
Parameters:
-
parentNode, parent to node to be append the new element.
Class
org.w3c.dom.Node
- nameElement, name of element to be added
- textContent, text body of the the new element
Exceptions:
- JSXLockException, exception thrown if JSX-Lock_ failed
Example:
JSX jsx = new JSX("path/to/file.xml"); Node node = jsx.getElementById("element", "jsx"); jsx.appendElement(node, "time", "420");
throws JSXLockException
This method append new element on parent node.
Implement JSX-Lock. For more info JSX-Lock.
Parameters:
-
parentNode, parent to node to be append the new element.
Class
org.w3c.dom.Node
- nameElement, name of element to be added
- idElement, id for element
- textContent, text body of the the new element
Exceptions:
- JSXLockException, exception thrown if JSX-Lock_ failed
Example:
JSX jsx = new JSX("path/to/file.xml"); Node node = jsx.getElementById("element", "jsx"); jsx.appendElement(node, "time", "time-element", "420");
void appendElement(Node parentNode, String nameElement, Map<String, String> attributesMap, String textContext)
throws JSXLockException
This method append new element on parent node.
Implement JSX-Lock. For more info JSX-Lock.
Parameters:
-
parentNode, parent to node to be append the new element.
Class
org.w3c.dom.Node
- nameElement, name of element to be added
- attributesMap, map of attributes
- textContent, text body of the the new element
Exceptions:
- JSXLockException, exception thrown if JSX-Lock_ failed
Example:
JSX jsx = new JSX("path/to/file.xml"); HashMap<String, String> attrMap = new HashMap<String, String>(); Node node = jsx.getElementById("element", "jsx"); attrMap.put("need", "beer"); jsx.appendElement(node, "new-element", attrMap, "YEEEEEAAAAAHHHH!!!");
throws JSXLockException
This method append new element on parent node.
Implement JSX-Lock. For more info JSX-Lock.
Parameters:
-
parentNode, parent to node to be append the new element.
Class
org.w3c.dom.Node
- nameElement, name of element to be added
- mapChildNode, map of child node for new element. The key is name of child element, the value is the text body
Exceptions:
- JSXLockException, exception thrown if JSX-Lock_ failed
Example:
JSX jsx = new JSX("path/to/file.xml"); HashMap<String, String> childs = new HashMap<String, String>(); Node node = jsx.getElementById("element", "jsx"); childs.put("time", "hacking"); jsx.appendElement(node, "new-element", childs);
throws LogFileException
This method get the path of log file to work on.
Return:
Return the string with the path of log file to work on.
Exceptions:
- LogFileException, exception thrown if an error is return while working on the log file
Example:
Jogger jogger = new Jogger(); String logFilePath = jogger.getLogFilePath();
throws LogFileException
This method get the log file to work on.
Return:
Return the log file to work on.
Exceptions:
- LogFileException, exception thrown if an error is return while working on the log file
Example:
Jogger jogger = new Jogger(); File logFile = jogger.getFile();
throws LogFileException
This method get the log file to work on, only if it exists.
Return:
If the log file exists return it, otherwise return null.
Exceptions:
- LogFileException, exception thrown if an error is return while working on the log file
Example:
Jogger jogger = new Jogger(); File logFile = jogger.getFileIfExists();
throws LockLogException
This method is used to implement Jogger-Lock.
It check if Jogger-Lock is enable,
then in this case try to lock the file using the class java.util.concurrent.locks.ReentrantLock
.
For more info Jogger-Lock.
Return:
Return true if Jogger-Lock is disable or the lock is successful, false otherwise.
Exceptions:
- LockLogException, exception thrown if the timeout for the lock expires
This method is used to implement Jogger-Lock.
It check if Jogger-Lock is enable,
then in this case unlock the file using the class java.util.concurrent.locks.ReentrantLock
.
For more info Jogger-Lock.