Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rhbz760390 Add support for GWT's UTF-8 Properties files; handle entri…

…es where value is the empty string
  • Loading branch information...
commit f072bb3814fcb3f1680d98b0e2028c8a32dd84f8 1 parent 60006fc
Sean Flanigan seanf authored
30 client/zanata-adapter-properties/src/main/java/org/zanata/adapter/properties/PropWriter.java
View
@@ -3,7 +3,8 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import org.fedorahosted.openprops.Properties;
import org.zanata.rest.dto.extensions.comment.SimpleComment;
@@ -27,7 +28,7 @@ private static void makeParentDirs(File f)
parentFile.mkdirs();
}
- public static void write(final Resource doc, final File baseDir) throws IOException
+ public static void write(final Resource doc, final File baseDir, String charset) throws IOException
{
File baseFile = new File(baseDir, doc.getName() + ".properties");
makeParentDirs(baseFile);
@@ -42,13 +43,19 @@ public static void write(final Resource doc, final File baseDir) throws IOExcept
props.setComment(textFlow.getId(), simpleComment.getValue());
}
// props.store(System.out, null);
- PrintStream out = new PrintStream(new FileOutputStream(baseFile));
- props.store(out, null);
+ Writer out = new OutputStreamWriter(new FileOutputStream(baseFile), charset);
+ try
+ {
+ props.store(out, null);
+ }
+ finally
+ {
+ out.close();
+ }
}
- public static void write(final TranslationsResource doc, final File baseDir, String bundleName, String locale) throws IOException
+ public static void write(final TranslationsResource doc, final File baseDir, String bundleName, String locale, String charset) throws IOException
{
-
Properties targetProp = new Properties();
for (TextFlowTarget target : doc.getTextFlowTargets())
{
@@ -62,8 +69,15 @@ public static void write(final TranslationsResource doc, final File baseDir, Str
makeParentDirs(langFile);
logVerbose("Creating target file " + langFile);
// targetProp.store(System.out, null);
- PrintStream out2 = new PrintStream(new FileOutputStream(langFile));
- targetProp.store(out2, null);
+ Writer out2 = new OutputStreamWriter(new FileOutputStream(langFile), charset);
+ try
+ {
+ targetProp.store(out2, null);
+ }
+ finally
+ {
+ out2.close();
+ }
}
}
9 client/zanata-adapter-properties/src/test/java/org/zanata/adapter/properties/PropReaderTests.java
View
@@ -21,6 +21,7 @@
public class PropReaderTests
{
private static final Logger log = LoggerFactory.getLogger(PropReaderTests.class);
+ static final String ISO_8859_1 = "ISO-8859-1";
@SuppressWarnings("deprecation")
PropReader propReader = new PropReader();
@@ -42,9 +43,9 @@ public void roundtripSrcPropsToDocXmlToProps() throws Exception
Unmarshaller unmarshal = jc.createUnmarshaller();
Resource docIn = (Resource) unmarshal.unmarshal(new StringReader(sw.toString()));
- PropWriter.write(docIn, new File("target/test-output"));
+ PropWriter.write(docIn, new File("target/test-output"), ISO_8859_1);
- // TODO check output files against input
+ // FIXME check output files against input
}
@Test
@@ -65,9 +66,9 @@ public void roundtripTransPropsToDocXmlToProps() throws Exception
Unmarshaller unmarshal = jc.createUnmarshaller();
TranslationsResource docIn = (TranslationsResource) unmarshal.unmarshal(new StringReader(sw.toString()));
- PropWriter.write(docIn, new File("target/test-output"), "test", locale);
+ PropWriter.write(docIn, new File("target/test-output"), "test", locale, ISO_8859_1);
- // TODO check output files against input
+ // FIXME check output files against input
}
private InputStream getResourceAsStream(String relativeResourceName) throws FileNotFoundException
3  client/zanata-client-commands/src/main/java/org/zanata/client/commands/ConfigurableProjectCommand.java
View
@@ -34,8 +34,9 @@
public abstract class ConfigurableProjectCommand<O extends ConfigurableProjectOptions> extends ConfigurableCommand<O>
{
- protected static final String PROJECT_TYPE_PUBLICAN = "podir";
+ protected static final String PROJECT_TYPE_UTF8_PROPERTIES = "utf8properties";
protected static final String PROJECT_TYPE_PROPERTIES = "properties";
+ protected static final String PROJECT_TYPE_PUBLICAN = "podir";
protected static final String PROJECT_TYPE_XLIFF = "xliff";
protected static final String PROJECT_TYPE_XML = "xml";
18 client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PropertiesStrategy.java
View
@@ -35,8 +35,22 @@
*/
public class PropertiesStrategy implements PullStrategy
{
+ // "8859_1" is used in Properties.java...
+ private static final String ISO_8859_1 = "ISO-8859-1";
+
StringSet extensions = new StringSet("comment");
private PullOptions opts;
+ private final String charset;
+
+ public PropertiesStrategy()
+ {
+ this(ISO_8859_1);
+ }
+
+ public PropertiesStrategy(String charset)
+ {
+ this.charset = charset;
+ }
@Override
public void setPullOptions(PullOptions opts)
@@ -59,13 +73,13 @@ public boolean needsDocToWriteTrans()
@Override
public void writeSrcFile(Resource doc) throws IOException
{
- PropWriter.write(doc, opts.getSrcDir());
+ PropWriter.write(doc, opts.getSrcDir(), charset);
}
@Override
public void writeTransFile(Resource doc, String docName, LocaleMapping localeMapping, TranslationsResource targetDoc) throws IOException
{
- PropWriter.write(targetDoc, opts.getTransDir(), docName, localeMapping.getJavaLocale());
+ PropWriter.write(targetDoc, opts.getTransDir(), docName, localeMapping.getJavaLocale(), charset);
}
}
2  client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PullCommand.java
View
@@ -38,10 +38,12 @@
public class PullCommand extends ConfigurableProjectCommand
{
private static final Logger log = LoggerFactory.getLogger(PullCommand.class);
+ private static final String UTF_8 = "UTF-8";
private static final Map<String, PullStrategy> strategies = new HashMap<String, PullStrategy>();
{
+ strategies.put(PROJECT_TYPE_UTF8_PROPERTIES, new PropertiesStrategy(UTF_8));
strategies.put(PROJECT_TYPE_PROPERTIES, new PropertiesStrategy());
strategies.put(PROJECT_TYPE_PUBLICAN, new GettextDirStrategy());
strategies.put(PROJECT_TYPE_XLIFF, new XliffStrategy());
30 client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PropertiesStrategy.java
View
@@ -21,12 +21,12 @@
package org.zanata.client.commands.push;
-import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -46,9 +46,20 @@
class PropertiesStrategy extends AbstractPushStrategy
{
+ // "8859_1" is used in Properties.java...
+ private static final String ISO_8859_1 = "ISO-8859-1";
+
+ private final String charset;
+
public PropertiesStrategy()
{
+ this(ISO_8859_1);
+ }
+
+ public PropertiesStrategy(String charset)
+ {
super(new StringSet("comment"), ".properties");
+ this.charset = charset;
}
@Override
@@ -68,16 +79,16 @@ public PropertiesStrategy()
private Properties loadPropFile(File propFile) throws FileNotFoundException, IOException
{
- InputStream is = new BufferedInputStream(new FileInputStream(propFile));
+ Reader reader = new InputStreamReader(new FileInputStream(propFile), charset);
try
{
Properties props = new Properties();
- props.load(is);
+ props.load(reader);
return props;
}
finally
{
- is.close();
+ reader.close();
}
}
@@ -147,7 +158,14 @@ private void addPropEntryToDoc(TranslationsResource targetDoc, Properties props,
return;
TextFlowTarget textFlowTarget = new TextFlowTarget(key);
textFlowTarget.setContent(content);
- textFlowTarget.setState(ContentState.Approved);
+ if (!content.isEmpty())
+ {
+ textFlowTarget.setState(ContentState.Approved);
+ }
+ else
+ {
+ textFlowTarget.setState(ContentState.New);
+ }
String comment = props.getComment(key);
if (comment != null)
{
2  client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushCommand.java
View
@@ -39,6 +39,7 @@
public class PushCommand extends ConfigurableProjectCommand
{
private static final Logger log = LoggerFactory.getLogger(PushCommand.class);
+ private static final String UTF_8 = "UTF-8";
private static final Map<String, AbstractPushStrategy> strategies = new HashMap<String, AbstractPushStrategy>();
@@ -48,6 +49,7 @@
}
{
+ strategies.put(PROJECT_TYPE_UTF8_PROPERTIES, new PropertiesStrategy(UTF_8));
strategies.put(PROJECT_TYPE_PROPERTIES, new PropertiesStrategy());
strategies.put(PROJECT_TYPE_PUBLICAN, new GettextDirStrategy());
strategies.put(PROJECT_TYPE_XLIFF, new XliffStrategy());
Please sign in to comment.
Something went wrong with that request. Please try again.