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