Class XMQ

java.lang.Object
org.libxmq.XMQ

public class XMQ extends Object
The XMQ class is used to parse/print/render XMQ/XML/HTML/JSON documents.
  • Constructor Details

    • XMQ

      public XMQ()
      Construct an XMQ with the default DOM implementation.
    • XMQ

      public XMQ(DocumentBuilderFactory f)
      Construct an XMQ with a DocumentBuilderFactory if you need to override the default DOM implementation.
      Parameters:
      f - The document builder factory.
  • Method Details

    • parseFile

      public Document parseFile(Path file, InputSettings is) throws IOException, ParseException
      Parse a file containing XMQ/XML/HTML/JSON/CLINES.
      Parameters:
      file - The file to parse.
      is - The input settings, should white space be trimmed, should text nodes be merged etc.
      Returns:
      A DOM document.
      Throws:
      IOException - if file cannot be read.
      ParseException - if the parse failed.
    • parseBuffer

      public Document parseBuffer(String buffer, InputSettings is) throws ParseException
      Parse a buffer containing XMQ/XML/HTML/JSON/CLINES.
      Parameters:
      buffer - The string to parse.
      is - The input settings, should white space be trimmed, should text nodes be merged etc.
      Returns:
      A DOM document.
      Throws:
      ParseException - if the parse failed.
    • queryFile

      public Query queryFile(Path file, InputSettings is) throws IOException, ParseException
      Parse a file containing XMQ/XML/HTML/JSON/CLINES and return a Query object to the DOM.
      Parameters:
      file - The file to parse.
      is - The input settings, should white space be trimmed, should text nodes be merged etc.
      Returns:
      A Query object.
      Throws:
      IOException - if file cannot be read.
      ParseException - if the parse failed.
    • queryBuffer

      public Query queryBuffer(String buffer, InputSettings is) throws ParseException
      Parse a buffer containing XMQ/XML/HTML/JSON/CLINES and return a Query object for the DOM.
      Parameters:
      buffer - The string to parse.
      is - The input settings, should white space be trimmed, should text nodes be merged etc.
      Returns:
      A Query object.
      Throws:
      ParseException - if the parse failed.
    • toXMQ

      public String toXMQ(Document doc, OutputSettings os)
      Print the document as XMQ.
      Parameters:
      doc - Document to print.
      os - Settings for printing.
      Returns:
      A string with XMQ.
    • toXML

      public String toXML(Document doc, OutputSettings os)
      Print the document as XML. This means that the argument doc is assumed to store an XML document. By printing it as XML the document will follow the XML rules.
      Parameters:
      doc - Document to print.
      os - Settings for printing.
      Returns:
      A string with XML.
    • toHTML

      public String toHTML(Document doc, OutputSettings os)
      Print the document as HTML. This means that the argument doc is assumed to store a HTML document. By printing it as HTML the document will follow the HTML rules (using self closing tags like <br> and potentially using HTML entities like &nbsp;)
      Parameters:
      doc - Document to print.
      os - Settings for printing.
      Returns:
      A string with HTML.
    • toJSON

      public String toJSON(Document doc, OutputSettings os)
      Print the document as json.
      Parameters:
      doc - Document to print.
      os - Settings for printing.
      Returns:
      A string with JSON.
    • toCLINES

      public String toCLINES(Document doc, OutputSettings os)
      Print the document as clines.
      Parameters:
      doc - Document to print.
      os - Settings for printing.
      Returns:
      A string with clines.
    • renderHTML

      public String renderHTML(Document doc, OutputSettings os)
      Render the document as XMQ in HTML. I.e. build a new HTML document that when viewed in a browser makes it easy to read the XMQ.
      Parameters:
      doc - Document to render
      os - Settings for rendering
      Returns:
      A string with HTML.
    • renderTEX

      public String renderTEX(Document doc, OutputSettings os)
      Render the document as XMQ in TeX. When the TeX document is rendered using for example xetex/xelatex, it will generate a pdf containing the human readable XMQ.
      Parameters:
      doc - Document to render
      os - Settings for rendering
      Returns:
      A string with TeX commands.
    • printException

      public static String printException(ParseException e, Locale locale)
      Render a locale adapted text cli error printout of a parse exception.
      Parameters:
      e - The parse exception.
      locale - The locale to use.
      Returns:
      A string to be printed on the console.
    • printException

      public static String printException(ParseException e)
      Render a locale adapted text cli error printout of a parse exception using the default locale.
      Parameters:
      e - The parse exception.
      Returns:
      A string to be printed on the console.