Page 1 of 1

2.6.0 - Document setting / document protection

PostPosted: Sat Apr 23, 2011 12:10 am
by verrnum
Hi,

Since i upgraded from 2.5.0 to 2.6.0 , i can't find the document protection, for example the next code dosen't work anymore :

Code: Select all
List<DefaultElement> elementList = documentSettings.getDocument().getRootElement().elements();
      for(DefaultElement e:elementList){
         if(e.getName().equals("documentProtection")) {
            List<DefaultAttribute> attributeList = e.attributes();
            for(DefaultAttribute a:attributeList) {
               if(a.getName().equals("edit")) {
                  if(a.getValue().equals("comments")) protectType = STDocProtect.COMMENTS;
                  if(a.getValue().equals("forms")) protectType = STDocProtect.FORMS;
                  if(a.getValue().equals("none")) protectType = STDocProtect.NONE;
                  if(a.getValue().equals("readOnly")) protectType = STDocProtect.READ_ONLY;
                  if(a.getValue().equals("trackedChanges")) protectType = STDocProtect.TRACKED_CHANGES;
                  
               }
                           }
         }
      }


Where can i find information on document protection in 2.6.0 version ?

Thanks a lot.

Best regards

Re: 2.6.0 - Document setting / document protection

PostPosted: Sat Apr 23, 2011 12:37 am
by jason
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<w:settings xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:documentProtection w:edit="readOnly" .../>
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Given MainDocumentPart documentPart:

Code: Select all
      DocumentSettingsPart dsp = documentPart.getDocumentSettingsPart();
      CTDocProtect dp = dsp.getJaxbElement().getDocumentProtection();
      STDocProtect protectType = dp.getEdit();

Re: 2.6.0 - Document setting / document protection

PostPosted: Sat Apr 23, 2011 1:16 am
by verrnum
jason wrote:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<w:settings xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:documentProtection w:edit="readOnly" .../>
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Given MainDocumentPart documentPart:

Code: Select all
      DocumentSettingsPart dsp = documentPart.getDocumentSettingsPart();
      CTDocProtect dp = dsp.getJaxbElement().getDocumentProtection();
      STDocProtect protectType = dp.getEdit();



Hi Jason,

Thanks a lot !!

To set the protectino then :


Code: Select all
DocumentSettingsPart dsp
         = wordMLPackage.getMainDocumentPart().getDocumentSettingsPart();
      dsp.getJaxbElement().getDocumentProtection().setEdit(protectType);


Best Regards