Posted By

nausherwan on 05/25/14


Tagged

doc protect word protection AsposeWords Aspose


Versions (?)

Java Sample Code to Protect a Word Document using Aspose.Words for Cloud


 / Published in: Java
 

URL: http://www.aspose.com/docs/display/wordscloud/Protect+a+Word+Document

This java sample code allows developers to protect a Word document using Aspose.Words for Cloud API on the Aspose Cloud Storage. You can use Aspose.Words for Cloud API in any language of your choice.

  1. String appSID = "******************";
  2. String appKey = "******************";
  3. String fileName = "MyFile.doc";
  4.  
  5. // build URI to protect a Word document
  6. String strURI = "http://api.aspose.com/v1.1/words/" + fileName + "/protection";
  7. // sign the remote URI
  8. String signedURI = Sign(strURI, appSID, appKey);
  9.  
  10. ProtectionRequest protectionRequest = new ProtectionRequest();
  11. protectionRequest.setPassword("123456");
  12. protectionRequest.setProtectionType(ProtectionType.AllowOnlyFormFields.toString());
  13.  
  14. Gson gson = new Gson();
  15. String strJSON = gson.toJson(protectionRequest, ProtectionRequest.class);
  16. InputStream responseStream = ProcessCommand(signedURI, "PUT", strJSON);
  17. String responseJSON = Utils.StreamToString(responseStream);
  18.  
  19. ProtectionResponse docResponse = gson.fromJson(responseJSON, ProtectionResponse.class);
  20.  
  21. if(docResponse.getCode().equals("200"))
  22. System.out.println("Document has been protected successfully");
  23.  
  24. //Here is the BaseResponse class
  25. public class BaseResponse {
  26. public BaseResponse() { }
  27.  
  28. private String Code;
  29. private String Status;
  30.  
  31. public String getCode(){return Code;}
  32. public String getStatus(){return Status;}
  33.  
  34. public void setCode(String temCode){ Code=temCode;}
  35. public void setStatus(String temStatus){ Status=temStatus;}
  36. }
  37.  
  38. //Here is the ProtectionRequest class
  39. public class ProtectionRequest {
  40. private String Password;
  41. public String getPassword(){return Password;}
  42. public void setPassword(String Password){this.Password=Password;}
  43.  
  44. private String NewPassword;
  45. public String getNewPassword(){return NewPassword;}
  46. public void setNewPassword(String NewPassword){this.NewPassword=NewPassword;}
  47.  
  48. private String ProtectionType;
  49. public String getProtectionType(){return ProtectionType;}
  50. public void setProtectionType(String ProtectionType){this.ProtectionType=ProtectionType;}
  51. }
  52.  
  53. //Here is the ProtectionResponse class
  54. public class ProtectionResponse extends BaseResponse {
  55. private DocumentLink DocumentLink;
  56. public DocumentLink getDocumentLink(){return DocumentLink;}
  57. public void setDocumentLink(DocumentLink DocumentLink){this.DocumentLink=DocumentLink;}
  58.  
  59. private ProtectionData ProtectionData;
  60. public ProtectionData getProtectionData(){return ProtectionData;}
  61. public void setProtectionData(ProtectionData ProtectionData){this.ProtectionData=ProtectionData;}
  62. }
  63.  
  64. //Here is the DocumentLink class
  65. public class DocumentLink {
  66. private String Href ;
  67. private String Rel ;
  68. private Object Type ;
  69. private Object Title ;
  70.  
  71. public String getHref(){return Href;}
  72. public String getRel(){return Rel;}
  73. public Object getType(){return Type;}
  74. public Object getTitle(){return Title;}
  75.  
  76. public void setHref(String Href) {this.Href=Href;}
  77. public void setRel(String Rel) {this.Rel=Rel;}
  78. public void setType (Object Type) {this.Type=Type;}
  79. public void setTitle(Object Title) {this.Title=Title;}
  80. }
  81.  
  82. //Here is the ProtectionData class
  83. public class ProtectionData {
  84. private String ProtectionType;
  85. public String getProtectionType(){return ProtectionType;}
  86. public void setProtectionType(String ProtectionType){this.ProtectionType=ProtectionType;}
  87. }

Report this snippet  

You need to login to post a comment.