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 = Jogger.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 = Jogger.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 = Jogger.createDocument("path/to/file.xml");
Jogger.removeBlankLines(doc);

Get and Set

String getPrefixLogFile()

This method get the prefix for log file name.

Default "log_"

Return:
Return the prefix for log file name.

Example:

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

void setPrefixLogFile(String prefixLogFile)

This method set the prefix for log file name.

Parameters:

  • prefixLogFile, prefix for log file name

Example:

Jogger jogger = new Jogger();
jogger.setPrefixLogFile("mylog_");

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