@@ -645,31 +645,39 @@ private static void reference(final HttpServletRequest request,
645
645
scanner .useDelimiter ("\\ A" );
646
646
String bodyString = scanner .hasNext () ? scanner .next () : "" ;
647
647
scanner .close ();
648
- Gson gson = new GsonBuilder ().disableHtmlEscaping ().create ();
649
-
650
- JSONParser parser = new JSONParser ();
651
- JSONObject body = (JSONObject ) parser .parse (bodyString );
652
- JSONObject referenceDataObj = (JSONObject ) body .get ("referenceData" );
653
- String instanceId = (String ) referenceDataObj .get ("instanceId" );
654
648
655
649
String fileKeyValue = "" ;
656
650
String userAddress = "" ;
657
651
String fileName = "" ;
652
+ boolean incorrectFileKey = false ;
653
+
654
+ JSONParser parser = new JSONParser ();
655
+ Gson gson = new GsonBuilder ().disableHtmlEscaping ().create ();
656
+ JSONObject body = (JSONObject ) parser .parse (bodyString );
658
657
659
- if (instanceId .equals (DocumentManager .getServerUrl (false ))) {
660
- JSONObject fileKey = (JSONObject ) referenceDataObj .get ("fileKey" );
661
- fileKeyValue = gson .toJson (fileKey );
662
- userAddress = (String ) fileKey .get ("userAddress" );
663
- if (userAddress .equals (DocumentManager .curUserHostAddress (null ))) {
664
- fileName = (String ) fileKey .get ("fileName" );
658
+ if (body .containsKey ("referenceData" )) {
659
+ JSONObject referenceDataObj = (JSONObject ) body .get ("referenceData" );
660
+ String instanceId = (String ) referenceDataObj .get ("instanceId" );
661
+
662
+ if (instanceId .equals (DocumentManager .getServerUrl (false ))) {
663
+ try {
664
+ JSONObject fileKey = (JSONObject ) parser .parse ((String ) referenceDataObj .get ("fileKey" ));
665
+ userAddress = (String ) fileKey .get ("userAddress" );
666
+
667
+ if (userAddress .equals (DocumentManager .curUserHostAddress (null ))) {
668
+ fileName = (String ) fileKey .get ("fileName" );
669
+ }
670
+ } catch (Exception e ) {
671
+ incorrectFileKey = true ; //data from DocEditor can give incorrect fileKey param in java Example
672
+ }
665
673
}
666
674
}
667
675
668
- if (fileName .equals ("" ) && ! userAddress . equals ( "" ) ) {
676
+ if (fileName .equals ("" )) {
669
677
try {
670
678
String path = (String ) body .get ("path" );
671
679
path = FileUtility .getFileName (path );
672
- File f = new File (DocumentManager .storagePath (path , userAddress ));
680
+ File f = new File (DocumentManager .storagePath (path , null ));
673
681
if (f .exists ()) {
674
682
fileName = path ;
675
683
}
@@ -684,16 +692,20 @@ private static void reference(final HttpServletRequest request,
684
692
return ;
685
693
}
686
694
695
+ HashMap <String , Object > fileKey = new HashMap <>();
696
+ fileKey .put ("fileName" , fileName );
697
+ fileKey .put ("userAddress" , DocumentManager .curUserHostAddress (null ));
698
+
687
699
HashMap <String , Object > referenceData = new HashMap <>();
688
700
referenceData .put ("instanceId" , DocumentManager .getServerUrl (false ));
689
- referenceData .put ("fileKey" , fileKeyValue );
701
+ referenceData .put ("fileKey" , gson . toJson ( fileKey ) );
690
702
691
703
HashMap <String , Object > data = new HashMap <>();
692
704
data .put ("fileType" , FileUtility .getFileExtension (fileName ));
693
705
data .put ("url" , DocumentManager .getDownloadUrl (fileName , true ));
694
706
data .put ("directUrl" , DocumentManager .getDownloadUrl (fileName , true ));
695
707
data .put ("referenceData" , referenceData );
696
- data .put ("path" , referenceData );
708
+ data .put ("path" , fileName );
697
709
698
710
if (DocumentManager .tokenEnabled ()) {
699
711
String token = DocumentManager .createToken (data );
0 commit comments