Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

rhbz748727 Remove server-side Content-Type charset validation in favo…

…ur of client-side
  • Loading branch information...
commit c16ae7af44c5e10203a1fc7f2b9615cd784dcf6f 1 parent eaae695
Sean Flanigan authored February 01, 2012
44  server/zanata-war/src/main/java/org/zanata/rest/service/ResourceUtils.java
@@ -25,6 +25,7 @@
25 25
 import javax.ws.rs.core.Response.Status;
26 26
 
27 27
 import org.apache.commons.lang.StringUtils;
  28
+import org.fedorahosted.tennera.jgettext.HeaderFields;
28 29
 import org.jboss.seam.Component;
29 30
 import org.jboss.seam.ScopeType;
30 31
 import org.jboss.seam.annotations.AutoCreate;
@@ -75,27 +76,20 @@
75 76
     * Newline character used for multi-line comments
76 77
     */
77 78
    private static final char     NEWLINE = '\n';
78  
-
79 79
    private static final String   ZANATA_GENERATOR_PREFIX = "Zanata";
80  
-   
81 80
    private static final String   ZANATA_TAG = "#zanata";
82  
-   
83 81
    private static final String   PO_DATE_FORMAT = "yyyy-MM-dd hh:mmZ";
84  
-   
85  
-   private static final String[] PO_VALID_CONTENT_TYPES = {"charset=UTF-8", "charset=UTF8", "charset=ASCII", "charset=CHARSET"};
86  
-   
87 82
    private static final String   PO_DEFAULT_CONTENT_TYPE = "text/plain; charset=UTF-8";
88  
-
89 83
    
90 84
    /**
91 85
     * PO Header entries
92 86
     */
93 87
    private static final String LAST_TRANSLATOR_HDR    = "Last-Translator";
94  
-   private static final String PO_REVISION_DATE_HDR   = "PO-Revision-Date";
95  
-   private static final String LANGUAGE_TEAM_HDR      = "Language-Team";
  88
+   private static final String PO_REVISION_DATE_HDR = HeaderFields.KEY_PoRevisionDate;
  89
+   private static final String LANGUAGE_TEAM_HDR = HeaderFields.KEY_LanguageTeam;
96 90
    private static final String X_GENERATOR_HDR        = "X-Generator";
97  
-   private static final String LANGUAGE_HDR           = "Language";
98  
-   private static final String CONTENT_TYPE_HDR       = "Content-Type";
  91
+   private static final String LANGUAGE_HDR = HeaderFields.KEY_Language;
  92
+   private static final String CONTENT_TYPE_HDR = HeaderFields.KEY_ContentType;
99 93
    private static final String PLURAL_FORMS_HDR       = "Plural-Forms";
100 94
 
101 95
    private static final Log log = Logging.getLog(ResourceUtils.class);
@@ -1175,32 +1169,4 @@ public void transferToTranslationsResource(TranslationsResource transRes, HDocum
1175 1169
       }
1176 1170
    }
1177 1171
    
1178  
-   public boolean validateResourceEncoding(Resource res)
1179  
-   {
1180  
-      PoHeader poHeader = res.getExtensions(true).findByType(PoHeader.class);
1181  
-      if( poHeader != null )
1182  
-      {
1183  
-         for( HeaderEntry entry : poHeader.getEntries() )
1184  
-         {
1185  
-            if( entry.getKey().equalsIgnoreCase( CONTENT_TYPE_HDR ) )
1186  
-            {
1187  
-               for( String acceptedContentType : PO_VALID_CONTENT_TYPES )
1188  
-               {
1189  
-                  // Case-insensitive check
1190  
-                  if( entry.getValue().toLowerCase().contains( acceptedContentType.toLowerCase() ) )
1191  
-                  {
1192  
-                     return true;
1193  
-                  }
1194  
-               }
1195  
-            }
1196  
-         }
1197  
-         
1198  
-         return false;
1199  
-      }
1200  
-      else
1201  
-      {
1202  
-         return true;
1203  
-      }
1204  
-   }
1205  
-
1206 1172
 }
9  server/zanata-war/src/main/java/org/zanata/rest/service/TranslationResourcesService.java
@@ -409,7 +409,6 @@ public Response putResource(@PathParam("id") String idNoSlash, Resource resource
409 409
       validateExtensions();
410 410
 
411 411
       log.debug("resource details: {0}", resource);
412  
-      boolean validResourceEnc = this.resourceUtils.validateResourceEncoding(resource);
413 412
       
414 413
       HDocument document = documentDAO.getByDocId(hProjectIteration, id);
415 414
       HLocale hLocale = validateSourceLocale(resource.getLang());
@@ -458,7 +457,6 @@ else if (document.isObsolete())
458 457
 
459 458
       changed |= resourceUtils.transferFromResource(resource, document, extensions, hLocale, nextDocRev);
460 459
 
461  
-
462 460
       if (changed)
463 461
       {
464 462
          document = documentDAO.makePersistent(document);
@@ -466,20 +464,13 @@ else if (document.isObsolete())
466 464
          etag = eTagUtils.generateETagForDocument(hProjectIteration, id, extensions);
467 465
       }
468 466
 
469  
-
470 467
       if (copytrans && nextDocRev == 1)
471 468
       {
472 469
          copyClosestEquivalentTranslation(document.getId(), resource.getName(), projectSlug, iterationSlug);
473 470
       }
474 471
       
475  
-      if( !validResourceEnc )
476  
-      {
477  
-         response.entity("warning: potentially incompatible character encoding.");
478  
-      }
479  
-            
480 472
       log.debug("put resource successfully");
481 473
       return response.tag(etag).build();
482  
-
483 474
    }
484 475
 
485 476
    @Override

0 notes on commit c16ae7a

Please sign in to comment.
Something went wrong with that request. Please try again.