/*
|
neon-fm - Dateiverwaltung fuer neon
|
Copyright (C) 2024 Ulrich Hilger
|
|
This program is free software: you can redistribute it and/or modify
|
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
|
You should have received a copy of the GNU Affero General Public License
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
*/
|
package de.uhilger.neon.fm;
|
|
import com.sun.net.httpserver.HttpExchange;
|
import de.uhilger.neon.FileServer;
|
import de.uhilger.neon.HttpResponder;
|
import de.uhilger.fm.FileHelper;
|
import java.io.IOException;
|
import java.util.logging.Level;
|
import java.util.logging.Logger;
|
|
/**
|
*
|
* @author Ulrich Hilger
|
* @version 0.1, 08.11.2024
|
*/
|
public class FileCreator extends AbstractFileActor {
|
|
public void run(HttpExchange exchange) {
|
try {
|
super.run(exchange);
|
if (fileName.endsWith(FileServer.STR_SLASH)) { // es ist ein Ordner
|
if (!file.exists()) {
|
file.mkdir();
|
antwort(exchange, HttpResponder.SC_OK, file.getAbsolutePath());
|
} else {
|
String antw = "Ordner existiert bereits.";
|
antwort(exchange, HttpResponder.SC_UNPROCESSABLE_ENTITY, antw);
|
}
|
} else { // es ist eine Datei
|
if (file.exists()) {
|
FileHelper trans = new FileHelper();
|
file = trans.getNewFileName(file);
|
}
|
speichern(exchange);
|
}
|
} catch (IOException ex) {
|
Logger.getLogger(FileCreator.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
|
} finally {
|
free();
|
}
|
}
|
}
|