001/* 002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo 016 */ 017 018package org.nuxeo.ecm.platform.publisher.remoting.marshaling.io; 019 020import org.dom4j.Document; 021import org.dom4j.DocumentException; 022import org.dom4j.DocumentHelper; 023import org.nuxeo.ecm.core.api.DocumentModel; 024import org.nuxeo.ecm.core.io.ExportedDocument; 025import org.nuxeo.ecm.core.io.impl.AbstractDocumentReader; 026import org.nuxeo.ecm.core.io.impl.ExportedDocumentImpl; 027import org.nuxeo.ecm.core.io.impl.plugins.DocumentModelReader; 028 029import java.io.IOException; 030 031/** 032 * {@link DocumentModelReader} that reads the {@link DocumentModel} from a String. 033 * 034 * @author tiry 035 */ 036public class SingleXMlDocumentReader extends AbstractDocumentReader { 037 038 protected Document xmldoc; 039 040 public SingleXMlDocumentReader(String data) throws DocumentException { 041 xmldoc = DocumentHelper.parseText(data); 042 } 043 044 @Override 045 public ExportedDocument read() throws IOException { 046 if (xmldoc != null) { 047 ExportedDocument xdoc = new ExportedDocumentImpl(); 048 xdoc.setDocument(xmldoc); 049 close(); 050 return xdoc; 051 } else { 052 return null; 053 } 054 } 055 056 public void close() { 057 xmldoc = null; 058 } 059 060}