Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,18 @@ public void deserialize(IMessagesBundle messagesBundle, String properties) {
value = value.replaceAll("\\\\n", "\n"); //$NON-NLS-1$//$NON-NLS-2$
}
IMessage entry = messagesBundle.getMessage(key);
boolean addEntry = false;
if (entry == null) {
entry = new Message(key, locale);
messagesBundle.addMessage(entry);
addEntry = true;
}
entry.setActive(!isCommentedLine);
entry.setComment(comment);
entry.setText(value);
if ( addEntry ) {
messagesBundle.addMessage(entry);
}

newKeys.add(key);
// parse comment line
} else if (lineBuf.indexOf("#") == 0) { //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
******************************************************************************/
package org.eclipse.babel.core.message.resource.ser;

import java.io.StringReader;
import java.util.Arrays;
import java.util.Properties;

Expand All @@ -26,8 +27,9 @@
public class PropertiesSerializer {

/** Generator header comment. */
public static final String GENERATED_BY = "#Generated by Eclipse Messages Editor " //$NON-NLS-1$
+ "(Eclipse Babel)"; //$NON-NLS-1$
public static final String GENERATED_BY_PRE = "#Generated by"; //$NON-NLS-1$
public static final String MESSAGE_EDITOR_NAME = "Eclipse Messages Editor (Eclipse Babel)"; //$NON-NLS-1$
public static final String GENERATED_BY = GENERATED_BY_PRE + " " + MESSAGE_EDITOR_NAME;

/** A table of hex digits */
private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5',
Expand Down Expand Up @@ -78,15 +80,36 @@ public String serialize(IMessagesBundle messagesBundle) {
int numOfLineBreaks = config.getGroupSepBlankLineCount();
StringBuffer text = new StringBuffer();

// Header comment
// Header comment
String headComment = messagesBundle.getComment();
if (config.isShowSupportEnabled()
&& !headComment.startsWith(GENERATED_BY)) {

// If enabled, insert exactly one current header at the very top
if (config.isShowSupportEnabled()) {
text.append(GENERATED_BY);
text.append(SYSTEM_LINE_SEP);
}

// Process the existing comment line by line
if (headComment != null && headComment.length() > 0) {
text.append(headComment);
// Split the comment into lines.
// The '-1' limit ensures we don't lose trailing empty lines.
String[] lines = headComment.split("\r\n|\r|\n", -1);

for (int i = 0; i < lines.length; i++) {
String line = lines[i];

// Skip ANY line that starts with "#Generated by"
if (line.startsWith(GENERATED_BY_PRE)) {
continue;
}

text.append(line);

// Restore the line break, unless it's the absolute last element in the array
if (i < lines.length - 1) {
text.append(SYSTEM_LINE_SEP);
}
}
}

// Format
Expand Down Expand Up @@ -126,7 +149,7 @@ public String serialize(IMessagesBundle messagesBundle) {
// handle group equal align and line break options
if (config.isGroupKeysEnabled()) {
String newGroup = getKeyGroup(key);
if (newGroup == null || !newGroup.equals(group)) {
if (group == null ? newGroup != null : !group.equals(newGroup)) {
group = newGroup;
equalIndex = getEqualIndex(key, group, messagesBundle);
for (int j = 0; j < numOfLineBreaks; j++) {
Expand Down Expand Up @@ -161,8 +184,12 @@ public String serialize(IMessagesBundle messagesBundle) {
* @see java.util.Properties
*/
private String convertUnicodeToEncoded(String str) {
if (str == null) {
return null;
}

int len = str.length();
StringBuffer outBuffer = new StringBuffer(len * 2);
StringBuilder outBuffer = new StringBuilder(len * 2);

for (int x = 0; x < len; x++) {
char aChar = str.charAt(x);
Expand Down Expand Up @@ -239,16 +266,15 @@ private void appendValue(StringBuffer text, String value, int equalIndex,
if (breakPos != -1) {
endPos = breakPos + SYSTEM_LINE_SEP.length();
saveValue(text, valueBuf.substring(0, endPos));
// text.append(valueBuf.substring(0, endPos));
} else {
breakPos = line.lastIndexOf(' ');
if (breakPos != -1) {
endPos = breakPos + 1;
saveValue(text, valueBuf.substring(0, endPos));
// text.append(valueBuf.substring(0, endPos));
text.append("\\"); //$NON-NLS-1$
text.append(SYSTEM_LINE_SEP);
if (breakPos == -1) {
breakPos = endPos - 1;
}
endPos = breakPos + 1;
saveValue(text, valueBuf.substring(0, endPos));
text.append("\\"); //$NON-NLS-1$
text.append(SYSTEM_LINE_SEP);
}
valueBuf.delete(0, endPos);
// Figure out starting position for next line
Expand Down
Loading