/** * LibreSource * Copyright (C) 2004-2007 Artenum SARL / INRIA * http://www.libresource.org - contact@libresource.org * * This software is free software; you can redistribute it and/or * modify it under the terms of QPL. See licenses details in QPL.txt * * Initial authors : * * Guillaume Bort / INRIA * Francois Charoy / Universite Nancy 2 * Julien Forest / Artenum * Claude Godart / Universite Henry Poincare * Florent Jouille / INRIA * Sebastien Jourdain / INRIA / Artenum * Yves Lerumeur / Artenum * Pascal Molli / Universite Henry Poincare * Gerald Oster / INRIA * Mariarosa Penzi / Artenum * Gerard Sookahet / Artenum * Raphael Tani / INRIA * * Contributors : * * Stephane Bagnier / Artenum * Amadou Dia / Artenum-IUP Blois * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ package org.libresource.subversion; import org.libresource.Libresource; import org.libresource.subversion.interfaces.LibresourceSubversionService; import org.libresource.xml.ImportExportLogger; import org.libresource.xml.LibresourceImportHandler; import org.xml.sax.Attributes; import java.net.URI; /** * LibreSource * Import d'une ressource Subversion en XML * format : * * @author georgy (gdf) */ public class SubversionImportHandler extends LibresourceImportHandler { private URI node; private String oldId; private String repertoryName; private String name; private String description; private String commiters; private String readers; private boolean enteredInDefinition = false; private StringBuffer tmpContent; private LibresourceSubversionService libresourceSubversionService; public void handleBeginElement(String name, Attributes attributes, ImportExportLogger logger) throws Exception { if (name.equals("libresource:subversion")) { enteredInDefinition = true; oldId = attributes.getValue("id"); repertoryName = attributes.getValue("repertoryName"); } if (name.equals("subversion:name")) { tmpContent = new StringBuffer(); } if (name.equals("subversion:description")) { tmpContent = new StringBuffer(); } if (name.equals("subversion:commiters")) { tmpContent = new StringBuffer(); } if (name.equals("subversion:readers")) { tmpContent = new StringBuffer(); } } public boolean handleEndElement(String name, ImportExportLogger logger) throws Exception { if (name.equals("libresource:subversion")) { enteredInDefinition = false; // Create the repository libresourceSubversionService.createRepository(node, this.name, this.description, this.commiters, this.readers); // Rename the repository if necessary if (!repertoryName.equals(oldId)) { libresourceSubversionService.editRepository(node, this.name, this.repertoryName, this.description, this.commiters, this.readers); } return true; } if (name.equals("subversion:name")) { this.name = tmpContent.toString().trim(); return false; } if (name.equals("subversion:description")) { this.description = tmpContent.toString().trim(); return false; } if (name.equals("subversion:commiters")) { this.commiters = tmpContent.toString().trim(); return false; } if (name.equals("subversion:readers")) { this.readers = tmpContent.toString().trim(); return false; } return false; } public void handleContent(String content, ImportExportLogger logger) throws Exception { if (tmpContent != null) { tmpContent.append(content); } } public void init(URI node, ImportExportLogger logger) throws Exception { this.node = node; name = null; description = null; commiters = null; readers = null; tmpContent = null; libresourceSubversionService = (LibresourceSubversionService) Libresource.getService(SubversionConstants.SERVICE); } }