Class XMLMapHandler


  • @Immutable
    public final class XMLMapHandler
    extends Object
    Simple class that reads a generic String-to-String mapping from a classpath resource into a Map.
    The XML file needs to look as follows:
     <mapping>
       <map key="..." value="..."/>
       <map key="..." value="..."/>
       ...
     </mapping>
     
    Author:
    Philip
    • Method Detail

      • readMap

        @Nullable
        @ReturnsMutableCopy
        public static com.helger.commons.collection.impl.ICommonsMap<String,​String> readMap​(@Nonnull
                                                                                                  com.helger.commons.io.IHasInputStream aISP)
      • readMap

        @Nullable
        @ReturnsMutableCopy
        public static com.helger.commons.collection.impl.ICommonsMap<String,​String> readMap​(@Nonnull @WillClose
                                                                                                  InputStream aIS)
        Read a mapping from the passed input stream.
        Parameters:
        aIS - The input stream to read from. May not be null.
        Returns:
        null if reading the map failed
      • readMap

        @Nonnull
        public static com.helger.commons.state.ESuccess readMap​(@Nonnull @WillClose
                                                                InputStream aIS,
                                                                @Nonnull
                                                                Map<String,​String> aTargetMap)
        Read a mapping from the passed input stream.
        Parameters:
        aIS - The input stream to read from. May not be null.
        aTargetMap - The target map to be filled.
        Returns:
        ESuccess.SUCCESS if the stream could be opened, if it could be read as XML and if the root element was correct. ESuccess.FAILURE otherwise.
      • writeMap

        @Nonnull
        public static com.helger.commons.state.ESuccess writeMap​(@Nonnull
                                                                 Map<String,​String> aMap,
                                                                 @Nonnull @WillClose
                                                                 OutputStream aOS)
        Write the passed map to the passed output stream using the predefined XML layout.
        Parameters:
        aMap - The map to be written. May not be null.
        aOS - The output stream to write to. The stream is closed independent of success or failure. May not be null.
        Returns:
        ESuccess.SUCCESS when everything went well, ESuccess.FAILURE otherwise.