View Javadoc
1   package com.helger.schematron;
2   
3   import java.io.File;
4   import java.util.concurrent.atomic.AtomicBoolean;
5   
6   import javax.annotation.Nonnull;
7   import javax.annotation.concurrent.ThreadSafe;
8   
9   import com.helger.commons.ValueEnforcer;
10  
11  /**
12   * Global Schematron debug settings etc.
13   *
14   * @author Philip Helger
15   * @since 4.3.4
16   */
17  @ThreadSafe
18  public final class SchematronDebug
19  {
20    private static final AtomicBoolean s_bSaveIntermediateXSLTFiles = new AtomicBoolean (false);
21    private static File s_aIntermediateMinifiedSCHFolder = new File ("test-minified");
22    private static File s_aIntermediateFinalXSLTFolder = new File ("test-final");
23    private static final AtomicBoolean s_aShowCreatedXSLT = new AtomicBoolean (false);
24    private static final AtomicBoolean s_aShowCreatedSVRL = new AtomicBoolean (false);
25    private static final AtomicBoolean s_aShowPreprocessedSchematron = new AtomicBoolean (false);
26    private static final AtomicBoolean s_aShowResolvedSourceSchematron = new AtomicBoolean (false);
27  
28    private SchematronDebug ()
29    {}
30  
31    /**
32     * Globally enable/disable debug mode
33     *
34     * @param bDebugMode
35     *        <code>true</code> to enable debug mode, <code>false</code>
36     *        otherwise.
37     * @see #setSaveIntermediateXSLTFiles(boolean)
38     * @see #setShowCreatedXSLT(boolean)
39     * @see #setShowCreatedSVRL(boolean)
40     * @see #setShowResolvedSourceSchematron(boolean)
41     * @see #setShowPreprocessedSchematron(boolean)
42     */
43    public static void setDebugMode (final boolean bDebugMode)
44    {
45      setSaveIntermediateXSLTFiles (bDebugMode);
46      setShowCreatedXSLT (bDebugMode);
47      setShowCreatedSVRL (bDebugMode);
48      setShowResolvedSourceSchematron (bDebugMode);
49      setShowPreprocessedSchematron (bDebugMode);
50    }
51  
52    /**
53     * @return <code>true</code> if the intermediate files during XSLT creation.
54     *         Applied only in XSTL based modes.
55     */
56    public static final boolean isSaveIntermediateXSLTFiles ()
57    {
58      return s_bSaveIntermediateXSLTFiles.get ();
59    }
60  
61    public static final void setSaveIntermediateXSLTFiles (final boolean bSaveIntermediateFiles)
62    {
63      s_bSaveIntermediateXSLTFiles.set (bSaveIntermediateFiles);
64    }
65  
66    /**
67     * @return The folder to which the minified SCH should be stored. Never
68     *         <code>null</code>. Only used in XSLT based modes if
69     *         {@link #isSaveIntermediateXSLTFiles()} is <code>true</code>.
70     */
71    @Nonnull
72    public static final File getIntermediateMinifiedSCHFolder ()
73    {
74      return s_aIntermediateMinifiedSCHFolder;
75    }
76  
77    public static final void setIntermediateMinifiedSCHFolder (@Nonnull final File aIntermediateMinifiedSCHFolder)
78    {
79      ValueEnforcer.notNull (aIntermediateMinifiedSCHFolder, "IntermediateMinifiedSCHFolder");
80      s_aIntermediateMinifiedSCHFolder = aIntermediateMinifiedSCHFolder;
81    }
82  
83    /**
84     * @return The folder to which the final XSLT should be stored. Never
85     *         <code>null</code>. Only used in XSLT based modes if
86     *         {@link #isSaveIntermediateXSLTFiles()} is <code>true</code>.
87     */
88    @Nonnull
89    public static final File getIntermediateFinalXSLTFolder ()
90    {
91      return s_aIntermediateFinalXSLTFolder;
92    }
93  
94    public static final void setIntermediateFinalXSLTFolder (@Nonnull final File aIntermediateFinalXSLTFolder)
95    {
96      ValueEnforcer.notNull (aIntermediateFinalXSLTFolder, "IntermediateFinalXSLTFolder");
97      s_aIntermediateFinalXSLTFolder = aIntermediateFinalXSLTFolder;
98    }
99  
100   public static void setShowCreatedXSLT (final boolean bShow)
101   {
102     s_aShowCreatedXSLT.set (bShow);
103   }
104 
105   /**
106    * @return <code>true</code> if the created XSLT should be logged. Only
107    *         applied in XSLT based mode.
108    */
109   public static boolean isShowCreatedXSLT ()
110   {
111     return s_aShowCreatedXSLT.get ();
112   }
113 
114   public static void setShowCreatedSVRL (final boolean bShow)
115   {
116     s_aShowCreatedSVRL.set (bShow);
117   }
118 
119   /**
120    * @return <code>true</code> to log the created SVRL.
121    */
122   public static boolean isShowCreatedSVRL ()
123   {
124     return s_aShowCreatedSVRL.get ();
125   }
126 
127   public static void setShowResolvedSourceSchematron (final boolean bShow)
128   {
129     s_aShowResolvedSourceSchematron.set (bShow);
130   }
131 
132   /**
133    * @return <code>true</code> to log the read, with includes resolved,
134    *         Schematron. This is only applied in pure mode.
135    */
136   public static boolean isShowResolvedSourceSchematron ()
137   {
138     return s_aShowResolvedSourceSchematron.get ();
139   }
140 
141   public static void setShowPreprocessedSchematron (final boolean bShow)
142   {
143     s_aShowPreprocessedSchematron.set (bShow);
144   }
145 
146   /**
147    * @return <code>true</code> to log the created preprocessed Schematron. This
148    *         is only applied in pure mode.
149    */
150   public static boolean isShowPreprocessedSchematron ()
151   {
152     return s_aShowPreprocessedSchematron.get ();
153   }
154 }