Class SecureParserFactory

java.lang.Object
cloud.opencode.base.xml.security.SecureParserFactory

public final class SecureParserFactory extends Object
Secure Parser Factory - Factory for creating secure XML parsers 安全解析器工厂 - 创建安全 XML 解析器的工厂

This class provides cached, thread-safe factories for creating secure XML parsers. The factories are pre-configured with security settings to prevent XXE attacks.

此类提供缓存的线程安全工厂,用于创建安全的 XML 解析器。工厂已预配置安全设置以防止 XXE 攻击。

Features | 主要功能:

  • Cached, thread-safe factories for secure XML parsers - 缓存的线程安全安全 XML 解析器工厂
  • Pre-configured XXE attack prevention - 预配置的 XXE 攻击防护
  • Supports DOM, SAX, StAX, and Transformer creation - 支持 DOM、SAX、StAX 和 Transformer 创建

Thread Safety | 线程安全:

The factories are thread-safe and can be reused. However, the parsers created from them are NOT thread-safe and should be used by a single thread at a time.

工厂是线程安全的,可以重复使用。但是,从它们创建的解析器不是线程安全的,应该一次只由一个线程使用。

Usage Examples | 使用示例:

// Create a secure DocumentBuilder
DocumentBuilder builder = SecureParserFactory.createDocumentBuilder();

// Create a secure SAXParser
SAXParser parser = SecureParserFactory.createSAXParser();

// Create a secure XMLStreamReader
XMLStreamReader reader = SecureParserFactory.createXMLStreamReader(inputStream);

Performance | 性能特性:

  • Time complexity: O(1) for factory creation - 工厂创建 O(1)
  • Space complexity: O(1) - O(1)
Since:
JDK 25, opencode-base-xml V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • createDocumentBuilder

      public static DocumentBuilder createDocumentBuilder()
      Creates a secure DocumentBuilder. 创建安全的 DocumentBuilder。
      Returns:
      a secure DocumentBuilder | 安全的 DocumentBuilder
    • createNamespaceAwareDocumentBuilder

      public static DocumentBuilder createNamespaceAwareDocumentBuilder()
      Creates a namespace-aware secure DocumentBuilder. 创建支持命名空间的安全 DocumentBuilder。
      Returns:
      a namespace-aware secure DocumentBuilder | 支持命名空间的安全 DocumentBuilder
    • createSAXParser

      public static SAXParser createSAXParser()
      Creates a secure SAXParser. 创建安全的 SAXParser。
      Returns:
      a secure SAXParser | 安全的 SAXParser
    • createNamespaceAwareSAXParser

      public static SAXParser createNamespaceAwareSAXParser()
      Creates a namespace-aware secure SAXParser. 创建支持命名空间的安全 SAXParser。
      Returns:
      a namespace-aware secure SAXParser | 支持命名空间的安全 SAXParser
    • createXMLStreamReader

      public static XMLStreamReader createXMLStreamReader(InputStream input)
      Creates a secure XMLStreamReader from an InputStream. 从 InputStream 创建安全的 XMLStreamReader。
      Parameters:
      input - the input stream | 输入流
      Returns:
      a secure XMLStreamReader | 安全的 XMLStreamReader
    • createXMLStreamReader

      public static XMLStreamReader createXMLStreamReader(Reader reader)
      Creates a secure XMLStreamReader from a Reader. 从 Reader 创建安全的 XMLStreamReader。
      Parameters:
      reader - the reader | 读取器
      Returns:
      a secure XMLStreamReader | 安全的 XMLStreamReader
    • createTransformer

      public static Transformer createTransformer()
      Creates a secure Transformer. 创建安全的 Transformer。
      Returns:
      a secure Transformer | 安全的 Transformer
    • getDocumentBuilderFactory

      public static DocumentBuilderFactory getDocumentBuilderFactory()
      Returns the shared secure DocumentBuilderFactory. 返回共享的安全 DocumentBuilderFactory。
      Returns:
      the factory | 工厂
    • getNamespaceAwareDocumentBuilderFactory

      public static DocumentBuilderFactory getNamespaceAwareDocumentBuilderFactory()
      Returns the shared namespace-aware secure DocumentBuilderFactory. 返回共享的支持命名空间的安全 DocumentBuilderFactory。
      Returns:
      the factory | 工厂
    • getSAXParserFactory

      public static SAXParserFactory getSAXParserFactory()
      Returns the shared secure SAXParserFactory. 返回共享的安全 SAXParserFactory。
      Returns:
      the factory | 工厂
    • getNamespaceAwareSAXParserFactory

      public static SAXParserFactory getNamespaceAwareSAXParserFactory()
      Returns the shared namespace-aware secure SAXParserFactory. 返回共享的支持命名空间的安全 SAXParserFactory。
      Returns:
      the factory | 工厂
    • getXMLInputFactory

      public static XMLInputFactory getXMLInputFactory()
      Returns the shared secure XMLInputFactory. 返回共享的安全 XMLInputFactory。
      Returns:
      the factory | 工厂
    • createXMLInputFactory

      public static XMLInputFactory createXMLInputFactory()
      Creates and returns a new secure XMLInputFactory. 创建并返回新的安全 XMLInputFactory。

      Use this when you need a separate factory instance.

      当需要单独的工厂实例时使用此方法。

      Returns:
      a new secure XMLInputFactory | 新的安全 XMLInputFactory
    • getTransformerFactory

      public static TransformerFactory getTransformerFactory()
      Returns the shared secure TransformerFactory. 返回共享的安全 TransformerFactory。
      Returns:
      the factory | 工厂