abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r611861 - /incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/LangTagExample.java
Date Mon, 14 Jan 2008 17:19:35 GMT
Author: jmsnell
Date: Mon Jan 14 09:19:32 2008
New Revision: 611861

URL: http://svn.apache.org/viewvc?rev=611861&view=rev
Log:
New Lang tag example

Added:
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/LangTagExample.java

Added: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/LangTagExample.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/LangTagExample.java?rev=611861&view=auto
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/LangTagExample.java
(added)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/LangTagExample.java
Mon Jan 14 09:19:32 2008
@@ -0,0 +1,57 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.examples.simple;
+
+import java.util.Locale;
+
+import org.apache.abdera.i18n.rfc4646.Lang;
+import org.apache.abdera.i18n.rfc4646.Range;
+import org.apache.abdera.i18n.rfc4646.Subtag;
+
+/**
+ * Example using the Lang tag implementation
+ */
+public class LangTagExample {
+
+  public static void main(String... args) throws Exception {
+    
+    // English, written in Latin script, as spoken in California
+    Lang lang = new Lang("en-Latn-US-calif");
+    
+    // Iterate over the tags
+    for (Subtag tag : lang) 
+      System.out.println(
+        tag.getType() + "\t" + 
+        tag.getName());
+    
+    // Access individual tags
+    String language = lang.getLanguage().getName();
+    String script = lang.getScript().getName();
+    String region = lang.getRegion().getName();
+    String variant = lang.getVariant().getName();
+    
+    // Perform extended range matching
+    Range range = new Range("en-US-*",true);
+    System.out.println(range.matches(lang,true));
+    
+    // Locale integration
+    Locale locale = lang.getLocale();
+    System.out.println(locale);
+  }
+  
+}



Mime
View raw message