Decode alfresco file name or replace unicode[_x0020_] characters in String/fileName











up vote
2
down vote

favorite












I am using alfresco download upload services using java.



When I upload the file to alfreco server it gives me the following path :



/app:Home/cm:Company_x0020_Home/cm:Abc/cm:TestFile/cm:V4/cm:BC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf


When I use the same file path and download using alfresco services I took the file name at the end of the path



i.e    ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf


How can I remove or decode the [Unicode] characters in fileName



String decoded = URLDecoder.decode(queryString, "UTF-8");


The above does not work .



These are some Unicode characters which appeared in my file name.
https://en.wikipedia.org/wiki/List_of_Unicode_characters



Please do not mark the question as duplicate as I have searched below links but non of those gave the solution.
Following are the links that I have searched for replacing unicode charectors in String with java.



Java removing unicode characters



Remove non-ASCII characters from String in Java



How can I replace a unicode character in java string



Java Replace Unicode Characters in a String










share|improve this question




























    up vote
    2
    down vote

    favorite












    I am using alfresco download upload services using java.



    When I upload the file to alfreco server it gives me the following path :



    /app:Home/cm:Company_x0020_Home/cm:Abc/cm:TestFile/cm:V4/cm:BC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf


    When I use the same file path and download using alfresco services I took the file name at the end of the path



    i.e    ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf


    How can I remove or decode the [Unicode] characters in fileName



    String decoded = URLDecoder.decode(queryString, "UTF-8");


    The above does not work .



    These are some Unicode characters which appeared in my file name.
    https://en.wikipedia.org/wiki/List_of_Unicode_characters



    Please do not mark the question as duplicate as I have searched below links but non of those gave the solution.
    Following are the links that I have searched for replacing unicode charectors in String with java.



    Java removing unicode characters



    Remove non-ASCII characters from String in Java



    How can I replace a unicode character in java string



    Java Replace Unicode Characters in a String










    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I am using alfresco download upload services using java.



      When I upload the file to alfreco server it gives me the following path :



      /app:Home/cm:Company_x0020_Home/cm:Abc/cm:TestFile/cm:V4/cm:BC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf


      When I use the same file path and download using alfresco services I took the file name at the end of the path



      i.e    ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf


      How can I remove or decode the [Unicode] characters in fileName



      String decoded = URLDecoder.decode(queryString, "UTF-8");


      The above does not work .



      These are some Unicode characters which appeared in my file name.
      https://en.wikipedia.org/wiki/List_of_Unicode_characters



      Please do not mark the question as duplicate as I have searched below links but non of those gave the solution.
      Following are the links that I have searched for replacing unicode charectors in String with java.



      Java removing unicode characters



      Remove non-ASCII characters from String in Java



      How can I replace a unicode character in java string



      Java Replace Unicode Characters in a String










      share|improve this question















      I am using alfresco download upload services using java.



      When I upload the file to alfreco server it gives me the following path :



      /app:Home/cm:Company_x0020_Home/cm:Abc/cm:TestFile/cm:V4/cm:BC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf


      When I use the same file path and download using alfresco services I took the file name at the end of the path



      i.e    ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf


      How can I remove or decode the [Unicode] characters in fileName



      String decoded = URLDecoder.decode(queryString, "UTF-8");


      The above does not work .



      These are some Unicode characters which appeared in my file name.
      https://en.wikipedia.org/wiki/List_of_Unicode_characters



      Please do not mark the question as duplicate as I have searched below links but non of those gave the solution.
      Following are the links that I have searched for replacing unicode charectors in String with java.



      Java removing unicode characters



      Remove non-ASCII characters from String in Java



      How can I replace a unicode character in java string



      Java Replace Unicode Characters in a String







      java unicode alfresco decode






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 at 11:40

























      asked Nov 8 at 11:12









      I am a Coder

      157




      157
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          The solution given by Jeff Potts will be perfect .
          But i had a situation where i was using file name in diffrent project where i wont use org.alfresco related jars



          I had to take all those dependencies to use for a simple file decoding
          So i used java native methods which uses regex to parse the file name and decode it,which gave me the perfect solution which was same from using



          ISO9075.decode(test);


          This is the code which can be used



           public String decode_FileName(String fileName) {
          System.out.println("fileName : " + fileName);
          String decodedfileName = fileName;
          String temp = "";
          Matcher m = Pattern.compile("\_x(.*?)\_").matcher(decodedfileName); //rejex which matches _x0020_ kind of charectors
          List<String> unicodeChars = new ArrayList<String>();
          while (m.find()) {
          unicodeChars.add(m.group(1));
          }
          for (int i = 0; i < unicodeChars.size(); i++) {
          temp = unicodeChars.get(i);
          if (isInteger(temp)) {
          String replace_char = String.valueOf(((char) Integer.parseInt(String.valueOf(temp), 16)));//converting
          decodedfileName = decodedfileName.replace("_x" + temp + "_", replace_char);
          }
          }
          System.out.println("Decoded FileName :" + decodedfileName);
          return decodedfileName;
          }


          And use this small java util to know Is integer



          public static boolean isInteger(String s) {
          try {
          Integer.parseInt(s);
          } catch (NumberFormatException e) {
          return false;
          } catch (NullPointerException e) {
          return false;
          }
          return true;
          }


          So the above code works as simple as this :



          Example :



          0028 Left parenthesis U+0028 You can see in the link
          https://en.wikipedia.org/wiki/List_of_Unicode_characters



          String replace_char = String.valueOf(((char) Integer.parseInt(String.valueOf("0028"), 16)));
          System.out.println(replace_char);


          This code gives output : ( which is a Left parenthesis



          This is what the logic i have used in my java program.



          The above program will give results same as ISO9075.decode(test)



          Output :

          fileName : ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf
          Decoded FileName :ABC1X 0400 0109-(1-2)_v2.pdf





          share|improve this answer





















          • I am using the service outside the project So this code works perfect for me
            – I am a Coder
            Nov 13 at 14:23


















          up vote
          1
          down vote













          In the org.alfresco.util package you will find a class called ISO9075. You can use it to encode and decode strings according to that spec. For example:



              String test = "ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf";
          String out = ISO9075.decode(test);
          System.out.println(out);


          Returns:



              ABC1X 0400 0109-(1-2)_v2.pdf


          If you want to see what it does behind the scenes, look at the source.






          share|improve this answer





















          • Thank you for help !!
            – I am a Coder
            Nov 13 at 14:23











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206591%2fdecode-alfresco-file-name-or-replace-unicode-x0020-characters-in-string-filen%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          The solution given by Jeff Potts will be perfect .
          But i had a situation where i was using file name in diffrent project where i wont use org.alfresco related jars



          I had to take all those dependencies to use for a simple file decoding
          So i used java native methods which uses regex to parse the file name and decode it,which gave me the perfect solution which was same from using



          ISO9075.decode(test);


          This is the code which can be used



           public String decode_FileName(String fileName) {
          System.out.println("fileName : " + fileName);
          String decodedfileName = fileName;
          String temp = "";
          Matcher m = Pattern.compile("\_x(.*?)\_").matcher(decodedfileName); //rejex which matches _x0020_ kind of charectors
          List<String> unicodeChars = new ArrayList<String>();
          while (m.find()) {
          unicodeChars.add(m.group(1));
          }
          for (int i = 0; i < unicodeChars.size(); i++) {
          temp = unicodeChars.get(i);
          if (isInteger(temp)) {
          String replace_char = String.valueOf(((char) Integer.parseInt(String.valueOf(temp), 16)));//converting
          decodedfileName = decodedfileName.replace("_x" + temp + "_", replace_char);
          }
          }
          System.out.println("Decoded FileName :" + decodedfileName);
          return decodedfileName;
          }


          And use this small java util to know Is integer



          public static boolean isInteger(String s) {
          try {
          Integer.parseInt(s);
          } catch (NumberFormatException e) {
          return false;
          } catch (NullPointerException e) {
          return false;
          }
          return true;
          }


          So the above code works as simple as this :



          Example :



          0028 Left parenthesis U+0028 You can see in the link
          https://en.wikipedia.org/wiki/List_of_Unicode_characters



          String replace_char = String.valueOf(((char) Integer.parseInt(String.valueOf("0028"), 16)));
          System.out.println(replace_char);


          This code gives output : ( which is a Left parenthesis



          This is what the logic i have used in my java program.



          The above program will give results same as ISO9075.decode(test)



          Output :

          fileName : ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf
          Decoded FileName :ABC1X 0400 0109-(1-2)_v2.pdf





          share|improve this answer





















          • I am using the service outside the project So this code works perfect for me
            – I am a Coder
            Nov 13 at 14:23















          up vote
          2
          down vote



          accepted










          The solution given by Jeff Potts will be perfect .
          But i had a situation where i was using file name in diffrent project where i wont use org.alfresco related jars



          I had to take all those dependencies to use for a simple file decoding
          So i used java native methods which uses regex to parse the file name and decode it,which gave me the perfect solution which was same from using



          ISO9075.decode(test);


          This is the code which can be used



           public String decode_FileName(String fileName) {
          System.out.println("fileName : " + fileName);
          String decodedfileName = fileName;
          String temp = "";
          Matcher m = Pattern.compile("\_x(.*?)\_").matcher(decodedfileName); //rejex which matches _x0020_ kind of charectors
          List<String> unicodeChars = new ArrayList<String>();
          while (m.find()) {
          unicodeChars.add(m.group(1));
          }
          for (int i = 0; i < unicodeChars.size(); i++) {
          temp = unicodeChars.get(i);
          if (isInteger(temp)) {
          String replace_char = String.valueOf(((char) Integer.parseInt(String.valueOf(temp), 16)));//converting
          decodedfileName = decodedfileName.replace("_x" + temp + "_", replace_char);
          }
          }
          System.out.println("Decoded FileName :" + decodedfileName);
          return decodedfileName;
          }


          And use this small java util to know Is integer



          public static boolean isInteger(String s) {
          try {
          Integer.parseInt(s);
          } catch (NumberFormatException e) {
          return false;
          } catch (NullPointerException e) {
          return false;
          }
          return true;
          }


          So the above code works as simple as this :



          Example :



          0028 Left parenthesis U+0028 You can see in the link
          https://en.wikipedia.org/wiki/List_of_Unicode_characters



          String replace_char = String.valueOf(((char) Integer.parseInt(String.valueOf("0028"), 16)));
          System.out.println(replace_char);


          This code gives output : ( which is a Left parenthesis



          This is what the logic i have used in my java program.



          The above program will give results same as ISO9075.decode(test)



          Output :

          fileName : ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf
          Decoded FileName :ABC1X 0400 0109-(1-2)_v2.pdf





          share|improve this answer





















          • I am using the service outside the project So this code works perfect for me
            – I am a Coder
            Nov 13 at 14:23













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          The solution given by Jeff Potts will be perfect .
          But i had a situation where i was using file name in diffrent project where i wont use org.alfresco related jars



          I had to take all those dependencies to use for a simple file decoding
          So i used java native methods which uses regex to parse the file name and decode it,which gave me the perfect solution which was same from using



          ISO9075.decode(test);


          This is the code which can be used



           public String decode_FileName(String fileName) {
          System.out.println("fileName : " + fileName);
          String decodedfileName = fileName;
          String temp = "";
          Matcher m = Pattern.compile("\_x(.*?)\_").matcher(decodedfileName); //rejex which matches _x0020_ kind of charectors
          List<String> unicodeChars = new ArrayList<String>();
          while (m.find()) {
          unicodeChars.add(m.group(1));
          }
          for (int i = 0; i < unicodeChars.size(); i++) {
          temp = unicodeChars.get(i);
          if (isInteger(temp)) {
          String replace_char = String.valueOf(((char) Integer.parseInt(String.valueOf(temp), 16)));//converting
          decodedfileName = decodedfileName.replace("_x" + temp + "_", replace_char);
          }
          }
          System.out.println("Decoded FileName :" + decodedfileName);
          return decodedfileName;
          }


          And use this small java util to know Is integer



          public static boolean isInteger(String s) {
          try {
          Integer.parseInt(s);
          } catch (NumberFormatException e) {
          return false;
          } catch (NullPointerException e) {
          return false;
          }
          return true;
          }


          So the above code works as simple as this :



          Example :



          0028 Left parenthesis U+0028 You can see in the link
          https://en.wikipedia.org/wiki/List_of_Unicode_characters



          String replace_char = String.valueOf(((char) Integer.parseInt(String.valueOf("0028"), 16)));
          System.out.println(replace_char);


          This code gives output : ( which is a Left parenthesis



          This is what the logic i have used in my java program.



          The above program will give results same as ISO9075.decode(test)



          Output :

          fileName : ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf
          Decoded FileName :ABC1X 0400 0109-(1-2)_v2.pdf





          share|improve this answer












          The solution given by Jeff Potts will be perfect .
          But i had a situation where i was using file name in diffrent project where i wont use org.alfresco related jars



          I had to take all those dependencies to use for a simple file decoding
          So i used java native methods which uses regex to parse the file name and decode it,which gave me the perfect solution which was same from using



          ISO9075.decode(test);


          This is the code which can be used



           public String decode_FileName(String fileName) {
          System.out.println("fileName : " + fileName);
          String decodedfileName = fileName;
          String temp = "";
          Matcher m = Pattern.compile("\_x(.*?)\_").matcher(decodedfileName); //rejex which matches _x0020_ kind of charectors
          List<String> unicodeChars = new ArrayList<String>();
          while (m.find()) {
          unicodeChars.add(m.group(1));
          }
          for (int i = 0; i < unicodeChars.size(); i++) {
          temp = unicodeChars.get(i);
          if (isInteger(temp)) {
          String replace_char = String.valueOf(((char) Integer.parseInt(String.valueOf(temp), 16)));//converting
          decodedfileName = decodedfileName.replace("_x" + temp + "_", replace_char);
          }
          }
          System.out.println("Decoded FileName :" + decodedfileName);
          return decodedfileName;
          }


          And use this small java util to know Is integer



          public static boolean isInteger(String s) {
          try {
          Integer.parseInt(s);
          } catch (NumberFormatException e) {
          return false;
          } catch (NullPointerException e) {
          return false;
          }
          return true;
          }


          So the above code works as simple as this :



          Example :



          0028 Left parenthesis U+0028 You can see in the link
          https://en.wikipedia.org/wiki/List_of_Unicode_characters



          String replace_char = String.valueOf(((char) Integer.parseInt(String.valueOf("0028"), 16)));
          System.out.println(replace_char);


          This code gives output : ( which is a Left parenthesis



          This is what the logic i have used in my java program.



          The above program will give results same as ISO9075.decode(test)



          Output :

          fileName : ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf
          Decoded FileName :ABC1X 0400 0109-(1-2)_v2.pdf






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 6:19









          Kishan C S

          9001828




          9001828












          • I am using the service outside the project So this code works perfect for me
            – I am a Coder
            Nov 13 at 14:23


















          • I am using the service outside the project So this code works perfect for me
            – I am a Coder
            Nov 13 at 14:23
















          I am using the service outside the project So this code works perfect for me
          – I am a Coder
          Nov 13 at 14:23




          I am using the service outside the project So this code works perfect for me
          – I am a Coder
          Nov 13 at 14:23












          up vote
          1
          down vote













          In the org.alfresco.util package you will find a class called ISO9075. You can use it to encode and decode strings according to that spec. For example:



              String test = "ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf";
          String out = ISO9075.decode(test);
          System.out.println(out);


          Returns:



              ABC1X 0400 0109-(1-2)_v2.pdf


          If you want to see what it does behind the scenes, look at the source.






          share|improve this answer





















          • Thank you for help !!
            – I am a Coder
            Nov 13 at 14:23















          up vote
          1
          down vote













          In the org.alfresco.util package you will find a class called ISO9075. You can use it to encode and decode strings according to that spec. For example:



              String test = "ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf";
          String out = ISO9075.decode(test);
          System.out.println(out);


          Returns:



              ABC1X 0400 0109-(1-2)_v2.pdf


          If you want to see what it does behind the scenes, look at the source.






          share|improve this answer





















          • Thank you for help !!
            – I am a Coder
            Nov 13 at 14:23













          up vote
          1
          down vote










          up vote
          1
          down vote









          In the org.alfresco.util package you will find a class called ISO9075. You can use it to encode and decode strings according to that spec. For example:



              String test = "ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf";
          String out = ISO9075.decode(test);
          System.out.println(out);


          Returns:



              ABC1X 0400 0109-(1-2)_v2.pdf


          If you want to see what it does behind the scenes, look at the source.






          share|improve this answer












          In the org.alfresco.util package you will find a class called ISO9075. You can use it to encode and decode strings according to that spec. For example:



              String test = "ABC1X_x0020_0400_x0020_0109-_x0028_1-2_x0029__v2.pdf";
          String out = ISO9075.decode(test);
          System.out.println(out);


          Returns:



              ABC1X 0400 0109-(1-2)_v2.pdf


          If you want to see what it does behind the scenes, look at the source.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 3:32









          Jeff Potts

          9,0681137




          9,0681137












          • Thank you for help !!
            – I am a Coder
            Nov 13 at 14:23


















          • Thank you for help !!
            – I am a Coder
            Nov 13 at 14:23
















          Thank you for help !!
          – I am a Coder
          Nov 13 at 14:23




          Thank you for help !!
          – I am a Coder
          Nov 13 at 14:23


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206591%2fdecode-alfresco-file-name-or-replace-unicode-x0020-characters-in-string-filen%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)