View Javadoc
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 java.util.List;
20  
21  import javax.annotation.Nonnull;
22  import javax.annotation.Nullable;
23  import javax.annotation.concurrent.NotThreadSafe;
24  
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  import com.helger.commons.annotation.PresentForCodeCoverage;
29  import com.helger.commons.debug.GlobalDebug;
30  import com.helger.commons.lang.ServiceLoaderHelper;
31  
32  /**
33   * A central registry for all {@link ISVRLLocationBeautifierSPI} instances.
34   *
35   * @author Philip Helger
36   */
37  @NotThreadSafe
38  public final class SVRLLocationBeautifierRegistry
39  {
40    private static final Logger s_aLogger = LoggerFactory.getLogger (SVRLLocationBeautifierRegistry.class);
41    private static final List <ISVRLLocationBeautifierSPI> s_aList = ServiceLoaderHelper.getAllSPIImplementations (ISVRLLocationBeautifierSPI.class);
42  
43    @PresentForCodeCoverage
44    private static final SVRLLocationBeautifierRegistry s_aInstance = new SVRLLocationBeautifierRegistry ();
45  
46    private SVRLLocationBeautifierRegistry ()
47    {}
48  
49    /**
50     * Get the beautified location for the given namespace and local name.
51     *
52     * @param sNamespaceURI
53     *        The namespace URI
54     * @param sLocalName
55     *        The element local name
56     * @return <code>null</code> if no beautification is available
57     */
58    @Nullable
59    public static String getBeautifiedLocation (@Nonnull final String sNamespaceURI, @Nonnull final String sLocalName)
60    {
61      for (final ISVRLLocationBeautifierSPI aBeautifier : s_aList)
62      {
63        final String sBeautified = aBeautifier.getReplacementText (sNamespaceURI, sLocalName);
64        if (sBeautified != null)
65          return sBeautified;
66      }
67      if (GlobalDebug.isDebugMode ())
68        s_aLogger.warn ("Unsupported elements for beautification: " + sNamespaceURI + " -- " + sLocalName);
69      return null;
70    }
71  }