Exemplo n.º 1
0
 /**
  * Determine the text being shown for given panel.
  *
  * @param panel
  * @return The text shown, i18n.
  */
 public Map getHtmlCode(Panel panel) {
   PanelSession pSession = SessionManager.getPanelSession(panel);
   Map m = (Map) pSession.getAttribute(ATTR_TEXT);
   if (m != null) return m;
   HTMLText text = load(panel.getInstance());
   if (text != null) return text.getText();
   try {
     HTMLText textToCreate = new HTMLText();
     textToCreate.setPanelInstance(panel.getInstance());
     Locale[] locales = LocaleManager.lookup().getPlatformAvailableLocales();
     for (int i = 0; i < locales.length; i++) {
       Locale locale = locales[i];
       ResourceBundle i18n =
           localeManager.getBundle("org.jboss.dashboard.ui.panel.advancedHTML.messages", locale);
       textToCreate.setText(locale.getLanguage(), i18n.getString("defaultContent"));
     }
     textToCreate.save();
   } catch (Exception e) {
     log.error("Error creating empty text for panel: ", e);
   }
   text = load(panel.getInstance());
   if (text != null) return text.getText();
   log.error("Current HTML code is null for panel " + panel);
   return null;
 }
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
 /** Write instance content to given OutputStream, which must not be closed. */
 public void exportContent(PanelInstance instance, OutputStream os) throws Exception {
   HTMLText text = load(instance);
   if (text == null) {
     try {
       text = new HTMLText();
       text.setPanelInstance(instance);
       text.save();
     } catch (Exception e) {
       log.error("Error creating empty HTMLText object", e);
     }
   }
   ObjectOutputStream oos = new ObjectOutputStream(os);
   if (log.isDebugEnabled()) log.debug("Exporting content: " + text.getText());
   HashMap h = new HashMap(); // Avoids serializing a hibernate map
   h.putAll(text.getText());
   oos.writeObject(h);
 }