// Path: src/org/dmfs/dav/DavParserContext.java
// public class DavParserContext extends ParserContext
// {
// 	private boolean mStrict = true;
// 	private boolean mKeepNotFoundProperties = false;
// 
// 
// 	/**
// 	 * Create a new {@link DavParserContext}.
// 	 */
// 	public DavParserContext()
// 	{
// 		mStrict = true;
// 	}
// 
// 
// 	/**
// 	 * Enable or disable strict parsing. Strict parsing will throw an error in some cases when the response is malformed. If strict parsing is not enabled the
// 	 * parser is supposed to make assumptions about the intent and continue if possible.
// 	 * 
// 	 * @param strict
// 	 *            <code>true</code> to be strict with errors, <code>false</code> otherwise.
// 	 * @return
// 	 */
// 	public DavParserContext setStrict(boolean strict)
// 	{
// 		mStrict = strict;
// 		return this;
// 	}
// 
// 
// 	/**
// 	 * Return whether strict parsing has been requested or not.
// 	 * 
// 	 * @return <code>true</code> to be strict with issues.
// 	 */
// 	public boolean isStrict()
// 	{
// 		return mStrict;
// 	}
// 
// 
// 	/**
// 	 * Set whether to allow dropping propstat elements with status {@link HttpStatus#NOT_FOUND}. In many cases there is no benefit in keeping them, so the
// 	 * default is not to store them.
// 	 * 
// 	 * @param keepNotFoundProperties
// 	 *            <code>true</code> to keep propstat elements with status {@link HttpStatus#NOT_FOUND}.
// 	 */
// 	public DavParserContext setKeepNotFoundProperties(boolean keepNotFoundProperties)
// 	{
// 		mKeepNotFoundProperties = keepNotFoundProperties;
// 		return this;
// 	}
// 
// 
// 	/**
// 	 * Returns whether to keep properties with status {@link HttpStatus#NOT_FOUND} or not.
// 	 * 
// 	 * @return <code>true</code> to keep such properties, <code>false</code> otherwise.
// 	 */
// 	public boolean getKeepNotFoundProperties()
// 	{
// 		return mKeepNotFoundProperties;
// 	}
// }


import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.dmfs.dav.DavParserContext;
import org.dmfs.httpclientinterfaces.HttpStatus;
import org.dmfs.xmlobjects.ElementDescriptor;
import org.dmfs.xmlobjects.builder.AbstractObjectBuilder;
import org.dmfs.xmlobjects.builder.IObjectBuilder;
import org.dmfs.xmlobjects.pull.ParserContext;
import org.dmfs.xmlobjects.pull.Recyclable;
import org.dmfs.xmlobjects.pull.XmlObjectPullParserException;
import org.dmfs.xmlobjects.serializer.SerializerContext;
import org.dmfs.xmlobjects.serializer.SerializerException;
import org.dmfs.xmlobjects.serializer.XmlObjectSerializer.IXmlChildWriter;
/*
 * Copyright (C) 2014 Marten Gajda <marten@dmfs.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

package org.dmfs.dav.rfc4918;




/**
 * This class represents a multistatus <code>response</code> element as defined in <a href="http://tools.ietf.org/html/rfc4918#section-14.24">RFC 4918 section
 * 14.24</a>.
 * 
 * @author Marten Gajda <marten@dmfs.org>
 */
public class Response implements Recyclable
{

	/**
	 * The status code if there was no status element.
	 */
	public final static int STATUS_NONE = -1;

	/**
	 * An {@link IXmlObjectBuilder} for {@link Response} elements.
	 */
	public final static IObjectBuilder<Response> BUILDER = new AbstractObjectBuilder<Response>()
	{
		@Override
		public Response get(ElementDescriptor<Response> descriptor, Response recycle, ParserContext context) throws XmlObjectPullParserException
		{
			if (recycle != null)
			{
				recycle.recycle();
				return recycle;
			}
			return new Response();
		};


		@Override
		public <V> Response update(ElementDescriptor<Response> descriptor, Response object, ElementDescriptor<V> childDescriptor, V child, ParserContext context)
			throws XmlObjectPullParserException
		{
			if (childDescriptor == WebDav.PROPSTAT)
			{
				PropStat propStat = (PropStat) child;
// Path: src/org/dmfs/dav/DavParserContext.java
// public class DavParserContext extends ParserContext
// {
// 	private boolean mStrict = true;
// 	private boolean mKeepNotFoundProperties = false;
// 
// 
// 	/**
// 	 * Create a new {@link DavParserContext}.
// 	 */
// 	public DavParserContext()
// 	{
// 		mStrict = true;
// 	}
// 
// 
// 	/**
// 	 * Enable or disable strict parsing. Strict parsing will throw an error in some cases when the response is malformed. If strict parsing is not enabled the
// 	 * parser is supposed to make assumptions about the intent and continue if possible.
// 	 * 
// 	 * @param strict
// 	 *            <code>true</code> to be strict with errors, <code>false</code> otherwise.
// 	 * @return
// 	 */
// 	public DavParserContext setStrict(boolean strict)
// 	{
// 		mStrict = strict;
// 		return this;
// 	}
// 
// 
// 	/**
// 	 * Return whether strict parsing has been requested or not.
// 	 * 
// 	 * @return <code>true</code> to be strict with issues.
// 	 */
// 	public boolean isStrict()
// 	{
// 		return mStrict;
// 	}
// 
// 
// 	/**
// 	 * Set whether to allow dropping propstat elements with status {@link HttpStatus#NOT_FOUND}. In many cases there is no benefit in keeping them, so the
// 	 * default is not to store them.
// 	 * 
// 	 * @param keepNotFoundProperties
// 	 *            <code>true</code> to keep propstat elements with status {@link HttpStatus#NOT_FOUND}.
// 	 */
// 	public DavParserContext setKeepNotFoundProperties(boolean keepNotFoundProperties)
// 	{
// 		mKeepNotFoundProperties = keepNotFoundProperties;
// 		return this;
// 	}
// 
// 
// 	/**
// 	 * Returns whether to keep properties with status {@link HttpStatus#NOT_FOUND} or not.
// 	 * 
// 	 * @return <code>true</code> to keep such properties, <code>false</code> otherwise.
// 	 */
// 	public boolean getKeepNotFoundProperties()
// 	{
// 		return mKeepNotFoundProperties;
// 	}
// }


// Path: src/org/dmfs/dav/rfc4918/Response.java
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.dmfs.dav.DavParserContext;
import org.dmfs.httpclientinterfaces.HttpStatus;
import org.dmfs.xmlobjects.ElementDescriptor;
import org.dmfs.xmlobjects.builder.AbstractObjectBuilder;
import org.dmfs.xmlobjects.builder.IObjectBuilder;
import org.dmfs.xmlobjects.pull.ParserContext;
import org.dmfs.xmlobjects.pull.Recyclable;
import org.dmfs.xmlobjects.pull.XmlObjectPullParserException;
import org.dmfs.xmlobjects.serializer.SerializerContext;
import org.dmfs.xmlobjects.serializer.SerializerException;
import org.dmfs.xmlobjects.serializer.XmlObjectSerializer.IXmlChildWriter;

/*
 * Copyright (C) 2014 Marten Gajda <marten@dmfs.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

package org.dmfs.dav.rfc4918;




/**
 * This class represents a multistatus <code>response</code> element as defined in <a href="http://tools.ietf.org/html/rfc4918#section-14.24">RFC 4918 section
 * 14.24</a>.
 * 
 * @author Marten Gajda <marten@dmfs.org>
 */
public class Response implements Recyclable
{

	/**
	 * The status code if there was no status element.
	 */
	public final static int STATUS_NONE = -1;

	/**
	 * An {@link IXmlObjectBuilder} for {@link Response} elements.
	 */
	public final static IObjectBuilder<Response> BUILDER = new AbstractObjectBuilder<Response>()
	{
		@Override
		public Response get(ElementDescriptor<Response> descriptor, Response recycle, ParserContext context) throws XmlObjectPullParserException
		{
			if (recycle != null)
			{
				recycle.recycle();
				return recycle;
			}
			return new Response();
		};


		@Override
		public <V> Response update(ElementDescriptor<Response> descriptor, Response object, ElementDescriptor<V> childDescriptor, V child, ParserContext context)
			throws XmlObjectPullParserException
		{
			if (childDescriptor == WebDav.PROPSTAT)
			{
				PropStat propStat = (PropStat) child;
				if (propStat.getStatusCode() == HttpStatus.NOT_FOUND && context instanceof DavParserContext