com.chingo247.structureapi.plan.document.PlanDocument.java Source code

Java tutorial

Introduction

Here is the source code for com.chingo247.structureapi.plan.document.PlanDocument.java

Source

/*
 * Copyright (C) 2014 Chingo
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */
package com.chingo247.structureapi.plan.document;

import java.io.File;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 *
 * @author Chingo
 */
public class PlanDocument extends AbstractDocument<PlanDocumentPluginElement> {

    private final PlanDocumentManager documentManager;

    PlanDocument(PlanDocumentManager documentManager, File documentFile) throws DocumentException {
        super(documentFile);
        this.documentFile = documentFile;
        this.document = new SAXReader().read(documentFile);
        this.documentManager = documentManager;
    }

    @Override
    public void save() {
        documentManager.save(this);
    }

    @Override
    protected void save(PlanDocumentPluginElement element) {
        Element e = (Element) document.getRootElement().selectSingleNode(element.pluginName);
        e.clearContent();
        e.setContent(element.pluginElement.elements());
        documentManager.save(element);
    }

}