[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xerces-cvs
Subject:    cvs commit: xml-xerces/java/src/org/apache/xerces/xinclude XIncludeHandler.java
From:       mrglavas () apache ! org
Date:       2005-06-24 1:06:07
Message-ID: 20050624010607.32634.qmail () minotaur ! apache ! org
[Download RAW message or body]

mrglavas    2005/06/23 18:06:07

  Modified:    java/src/org/apache/xerces/util URI.java
               java/src/org/apache/xerces/xinclude XIncludeHandler.java
  Log:
  Fixing JIRA Issue #1047:
  http://issues.apache.org/jira/browse/XERCESJ-1047
  
  Fixing the computation of relative URIs when the scheme
  and/or authority component differ between the two URIs.
  
  Revision  Changes    Path
  1.23      +35 -2     xml-xerces/java/src/org/apache/xerces/util/URI.java
  
  Index: URI.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/util/URI.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- URI.java	17 Nov 2004 19:04:50 -0000	1.22
  +++ URI.java	24 Jun 2005 01:06:07 -0000	1.23
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 The Apache Software Foundation.
    * 
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -1287,6 +1287,39 @@
     public String getRegBasedAuthority() {
       return m_regAuthority;
     }
  +  
  +  /**
  +   * Get the authority for this URI.
  +   * 
  +   * @return the authority
  +   */
  +  public String getAuthority() {
  +      StringBuffer authority = new StringBuffer();
  +      if (m_host != null || m_regAuthority != null) {
  +          authority.append("//");
  +          
  +          // Server based authority.
  +          if (m_host != null) {
  +              
  +              if (m_userinfo != null) {
  +                  authority.append(m_userinfo);
  +                  authority.append('@');
  +              }
  +              
  +              authority.append(m_host);
  +              
  +              if (m_port != -1) {
  +                  authority.append(':');
  +                  authority.append(m_port);
  +              }
  +          }
  +          // Registry based authority.
  +          else {
  +              authority.append(m_regAuthority);
  +          }
  +      }
  +      return authority.toString();
  +  }
   
    /**
     * Get the path for this URI (optionally with the query string and
  
  
  
  1.54      +47 -4     xml-xerces/java/src/org/apache/xerces/xinclude/XIncludeHandler.java
  
  Index: XIncludeHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xinclude/XIncludeHandler.java,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- XIncludeHandler.java	17 Jun 2005 22:00:21 -0000	1.53
  +++ XIncludeHandler.java	24 Jun 2005 01:06:07 -0000	1.54
  @@ -2076,9 +2076,48 @@
                   if (fParentRelativeURI.equals("")) {
                       return relativeURI;
                   }
  -                URI uri = new URI("file", fParentRelativeURI);
  -                uri = new URI(uri, relativeURI);
  -                return uri.getPath();
  +
  +                URI base = new URI(fParentRelativeURI, true);
  +                URI uri = new URI(base, relativeURI);
  +                
  +                /** Check whether the scheme components are equal. */
  +                final String baseScheme = base.getScheme();
  +                final String literalScheme = uri.getScheme();
  +                if (!isEqual(baseScheme, literalScheme)) {
  +                    return relativeURI;
  +                }
  +                
  +                /** Check whether the authority components are equal. */
  +                final String baseAuthority = base.getAuthority();
  +                final String literalAuthority = uri.getAuthority();
  +                if (!isEqual(baseAuthority, literalAuthority)) {
  +                    return uri.getSchemeSpecificPart();
  +                }
  +                
  +                /** 
  +                 * The scheme and authority components are equal,
  +                 * return the path and the possible query and/or
  +                 * fragment which follow.
  +                 */
  +                final String literalPath = uri.getPath();
  +                final String literalQuery = uri.getQueryString();
  +                final String literalFragment = uri.getFragment();
  +                if (literalQuery != null || literalFragment != null) {
  +                    StringBuffer buffer = new StringBuffer();
  +                    if (literalPath != null) {
  +                        buffer.append(literalPath);
  +                    }
  +                    if (literalQuery != null) {
  +                        buffer.append('?');
  +                        buffer.append(literalQuery);
  +                    }
  +                    if (literalFragment != null) {
  +                        buffer.append('#');
  +                        buffer.append(literalFragment);
  +                    }
  +                    return buffer.toString();
  +                }
  +                return literalPath;
               }
               else {
                   return relativeURI;
  @@ -2842,6 +2881,10 @@
           return httpSource;
       }
       
  +    private boolean isEqual(String one, String two) {
  +        return (one == two || (one != null && one.equals(two)));
  +    }
  +    
       // which ASCII characters need to be escaped
       private static boolean gNeedEscaping[] = new boolean[128];
       // the first hex character if a character needs to be escaped
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic