Package com.helger.xml.microdom.util
Class XMLMapHandler
java.lang.Object
com.helger.xml.microdom.util.XMLMapHandler
Simple class that reads a generic String-to-String mapping from a classpath
resource into a
The XML file needs to look as follows:
Map.The XML file needs to look as follows:
<mapping> <map key="..." value="..."/> <map key="..." value="..."/> ... </mapping>
- Author:
- Philip
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic IMicroDocumentcreateMapDocument(Map<String, String> aMap) readMap(com.helger.commons.io.IHasInputStream aISP) static com.helger.commons.state.ESuccessstatic com.helger.commons.state.ESuccessreadMap(IMicroElement aParentElement, Map<String, String> aTargetMap) readMap(InputStream aIS) Read a mapping from the passed input stream.static com.helger.commons.state.ESuccessreadMap(InputStream aIS, Map<String, String> aTargetMap) Read a mapping from the passed input stream.static com.helger.commons.state.ESuccessstatic com.helger.commons.state.ESuccesswriteMap(Map<String, String> aMap, OutputStream aOS) Write the passed map to the passed output stream using the predefined XML layout.
-
Field Details
-
ELEMENT_MAPPING
Root element name- See Also:
-
ELEMENT_MAP
Element name for a single mapping- See Also:
-
ATTR_KEY
Attribute name for key of a single mapping- See Also:
-
ATTR_VALUE
Attribute name for value of a single mapping- See Also:
-
-
Method Details
-
readMap
-
readMap
-
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 benull.- Returns:
nullif 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 benull.aTargetMap- The target map to be filled.- Returns:
ESuccess.SUCCESSif the stream could be opened, if it could be read as XML and if the root element was correct.ESuccess.FAILUREotherwise.
-
readMap
-
createMapDocument
-
writeMap
-
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 benull.aOS- The output stream to write to. The stream is closed independent of success or failure. May not benull.- Returns:
ESuccess.SUCCESSwhen everything went well,ESuccess.FAILUREotherwise.
-