/** 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(); }
/** 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); }