java.lang.Object
net.i2p.jetty.JettyXmlConfigurationParser

public class JettyXmlConfigurationParserextends Object
Parses a Jetty XML configuration file. Copied from Jetty XmlConfiguration.java, where the parser is private.
  • Constructor Details

    • JettyXmlConfigurationParser

      public JettyXmlConfigurationParser()
      Constructor. Each parse call builds its own SAX parser through initParser(), so an instance carries no state.
  • Method Details

    • initParser

      private static XmlParser initParser()
      Builds the XML parser used to read the jetty configuration.
      Returns:
      the new parser
    • parse

      public static XmlParser.Node parse(File f) throws SAXException, IOException
      Reads and parses the XML configuration file.
      Parameters:
      f - an XML configuration file
      Returns:
      the parsed configuration tree, rooted at the document node
      Throws:
      IOException - if the configuration could not be read
      SAXException - if the configuration could not be parsed
    • getValue

      public static String getValue(XmlParser.Node node, String name)
      Recursively go through the entire tree starting at node. Return the value for the first node with the name set, e.g. [Set name="name"]value[/Set]
      Parameters:
      node - the node whose descendants are searched for the Set
      name - matched case-insensitively against a Set's name attribute
      Returns:
      the text of the first Set node matching name, or null if none
    • setValue

      public static boolean setValue(XmlParser.Node node, String name, String value)
      Recursively go through the entire tree starting at node. Return the value for the first node with the name set, e.g. [Set name="name"]value[/Set]
      Parameters:
      node - the node whose descendants are searched for the Set
      name - matched case-insensitively against a Set's name attribute
      value - the text to store as the new content of the matched Set
      Returns:
      true if a matching Set was found and rewritten, false if the search reached the leaves without a match
    • write

      public static void write(XmlParser.Node node, Writer out) throws IOException
      Write out the XML. Adapted from Node.toString(). That synchronized method caused classpath issues when called from the webapp. Also add newlines here for readability.
      Parameters:
      node - the node to serialize, written with its tag, attributes and children
      out - the writer that receives the XML text
      Throws:
      IOException - if the writer rejects the data
    • obfuscate

      public static String obfuscate(String s)
      Obfuscate a password for storage in the XML
      Parameters:
      s - the cleartext password, or an already obfuscated value prefixed with "OBF:"
      Returns:
      a string starting with "OBF:"
    • deobfuscate

      public static String deobfuscate(String s)
      De-Obfuscate a password from the XML
      Parameters:
      s - a string starting with "OBF:"
      Returns:
      the cleartext password, or s itself if it carries no "OBF:" prefix