Exemplo n.º 1
0
 protected Map toEditableObject(HTMLText text) {
   Map m = new HashMap();
   for (Iterator it = text.getText().keySet().iterator(); it.hasNext(); ) {
     String lang = (String) it.next();
     String val = text.getText(lang);
     m.put(lang, val);
   }
   return m;
 }
Exemplo n.º 2
0
  /**
   * Replicates panel data.
   *
   * @param src Source PanelInstance
   * @param dest Destinaton PanelInstance
   */
  public void replicateData(final PanelInstance src, PanelInstance dest) throws Exception {
    super.replicateData(src, dest);
    log.debug(
        "HTMLDriver replicating Data from PanelInstance "
            + src.getDbid()
            + " to "
            + dest.getDbid()
            + ").");
    if (src.equals(dest)) {
      log.debug("Ignoring replication, panel instance is the same.");
      return;
    }

    final HTMLText[] textArray = new HTMLText[1];
    try {
      new HibernateTxFragment() {
        protected void txFragment(Session session) throws Exception {
          log.debug("Getting text to duplicate for instance " + src.getDbid());
          FlushMode oldMode = session.getFlushMode();
          session.setFlushMode(
              FlushMode
                  .COMMIT); // Avoids flushing, as we know the text was not modified in this
                            // transaction.
          textArray[0] = load(src);
          session.setFlushMode(oldMode);
          log.debug("Got text to duplicate for instance " + src.getDbid());
        }
      }.execute();
    } catch (Exception e) {
      log.error("Error loading text for instance. ", e);
    }
    HTMLText text = textArray[0];
    if (text == null) {
      log.debug(
          "Nothing to replicate from PanelInstance " + src.getDbid() + " to " + dest.getDbid());
      return;
    }
    Map htmlSrc = text.getText();

    log.debug("htmlCode to replicate = " + htmlSrc);
    HTMLText htmlDest = new HTMLText();
    htmlDest.setPanelInstance(dest.getInstance());
    for (Iterator it = htmlSrc.keySet().iterator(); it.hasNext(); ) {
      String key = (String) it.next();
      String val = (String) htmlSrc.get(key);
      htmlDest.setText(key, val);
    }
    try {
      log.debug("Updating HTMLText: IDText " + htmlDest.getDbid() + " Text " + htmlDest.getText());
      htmlDest.save();
    } catch (Exception e) {
      log.error("Replicating panel data", e);
    }
  }
Exemplo n.º 3
0
 /** Read instance content from given InputStream, which must not be closed. */
 public void importContent(PanelInstance instance, InputStream is) throws Exception {
   HTMLText currentText = new HTMLText();
   currentText.setPanelInstance(instance);
   ObjectInputStream ois = new ObjectInputStream(is);
   Map text = (Map) ois.readObject();
   if (log.isDebugEnabled()) log.debug("Importing content: " + text);
   for (Iterator it = text.keySet().iterator(); it.hasNext(); ) {
     String lang = (String) it.next();
     String value = (String) text.get(lang);
     currentText.setText(lang, value);
   }
   currentText.save();
 }
Exemplo n.º 4
0
 public CommandResponse actionSaveChanges(Panel panel, CommandRequest request) throws Exception {
   String currentText = request.getRequestObject().getParameter(PARAMETER_HTML);
   Map m = (Map) SessionManager.getPanelSession(panel).getAttribute(ATTR_TEXT);
   HTMLText text = load(panel.getInstance());
   for (Iterator it = m.keySet().iterator(); it.hasNext(); ) {
     String lang = (String) it.next();
     String val = (String) m.get(lang);
     text.setText(lang, val);
   }
   text.setText(getEditingLanguage(panel), currentText);
   text.save();
   activateNormalMode(panel, request);
   return new ShowPanelPage();
 }
Exemplo n.º 5
0
 public CommandResponse actionChangeEditingLanguage(Panel panel, CommandRequest request)
     throws Exception {
   String currentText = request.getRequestObject().getParameter(PARAMETER_HTML);
   Map text = (Map) SessionManager.getPanelSession(panel).getAttribute(ATTR_TEXT);
   if (text == null) {
     text = toEditableObject(load(panel.getInstance()));
     SessionManager.getPanelSession(panel).setAttribute(ATTR_TEXT, text);
   }
   text.put(getEditingLanguage(panel), currentText);
   SessionManager.getPanelSession(panel).setAttribute(ATTR_TEXT, text);
   String paramLang = request.getRequestObject().getParameter(PARAMETER_EDITING_LANG);
   SessionManager.getPanelSession(panel).setAttribute(ATTR_EDITING_LANGUAGE, paramLang);
   return new ShowPanelPage();
 }