[okapi] 2 new revisions pushed by fli...@enlaso.com on 2012-03-02 21:39 GMT

0 views
Skip to first unread message

ok...@googlecode.com

unread,
Mar 2, 2012, 4:41:04 PM3/2/12
to okapi-...@googlegroups.com
2 new revisions:

Revision: 37bc63d7f1ab
Author: Fredrik Liden <fli...@enlaso.com>
Date: Fri Mar 2 13:37:56 2012
Log: Updated the writer to use the neutralLikeSource option
http://code.google.com/p/okapi/source/detail?r=37bc63d7f1ab

Revision: 4a3c1c62a1aa
Author: Fredrik Liden <fli...@enlaso.com>
Date: Fri Mar 2 13:39:21 2012
Log: Merge branch 'master' of https://code.google.com/p/okapi
http://code.google.com/p/okapi/source/detail?r=4a3c1c62a1aa

==============================================================================
Revision: 37bc63d7f1ab
Author: Fredrik Liden <fli...@enlaso.com>
Date: Fri Mar 2 13:37:56 2012
Log: Updated the writer to use the neutralLikeSource option

http://code.google.com/p/okapi/source/detail?r=37bc63d7f1ab

Modified:

/okapi/filters/drupal/src/main/java/net/sf/okapi/filters/drupal/DrupalFilterWriter.java
/okapi/filters/drupal/src/main/java/net/sf/okapi/filters/drupal/Node.java
/okapi/filters/drupal/src/test/resources/test.drp

=======================================
---
/okapi/filters/drupal/src/main/java/net/sf/okapi/filters/drupal/DrupalFilterWriter.java
Thu Mar 1 11:32:56 2012
+++
/okapi/filters/drupal/src/main/java/net/sf/okapi/filters/drupal/DrupalFilterWriter.java
Fri Mar 2 13:37:56 2012
@@ -210,10 +210,12 @@
return event;
}

- // Update the fields
- node.setTitle(trgLoc.getLanguage(), outFields.get("title"));
- node.setBody(trgLoc.getLanguage(), outFields.get("body"),
outFields.get("summary"));
-
+ boolean neutralLikeSource = ann.getProject().getNeutralLikeSource();
+
+ // Update the fields
+ node.setTitle(trgLoc.getLanguage(), outFields.get("title"),
neutralLikeSource);
+ node.setBody(trgLoc.getLanguage(), outFields.get("body"),
outFields.get("summary"), neutralLikeSource);
+
// Push the updated field
cli.updateNode(node);

=======================================
---
/okapi/filters/drupal/src/main/java/net/sf/okapi/filters/drupal/Node.java
Wed Feb 29 16:21:22 2012
+++
/okapi/filters/drupal/src/main/java/net/sf/okapi/filters/drupal/Node.java
Fri Mar 2 13:37:56 2012
@@ -21,12 +21,15 @@
package net.sf.okapi.filters.drupal;

import java.util.Map;
+import java.util.logging.Logger;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

public class Node {

+ private final Logger logger = Logger.getLogger(getClass().getName());
+
private JSONObject store;

public Node (JSONObject store) {
@@ -135,40 +138,109 @@
}

public void setBody (String lang, String body) {
- setBody(lang, body, null);
+ setBody(lang, body, null, true);
+ }
+
+ public void setBody (String lang, String body, boolean neutralLikeSource)
{
+ setBody(lang, body, null, neutralLikeSource);
}

@SuppressWarnings("unchecked")
- public void setBody (String lang, String body, String summary) {
-
- JSONObject bodyVal = new JSONObject();
- bodyVal.put("value", body);
-
- if(summary != null){
- bodyVal.put("summary", summary);
- }
-
- JSONArray bodyArr = new JSONArray();
- bodyArr.add(bodyVal);
-
- JSONObject bodyLang = new JSONObject();
- bodyLang.put(lang, bodyArr);
-
- store.put("body", bodyLang);
+ public void setBody (String lang, String body, String summary, boolean
neutralLikeSource) {
+
+ //if existing update the fields else create field from scratch
+ JSONObject field = (JSONObject) store.get("body");
+ if(field != null){
+
+ //--check language
+ if(!field.containsKey(lang)){
+
+ if(field.containsKey("und")){
+ if(neutralLikeSource){
+ lang = "und";
+ }else{
+ logger.warning("Specified language not found for current body.
Content will not be updated. Enable the neutralLikeSource option to write
back to \"undefined\" language.");
+ return;
+ }
+ }else{
+ //--neither the specified language or an undefined language exists
+ //--TODO: update if we're able to create new targets--
+ logger.warning("Specified language not found for current body.
Content will not be updated.");
+ return;
+ }
+ }
+
+ JSONArray langField = (JSONArray) field.get(lang);
+ JSONObject arrayObj = (JSONObject) langField.get(0);
+
+ //--overwrite value
+ arrayObj.put("value", body);
+ arrayObj.put("summary", summary);
+
+ }else{
+ JSONObject bodyVal = new JSONObject();
+ bodyVal.put("value", body);
+
+ if(summary != null){
+ bodyVal.put("summary", summary);
+ }
+
+ JSONArray bodyArr = new JSONArray();
+ bodyArr.add(bodyVal);
+
+ JSONObject bodyLang = new JSONObject();
+ bodyLang.put(lang, bodyArr);
+
+ store.put("body", bodyLang);
+ }
}

- @SuppressWarnings("unchecked")
public void setTitle (String lang, String title) {
-
- JSONObject titleVal = new JSONObject();
- titleVal.put("value", title);
-
- JSONArray titleArr = new JSONArray();
- titleArr.add(titleVal);
-
- JSONObject titleLang = new JSONObject();
- titleLang.put(lang, titleArr);
-
- store.put("title_field", titleLang);
+ setTitle(lang, title, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setTitle (String lang, String title, boolean
neutralLikeSource) {
+
+ //if existing update the fields else create field from scratch
+ JSONObject field = (JSONObject) store.get("title_field");
+ if(field != null){
+
+ //--check language
+ if(!field.containsKey(lang)){
+ if(field.containsKey("und")){
+ if(neutralLikeSource){
+ lang = "und";
+ }else{
+ logger.warning("Specified language not found for current title.
Content will not be updated. Enable the neutralLikeSource option to write
back to \"undefined\" language.");
+ return;
+ }
+ }else{
+ //--neither the specified language or an undefined language exists
+ //--TODO: update if we're able to create new targets--
+ logger.warning("Specified language not found for current title.
Content will not be updated.");
+ return;
+ }
+ }
+
+ JSONArray langField = (JSONArray) field.get(lang);
+ JSONObject arrayObj = (JSONObject) langField.get(0);
+
+ //--overwrite value
+ arrayObj.put("value", title);
+
+ }else{
+
+ JSONObject titleVal = new JSONObject();
+ titleVal.put("value", title);
+
+ JSONArray titleArr = new JSONArray();
+ titleArr.add(titleVal);
+
+ JSONObject titleLang = new JSONObject();
+ titleLang.put(lang, titleArr);
+
+ store.put("title_field", titleLang);
+ }
}
}
=======================================
--- /okapi/filters/drupal/src/test/resources/test.drp Wed Feb 29 15:02:22
2012
+++ /okapi/filters/drupal/src/test/resources/test.drp Fri Mar 2 13:37:56
2012
@@ -6,4 +6,3 @@
9 yes
8 no
3 no
-1 yes

==============================================================================
Revision: 4a3c1c62a1aa
Author: Fredrik Liden <fli...@enlaso.com>
Date: Fri Mar 2 13:39:21 2012
Log: Merge branch 'master' of https://code.google.com/p/okapi

http://code.google.com/p/okapi/source/detail?r=4a3c1c62a1aa


Reply all
Reply to author
Forward
0 new messages