abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r591720 - in /incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri: Escaping.java FtpScheme.java IRI.java SchemeRegistry.java
Date Sun, 04 Nov 2007 01:23:22 GMT
Author: jmsnell
Date: Sat Nov  3 18:23:21 2007
New Revision: 591720

URL: http://svn.apache.org/viewvc?rev=591720&view=rev
Log:
General improvements to the IRI implementation. There's still a lot more to do to clean this
up

Added:
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/FtpScheme.java
Modified:
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/Escaping.java
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRI.java
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/SchemeRegistry.java

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/Escaping.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/Escaping.java?rev=591720&r1=591719&r2=591720&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/Escaping.java
(original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/Escaping.java
Sat Nov  3 18:23:21 2007
@@ -23,7 +23,6 @@
 import java.util.BitSet;
 
 import org.apache.abdera.i18n.io.CharUtils;
-import org.apache.abdera.i18n.iri.Constants;
 
 
 /**
@@ -31,14 +30,23 @@
  */
 public final class Escaping {
 
+  public final static char[] HEX = {
+    '0','1','2','3','4','5','6','7',
+    '8','9','A','B','C','D','E','F'
+  };
+  
   private Escaping() {}
   
   private static void encode(StringBuffer sb, byte... bytes) {
     for (byte c : bytes) {
       sb.append("%");
-      sb.append(Constants.hex[(c >> 4) & 0x0f]);
-      sb.append(Constants.hex[(c >> 0) & 0x0f]);
+      sb.append(HEX[(c >> 4) & 0x0f]);
+      sb.append(HEX[(c >> 0) & 0x0f]);
     }
+  }
+  
+  public static String encode(String s) {
+    return encode(s,(BitSet)null);
   }
   
   public static String encode(String s, BitSet... maps) {

Added: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/FtpScheme.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/FtpScheme.java?rev=591720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/FtpScheme.java
(added)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/FtpScheme.java
Sat Nov  3 18:23:21 2007
@@ -0,0 +1,34 @@
+/*
+* 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.i18n.iri;
+
+
+class FtpScheme 
+  extends HttpScheme {
+
+  static final String NAME = "ftp";
+  static final int DEFAULT_PORT = 21;
+  
+  public FtpScheme() {
+    super(NAME);
+  }
+  
+  protected int getDefaultPort() {
+    return FtpScheme.DEFAULT_PORT;
+  }
+}

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRI.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRI.java?rev=591720&r1=591719&r2=591720&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRI.java
(original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRI.java
Sat Nov  3 18:23:21 2007
@@ -85,8 +85,7 @@
   }
   
   public IRI(String iri) {
-    Builder b = new Builder();
-    parse(CharUtils.stripBidi(iri), b);
+    Builder b = parse(CharUtils.stripBidi(iri));
     init(
       b.schemeobj,
       b.scheme,
@@ -127,7 +126,8 @@
     String query,
     String fragment) {
     Builder builder = new Builder();
-    Parser.parseAuthority(authority, builder);
+    builder.authority = authority;
+    Parser.parseAuthority(builder);
     SchemeRegistry reg = SchemeRegistry.getInstance();
     Scheme _scheme = reg.getScheme(scheme);
     init(_scheme,scheme,authority,builder.userinfo,
@@ -188,7 +188,7 @@
     a_fragment = Escaping.encode(getFragment(),Constants.FRAGMENT);
     a_path = Escaping.encode(getPath(), Constants.PATH);
     a_query = Escaping.encode(getQuery(),Constants.QUERY, Constants.PATH);
-    a_userinfo = Escaping.encode(getUserInfo(),Constants.USERINFO);
+    a_userinfo = Escaping.encode(getUserInfo(),Constants.USERINFO,Constants.COLON);
     a_authority = buildASCIIAuthority();
   }
     
@@ -672,11 +672,10 @@
   
   ////////// parse implementation
   
-  private static void parse(
-    String uri,
-    Builder builder) {
+  private static Builder parse(
+    String uri) {
     try {
-      Parser.parse(uri, builder, SchemeRegistry.getInstance());
+      return Parser.parse(uri, SchemeRegistry.getInstance());
     } catch (IOException e) {
       throw new IRISyntaxException(e);
     }
@@ -704,34 +703,25 @@
     private String path;
     private String query;
     private String fragment;
-    
-    public IRI getAtomURI() {
-      return new IRI(
-        schemeobj,
-        scheme,authority,userinfo,
-        host,port,path,query,fragment);
-    }
   }
   
   static class Parser {
     
     static final Pattern p = 
       Pattern.compile(
-        "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");
+        "^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\\?([^#]*))?(?:#(.*))?");
     
     static final Pattern a =
-      Pattern.compile("^((.*)?@)?(\\[.*\\])?([^:]*)?(:(\\d*))?");
+      Pattern.compile("^(?:(.*)?@)?((?:\\[.*\\])|(?:[^:]*))?(?::(\\d*))?");
     
-    static void parseAuthority(String authority, Builder builder) {
-      if (authority != null) {
-        Matcher auth = a.matcher(authority);
+    static void parseAuthority(Builder builder) {
+      if (builder.authority != null) {
+        Matcher auth = a.matcher(builder.authority);
         if (auth.find()) {
-          if (auth.group(2) != null) builder.userinfo = auth.group(2);
-          if (auth.group(3) != null) builder.host = auth.group(3);
-          else builder.host = auth.group(4);
-          try {
-            if (auth.group(6) != null) builder.port = Integer.parseInt(auth.group(6));
-          } catch (NumberFormatException e) {}
+          builder.userinfo = auth.group(1);
+          builder.host = auth.group(2);
+          if (auth.group(3) != null)
+            builder.port = Integer.parseInt(auth.group(3));
         }
         try {
           CharUtils.verify(builder.userinfo, Constants.IUSERINFO);
@@ -742,20 +732,18 @@
       }
     }
     
-    static void parse(String iri, Builder builder, SchemeRegistry reg) 
+    static Builder parse(String iri, SchemeRegistry reg) 
       throws IOException {
       Matcher irim = p.matcher(iri);
+      Builder builder = new Builder();
       if (irim.find()) {
-        
-        builder.scheme = irim.group(2);
+        builder.scheme = irim.group(1);
         builder.schemeobj = reg.getScheme(builder.scheme);
-        builder.authority = irim.group(4);
-        builder.path = irim.group(5);
-        builder.query = irim.group(7);
-        builder.fragment = irim.group(9);
-        
-        parseAuthority(builder.authority, builder);
-        
+        builder.authority = irim.group(2);
+        builder.path = irim.group(3);
+        builder.query = irim.group(4);
+        builder.fragment = irim.group(5);
+        parseAuthority(builder);        
         try {
           CharUtils.verify(builder.scheme, Constants.SCHEME);
           CharUtils.verify(builder.path, Constants.IPATH);
@@ -764,6 +752,7 @@
         } catch (InvalidCharacterException e) {
           throw new IRISyntaxException(e);
         }
+        return builder;
       } else {
         throw new IRISyntaxException("Invalid Syntax");
       }

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/SchemeRegistry.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/SchemeRegistry.java?rev=591720&r1=591719&r2=591720&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/SchemeRegistry.java
(original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/SchemeRegistry.java
Sat Nov  3 18:23:21 2007
@@ -20,12 +20,6 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.abdera.i18n.iri.DefaultScheme;
-import org.apache.abdera.i18n.iri.HttpScheme;
-import org.apache.abdera.i18n.iri.HttpsScheme;
-import org.apache.abdera.i18n.iri.Scheme;
-import org.apache.abdera.i18n.iri.SchemeRegistry;
-
 /**
  * Static registry of custom IRI schemes.
  */
@@ -44,6 +38,7 @@
     schemes = new HashMap<String,Scheme>();
     schemes.put(HttpScheme.NAME, new HttpScheme());
     schemes.put(HttpsScheme.NAME, new HttpsScheme());
+    schemes.put(FtpScheme.NAME, new FtpScheme());
   }
   
   @SuppressWarnings("unchecked")



Mime
View raw message