1 /** 2 * Copyright (C) 2014-2017 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.Source; 23 24 import org.oclc.purl.dsdl.svrl.SchematronOutputType; 25 import org.w3c.dom.Node; 26 27 import com.helger.commons.annotation.PresentForCodeCoverage; 28 import com.helger.commons.io.resource.IReadableResource; 29 30 /** 31 * This is the XML reader for Schematron SVRL documents. It reads XML DOM 32 * documents and returns {@link SchematronOutputType} elements. The reading 33 * itself is done with JAXB.<br> 34 * 35 * @author Philip Helger 36 */ 37 @Immutable 38 public final class SVRLReader 39 { 40 @PresentForCodeCoverage 41 private static final SVRLReader s_aInstance = new SVRLReader (); 42 43 private SVRLReader () 44 {} 45 46 /** 47 * Convert the passed resource into a SVRL domain object 48 * 49 * @param aRes 50 * The resource to be converted. May not be <code>null</code>. 51 * @return <code>null</code> if the passed object could not be interpreted as 52 * SVRL. 53 */ 54 @Nullable 55 public static SchematronOutputType readXML (@Nonnull final IReadableResource aRes) 56 { 57 return new SVRLMarshaller ().read (aRes); 58 } 59 60 /** 61 * Convert the passed W3C node into a SVRL domain object 62 * 63 * @param aNode 64 * The node to be converted. May not be <code>null</code>. 65 * @return <code>null</code> if the passed object could not be interpreted as 66 * SVRL. 67 */ 68 @Nullable 69 public static SchematronOutputType readXML (@Nonnull final Node aNode) 70 { 71 return new SVRLMarshaller ().read (aNode); 72 } 73 74 /** 75 * Convert the passed object into a SVRL domain object 76 * 77 * @param aSource 78 * The source to be converted. May not be <code>null</code>. 79 * @return <code>null</code> if the passed object could not be interpreted as 80 * SVRL. 81 */ 82 @Nullable 83 public static SchematronOutputType readXML (@Nonnull final Source aSource) 84 { 85 return new SVRLMarshaller ().read (aSource); 86 } 87 }