1 /**
2 * Copyright (C) 2014-2015 Philip Helger (www.helger.com)
3 * philip[at]helger[dot]com
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package com.helger.schematron.svrl;
18
19 import javax.annotation.Nonnull;
20 import javax.annotation.Nullable;
21 import javax.annotation.concurrent.Immutable;
22 import javax.xml.transform.Result;
23
24 import org.oclc.purl.dsdl.svrl.SchematronOutputType;
25 import org.w3c.dom.Document;
26
27 import com.helger.commons.annotation.PresentForCodeCoverage;
28 import com.helger.commons.state.ESuccess;
29
30 /**
31 * This is the XML writer for Schematron SVRL documents. It reads
32 * {@link SchematronOutputType} elements and converts them to W3C nodes. The
33 * writing itself is done with JAXB.
34 *
35 * @author Philip Helger
36 */
37 @Immutable
38 public final class SVRLWriter
39 {
40 @PresentForCodeCoverage
41 private static final SVRLWriter s_aInstance = new SVRLWriter ();
42
43 private SVRLWriter ()
44 {}
45
46 /**
47 * Convert the passed schematron output element into an W3C Document node.
48 *
49 * @param aSchematronOutput
50 * The schematron output to be converted. May not be <code>null</code>.
51 * @param aResult
52 * The result object to write to.
53 * @return {@link ESuccess}
54 */
55 @Nonnull
56 public static ESuccess writeSVRL (@Nonnull final SchematronOutputType aSchematronOutput, @Nonnull final Result aResult)
57 {
58 return new SVRLMarshaller ().write (aSchematronOutput, aResult);
59 }
60
61 /**
62 * Convert the passed schematron output element into an W3C Document node.
63 *
64 * @param aSchematronOutput
65 * The schematron output to be converted. May not be <code>null</code>.
66 * @return <code>null</code> if conversion failed.
67 */
68 @Nullable
69 public static Document createXML (@Nonnull final SchematronOutputType aSchematronOutput)
70 {
71 return new SVRLMarshaller ().write (aSchematronOutput);
72 }
73
74 /**
75 * Utility method to directly convert the passed SVRL domain object to an XML
76 * string.
77 *
78 * @param aSchematronOutput
79 * The SVRL domain object to be converted. May not be null.
80 * @return <code>null</code> if the passed domain object could not be
81 * converted because of validation errors.
82 */
83 @Nullable
84 public static String createXMLString (@Nonnull final SchematronOutputType aSchematronOutput)
85 {
86 return new SVRLMarshaller ().getAsXMLString (aSchematronOutput);
87 }
88 }