package com.bradmcevoy.http.values;

import com.bradmcevoy.http.XmlWriter;
import com.bradmcevoy.http.XmlWriter.Element;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ResourceTypeValueWriter implements ValueWriter {

    private static final Logger log = LoggerFactory.getLogger( ResourceTypeValueWriter.class );

    public boolean supports( String nsUri, String localName, Class c ) {
        return localName.equals( "resourcetype" );
    }

    public void writeValue( XmlWriter writer, String nsUri, String prefix, String localName, Object val, String href, Map<String, String> nsPrefixes ) {
        List<QName> list = (List<QName>) val;
        if( list != null && list.size() > 0 ) {
            Element rt = writer.begin( prefix, localName );
            for( QName name : list ) {
                String childNsUri = name.getNamespaceURI();
                String childPrefix = nsPrefixes.get( childNsUri );
                // don't write a new line - see http://www.ettrema.com:8080/browse/MIL-83
                rt.begin( childPrefix, name.getLocalPart() ).noContent(false);
            }
            rt.close();
        } else {
            writer.writeProperty( prefix, localName );
        }
    }

    public Object parse( String namespaceURI, String localPart, String value ) {
        throw new UnsupportedOperationException( "Not supported yet." );
    }
}

@@ -314,20 +314,17 @@
 iter %7B%0A%0A
-    
+%09
 private 
@@ -373,17 +373,16 @@
 tLogger(
- 
 Resource
@@ -406,17 +406,24 @@
 lass
- 
 );%0A%0A
-    
+%09@Override%0A%09
 publ
@@ -442,17 +442,16 @@
 upports(
- 
 String n
@@ -481,29 +481,22 @@
  Class c
- 
 ) %7B%0A
-        
+%09%09
 return l
@@ -511,17 +511,16 @@
 .equals(
- 
 %22resourc
@@ -529,23 +529,27 @@
 ype%22
- 
 );%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09@Override%0A%09
 publ
@@ -567,17 +567,16 @@
 teValue(
- 
 XmlWrite
@@ -687,29 +687,22 @@
 Prefixes
- 
 ) %7B%0A
-        
+%09%09
 List%3CQNa
@@ -735,20 +735,14 @@
 al;%0A
-        if( 
+%09%09if (
 list
@@ -768,33 +768,23 @@
 ze() %3E 0
- 
 ) %7B%0A
-            
+%09%09%09
 Element 
@@ -801,17 +801,16 @@
 r.begin(
- 
 prefix, 
@@ -822,29 +822,19 @@
 Name
- 
 );%0A
-            
+%09%09%09
 for
-(
  
+(
 QNam
@@ -850,29 +850,16 @@
 list
- 
 ) %7B%0A
-                
+%09%09%09%09
 Stri
@@ -898,32 +898,20 @@
 eURI();%0A
-                
+%09%09%09%09
 String c
@@ -938,17 +938,16 @@
 xes.get(
- 
 childNsU
@@ -952,28 +952,278 @@
 sUri
- 
 );%0A
-                
+%09%09%09%09// might be null if the namespace is on a value qname but not a property (eg caldav resource type)%0A%09%09%09%09// so if null write the full uri%0A%09%09%09%09if (childPrefix == null) %7B%0A%09%09%09%09%09rt.begin(childNsUri, childPrefix, name.getLocalPart()).noContent(false);%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09
 // d
@@ -1296,24 +1296,13 @@
 -83%0A
-                
+%09%09%09%09%09
 rt.b
@@ -1306,17 +1306,16 @@
 t.begin(
- 
 childPre
@@ -1338,17 +1338,16 @@
 alPart()
- 
 ).noCont
@@ -1362,34 +1362,22 @@
 e);%0A
-            %7D%0A            
+%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09
 rt.c
@@ -1384,24 +1384,18 @@
 lose();%0A
-        
+%09%09
 %7D else %7B
@@ -1399,20 +1399,11 @@
 e %7B%0A
-            
+%09%09%09
 writ
@@ -1419,17 +1419,16 @@
 roperty(
- 
 prefix, 
@@ -1440,33 +1440,31 @@
 Name
- 
 );%0A
-        %7D%0A    %7D%0A%0A    
+%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09
 publ
@@ -1479,17 +1479,16 @@
 t parse(
- 
 String n
@@ -1534,21 +1534,14 @@
 alue
- 
 ) %7B%0A
-        
+%09%09
 thro
@@ -1576,17 +1576,16 @@
 ception(
- 
 %22Not sup
@@ -1600,16 +1600,12 @@
 et.%22
- 
 );%0A
-    
+%09
 %7D%0A%7D%0A

fix for caldav resource types, output namespace uri even when namespace is not found in requested properties