@Test public void testWriteImageMapWithNamespaces() throws Exception { XmlWriter writer = mock( XmlWriter.class ); ImageMap imageMap = mockImageMap(); ArgumentCaptor<String> namespaceCaptor = ArgumentCaptor.forClass( String.class ); ArgumentCaptor<AttributeList> attrsCaptor = ArgumentCaptor.forClass( AttributeList.class ); ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass( String.class ); ArgumentCaptor<Boolean> statusCaptor = ArgumentCaptor.forClass( Boolean.class ); doNothing().when( writer ).writeTag( namespaceCaptor.capture(), nameCaptor.capture(), attrsCaptor.capture(), statusCaptor.capture() ); ImageMapWriter.writeImageMap( writer, imageMap, SCALE ); verify( writer, times( 2 ) ).writeTag( anyString(), anyString(), any( AttributeList.class ), anyBoolean() ); verify( writer ).writeCloseTag(); assertThat( namespaceCaptor.getAllValues().get( 0 ), is( equalTo( LibXmlInfo.XHTML_NAMESPACE ) ) ); assertThat( namespaceCaptor.getAllValues().get( 1 ), is( equalTo( LibXmlInfo.XHTML_NAMESPACE ) ) ); assertThat( attrsCaptor.getAllValues(), is( notNullValue() ) ); assertThat( attrsCaptor.getAllValues().get( 0 ).toArray().length, is( equalTo( 2 ) ) ); assertThat( attrsCaptor.getAllValues().get( 0 ).getAttribute( AttributeList.XMLNS_NAMESPACE, StringUtils.EMPTY ), is( equalTo( LibXmlInfo.XHTML_NAMESPACE ) ) ); assertThat( attrsCaptor.getAllValues().get( 0 ).getAttribute( MAP_NAMESPACE, MAP_NAME ), is( equalTo( MAP_VALUE ) ) ); assertThat( attrsCaptor.getAllValues().get( 1 ).toArray().length, is( equalTo( 3 ) ) ); assertThat( attrsCaptor.getAllValues().get( 1 ).getAttribute( MAP_ENTRY_NAMESPACE, MAP_ENTRY_NAME ), is( equalTo( MAP_ENTRY_VALUE ) ) ); assertThat( attrsCaptor.getAllValues().get( 1 ).getAttribute( LibXmlInfo.XHTML_NAMESPACE, "shape" ), is( equalTo( DEFAULT_SHAPE ) ) ); assertThat( attrsCaptor.getAllValues().get( 1 ).getAttribute( LibXmlInfo.XHTML_NAMESPACE, "coords" ), is( equalTo( "5.0,10.0,20.0,50.0" ) ) ); assertThat( nameCaptor.getAllValues().get( 0 ), is( equalTo( "map" ) ) ); assertThat( nameCaptor.getAllValues().get( 1 ), is( equalTo( "area" ) ) ); assertThat( statusCaptor.getAllValues().get( 0 ), is( equalTo( XmlWriter.OPEN ) ) ); assertThat( statusCaptor.getAllValues().get( 1 ), is( equalTo( XmlWriter.CLOSE ) ) ); }
public static void writeImageMap( final XmlWriter writer, final ImageMap imageMap, final double scale ) throws IOException { final AttributeList attrs = new AttributeList(); if ( writer.isNamespaceDefined( LibXmlInfo.XHTML_NAMESPACE ) == false ) { attrs.addNamespaceDeclaration( "", LibXmlInfo.XHTML_NAMESPACE ); } final String[] mapNamespaces = imageMap.getNameSpaces(); for ( int i = 0; i < mapNamespaces.length; i++ ) { final String namespace = mapNamespaces[i]; final String[] names = imageMap.getNames( namespace ); for ( int j = 0; j < names.length; j++ ) { final String name = names[j]; final String value = imageMap.getAttribute( namespace, name ); attrs.setAttribute( namespace, name, value ); } } writer.writeTag( LibXmlInfo.XHTML_NAMESPACE, "map", attrs, XmlWriter.OPEN ); final ImageMapEntry[] imageMapEntries = imageMap.getMapEntries(); for ( int i = 0; i < imageMapEntries.length; i++ ) { final ImageMapEntry mapEntry = imageMapEntries[i]; writeMapEntry( writer, mapEntry, scale ); } writer.writeCloseTag(); }
ImageMapWriter { public static void writeImageMap( final XmlWriter writer, final ImageMap imageMap, final double scale ) throws IOException { final AttributeList attrs = new AttributeList(); if ( writer.isNamespaceDefined( LibXmlInfo.XHTML_NAMESPACE ) == false ) { attrs.addNamespaceDeclaration( "", LibXmlInfo.XHTML_NAMESPACE ); } final String[] mapNamespaces = imageMap.getNameSpaces(); for ( int i = 0; i < mapNamespaces.length; i++ ) { final String namespace = mapNamespaces[i]; final String[] names = imageMap.getNames( namespace ); for ( int j = 0; j < names.length; j++ ) { final String name = names[j]; final String value = imageMap.getAttribute( namespace, name ); attrs.setAttribute( namespace, name, value ); } } writer.writeTag( LibXmlInfo.XHTML_NAMESPACE, "map", attrs, XmlWriter.OPEN ); final ImageMapEntry[] imageMapEntries = imageMap.getMapEntries(); for ( int i = 0; i < imageMapEntries.length; i++ ) { final ImageMapEntry mapEntry = imageMapEntries[i]; writeMapEntry( writer, mapEntry, scale ); } writer.writeCloseTag(); } }
ImageMapWriter { public static void writeImageMap( final XmlWriter writer, final ImageMap imageMap, final double scale ) throws IOException { final AttributeList attrs = new AttributeList(); if ( writer.isNamespaceDefined( LibXmlInfo.XHTML_NAMESPACE ) == false ) { attrs.addNamespaceDeclaration( "", LibXmlInfo.XHTML_NAMESPACE ); } final String[] mapNamespaces = imageMap.getNameSpaces(); for ( int i = 0; i < mapNamespaces.length; i++ ) { final String namespace = mapNamespaces[i]; final String[] names = imageMap.getNames( namespace ); for ( int j = 0; j < names.length; j++ ) { final String name = names[j]; final String value = imageMap.getAttribute( namespace, name ); attrs.setAttribute( namespace, name, value ); } } writer.writeTag( LibXmlInfo.XHTML_NAMESPACE, "map", attrs, XmlWriter.OPEN ); final ImageMapEntry[] imageMapEntries = imageMap.getMapEntries(); for ( int i = 0; i < imageMapEntries.length; i++ ) { final ImageMapEntry mapEntry = imageMapEntries[i]; writeMapEntry( writer, mapEntry, scale ); } writer.writeCloseTag(); } private  ImageMapWriter(); }
ImageMapWriter { public static void writeImageMap( final XmlWriter writer, final ImageMap imageMap, final double scale ) throws IOException { final AttributeList attrs = new AttributeList(); if ( writer.isNamespaceDefined( LibXmlInfo.XHTML_NAMESPACE ) == false ) { attrs.addNamespaceDeclaration( "", LibXmlInfo.XHTML_NAMESPACE ); } final String[] mapNamespaces = imageMap.getNameSpaces(); for ( int i = 0; i < mapNamespaces.length; i++ ) { final String namespace = mapNamespaces[i]; final String[] names = imageMap.getNames( namespace ); for ( int j = 0; j < names.length; j++ ) { final String name = names[j]; final String value = imageMap.getAttribute( namespace, name ); attrs.setAttribute( namespace, name, value ); } } writer.writeTag( LibXmlInfo.XHTML_NAMESPACE, "map", attrs, XmlWriter.OPEN ); final ImageMapEntry[] imageMapEntries = imageMap.getMapEntries(); for ( int i = 0; i < imageMapEntries.length; i++ ) { final ImageMapEntry mapEntry = imageMapEntries[i]; writeMapEntry( writer, mapEntry, scale ); } writer.writeCloseTag(); } private  ImageMapWriter(); static String writeImageMapAsString( final ImageMap imageMap ); static void writeImageMap( final XmlWriter writer, final ImageMap imageMap, final double scale ); }
ImageMapWriter { public static void writeImageMap( final XmlWriter writer, final ImageMap imageMap, final double scale ) throws IOException { final AttributeList attrs = new AttributeList(); if ( writer.isNamespaceDefined( LibXmlInfo.XHTML_NAMESPACE ) == false ) { attrs.addNamespaceDeclaration( "", LibXmlInfo.XHTML_NAMESPACE ); } final String[] mapNamespaces = imageMap.getNameSpaces(); for ( int i = 0; i < mapNamespaces.length; i++ ) { final String namespace = mapNamespaces[i]; final String[] names = imageMap.getNames( namespace ); for ( int j = 0; j < names.length; j++ ) { final String name = names[j]; final String value = imageMap.getAttribute( namespace, name ); attrs.setAttribute( namespace, name, value ); } } writer.writeTag( LibXmlInfo.XHTML_NAMESPACE, "map", attrs, XmlWriter.OPEN ); final ImageMapEntry[] imageMapEntries = imageMap.getMapEntries(); for ( int i = 0; i < imageMapEntries.length; i++ ) { final ImageMapEntry mapEntry = imageMapEntries[i]; writeMapEntry( writer, mapEntry, scale ); } writer.writeCloseTag(); } private  ImageMapWriter(); static String writeImageMapAsString( final ImageMap imageMap ); static void writeImageMap( final XmlWriter writer, final ImageMap imageMap, final double scale );  }