Hello Hussein, it worked like a charm. Thanks a lot.
2011/7/25 Hussein Shafie <[email protected]>: > On 07/24/2011 06:42 PM, Fabián Mandelbaum wrote: >> >> Hello Hussein, thanks again for your ideas. It's still not working >> though. I've changed the 'algorithm' and am now marking the whole >> document read-only, and a certain list of elements as read-write (to >> achieve the "read-write islands in a read-only ocean" concept). > > I've managed to reproduce the problem. Choosing "read-write islands in a > read-only ocean" rather than "read-write document with some read-only > elements" cannot solve your problem. See below. > > > XXE's CSS engine does not automatically react to property changes like it > automatically reacts to attribute and/or child element changes. You need to > explicitly invoke DocumentView.rebuildView after you change a ``visual'' > property of a node (I mean, which like property readOnly is rendered in the > CSS). > > If you add this snippet at the end of your checkingDocument(), this should > solve your problem: > > --- > import com.xmlmind.xml.doc.DocumentListener; > import com.xmlmind.xmledit.view.DocumentView; > > @Override > public void checkingDocument(Document doc, Reason reason, > URL saveAsURL) { > if (Reason.OPEN.equals(reason)) { > ... > doc.endEdit(); > > DocumentListener[] docListeners = > doc.getDocumentListeners(true); > for (DocumentListener docListener : docListeners) { > if (docListener instanceof DocumentView) { > ((DocumentView) docListener).rebuildView(doc); > brseak; > } > } > } > } > --- > > Reference: > > * > http://www.xmlmind.com/xmleditor/_distrib/doc/api/com/xmlmind/xml/doc/Document.html#getDocumentListeners(boolean) > > * > http://www.xmlmind.com/xmleditor/_distrib/doc/api/com/xmlmind/xmledit/view/DocumentView.html#rebuildView(com.xmlmind.xml.doc.Node) > > >> >> /** >> * (C) 2011 by NeoDoc SARL. All Rights Reserved >> */ >> package biz.neodoc.xxe.nexto; >> >> import java.io.BufferedReader; >> import java.io.File; >> import java.io.FileInputStream; >> import java.io.InputStreamReader; >> import java.net.URL; >> import java.util.ArrayList; >> import java.util.List; >> >> import com.xmlmind.xml.doc.Document; >> import com.xmlmind.xml.doc.Element; >> import com.xmlmind.xml.doc.Traversal; >> import com.xmlmind.xml.name.Name; >> import com.xmlmind.xmleditapp.validatehook.Reason; >> import com.xmlmind.xmleditapp.validatehook.ValidateHookBase; >> >> /** >> * This marks the whole book as read-only, and then marks only >> * specific parts of it as read-write >> * >> * @author fabman >> * >> */ >> public class MarkReadWriteParts extends ValidateHookBase { >> // Read-only XXE property >> private static final Name RO_PROP = Name.get( >> >> "http://www.xmlmind.com/xmleditor/namespace/property", >> "readOnly"); >> >> // Identifiers of the items to mark R/W >> private List<String> RW_ITEMS = new ArrayList<String>(); >> >> public MarkReadWriteParts() { >> System.out.println("Building up the list of items..."); >> List<String> items = new ArrayList<String>(); >> try { >> File addOnHome = new >> >> File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile(); >> BufferedReader breader = new BufferedReader( >> new InputStreamReader( >> new >> FileInputStream(new File(addOnHome, "rwitems.list")))); >> String line; >> while ((line = breader.readLine()) != null) { >> line = line.trim(); // Chop off whitespace >> if (!line.startsWith("#")&& >> !line.isEmpty()) { >> items.add(line); >> } >> } >> breader.close(); >> } catch (Exception ex) { >> System.err.println("Cannot process rwitems.list : " >> + ex.getMessage()); >> } finally { >> RW_ITEMS.addAll(items); >> } >> } >> >> @Override >> public void checkingDocument(Document doc, Reason reason, URL >> saveAsURL) { >> if (Reason.OPEN.equals(reason)) { >> final ArrayList<Element> rwItems = new >> ArrayList<Element>(); >> Traversal.traverse(doc.getRootElement(), new >> Traversal.HandlerBase() { >> @Override >> public Object enterElement(Element element) >> { >> if >> (RW_ITEMS.contains(element.getAttribute(Name.XML_ID))) { >> rwItems.add(element); >> } >> return null; >> } >> }); >> doc.beginEdit(); >> // Mark the whole doc as R/O >> doc.getRootElement().putProperty(RO_PROP, >> Boolean.TRUE); >> // Mark specific parts as R/W >> for (Element rwItem: rwItems) { >> rwItem.putProperty(RO_PROP, Boolean.FALSE); >> } >> doc.endEdit(); >> } >> } >> >> } >> > -- Fabián Mandelbaum IS Engineer -- XMLmind XML Editor Support List [email protected] http://www.xmlmind.com/mailman/listinfo/xmleditor-support

