public static void writeResources ( Element node , XMLResources resources , XMLBuilder builder ) { if ( resources != null ) { final Element resourcesNode = builder . createElement ( NODE_RESOURCES ) ; for ( final java . util . Map . Entry < Long , Entry > pair : resources . getPairs ( ) . entrySet ( ) ) { final Entry e = pair . getValue ( ) ; if ( e . isURL ( ) ) { final Element resourceNode = builder . createElement ( NODE_RESOURCE ) ; resourceNode . setAttribute ( ATTR_ID , XMLResources . getStringIdentifier ( pair . getKey ( ) ) ) ; resourceNode . setAttribute ( ATTR_URL , e . getURL ( ) . toExternalForm ( ) ) ; resourceNode . setAttribute ( ATTR_MIMETYPE , e . getMimeType ( ) ) ; resourcesNode . appendChild ( resourceNode ) ; } else if ( e . isFile ( ) ) { final Element resourceNode = builder . createElement ( NODE_RESOURCE ) ; resourceNode . setAttribute ( ATTR_ID , XMLResources . getStringIdentifier ( pair . getKey ( ) ) ) ; final File file = e . getFile ( ) ; final StringBuilder url = new StringBuilder ( ) ; url . append ( "file:" ) ; //$NON-NLS-1$ boolean addSlash = false ; for ( final String elt : FileSystem . split ( file ) ) { try { if ( addSlash ) { url . append ( "/" ) ; //$NON-NLS-1$ } url . append ( URLEncoder . encode ( elt , Charset . defaultCharset ( ) . name ( ) ) ) ; } catch ( UnsupportedEncodingException e1 ) { throw new Error ( e1 ) ; } addSlash = true ; } resourceNode . setAttribute ( ATTR_FILE , url . toString ( ) ) ; resourceNode . setAttribute ( ATTR_MIMETYPE , e . getMimeType ( ) ) ; resourcesNode . appendChild ( resourceNode ) ; } else if ( e . isEmbeddedData ( ) ) { final Element resourceNode = builder . createElement ( NODE_RESOURCE ) ; resourceNode . setAttribute ( ATTR_ID , XMLResources . getStringIdentifier ( pair . getKey ( ) ) ) ; resourceNode . setAttribute ( ATTR_MIMETYPE , e . getMimeType ( ) ) ; final byte [ ] data = e . getEmbeddedData ( ) ; final CDATASection cdata = builder . createCDATASection ( toString ( data ) ) ; resourceNode . appendChild ( cdata ) ; resourcesNode . appendChild ( resourceNode ) ; } } if ( resourcesNode . getChildNodes ( ) . getLength ( ) > 0 ) { node . appendChild ( resourcesNode ) ; } } }
Write the given resources into the given XML node .