001/* 002 * Copyright (c) 2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Nuxeo - initial API and implementation 011 * 012 */ 013 014package org.nuxeo.ecm.core.io.impl.transformers; 015 016import java.io.IOException; 017 018import org.dom4j.Element; 019import org.nuxeo.ecm.core.io.DocumentTransformer; 020import org.nuxeo.ecm.core.io.ExportedDocument; 021 022/** 023 * Migrate a DocumentType to a facet 024 * 025 * @since 7.4 026 */ 027public class DoctypeToFacetTranslator implements DocumentTransformer { 028 029 protected final String docType; 030 031 protected final String newDocType; 032 033 protected final String facet; 034 035 public DoctypeToFacetTranslator(String docType, String newDocType, String facet) { 036 this.docType = docType; 037 this.newDocType = newDocType; 038 this.facet = facet; 039 } 040 041 @Override 042 public boolean transform(ExportedDocument xdoc) throws IOException { 043 if (xdoc.getType().equals(docType)) { 044 Element root = xdoc.getDocument().getRootElement(); 045 Element sys = root.element("system"); 046 sys.element("type").setText(newDocType); 047 sys.addElement("facet").setText(facet); 048 } 049 return true; 050 } 051 052}