Skip to content

Class JSX

hxs edited this page Nov 27, 2019 · 19 revisions

JSX

Package jsx
File JSX.java

JSX is the principal class to manage the XML file.

Constructs


JSX()

This is a simple construct.

Example:

JSX jsx = new JSX();

JSX(String filePath)

throws JSXLockException

This construct set the file path of XML document to be load.

Parameters:

  • filePath, path to XML file

Exceptions:

  • JSXLockException, exception raised if JSX-Lock failed

Example:

JSX jsx = new JSX("path/to/file.xml");

JSX(Document document)

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);

Methods



Static

Document createDocument(String pathFile)

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 raised 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 raised the document creation return a error.

Example:

Document doc = JSX.createDocument("path/to/file.xml", false, false, false, false, false, false);

int getGreatId(Set<String> idSet)

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);

void removeBlankLines(Document document)

throws JSXException

This method remove the blank lines on XML document.

Parameters:

  • document, XML document. Class org.w3c.dom.Document

Exceptions:

  • JSXException, exception raised if the operation return a error.

Example:

Document doc = JSX.createDocument("path/to/file.xml");
JSX.removeBlankLines(doc);

Get and Set

String getFilePath()

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();

void setFilePath(String filePath)

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");

Document getDocument()

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();

void setDocument(Document document)

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);

boolean isLock()

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
}

void setLock(boolean lock)

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);

int getIndentAmount()

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();

void setIndentAmount(int indentAmount)

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);

boolean isAutoFlush()

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
}

void setAutoFlush(boolean autoFlush)

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);

boolean isValidating())

This method check if the validating is active.

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
}

void setValidating(boolean validating)

This method can enable or disable the validation of XML file.

Parameters:

  • validating, true for active it, false otherwise

Example:

JSX jsx = new JSX("path/to/file.xml");
jsx.setValidating(true);

boolean isFeatValidation())

This method check if the feature validation is active.

Default false

Return:
Return true if the feature validation is active, false otherwise.

Example:

JSX jogger = new JSX("path/to/file.xml");
if (jsx.isFeatValidation()) {
  //your code
}

void setFeatValidation(boolean featValidation)

This method can enable or disable the feature validation.

Parameters:

  • featValidation, true for active it, false otherwise

Example:

JSX jsx = new JSX("path/to/file.xml");
jsx.setFeatValidation(true);

boolean isValidating())

This method check if the validating is active.

Default false

Return:
Return true if Jogger-Lock is active, false otherwise.

Example:

JSX jogger = new JSX("path/to/file.xml");
if (jsx.isValidating()) {
  //your code
}

void setValidating(boolean validating)

This method can enable or disable the validating of XML file.

Parameters:

  • validating, true for active it, false otherwise

Example:

JSX jsx = new JSX("path/to/file.xml");
jsx.setValidating(true);

boolean isValidating())

This method check if the validating is active.

Default false

Return:
Return true if Jogger-Lock is active, false otherwise.

Example:

JSX jogger = new JSX("path/to/file.xml");
if (jsx.isValidating()) {
  //your code
}

void setValidating(boolean validating)

This method can enable or disable path of XML file.

Parameters:

  • validating, true for active it, false otherwise

Example:

JSX jsx = new JSX("path/to/file.xml");
jsx.setValidating(true);

boolean isValidating())

This method check if the validating is active.

Default false

Return:
Return true if Jogger-Lock is active, false otherwise.

Example:

JSX jogger = new JSX("path/to/file.xml");
if (jsx.isValidating()) {
  //your code
}

void setValidating(boolean validating)

This method can enable or disable the path of XML file.

Parameters:

  • validating, true for active it, false otherwise

Example:

JSX jsx = new JSX("path/to/file.xml");
jsx.setValidating(true);

boolean isValidating())

This method check if the validating is active.

Default false

Return:
Return true if Jogger-Lock is active, false otherwise.

Example:

JSX jogger = new JSX("path/to/file.xml");
if (jsx.isValidating()) {
  //your code
}

void setValidating(boolean validating)

This method can enable or disable the path of XML file.

Parameters:

  • validating, true for active it, false otherwise

Example:

JSX jsx = new JSX("path/to/file.xml");
jsx.setValidating(true);

String getFilePath()

This method get the path of XML file.

Default null

Return:
Return the path of XML file.

Example:

JSX jogger = new JSX("path/to/file.xml");
String path = jsx.getFilePath();

void setFilePath(String filePath)

This method set the path of XML file.

Parameters:

  • filePath, path of XML file

Example:

JSX jsx = new JSX("path/to/file.xml");
jsx.setFilePath("path/to/file.xml");

String getFilePath()

This method get the path of XML file.

Default null

Return:
Return the path of XML file.

Example:

JSX jogger = new JSX("path/to/file.xml");
String path = jsx.getFilePath();

void setFilePath(String filePath)

This method set the path of XML file.

Parameters:

  • filePath, path of XML file

Example:

JSX jsx = new JSX("path/to/file.xml");
jsx.setFilePath("path/to/file.xml");

String getFilePath()

This method get the path of XML file.

Default null

Return:
Return the path of XML file.

Example:

JSX jogger = new JSX("path/to/file.xml");
String path = jsx.getFilePath();

void setFilePath(String filePath)

This method set the path of XML file.

Parameters:

  • filePath, path of XML file

Example:

JSX jsx = new JSX("path/to/file.xml");
jsx.setFilePath("path/to/file.xml");

String getFilePath()

This method get the path of XML file.

Default null

Return:
Return the path of XML file.

Example:

JSX jogger = new JSX("path/to/file.xml");
String path = jsx.getFilePath();

void setFilePath(String filePath)

This method set the path of XML file.

Parameters:

  • filePath, path of XML file

Example:

JSX jsx = new JSX("path/to/file.xml");
jsx.setFilePath("path/to/file.xml");

String getFilePath()

This method get the path of XML file.

Default null

Return:
Return the path of XML file.

Example:

JSX jogger = new JSX("path/to/file.xml");
String path = jsx.getFilePath();

void setFilePath(String filePath)

This method set the path of XML file.

Parameters:

  • filePath, path of XML file

Example:

JSX jsx = new JSX("path/to/file.xml");
jsx.setFilePath("path/to/file.xml");

String getFilePath()

This method get the path of XML file.

Default null

Return:
Return the path of XML file.

Example:

JSX jogger = new JSX("path/to/file.xml");
String path = jsx.getFilePath();

String getLogName()

This method get the log name.

Default "jogger"

Return:
Return the log name.

Example:

Jogger jogger = new Jogger();
String string = jogger.getLogName();

void setLogName(String logName)

This method set the log name.

Parameters:

  • logName, log name

Example:

Jogger jogger = new Jogger();
jogger.setLogName("myapp");

String getFileType()

Default ".log"

This method get the log file type.

Return:
Return the log file type.

Example:

Jogger jogger = new Jogger();
String string = jogger.getFileType();

void setFileType(String fileType)

This method set the log file type.

Parameters:

  • fileType, log file type

Example:

Jogger jogger = new Jogger();
jogger.setFileType(".log");

int getMaxSizeBytes()

This method get the maximum size for log file.

Default 51200

Return:
Return the maximum size, in bytes, for log file.

Example:

Jogger jogger = new Jogger();
int maxSize = jogger.getMaxSizeBytes();

void setMaxSizeBytes(int maxSizeBytes)

This method set the maximum size for log file.

Parameters:

  • maxSizeBytes, maximum size, in bytes, for log file

Example:

Jogger jogger = new Jogger();
jogger.setMaxSizeBytes(1024000);

boolean isLock()

This method check if the Jogger-Lock is active.
Read Jogger-Lock.

Default false

Return:
Return true if Jogger-Lock is active, false otherwise.

Example:

Jogger jogger = new Jogger();
jogger.setLock(true);
if (jogger.isLock()) {
  //your code
}

void setLock(boolean lock)

This method can enable or disable Jogger-Lock. Read Jogger-Lock.

Parameters:

  • lock, true for active it, false otherwise

Example:

Jogger jogger = new Jogger();
jogger.setLock(true);

String[] getSplitLogDir()

This method get the split path of log directory.

Default {"jogger"}

Return:
Return the split path of log directory.

Example:

Jogger jogger = new Jogger();
String[] splitPath = jogger.getSplitLogDir();

void setSplitLogDir(String... splitLogDir)

This method get the split path of log directory.

Parameters:

  • splitLogDir, split path to log directory

Example:

Jogger jogger = new Jogger();
jogger.setSplitLogDir("my", "log", "dir");

Log

void writeLog(String write)

throws LockLogException

This method write the string passed, on the log.
Implement Jogger-Lock. For more info Jogger-Lock.

Parameters:

  • write, string to be writer on log file

Exceptions:

  • LockLogException, exception raised if Jogger-Lock failed

Example:

Jogger jogger = new Jogger();
jogger.writeLog("YEEEEEAAAAHH!!!");

String getLogFilePath()

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 raised if an error is return while working on the log file

Example:

Jogger jogger = new Jogger();
String logFilePath = jogger.getLogFilePath();

File getFile()

throws LogFileException

This method get the log file to work on.

Return:
Return the log file to work on.

Exceptions:

  • LogFileException, exception raised if an error is return while working on the log file

Example:

Jogger jogger = new Jogger();
File logFile = jogger.getFile();

File getFileIfExists()

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 raised if an error is return while working on the log file

Example:

Jogger jogger = new Jogger();
File logFile = jogger.getFileIfExists();

Protected

boolean tryLock()

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 raised if the timeout for the lock expires

void tryUnlock()

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.


Clone this wiki locally