Dateiverwaltung für die WebBox
ulrich
2017-03-06 fab80c872af697d61f200fd410a7ecc64ca0a537
dekodieren fuer Codemirror
3 files modified
76 ■■■■ changed files
src/java/de/uhilger/filecms/api/FileMgr.java 8 ●●●● patch | view | raw | blame | history
src/java/de/uhilger/filecms/web/Initialiser.java 39 ●●●● patch | view | raw | blame | history
web/ui/ui.js 29 ●●●●● patch | view | raw | blame | history
src/java/de/uhilger/filecms/api/FileMgr.java
@@ -21,10 +21,13 @@
import de.uhilger.filecms.data.FileRef;
import de.uhilger.filecms.web.Initialiser;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Iterator;
@@ -104,9 +107,12 @@
    
    Object p = getRequest().getUserPrincipal();
    if(p instanceof Principal) {
      FileReader reader = null;
      Reader reader = null;
      try {
        File targetFile = new File(getTargetDir(relPath), fileName);
        //reader = new InputStreamReader(new FileInputStream(targetFile), "UTF8");
        reader = new FileReader(targetFile);
        StringBuffer buf = new StringBuffer();
        char[] readBuffer = new char[1024];
src/java/de/uhilger/filecms/web/Initialiser.java
@@ -18,6 +18,7 @@
package de.uhilger.filecms.web;
import de.uhilger.wbx.WbxUtils;
import java.io.File;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
@@ -62,48 +63,16 @@
          ctx.setAttribute(FILE_BASE, pfad);
          logger.fine("Basis: " + pfad);
        } else {
          ctx.setAttribute(FILE_BASE, getWbxDataDir(ctx).getAbsolutePath());
          ctx.setAttribute(FILE_BASE, WbxUtils.getWbxDataDir(ctx).getAbsolutePath());
        }
      } else {
        ctx.setAttribute(FILE_BASE, getWbxDataDir(ctx).getAbsolutePath());
        ctx.setAttribute(FILE_BASE, WbxUtils.getWbxDataDir(ctx).getAbsolutePath());
      }    
    } catch(Exception ex) {
      ctx.setAttribute(FILE_BASE, getWbxDataDir(ctx).getAbsolutePath());
      ctx.setAttribute(FILE_BASE, WbxUtils.getWbxDataDir(ctx).getAbsolutePath());
    }
  }
  
  /**
   * Bei der WebBox ist das Datenverzeichnis relativ zum Verzeichnis
   * $CATALINA_BASE/webapps untergebracht.
   * Die Abfrage ServletContext.getRealPath
   * liefert das Verzeichnis des Context dieser Webanwendung, also
   * $CATALINA_BASE/webapps/file-cms
   * oder
   * $WBX/sys/base/webapps/file-cms
   *
   * Unter Windows z.B.
   * C:\Users\fred\Documents\srv\wbx\sys\base\webapps\file-cms
   * Unter Linux oder Mac OS z.B.
   * /home/fred/srv/wbx/sys/base/webapps/file-cms
   *
   * Das Datenverzeichis liegt dann auf
   * $WBX/daten
   *
   * Mit dem Verzeichnis des Context dieser Webanwendung ist das
   * Datenverzeichnis der WebBox hart kodierbar mit dieser Methode
   *
   * @return Verzeichnis 'daten' der WebBox
   */
  private File getWbxDataDir(ServletContext ctx) {
    String path = ctx.getRealPath("/");
    logger.fine("getRealPath: " + path); // file-cms in webapps
    File file = new File(path);
    file = file.getParentFile().getParentFile().getParentFile().getParentFile();
    file = new File(file, "daten/");
    logger.fine("Basis: " + file.getAbsolutePath());
    return file;
  }
  @Override
  public void contextDestroyed(ServletContextEvent sce) {
    // hier wird alles wieder aufgeraeumt
web/ui/ui.js
@@ -761,7 +761,9 @@
      }
    }
  });
  cm.setValue(htmlDecode(content));
  //cm.setValue(htmlDecode(content));
  //cm.setValue(content);
  cm.setValue(unescapeHtml(content));
}
@@ -804,6 +806,31 @@
  return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}';
}
function escapeHtml(text) {
  text = text.replace(/\u228/g,'ä');
  text = text.replace(/\u246/g,'ö');
  text = text.replace(/\u252/g,'ü');
  text = text.replace(/\u196/g,'Ä');
  text = text.replace(/\u214/g,'Ö');
  text = text.replace(/\u220/g,'Ü');
  text = text.replace(/\u223/g,'ß');
  text = text.replace(/\u26/g,'&');
  return text;
}
function unescapeHtml(text) {
  text = text.replace(/ä/g, String.fromCharCode(228));
  text = text.replace(/ö/g, String.fromCharCode(246));
  text = text.replace(/ü/g, String.fromCharCode(252));
  text = text.replace(/Ä/g, String.fromCharCode(196));
  text = text.replace(/Ö/g, String.fromCharCode(214));
  text = text.replace(/Ü/g, String.fromCharCode(220));
  text = text.replace(/ß/g, String.fromCharCode(223));
  text = text.replace(/&/g, String.fromCharCode(26));
  return text;
}
/* ----- Objekte ----- */
function FileList(fl) {