Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
merge branch 1.4 into master
Browse files Browse the repository at this point in the history
	conflicted: PropWriter, PropReaderTests
  • Loading branch information
davidmason committed Dec 16, 2011
1 parent 0fcf1c1 commit 3646cc5
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 23 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -35,7 +36,7 @@ private static void makeParentDirs(File f)
* @param baseDir
* @throws IOException
*/
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);
Expand All @@ -50,14 +51,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);
out.close();
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())
{
Expand All @@ -71,8 +77,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();
}
}

}
Expand Up @@ -32,8 +32,8 @@ public class PropReaderTests
private static final Logger log = LoggerFactory.getLogger(PropReaderTests.class);
private static final String TEST_OUTPUT_DIR_STRING = "target/test-output";
private static final File TEST_OUTPUT_DIR = new File(TEST_OUTPUT_DIR_STRING);

PropReader propReader;
static final String ISO_8859_1 = "ISO-8859-1";

@BeforeMethod
public void resetReader()
Expand All @@ -45,7 +45,6 @@ public void resetReader()
public void roundtripSrcPropsToDocXmlToProps() throws Exception
{
String docName = "test.properties";

Resource srcDoc = new Resource("test");
InputStream testStream = getResourceAsStream(docName);

Expand All @@ -60,7 +59,7 @@ public void roundtripSrcPropsToDocXmlToProps() throws Exception
Unmarshaller unmarshal = jc.createUnmarshaller();
Resource docIn = (Resource) unmarshal.unmarshal(new StringReader(sw.toString()));

PropWriter.write(docIn, TEST_OUTPUT_DIR);
PropWriter.write(docIn, TEST_OUTPUT_DIR, ISO_8859_1);

assertInputAndOutputDocContentSame(docName);
}
Expand All @@ -84,8 +83,8 @@ public void roundtripTransPropsToDocXmlToProps() throws Exception
Unmarshaller unmarshal = jc.createUnmarshaller();
TranslationsResource docIn = (TranslationsResource) unmarshal.unmarshal(new StringReader(sw.toString()));

PropWriter.write(docIn, TEST_OUTPUT_DIR, "test", locale);
PropWriter.write(docIn, TEST_OUTPUT_DIR, "test", locale, ISO_8859_1);

assertInputAndOutputDocContentSame(docName);
}

Expand Down
Expand Up @@ -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";

Expand Down
Expand Up @@ -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)
Expand All @@ -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);
}

}
Expand Up @@ -38,10 +38,12 @@
public class PullCommand extends ConfigurableProjectCommand<PullOptions>
{
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());
Expand Down
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -68,16 +79,16 @@ public Set<String> findDocNames(File srcDir, List<String> includes, List<String>

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();
}
}

Expand Down Expand Up @@ -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)
{
Expand Down
Expand Up @@ -39,6 +39,7 @@
public class PushCommand extends ConfigurableProjectCommand<PushOptions>
{
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>();

Expand All @@ -48,6 +49,7 @@ public static interface TranslationResourcesVisitor
}

{
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());
Expand Down

0 comments on commit 3646cc5

Please sign in to comment.