abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r607811 - in /incubator/abdera/java/trunk: core/src/main/java/org/apache/abdera/util/ core/src/test/java/org/apache/abdera/test/core/ dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/ extensions/main/src/main/java/org/apache/abder...
Date Tue, 01 Jan 2008 07:07:23 GMT
Author: jmsnell
Date: Mon Dec 31 23:07:21 2007
New Revision: 607811

URL: http://svn.apache.org/viewvc?rev=607811&view=rev
Log:
Removing old and unnecessary methods; moving things around a bit

Added:
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRIHelper.java
Removed:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/URIHelper.java
Modified:
    incubator/abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRI.java
    incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/features/Features.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMIRI.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMLink.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMSource.java
    incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
    incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FeedValidatorTest.java

Modified: incubator/abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java?rev=607811&r1=607810&r2=607811&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java
(original)
+++ incubator/abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java
Mon Dec 31 23:07:21 2007
@@ -65,7 +65,6 @@
 import org.apache.abdera.util.Configuration;
 import org.apache.abdera.util.Constants;
 import org.apache.abdera.util.MimeTypeHelper;
-import org.apache.abdera.util.URIHelper;
 import org.apache.abdera.util.XmlRestrictedCharReader;
 import org.apache.abdera.writer.WriterOptions;
 
@@ -87,19 +86,19 @@
   public static void testUriNormalization() {
     try {
       assertEquals(
-        URIHelper.normalize(
+        IRI.normalizeString(
           "HTTP://www.EXAMPLE.org:80/foo/../Bar/%3f/./foo/."), 
         "http://www.example.org/Bar/%3F/foo/");
       assertEquals(
-        URIHelper.normalize(
+          IRI.normalizeString(
           "HTTPs://www.EXAMPLE.org:443/foo/../Bar/%3f/./foo/."), 
         "https://www.example.org/Bar/%3F/foo/");
       assertEquals(
-        URIHelper.normalize(
+        IRI.normalizeString(
           "HTTP://www.EXAMPLE.org:81/foo/../Bar/%3f/./foo/."), 
         "http://www.example.org:81/Bar/%3F/foo/");
       assertEquals(
-        URIHelper.normalize(
+        IRI.normalizeString(
           "HTTPs://www.EXAMPLE.org:444/foo/../Bar/%3f/./foo/."), 
         "https://www.example.org:444/Bar/%3F/foo/");
     } catch (Exception e) {

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=607811&r1=607810&r2=607811&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
Mon Dec 31 23:07:21 2007
@@ -473,6 +473,10 @@
     return normalize(this);
   }
   
+  public static String normalizeString(String iri) {
+    return normalize(new IRI(iri)).toString();
+  }
+  
   public static IRI normalize(IRI iri) {
     if (iri.isOpaque() || iri.getPath() == null) return iri;
     IRI normalized = null;

Added: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRIHelper.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRIHelper.java?rev=607811&view=auto
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRIHelper.java
(added)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRIHelper.java
Mon Dec 31 23:07:21 2007
@@ -0,0 +1,47 @@
+/*
+* 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;
+
+import java.util.regex.Pattern;
+
+
+/**
+ * Utility methods for working with URI's / IRI's
+ */
+public class IRIHelper {
+
+  private static final Pattern javascript = 
+    Pattern.compile(
+      "\\s*j\\s*a\\s*v\\s*a\\s*s\\s*c\\s*r\\s*i\\s*p\\s*t\\s*:.*", 
+      Pattern.CASE_INSENSITIVE);
+  private static final Pattern mailto = 
+    Pattern.compile(
+      "\\s*m\\s*a\\s*i\\s*l\\s*t\\s*o\\s*:.*", 
+      Pattern.CASE_INSENSITIVE);
+  
+  public static boolean isJavascriptUri(IRI uri) {
+    if (uri == null) return false;
+    return javascript.matcher(uri.toString()).matches();
+  }
+  
+  public static boolean isMailtoUri(IRI uri) {
+    if (uri == null) return false;
+    return mailto.matcher(uri.toString()).matches();
+  }
+  
+}

Modified: incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/features/Features.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/features/Features.java?rev=607811&r1=607810&r2=607811&view=diff
==============================================================================
--- incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/features/Features.java
(original)
+++ incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/features/Features.java
Mon Dec 31 23:07:21 2007
@@ -26,7 +26,6 @@
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.model.Element;
 import org.apache.abdera.model.ExtensibleElementWrapper;
-import org.apache.abdera.util.URIHelper;
 
 public class Features 
   extends ExtensibleElementWrapper {
@@ -43,7 +42,9 @@
   }
 
   public IRI getResolvedHref() {
-    return URIHelper.resolve(getResolvedBaseUri(), getHref());
+    IRI base = getResolvedBaseUri();
+    IRI href = getHref();
+    return base != null ? base.resolve(href) : href;
   }
   
   public IRI getHref() {

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java?rev=607811&r1=607810&r2=607811&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
Mon Dec 31 23:07:21 2007
@@ -37,6 +37,7 @@
 
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.i18n.iri.IRIHelper;
 import org.apache.abdera.i18n.lang.Lang;
 import org.apache.abdera.model.Base;
 import org.apache.abdera.model.Content;
@@ -53,7 +54,6 @@
 import org.apache.abdera.parser.stax.util.FOMList;
 import org.apache.abdera.util.Constants;
 import org.apache.abdera.util.MimeTypeHelper;
-import org.apache.abdera.util.URIHelper;
 import org.apache.abdera.writer.Writer;
 import org.apache.abdera.writer.WriterOptions;
 import org.apache.axiom.om.OMAttribute;
@@ -234,8 +234,8 @@
 
   public IRI getBaseUri() {
     IRI uri = _getUriValue(getAttributeValue(BASE));
-    if (URIHelper.isJavascriptUri(uri) || 
-        URIHelper.isMailtoUri(uri)) { uri = null; }
+    if (IRIHelper.isJavascriptUri(uri) || 
+        IRIHelper.isMailtoUri(uri)) { uri = null; }
     if (uri == null) {
       if (parent instanceof Element) {
         uri = ((Element)parent).getBaseUri();
@@ -249,8 +249,8 @@
   public IRI getResolvedBaseUri() {
     IRI baseUri = null;
     IRI uri = _getUriValue(getAttributeValue(BASE));
-    if (URIHelper.isJavascriptUri(uri) || 
-        URIHelper.isMailtoUri(uri)) { uri = null; }
+    if (IRIHelper.isJavascriptUri(uri) || 
+        IRIHelper.isMailtoUri(uri)) { uri = null; }
     if (parent instanceof Element) 
       baseUri = ((Element)parent).getResolvedBaseUri();
     else if (parent instanceof Document)
@@ -334,7 +334,7 @@
   }
   
   protected IRI _resolve(IRI base, IRI value) {
-    return URIHelper.resolve(base, value);
+    return base != null ? base.resolve(value) : value;
   }
 
   public void writeTo(

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java?rev=607811&r1=607810&r2=607811&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
Mon Dec 31 23:07:21 2007
@@ -44,9 +44,9 @@
 import org.apache.abdera.model.Content.Type;
 import org.apache.abdera.parser.stax.util.FOMHelper;
 import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.URIHelper;
 import org.apache.abdera.i18n.text.io.InputStreamDataSource;
 import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.i18n.iri.IRIHelper;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
@@ -396,7 +396,7 @@
     } else {
       FOMFactory fomfactory = (FOMFactory) factory;
       IRIElement iri = fomfactory.newID(this);
-      iri.setValue((normalize) ? URIHelper.normalize(value) : value);
+      iri.setValue((normalize) ? IRI.normalizeString(value) : value);
       return iri;
     }
   }

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMIRI.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMIRI.java?rev=607811&r1=607810&r2=607811&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMIRI.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMIRI.java
Mon Dec 31 23:07:21 2007
@@ -22,7 +22,6 @@
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.model.Element;
 import org.apache.abdera.model.IRIElement;
-import org.apache.abdera.util.URIHelper;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
@@ -89,7 +88,7 @@
 
   public IRIElement setNormalizedValue(String uri) {
     if (uri != null)
-      setValue(URIHelper.normalize(uri));
+      setValue(IRI.normalizeString(uri));
     else 
       setValue(null);
     return this;

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMLink.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMLink.java?rev=607811&r1=607810&r2=607811&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMLink.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMLink.java
Mon Dec 31 23:07:21 2007
@@ -27,7 +27,6 @@
 import org.apache.abdera.model.Element;
 import org.apache.abdera.model.Link;
 import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.URIHelper;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
@@ -216,7 +215,7 @@
   }
   public static final String getRelEquiv(String val) {
     try {
-      val = URIHelper.normalize(val);
+      val = IRI.normalizeString(val);
     } catch (Exception e) {}
     String rel = REL_EQUIVS.get(val);
     return (rel != null) ? rel : val;

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMSource.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMSource.java?rev=607811&r1=607810&r2=607811&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMSource.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMSource.java
Mon Dec 31 23:07:21 2007
@@ -24,6 +24,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.i18n.iri.IRIHelper;
 import org.apache.abdera.model.AtomDate;
 import org.apache.abdera.model.Categories;
 import org.apache.abdera.model.Category;
@@ -40,7 +41,6 @@
 import org.apache.abdera.model.Text;
 import org.apache.abdera.parser.stax.util.FOMHelper;
 import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.URIHelper;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
@@ -245,7 +245,7 @@
     } else {
       FOMFactory fomfactory = (FOMFactory) factory;
       IRIElement iri = fomfactory.newID(this);
-      iri.setValue((normalize) ? URIHelper.normalize(value) : value);
+      iri.setValue((normalize) ? IRI.normalizeString(value) : value);
       return iri;
     }
   }
@@ -535,8 +535,8 @@
   public IRI getIcon() {
     IRIElement iri = getIconElement();
     IRI uri = (iri != null) ? iri.getResolvedValue() : null;
-    return (URIHelper.isJavascriptUri(uri) ||
-        URIHelper.isMailtoUri(uri)) ? null : uri;
+    return (IRIHelper.isJavascriptUri(uri) ||
+        IRIHelper.isMailtoUri(uri)) ? null : uri;
   }
 
   public IRIElement getLogoElement() {
@@ -567,8 +567,8 @@
   public IRI getLogo() {
     IRIElement iri = getLogoElement();
     IRI uri = (iri != null) ? iri.getResolvedValue() : null;
-    return (URIHelper.isJavascriptUri(uri) ||
-        URIHelper.isMailtoUri(uri)) ? null : uri;
+    return (IRIHelper.isJavascriptUri(uri) ||
+        IRIHelper.isMailtoUri(uri)) ? null : uri;
   }
   
   public Link getLink(String rel) {

Modified: incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java?rev=607811&r1=607810&r2=607811&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
(original)
+++ incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
Mon Dec 31 23:07:21 2007
@@ -19,8 +19,8 @@
 
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
-import java.io.InputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.net.URL;
@@ -35,9 +35,13 @@
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamResult;
 
+import junit.framework.TestCase;
+
 import org.apache.abdera.Abdera;
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.filter.ListParseFilter;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.i18n.lang.Lang;
 import org.apache.abdera.model.AtomDate;
 import org.apache.abdera.model.Category;
 import org.apache.abdera.model.Collection;
@@ -62,18 +66,14 @@
 import org.apache.abdera.parser.ParserOptions;
 import org.apache.abdera.util.AbderaSource;
 import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.URIHelper;
 import org.apache.abdera.util.Version;
 import org.apache.abdera.util.filter.BlackListParseFilter;
 import org.apache.abdera.util.filter.WhiteListParseFilter;
-import org.apache.abdera.i18n.lang.Lang;
 import org.apache.abdera.writer.Writer;
 import org.apache.abdera.writer.WriterFactory;
 import org.apache.abdera.xpath.XPath;
 import org.apache.axiom.attachments.ByteArrayDataSource;
 
-import junit.framework.TestCase;
-
 public class FOMTest extends TestCase   {
 
   private static Abdera abdera = new Abdera();
@@ -262,8 +262,8 @@
   public void testUriNormalization() throws Exception {
     String s1 = "HTTP://www.Example.ORG:80/./foo/%2d/../%2d/./foo";
     String s2 = "HTTP://www.Example.ORG:81/./foo/%2d/../%2d/./foo";
-    assertEquals(URIHelper.normalize(s1), "http://www.example.org/foo/-/foo");
-    assertEquals(URIHelper.normalize(s2), "http://www.example.org:81/foo/-/foo");
+    assertEquals(IRI.normalizeString(s1), "http://www.example.org/foo/-/foo");
+    assertEquals(IRI.normalizeString(s2), "http://www.example.org:81/foo/-/foo");
   }
   
   public void testFactory() throws Exception {

Modified: incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FeedValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FeedValidatorTest.java?rev=607811&r1=607810&r2=607811&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FeedValidatorTest.java
(original)
+++ incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FeedValidatorTest.java
Mon Dec 31 23:07:21 2007
@@ -26,6 +26,8 @@
 
 import javax.activation.DataHandler;
 
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.i18n.iri.IRISyntaxException;
 import org.apache.abdera.model.AtomDate;
 import org.apache.abdera.model.Category;
 import org.apache.abdera.model.Content;
@@ -42,9 +44,6 @@
 import org.apache.abdera.model.Source;
 import org.apache.abdera.model.Text;
 import org.apache.abdera.util.MimeTypeParseException;
-import org.apache.abdera.util.URIHelper;
-import org.apache.abdera.i18n.iri.IRI;
-import org.apache.abdera.i18n.iri.IRISyntaxException;
 import org.apache.axiom.om.OMException;
 
 public class FeedValidatorTest 
@@ -2733,7 +2732,7 @@
      Document<Feed> doc = get(uri);
      assertNotNull(doc);
      assertEquals(doc.getRoot().getId(), new IRI("http://example.org/./id/1234"));
-     assertEquals(URIHelper.normalize(doc.getRoot().getId()), new IRI("http://example.org/id/1234"));
+     assertEquals(IRI.normalize(doc.getRoot().getId()), new IRI("http://example.org/id/1234"));
    }
    
    public static void testSection426IdEmptyFragmentId() throws Exception {



Mime
View raw message