[jboss-svn-commits] JBL Code SVN: r16411 - in labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin: src/main/antlr and 13 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 7 15:00:43 EST 2007
Author: steve.ebersole at jboss.com
Date: 2007-11-07 15:00:43 -0500 (Wed, 07 Nov 2007)
New Revision: 16411
Added:
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/antlr/catalog.g
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/Catalog.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/Message.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/MessageHashKey.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/Occurence.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/parse/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/parse/CatalogLexer.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/parse/ParseException.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/parse/UnexpectedTokenException.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/write/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/write/CatalogWriter.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/write/MessageProcessor.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/xml/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/java/org/jboss/jgettext/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/java/org/jboss/jgettext/catalog/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/java/org/jboss/jgettext/catalog/parse/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/java/org/jboss/jgettext/catalog/parse/TestExtendedCatalogParser.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/invalid/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/invalid/mixed_up_obsolete.po
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/valid/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/valid/obsolete.po
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/valid/sample.po
Removed:
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/antlr/gettext2.g
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/java/org/jboss/jdocbook/
Modified:
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/pom.xml
Log:
work on gettext port
Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/pom.xml
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/pom.xml 2007-11-07 17:17:20 UTC (rev 16410)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/pom.xml 2007-11-07 20:00:43 UTC (rev 16411)
@@ -81,7 +81,7 @@
</dependency>
</dependencies>
<configuration>
- <grammars>gettext.g,gettext2.g</grammars>
+ <grammars>catalog.g</grammars>
</configuration>
<executions>
<execution>
Copied: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/antlr/catalog.g (from rev 16275, labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/antlr/gettext.g)
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/antlr/catalog.g (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/antlr/catalog.g 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,244 @@
+header {
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jgettext.catalog.parse;
+}
+
+/**
+ * Defines a parser for the GNU gettext PO/POT file formats.
+ * <p/>
+ * This grammar is copied nearly verbatim from the kdesdk project from its po/xml package. It makes certain
+ * assumptions about the PO/POT structure that are true for DocBook masters, which is what it was intended to
+ * deal with (as is jDocBook, so we can live with those assumptions).
+ */
+class CatalogParser extends Parser;
+
+options {
+ exportVocab=Catalog;
+ buildAST=true;
+ k=2;
+}
+
+tokens {
+ COMMENT;
+ EXTRACTION;
+ OCCURENCE;
+ FLAG;
+
+ DOMAIN;
+
+ MSGCTXT;
+ MSGID;
+ MSGID_PLURAL;
+
+ MSGSTR;
+ MSGSTR_PLURAL;
+
+ PREV_MSGCTXT;
+ PREV_MSGID;
+ PREV_MSGID_PLURAL;
+
+ OBSOLETE;
+
+ PLURALITY;
+
+ // synthetic grouping tokens
+ CATALOG;
+ MESSAGE;
+}
+
+{
+ protected AST buildCatalogNode(AST messageBlocks) {
+ return #( [CATALOG, "catalog"], messageBlocks );
+ }
+
+ private AST buildMessageBlockNode(AST entries) {
+ AST node = buildMessageBlockNode( "message", entries );
+ handleMessageBlock( node );
+ return node;
+ }
+
+ private AST buildObsoleteMessageBlockNode(AST entries) {
+ AST node = buildMessageBlockNode( "obsolete-message", entries );
+ handleObsoleteMessageBlock( node );
+ return node;
+ }
+
+ private AST buildMessageBlockNode(String text, AST entries) {
+ return #( [MESSAGE, text], entries );
+ }
+
+
+ // callbacks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ protected void handleMessageBlock(AST messageBlock) {
+ }
+
+ protected void handleObsoleteMessageBlock(AST messageBlock) {
+ }
+
+ protected void handleCatalogComment(AST comment) {
+ }
+
+ protected void handleExtractedComment(AST comment) {
+ }
+
+ protected void handleOccurence(AST occurence) {
+ }
+
+ protected void handleFlag(AST flag) {
+ }
+
+ protected void handlePreviousMsgctxt(AST previousMsgctxt) {
+ }
+
+ protected void handlePreviousMsgid(AST previousMsgid) {
+ }
+
+ protected void handlePreviousMsgidPlural(AST previousMsgidPlural) {
+ }
+
+ protected void handleDomain(AST domain) {
+ }
+
+ protected void handleMsgctxt(AST msgctxt) {
+ }
+
+ protected void handleMsgid(AST msgid) {
+ }
+
+ protected void handleMsgidPlural(AST msgidPlural) {
+ }
+
+ protected void handleMsgstr(AST msgstr) {
+ }
+
+ protected void handleMsgstrPlural(AST msgstr, AST plurality) {
+ }
+}
+
+/**
+ * Main rule
+ */
+catalog:
+ mb:messageBlocks {
+ #catalog = buildCatalogNode( #mb );
+ }
+ ;
+
+messageBlocks:
+ ( messageBlock )*
+ ;
+
+/**
+ * A message block defines all the lines related to a single translatable message entry.
+ */
+messageBlock:
+ ( catalogComment )*
+ ( extractedComment )*
+ ( occurence )*
+ ( flag )*
+ ( previousMsgctxt )?
+ ( previousMsgid )?
+ ( previousMsgidPlural )?
+ ( domain )?
+ ( entries | o:obsoleteEntries ) {
+ if ( #o == null ) {
+ #messageBlock = buildMessageBlockNode( #messageBlock );
+ }
+ else {
+ #messageBlock = buildObsoleteMessageBlockNode( #messageBlock );
+ }
+ }
+ ;
+
+entries:
+ ( msgctxt )?
+ msgid
+ ( msgstr | msgidPlural (msgstrPlural)+ )
+ ;
+
+obsoleteEntries:
+ ( OBSOLETE! msgctxt )?
+ OBSOLETE! msgid
+ ( OBSOLETE! msgstr | OBSOLETE! msgidPlural (OBSOLETE! msgstrPlural)+ )
+ ;
+
+catalogComment: c:COMMENT {
+ handleCatalogComment( #c );
+ }
+ ;
+
+extractedComment: c:EXTRACTION {
+ handleExtractedComment( #c );
+ }
+ ;
+
+occurence: o:OCCURENCE {
+ handleOccurence( #o );
+ }
+ ;
+
+flag: f:FLAG {
+ handleFlag( #f );
+ }
+ ;
+
+previousMsgctxt: pmc:PREV_MSGCTXT {
+ handlePreviousMsgctxt( #pmc );
+ }
+ ;
+
+previousMsgid: pmi:PREV_MSGID {
+ handlePreviousMsgid( #pmi );
+ }
+ ;
+
+previousMsgidPlural: pmip:PREV_MSGID_PLURAL {
+ handlePreviousMsgidPlural( #pmip );
+ }
+ ;
+
+domain: d:DOMAIN {
+ handleDomain( #d );
+ }
+ ;
+
+msgctxt: mc:MSGCTXT {
+ handleMsgctxt( #mc );
+ }
+ ;
+
+msgid: mi:MSGID {
+ handleMsgid( #mi );
+ }
+ ;
+
+msgidPlural: mip:MSGID_PLURAL {
+ handleMsgidPlural( #mip );
+ }
+ ;
+
+msgstr: t:MSGSTR {
+ handleMsgstr( #t );
+ }
+ ;
+
+msgstrPlural: t:MSGSTR_PLURAL p:PLURALITY {
+ handleMsgstrPlural( #t, #p );
+ }
+ ;
+
Deleted: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/antlr/gettext2.g
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/antlr/gettext2.g 2007-11-07 17:17:20 UTC (rev 16410)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/antlr/gettext2.g 2007-11-07 20:00:43 UTC (rev 16411)
@@ -1,161 +0,0 @@
-header {
-/*
- * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, v. 2.1. This program is distributed in the
- * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
- * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details. You should have received a
- * copy of the GNU Lesser General Public License, v.2.1 along with this
- * distribution; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Red Hat Author(s): Steve Ebersole
- */
-package org.jboss.jdocbook.i18n.gettext.po.parse2;
-}
-
-/**
- * Defines a parser for the GNU gettext PO/POT file formats.
- * <p/>
- * This grammar is copied nearly verbatim from the kdesdk project from its po/xml package. It makes certain
- * assumptions about the PO/POT structure that are true for DocBook masters, which is what it was intended to
- * deal with (as is jDocBook, so we can live with those assumptions).
- */
-class GetTextParser extends Parser;
-
-options {
- exportVocab=GetText;
- buildAST=true;
- k=2;
-}
-
-tokens {
- MSGID = "msgid";
- MSGID_PLURAL = "msgid_plural";
- MSGCTXT = "msgctxt";
- MSGSTR = "msgstr";
-
- TRANSLATOR_COMMENT = "#";
- EXTRACTED_COMMENT = "#.";
- REFERENCE_COMMENT = "#:";
- FLAG_COMMENT = "#,";
- PREV_ENTRY_COMMENT = "#|";
- KDESDK_COMMENT = "#~";
-
- OPEN_BRACKET = "[";
- CLOSE_BRACKET = "]";
- DOUBLE_QUOTE = "\"";
-
- // synthetic tokens used during tree construction for logical groupings
- PORTABLE_OBJECT;
- MESSAGE;
-}
-
-
-/**
- * Main rule
- */
-portableObject:
- mb:messageBlocks {
- #portableObject = #( [PORTABLE_OBJECT, "portable-object"], #mb );
- }
- ;
-
-messageBlocks:
- ( messageBlock | kdesdkCommentBlock )*
- ;
-
-kdesdkCommentBlock: (kdesdkComment)+ {
- #kdesdkCommentBlock = #( [MESSAGE, "kdesdk-message-block"], #kdesdkCommentBlock );
- }
- ;
-
-kdesdkComment:
- KDESDK_COMMENT^ ( messageId | messageTranslation )
- ;
-
-
-/**
- * A message block defines all the lines related to a single translatable message entry.
- */
-messageBlock:
- ( translatorComment | extractedComment | occurenceComment | flagComment | prevEntryComment )*
- ( messageId | messageIdPlural | messageContext )+ messageTranslation ( messageTranslationPlural )* {
- #messageBlock = #( [MESSAGE, "message-block"], #messageBlock );
- }
- ;
-
-translatorComment:
- TRANSLATOR_COMMENT^ SPACE (~NEWLINE)* NEWLINE!
- ;
-
-extractedComment:
- EXTRACTED_COMMENT^ SPACE (~NEWLINE)* NEWLINE!
- ;
-
-occurenceComment:
- REFERENCE_COMMENT^ SPACE (~NEWLINE)* NEWLINE!
- ;
-
-flagComment:
- FLAG_COMMENT^ SPACE (~NEWLINE)* NEWLINE!
- ;
-
-prevEntryComment:
- PREV_ENTRY_COMMENT^ ( messageId | messageIdPlural | messageContext | messageTranslation | messageTranslationPlural )
- ;
-
-messageId:
- MSGID^ quotedText
- ;
-
-messageIdPlural:
- MSGID_PLURAL^ quotedText
- ;
-
-messageContext:
- MSGCTXT^ quotedText
- ;
-
-messageTranslation:
- MSGSTR^ ( quotedText )?
- ;
-
-messageTranslationPlural:
- MSGSTR_PLURAL^ OPEN_BRACKET! INTEGER CLOSE_BRACKET! ( quotedText )?
- ;
-
-/**
- * Yikes!!!! ;)
- */
-quotedText: ( DOUBLE_QUOTE! (ESC|~DOUBLE_QUOTE)* (DOUBLE_QUOTE! (SPACE)*! NEWLINE! (SPACE)*!) )+
- ;
-
-// **** LEXER ******************************************************************
-
-class GetTextLexer extends Lexer;
-
-options {
- k=2;
- exportVocab=GetText;
- charVocabulary='\u0000'..'\uFFFE'; // Allow any char but \uFFFF (16 bit -1)
- caseSensitive = true;
-}
-
-SPACE: ( ' ' | '\t' )+;
-
-NEWLINE: (
- '\r' '\n' { newline(); }
- | '\r' { newline(); }
- | '\n' { newline(); }
- )
- ;
-HASH: '#';
-
-EOF: '\uFFFF';
-
-INTEGER: ( '0'..'9' )+;
-
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/Catalog.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/Catalog.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/Catalog.java 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jgettext;
+
+import java.util.LinkedHashMap;
+
+/**
+ * Models a catalog
+ *
+ * @author Steve Ebersole
+ */
+public class Catalog {
+ // todo : segment by domain?
+
+ private final LinkedHashMap<MessageHashKey,Message> messageMap = new LinkedHashMap<MessageHashKey,Message>();
+
+ public void addMessage(Message message) {
+ messageMap.put( new MessageHashKey( message ), message );
+ }
+
+ public Message locateHeader() {
+ for ( Message message : messageMap.values() ) {
+ if ( message.isHeader() ) {
+ return message;
+ }
+ }
+ return null;
+ }
+
+ public Message locateMessage(String msgctxt, String msgid) {
+ return locateMessage( new MessageHashKey( msgctxt, msgid ) );
+ }
+
+ public Message locateMessage(MessageHashKey key) {
+ return messageMap.get( key );
+ }
+
+ public boolean containsMessage(String msgctxt, String msgid) {
+ return containsMessage( new MessageHashKey( msgctxt, msgid ) );
+ }
+
+ public boolean containsMessage(MessageHashKey key) {
+ return messageMap.containsKey( key );
+ }
+
+ public void processMessages(MessageProcessor processor) {
+ for ( Message message : messageMap.values() ) {
+ processor.processMessage( message );
+ }
+ }
+
+ public static interface MessageProcessor {
+ public void processMessage(Message message);
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/Message.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/Message.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/Message.java 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,210 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jgettext;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * Message implementation
+ *
+ * @author Steve Ebersole
+ */
+public class Message {
+ private String domain;
+ private String msgctxt;
+ private String msgid;
+ private String msgidPlural;
+ private String msgstr;
+ private List<String> msgstrPlural = new ArrayList<String>();
+
+ private String prevMsgctx;
+ private String prevMsgid;
+ private String prevMsgidPlural;
+
+ private Collection<String> comments = new ArrayList<String>();
+ private Collection<String> extractedComments = new ArrayList<String>();
+ private SortedSet<Occurence> occurences = new TreeSet<Occurence>( new OccurenceComparator() );
+ private Collection<String> formats = new ArrayList<String>();
+
+ private boolean fuzzy;
+ private boolean obsolete;
+
+ private Boolean allowWrap;
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+
+ public String getMsgctxt() {
+ return msgctxt;
+ }
+
+ public void setMsgctxt(String msgctxt) {
+ this.msgctxt = msgctxt;
+ }
+
+ public String getPrevMsgctx() {
+ return prevMsgctx;
+ }
+
+ public void setPrevMsgctx(String prevMsgctx) {
+ this.prevMsgctx = prevMsgctx;
+ }
+
+ public String getMsgid() {
+ return msgid;
+ }
+
+ public void setMsgid(String msgid) {
+ this.msgid = msgid;
+ }
+
+ public String getPrevMsgid() {
+ return prevMsgid;
+ }
+
+ public void setPrevMsgid(String prevMsgid) {
+ this.prevMsgid = prevMsgid;
+ }
+
+ public String getMsgidPlural() {
+ return msgidPlural;
+ }
+
+ public void setMsgidPlural(String msgidPlural) {
+ this.msgidPlural = msgidPlural;
+ }
+
+ public String getPrevMsgidPlural() {
+ return prevMsgidPlural;
+ }
+
+ public void setPrevMsgidPlural(String prevMsgidPlural) {
+ this.prevMsgidPlural = prevMsgidPlural;
+ }
+
+ public String getMsgstr() {
+ return msgstr;
+ }
+
+ public void setMsgstr(String msgstr) {
+ this.msgstr = msgstr;
+ }
+
+ public void addMsgstrPlural(String msgstr, int position) {
+ if ( msgstrPlural == null ) {
+ msgstrPlural = new ArrayList<String>();
+ }
+ msgstrPlural.add( position, msgstr );
+ }
+
+ public void markFuzzy() {
+ this.fuzzy = true;
+ }
+
+ public boolean isFuzzy() {
+ return fuzzy;
+ }
+
+ public void markObsolete() {
+ this.obsolete = true;
+ }
+
+ public boolean isObsolete() {
+ return obsolete;
+ }
+
+ public Boolean getAllowWrap() {
+ return allowWrap;
+ }
+
+ public void setAllowWrap(Boolean allowWrap) {
+ this.allowWrap = allowWrap;
+ }
+
+ public void addComment(String comment) {
+ comments.add( comment );
+ }
+
+ public void addExtractedComment(String comment) {
+ extractedComments.add( comment );
+ }
+
+ public Occurence addOccurence(String file, int line) {
+ Occurence o = new Occurence( file, line );
+ addOccurence( o );
+ return o;
+ }
+
+ public void addOccurence(Occurence occurence) {
+ occurences.add( occurence );
+ }
+
+ public void addFormat(String format) {
+ formats.add( format );
+ }
+
+ public boolean isHeader() {
+ return msgctxt == null && "".equals( msgid );
+ }
+
+ public List<String> getMsgstrPlural() {
+ return msgstrPlural;
+ }
+
+ public SortedSet<Occurence> getOccurences() {
+ return occurences;
+ }
+
+ public Collection<String> getComments() {
+ return comments;
+ }
+
+ public Collection<String> getExtractedComments() {
+ return extractedComments;
+ }
+
+ public Collection<String> getFormats() {
+ return formats;
+ }
+
+ private static class OccurenceComparator implements Comparator<Occurence> {
+ public int compare(Occurence o1, Occurence o2) {
+ int sub = o1.getFileName().compareTo( o2.getFileName() );
+ if ( sub != 0 ) {
+ return sub;
+ }
+ if ( o1.getLine() == o2.getLine() ) {
+ return 0;
+ }
+ else if ( o1.getLine() < o2.getLine() ) {
+ return -1;
+ }
+ else {
+ return 1;
+ }
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/MessageHashKey.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/MessageHashKey.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/MessageHashKey.java 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jgettext;
+
+/**
+ * MessageHashKey implementation
+ *
+ * @author Steve Ebersole
+ */
+public class MessageHashKey {
+ private final String msgctxt;
+ private final String msgid;
+ private final int hashcode;
+
+ public MessageHashKey(Message message) {
+ this( message.getMsgctxt(), message.getMsgid() );
+ }
+
+ public MessageHashKey(String msgctxt, String msgid) {
+ this.msgctxt = msgctxt;
+ this.msgid = msgid;
+ this.hashcode = generateHashCode();
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ MessageHashKey that = ( MessageHashKey ) o;
+
+ return !( msgctxt != null ? !msgctxt.equals( that.msgctxt ) : that.msgctxt != null )
+ && msgid.equals( that.msgid );
+
+ }
+
+ public int hashCode() {
+ return hashcode;
+ }
+
+ private int generateHashCode() {
+ int result;
+ result = ( msgctxt != null ? msgctxt.hashCode() : 0 );
+ result = 31 * result + msgid.hashCode();
+ return result;
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/Occurence.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/Occurence.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/Occurence.java 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jgettext;
+
+/**
+ * Occurence implementation
+ *
+ * @author Steve Ebersole
+ */
+public class Occurence {
+ private final String fileName;
+ private final int line;
+
+ public Occurence(String fileName, int line) {
+ this.fileName = fileName;
+ this.line = line;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public int getLine() {
+ return line;
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/parse/CatalogLexer.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/parse/CatalogLexer.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/parse/CatalogLexer.java 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,387 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jgettext.catalog.parse;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import antlr.TokenStream;
+
+/**
+ * An Antlr lexer, hand-written to better match up with the processing of the GNU gettext po parser lexer.
+ *
+ * @author Steve Ebersole
+ */
+public class CatalogLexer implements TokenStream, CatalogTokenTypes {
+
+ private final Iterator<antlr.Token> tokens;
+
+ public CatalogLexer(File file) throws FileNotFoundException {
+ tokens = Tokenizer.tokenize( file ).iterator();
+ }
+
+ /**
+ * This is the main Antlr lexer contract.
+ * <p/>
+ * Here we are simply cycling through the Tokens we have already created and queued.
+ *
+ * @return The next token.
+ */
+ public antlr.Token nextToken() {
+ if ( !tokens.hasNext() ) {
+ return new antlr.CommonToken( EOF, "<eof>" );
+ }
+ return tokens.next();
+ }
+
+
+ /**
+ * (Stateful) delegate to process and tokenize the incoming stream.
+ * <p/>
+ * Its main purpose for existence is to provided isolated lexer state.
+ */
+ private static class Tokenizer {
+
+ private class Token extends antlr.CommonToken {
+ private Token(int i, String s) {
+ super( i, s );
+ super.setFilename( filename );
+ super.setLine( lineNumber() );
+ super.setColumn( column );
+ }
+ }
+
+ public static final String DOMAIN_TXT = "domain";
+ public static final String MSGCTXT_TXT = "msgctxt";
+ public static final String MSGID_TXT = "msgid";
+ public static final String MSGID_PLURAL_TXT = "msgid_plural";
+ public static final String MSGSTR_TXT = "msgstr";
+ public static final String MSGSTR_PLURAL_TXT = "msgstr[";
+
+ public static List<antlr.Token> tokenize(File file) throws FileNotFoundException {
+ LineNumberReader ioReader = new LineNumberReader( new BufferedReader( new FileReader( file ) ) );
+ try {
+ Tokenizer me = new Tokenizer( file.getName(), ioReader );
+ return me.buildTokens();
+ }
+ finally {
+ try {
+ ioReader.close();
+ }
+ catch ( Throwable ignore ) {
+ }
+ }
+ }
+
+ private final ArrayList<antlr.Token> tokens = new ArrayList<antlr.Token>();
+
+ private final LineNumberReader ioReader;
+ private final String filename;
+ private int column;
+
+ private EntryCollector entryCollector;
+
+ public Tokenizer(String filename, LineNumberReader ioReader) {
+ this.filename = filename;
+ this.ioReader = ioReader;
+ }
+
+ private List<antlr.Token> buildTokens() {
+ String line = readLine();
+ while ( line != null ) {
+ resetColumn();
+ processLine( line );
+ line = readLine();
+ }
+ if ( entryCollector != null ) {
+ entryCollector.wrapUp();
+ entryCollector = null;
+ }
+ return tokens;
+ }
+
+ private void resetColumn() {
+ column = -1;
+ }
+
+ private String readLine() {
+ try {
+ return ioReader.readLine();
+ }
+ catch ( IOException e ) {
+ throw new ParseException( "unable to read line", lineNumber() );
+ }
+ }
+
+ private int lineNumber() {
+ return ioReader.getLineNumber();
+ }
+
+ private void processLine(String line) {
+ line = line.trim();
+
+ if ( line.length() == 0 ) {
+ return;
+ }
+
+ if ( '\"' == line.charAt( 0 ) ) {
+ processContinuation( line );
+ return;
+ }
+
+ if ( entryCollector != null ) {
+ entryCollector.wrapUp();
+ entryCollector = null;
+ }
+
+ if ( '#' == line.charAt( 0 ) ) {
+ processComment( line );
+ }
+ else {
+ processEntry( line );
+ }
+ }
+
+ private void processComment(String line) {
+ if ( line.length() == 1 ) {
+ processCatalogComment( "" );
+ return;
+ }
+
+ switch ( line.charAt( 1 ) ) {
+ case ',' :
+ processFlag( line.substring( 2 ).trim() );
+ break;
+ case ':' :
+ processOccurence( line.substring( 2 ).trim() );
+ break;
+ case '.' :
+ processExtractedComment( line.substring( 2 ).trim() );
+ break;
+ case '|' :
+ processPreviousEntry( line.substring( 2 ).trim() );
+ break;
+ case '~' :
+ processObsolete( line.substring( 2 ).trim() );
+ break;
+ default:
+ processCatalogComment( line.substring( 1 ) );
+ }
+ }
+
+ private void processFlag(String flag) {
+ tokens.add( new Token( FLAG, flag ) );
+ }
+
+ private void processOccurence(String occurence) {
+ tokens.add( new Token( OCCURENCE, occurence ) );
+ }
+
+ private void processPreviousEntry(String entry) {
+ processLine( entry );
+ entryCollector.previous = true;
+ }
+
+ private void processObsolete(String entry) {
+ tokens.add( new Token( OBSOLETE, "<obsolete>" ) );
+ processLine( entry );
+ }
+
+ private void processExtractedComment(String comment) {
+ tokens.add( new Token( EXTRACTION, comment ) );
+ }
+
+ private void processCatalogComment(String comment) {
+ tokens.add( new Token( COMMENT, comment ) );
+ }
+
+ private void processContinuation(String line) {
+ if ( entryCollector == null ) {
+ throw new ParseException( "expecting continuation context", lineNumber() );
+ }
+
+ entryCollector.collect( stripQuotes( line ) );
+ }
+
+ private void processEntry(String line) {
+ if ( line.startsWith( DOMAIN_TXT ) ) {
+ processDomain( stripQuotes( line.substring( DOMAIN_TXT.length() ) ) );
+ }
+ else if ( line.startsWith( MSGCTXT_TXT ) ) {
+ processMessageContext( stripQuotes( line.substring( MSGCTXT_TXT.length() ) ) );
+ }
+ else if ( line.startsWith( MSGID_PLURAL_TXT ) ) {
+ processMsgidPlural( stripQuotes( line.substring( MSGID_PLURAL_TXT.length() ) ) );
+ }
+ else if ( line.startsWith( MSGSTR_PLURAL_TXT ) ) {
+ int pos = line.indexOf( ']' );
+ String n = line.substring( MSGSTR_PLURAL_TXT.length(), pos );
+ processTranslationPlural( Integer.parseInt( n ), stripQuotes( line.substring( pos + 1 ) ) );
+ }
+ else if ( line.startsWith( MSGSTR_TXT ) ) {
+ processTranslation( stripQuotes( line.substring( MSGSTR_TXT.length() ) ) );
+ }
+ else if ( line.startsWith( MSGID_TXT ) ) {
+ processMsgid( stripQuotes( line.substring( MSGID_TXT.length() ) ) );
+ }
+ else {
+ throw new UnexpectedTokenException( "unrecognized entry directive [" + line + "]", lineNumber() );
+ }
+ }
+
+ private void processDomain(String domain) {
+ tokens.add( new Token( DOMAIN, domain ) );
+ }
+
+ private void processMessageContext(String msgctxt) {
+ newEntryCollection( new MsgctxtCollector ( msgctxt ) );
+ }
+
+ private void processMsgid(String msgid) {
+ newEntryCollection( new MsgidCollector ( msgid ) );
+ }
+
+ private void processMsgidPlural(String msgidPlural) {
+ newEntryCollection( new MsgidPluralCollector ( msgidPlural ) );
+ }
+
+ private void processTranslationPlural(int n, String translation) {
+ newEntryCollection( new MsgstrPluralCollector( n, translation ) );
+ }
+
+ private void processTranslation(String translation) {
+ newEntryCollection( new MsgstrCollector( translation ) );
+ }
+
+ private void newEntryCollection(EntryCollector entryCollector) {
+ if ( this.entryCollector != null ) {
+ throw new ParseException( "illegal state; continuation collector encountered on new collectible entry start", lineNumber() );
+ }
+ this.entryCollector = entryCollector;
+ }
+
+ private String stripQuotes(String line) {
+ line = line.trim();
+ return line.substring( 1, line.length() - 1 );
+ }
+
+ private class MsgctxtCollector extends EntryCollector {
+ private MsgctxtCollector(String initial) {
+ super();
+ collect( initial );
+ }
+
+ protected void wrapUp(String entry, boolean isPrevious) {
+ if ( isPrevious ) {
+ tokens.add( new Token( PREV_MSGCTXT, entry ) );
+ }
+ else {
+ tokens.add( new Token( MSGCTXT, entry ) );
+ }
+ }
+ }
+
+ private class MsgidCollector extends EntryCollector {
+ private MsgidCollector(String initial) {
+ super();
+ collect( initial );
+ }
+
+ protected void wrapUp(String entry, boolean isPrevious) {
+ if ( isPrevious ) {
+ tokens.add( new Token( PREV_MSGID, entry ) );
+ }
+ else {
+ tokens.add( new Token( MSGID, entry ) );
+ }
+ }
+ }
+
+ private class MsgidPluralCollector extends EntryCollector {
+ private MsgidPluralCollector(String initial) {
+ super();
+ collect( initial );
+ }
+
+ protected void wrapUp(String entry, boolean isPrevious) {
+ if ( isPrevious ) {
+ tokens.add( new Token( PREV_MSGID_PLURAL, entry ) );
+ }
+ else {
+ tokens.add( new Token( MSGID_PLURAL, entry ) );
+ }
+ }
+ }
+
+ private class MsgstrCollector extends EntryCollector {
+ private MsgstrCollector(String initial) {
+ super();
+ collect( initial );
+ }
+
+ protected void wrapUp(String entry, boolean isPrevious) {
+ if ( isPrevious ) {
+ throw new ParseException( "translation does not allow previous entry according to PO schematic", lineNumber() );
+ }
+ else {
+ tokens.add( new Token( MSGSTR, entry ) );
+ }
+ }
+ }
+
+ private class MsgstrPluralCollector extends EntryCollector {
+ private final int n;
+
+ private MsgstrPluralCollector(int n, String initial) {
+ super();
+ this.n = n;
+ collect( initial );
+ }
+
+ protected void wrapUp(String entry, boolean isPrevious) {
+ if ( isPrevious ) {
+ throw new ParseException( "translation does not allow previous entry according to PO schematic", lineNumber() );
+ }
+ else {
+ tokens.add( new Token( MSGSTR_PLURAL, entry ) );
+ tokens.add( new Token( PLURALITY, Integer.toString( n ) ) );
+ }
+ }
+ }
+ }
+
+ private static abstract class EntryCollector {
+ private final StringBuilder buffer = new StringBuilder();
+ private boolean previous;
+
+ public void collect(String entry) {
+ buffer.append( entry );
+ }
+
+ protected abstract void wrapUp(String entry, boolean isPrevious);
+
+ public void wrapUp() {
+ wrapUp( buffer.toString(), previous );
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/parse/ParseException.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/parse/ParseException.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/parse/ParseException.java 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jgettext.catalog.parse;
+
+/**
+ * ParseException implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ParseException extends RuntimeException {
+ private static final long serialVersionUID = -7441231267536604971L;
+
+ private final int line;
+
+ public ParseException(String message, int line) {
+ super( message );
+ this.line = line;
+ }
+
+ public ParseException(String message, Throwable cause, int line) {
+ super( message, cause );
+ this.line = line;
+ }
+
+ public String toString() {
+ return super.toString() + " [line=" + line + "]";
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/parse/UnexpectedTokenException.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/parse/UnexpectedTokenException.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/parse/UnexpectedTokenException.java 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jgettext.catalog.parse;
+
+/**
+ * UnexpectedTokenException implementation
+ *
+ * @author Steve Ebersole
+ */
+public class UnexpectedTokenException extends ParseException {
+ private static final long serialVersionUID = -2659398412795354302L;
+
+ public UnexpectedTokenException(String message, int line) {
+ super( message, line );
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/write/CatalogWriter.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/write/CatalogWriter.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/write/CatalogWriter.java 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jgettext.catalog.write;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.jboss.jgettext.Catalog;
+import org.jboss.jgettext.Message;
+
+/**
+ * CatalogWriter implementation
+ *
+ * @author Steve Ebersole
+ */
+public class CatalogWriter {
+ protected final Catalog catalog;
+
+ public CatalogWriter(Catalog catalog) {
+ this.catalog = catalog;
+ }
+
+ public void writeTo(File file) throws IOException {
+ writeTo( new MessageProcessor( catalog.locateHeader(), new FileWriter( file ) ) );
+ }
+
+ void writeTo(MessageProcessor processor) {
+ final Message existingHeader = catalog.locateHeader();
+ if ( existingHeader == null ) {
+ processor.processMessage( generateHeader() );
+ }
+ else {
+ processor.processMessage( existingHeader );
+ }
+
+ catalog.processMessages( processor );
+ }
+
+ private Message generateHeader() {
+ Message header = new Message();
+ header.setMsgid( "" );
+ header.setMsgstr( "" );
+ header.addComment( "SOME DESCRIPTIVE TITLE." );
+ header.addComment( "FIRST AUTHOR <EMAIL at ADDRESS>, YEAR." );
+ header.addComment( "" );
+ header.markFuzzy();
+
+ return header;
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/write/MessageProcessor.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/write/MessageProcessor.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jgettext/catalog/write/MessageProcessor.java 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jgettext.catalog.write;
+
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.List;
+
+import org.jboss.jgettext.Catalog;
+import org.jboss.jgettext.Message;
+import org.jboss.jgettext.Occurence;
+
+/**
+ * MessageProcessor implementation
+ *
+ * @author Steve Ebersole
+ */
+public class MessageProcessor implements Catalog.MessageProcessor {
+ protected final Writer writer;
+ protected final Message header; // header handled specially...
+
+ public MessageProcessor(Message header, Writer writer) {
+ this.writer = writer;
+ this.header = header;
+ }
+
+ public MessageProcessor(Writer writer) {
+ this( null, writer );
+ }
+
+ public MessageProcessor() {
+ this( new OutputStreamWriter( System.out ) );
+ }
+
+ public void processMessage(Message message) {
+ if ( message == header ) {
+ return;
+ }
+
+ try {
+ messageStart( message );
+
+ for ( String comment : message.getComments() ) {
+ writer.write( "#" + comment ); // no space on purpose!!!
+ writer.write( '\n' );
+ }
+
+ for ( String comment : message.getExtractedComments() ) {
+ writer.write( "#. " + comment );
+ writer.write( '\n' );
+ }
+
+ for ( Occurence occurence : message.getOccurences() ) {
+ writer.write( "#: " + occurence.getFileName() + ":" + occurence.getLine() );
+ writer.write( '\n' );
+ }
+
+ if ( message.isFuzzy() ) {
+ writer.write( "#, fuzzy" );
+ writer.write( '\n' );
+ }
+
+ for ( String format : message.getFormats() ) {
+ writer.write( "#, " + format );
+ writer.write( '\n' );
+ }
+
+ if ( message.getPrevMsgctx() != null ) {
+ writeMsgctxt( "#| ", message.getPrevMsgctx() );
+ }
+
+ if ( message.getPrevMsgid() != null ) {
+ writeMsgid( "#| ", message.getPrevMsgid() );
+ }
+
+ if ( message.getPrevMsgidPlural() != null ) {
+ writeMsgidPlural( "#| ", message.getPrevMsgidPlural() );
+ }
+
+ String prefix = message.isObsolete() ? "#~ " : "";
+ if ( message.getMsgctxt() != null ) {
+ writeMsgctxt( prefix, message.getMsgctxt() );
+ }
+
+ writeMsgid( prefix, message.getMsgid() );
+
+ if ( message.getMsgidPlural() != null ) {
+ writeMsgidPlural( prefix, message.getMsgidPlural() );
+ }
+
+ writeMsgstr( prefix, message.getMsgstr() );
+
+ writeMsgstrPlurals( prefix, message.getMsgstrPlural() );
+
+ messageEnd( message );
+
+ writer.flush();
+ }
+ catch ( IOException e ) {
+ throw new RuntimeException( "Problem writing message : " + e.getMessage(), e );
+ }
+
+ }
+
+ protected void messageStart(Message message) throws IOException {
+ }
+
+ protected void messageEnd(Message message) throws IOException {
+ }
+
+ private void writeMsgctxt(String prefix, String ctxt) throws IOException {
+ writer.write( prefix + "msgctxt \"" + ctxt + "\"");
+ writer.write( '\n' );
+ }
+
+ private void writeMsgid(String prefix, String msgid) throws IOException {
+ writer.write( prefix + "msgid \"" + msgid + "\"");
+ writer.write( '\n' );
+ }
+
+ private void writeMsgidPlural(String prefix, String msgidPlural) throws IOException {
+ writer.write( prefix + "msgid_plural \"" + msgidPlural + "\"");
+ writer.write( '\n' );
+ }
+
+ private void writeMsgstr(String prefix, String msgstr) throws IOException {
+ if ( msgstr == null ) {
+ msgstr = "";
+ }
+ writer.write( prefix + "msgstr \"" + msgstr + "\"");
+ writer.write( '\n' );
+ }
+
+ private void writeMsgstrPlurals(String prefix, List<String> msgstrPlurals) throws IOException {
+ int i = 0;
+ for ( String msgstr : msgstrPlurals ) {
+ writer.write( prefix + "msgstr[" + i + "] \"" + msgstr + "\"" );
+ writer.write( '\n' );
+ i++;
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/java/org/jboss/jgettext/catalog/parse/TestExtendedCatalogParser.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/java/org/jboss/jgettext/catalog/parse/TestExtendedCatalogParser.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/java/org/jboss/jgettext/catalog/parse/TestExtendedCatalogParser.java 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jgettext.catalog.parse;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+import org.jboss.jdocbook.util.NoOpWriter;
+import org.jboss.jgettext.Catalog;
+import org.jboss.jgettext.Message;
+import org.jboss.jgettext.catalog.write.MessageProcessor;
+
+/**
+ * TestExtendedCatalogParser implementation
+ *
+ * @author Steve Ebersole
+ */
+public class TestExtendedCatalogParser extends TestCase {
+ public void testBasic() throws Throwable {
+ File poFile = new File( getClass().getResource( "/valid/sample.po" ).getFile() );
+ ExtendedCatalogParser parser = new ExtendedCatalogParser( poFile );
+ parser.catalog();
+ Catalog catalog = parser.getCatalog();
+ LocalProcessor processor = new LocalProcessor();
+ catalog.processMessages( processor );
+
+ assertNotNull( catalog.locateHeader() );
+ assertEquals( 7, processor.entryCount );
+ assertEquals( 3, processor.obsoleteCount );
+ }
+
+ public void testObsoleteEntries() throws Throwable {
+ File poFile = new File( getClass().getResource( "/valid/obsolete.po" ).getFile() );
+ ExtendedCatalogParser parser = new ExtendedCatalogParser( poFile );
+ parser.catalog();
+ Catalog catalog = parser.getCatalog();
+ LocalProcessor processor = new LocalProcessor();
+ catalog.processMessages( processor );
+
+ assertNotNull( catalog.locateHeader() );
+ assertEquals( 4, processor.entryCount );
+ assertEquals( 3, processor.obsoleteCount ); // - header...
+ }
+
+ public void testPartialObsoleteEntries() throws Throwable {
+ File poFile = new File( getClass().getResource( "/invalid/mixed_up_obsolete.po" ).getFile() );
+ ExtendedCatalogParser parser = new ExtendedCatalogParser( poFile );
+ try {
+ parser.catalog();
+ fail( "was expecting exception" );
+ }
+ catch ( ParseException expected ) {
+ }
+ }
+
+ public static class LocalProcessor extends MessageProcessor {
+ private int entryCount;
+ private int obsoleteCount;
+
+ public LocalProcessor() {
+ super( new NoOpWriter() );
+ }
+
+ protected void messageStart(Message message) throws IOException {
+ entryCount++;
+ if ( message.isObsolete() ) {
+ obsoleteCount++;
+ }
+ writer.write( "-----------------------------------------------------------------------------------\n" );
+ }
+
+ protected void messageEnd(Message message) throws IOException {
+ writer.write( "-----------------------------------------------------------------------------------\n" );
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/invalid/mixed_up_obsolete.po
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/invalid/mixed_up_obsolete.po (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/invalid/mixed_up_obsolete.po 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,13 @@
+###############################################################################
+## Catalog with a mixed up obsolete message block (partially obsolete)
+###############################################################################
+msgid ""
+msgstr ""
+"Header entries..."
+
+
+# Simple obsolete entry (obsolete1)
+#. Extracted comment
+#: SomeFile.java:1
+msgid "obsolete1"
+#~ msgstr "obsolete1"
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/valid/obsolete.po
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/valid/obsolete.po (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/valid/obsolete.po 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,27 @@
+# Here we have a file with a series of obsolete message blocks.
+msgid ""
+msgstr ""
+"Header entries..."
+
+
+# Simple obsolete entry (obsolete1)
+#. Extracted comment
+#: SomeFile.java:1
+#~ msgid "obsolete1"
+#~ msgstr "obsolete1"
+
+# Plural obsolete entry (obsolete2)
+#. Extracted comment
+#: SomeFile.java:1
+#~ msgid "obsolete2"
+#~ msgid_plural "obsolete2_plural"
+#~ msgstr[0] "obsolete2-0"
+#~ msgstr[1] "obsolete2-1"
+#~ msgstr[2] "obsolete2-2"
+
+# Simple obsolete entry with context (obsolete3)
+#. Extracted comment
+#: SomeFile.java:1
+#~ msgctxt "xyz"
+#~ msgid "obsolete3"
+#~ msgstr "obsolete3"
Copied: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/valid/sample.po (from rev 16275, labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/sample.po)
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/valid/sample.po (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/test/resources/valid/sample.po 2007-11-07 20:00:43 UTC (rev 16411)
@@ -0,0 +1,42 @@
+## SOME DESCRIPTIVE TITLE.
+# FIRST AUTHOR <EMAIL at ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2007-10-26 22:09+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
+"Language-Team: LANGUAGE <kde-i18n-doc at kde.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: application/x-xml2pot; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: Hibernate_Reference.xml:25
+#, no-c-format
+msgid "HIBERNATE - Relational Persistence for Idiomatic Java"
+msgstr "HIBERNATE - Relational Persistence for Idiomatic Java"
+
+#. Tag: subtitle
+#: Hibernate_Reference.xml:26
+#, no-c-format
+msgid "Hibernate Reference Documentation"
+msgstr "Documentação da Referência do Hibernate"
+
+#. Tag: ulink
+#: Hibernate_Reference.xml:40
+#, no-c-format
+msgid "Red Hat Middleware, LLC."
+msgstr ""
+
+#~ msgid "©rightHolder;"
+#~ msgstr "©rightHolder;"
+
+#~ msgid "ROLES_OF_TRANSLATORS"
+#~ msgstr "<!--TRANS:ROLES_OF_TRANSLATORS-->"
+
+#~ msgid "CREDIT_FOR_TRANSLATORS"
+#~ msgstr "<!--TRANS:CREDIT_FOR_TRANSLATORS-->"
More information about the jboss-svn-commits
mailing list