Java tutorial
/* * Copyright 2009 Martin Palma * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package it.unibz.inf.xmlssd.metadator.helpers; import it.unibz.inf.xmlssd.metadator.sqlite.SQLiteManager; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; /** * Simple class for exporting the files stored in the Database as * XML files. * @author Martin Palma <martin@palma.bz> * */ public class Exporter { File aFile; /** * Constructs a exporter object. * @param file */ public Exporter(File file) { aFile = file; } /** * Export method which exports all the stored data as a XML document. * @throws IOException */ public void export() throws IOException { OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(aFile.getCanonicalPath()), format); SQLiteManager sqlite = new SQLiteManager(); writer.write(sqlite.get()); writer.close(); } /** * Export method which exports the given string. * @param str */ public void export(String str) throws IOException { FileOutputStream fStream = new FileOutputStream(aFile); fStream.write(str.getBytes()); fStream.close(); } }