juergen     02/03/11 23:22:02

  Modified:    src/webdav/server/org/apache/slide/webdav/util
                        PropertyRetrieverImpl.java
  Log:
  Provide <href> property values as abslute URLs.
  (ralf)
  
  Revision  Changes    Path
  1.4       +59 -11    
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyRetrieverImpl.java
  
  Index: PropertyRetrieverImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyRetrieverImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PropertyRetrieverImpl.java        8 Mar 2002 11:57:29 -0000       1.3
  +++ PropertyRetrieverImpl.java        12 Mar 2002 07:22:02 -0000      1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyRetrieverImpl.java,v
 1.3 2002/03/08 11:57:29 juergen Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/03/08 11:57:29 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyRetrieverImpl.java,v
 1.4 2002/03/12 07:22:02 juergen Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/03/12 07:22:02 $
    *
    * ====================================================================
    *
  @@ -132,7 +132,7 @@
    * providing property information (<code>PropFindMethod</code>,
    * <code>ReportMethod</code>) should use this class.
    *
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Ralf Stuckert</a>
    */
  @@ -555,7 +555,7 @@
                       generateNamespaceAbbreviation(
                           currentProperty.getNamespace());
                       
  -                    writeSingleProperty(generatedXML, currentProperty);
  +                    writeSingleProperty(generatedXML, currentProperty, contextPath, 
serverURL);
                   }
               }
               
  @@ -666,7 +666,7 @@
                           revisionDescriptor.getProperty(property.getName(),
                                                          property.getNamespace());
                       if (currentProperty != null) {
  -                        writeSingleProperty(generatedXML, currentProperty);
  +                        writeSingleProperty(generatedXML, currentProperty, 
contextPath, serverURL);
                       } else {
                           propertiesNotFoundVector.addElement(property);
                       }
  @@ -718,13 +718,19 @@
        *
        * @param generatedXML the output channel
        * @param currentProperty the property to be written to the output channel
  +     * @param      contextPath          the context path of the uri. The 
concatenation of
  +     *                                  
<code>serverURL</code>/<code>contextPath</code>
  +     *                                  /<code>uri</code> gives the absolute URL of 
the resource.
  +     * @param      serverURL            the URL of the server (e.g. 
<code>http://www.abc.com</code>).
        */
  -    private void writeSingleProperty(XMLPrinter generatedXML, NodeProperty 
currentProperty) {
  +    private void writeSingleProperty(XMLPrinter generatedXML, NodeProperty 
currentProperty, String contextPath, String serverURL) {
           if (currentProperty != null) {
               writeSingleProperty(generatedXML,
                                   currentProperty.getNamespace(),
                                   currentProperty.getName(),
  -                                currentProperty.getValue());
  +                                currentProperty.getValue(),
  +                                contextPath,
  +                                serverURL);
           }
       }
       
  @@ -735,11 +741,17 @@
        * @param namespace the property namespace
        * @param propertyName the property Name
        * @param propertyValue the property Value
  +     * @param      contextPath          the context path of the uri. The 
concatenation of
  +     *                                  
<code>serverURL</code>/<code>contextPath</code>
  +     *                                  /<code>uri</code> gives the absolute URL of 
the resource.
  +     * @param      serverURL            the URL of the server (e.g. 
<code>http://www.abc.com</code>).
        */
       private void writeSingleProperty(XMLPrinter generatedXML,
                                        String namespace,
                                        String propertyName,
  -                                     Object propertyValue) {
  +                                     Object propertyValue,
  +                                     String contextPath,
  +                                     String serverURL) {
           if ((propertyValue == null) ||
                   (propertyValue.toString().equals(""))) {
               generatedXML.writeElement
  @@ -754,7 +766,7 @@
                            currentPropertyString.indexOf("<") != -1  )) {
                   generatedXML.writeData(currentPropertyString);
               } else {
  -                generatedXML.writeText(currentPropertyString);
  +                
generatedXML.writeText(convertHrefValueToAbsoluteURL(currentPropertyString, 
contextPath, serverURL));
               }
               generatedXML.writeElement
                   (null, namespace, propertyName, XMLPrinter.CLOSING);
  @@ -1562,7 +1574,7 @@
        */
       protected void writeLiveProperty(String propertyName, NodeRevisionDescriptors 
revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String contextPath, 
String serverURL, PropertyHelper propertyHelper, XMLPrinter generatedXML) throws 
ObjectLockedException, ServiceAccessException, LinkedObjectNotFoundException, 
AccessDeniedException, ObjectNotFoundException, RevisionDescriptorNotFoundException, 
LockTokenNotFoundException {
   
  -        NodeProperty property = propertyHelper.getProperty(propertyName, 
revisionDescriptors, revisionDescriptor);
  +        NodeProperty property = propertyHelper.getProperty(propertyName, 
revisionDescriptors, revisionDescriptor, contextPath, serverURL);
           if (property != null) {
               generatedXML.writeElement(null, DEFAULT_NAMESPACE, propertyName, 
XMLPrinter.OPENING);
               generatedXML.writeText(property.getValue().toString());
  @@ -1599,6 +1611,42 @@
               writeLiveProperty((String)iterator.next(), revisionDescriptors, 
revisionDescriptor, contextPath, serverURL, propertyHelper, generatedXML);
           }
   }
  +    
  +    /**
  +     * If the given <code>value</code> is a <code>&lt;href&gt;</code> value
  +     * the relative URI is converted to an absolute one.
  +     *
  +     * @param      value  the value to convert in case it is a 
<code>&lt;href&gt;</code>
  +     *                    value.
  +     * @param      contextPath          the context path of the uri. The 
concatenation of
  +     *                                  
<code>serverURL</code>/<code>contextPath</code>
  +     *                                  /<code>uri</code> gives the absolute URL of 
the resource.
  +     * @param      serverURL            the URL of the server (e.g. 
<code>http://www.abc.com</code>).
  +     *
  +     * @return     the converted value.
  +     */
  +    protected static String convertHrefValueToAbsoluteURL(String value, String 
contextPath, String serverURL) {
  +
  +        String convertedValue = value;
  +        if ( (value != null) && (value.startsWith("<"+E_HREF)) ) {
  +            try {
  +                XMLValue xmlValue = new XMLValue(value);
  +                Iterator iterator = xmlValue.iterator();
  +                Element element = null;
  +                while (iterator.hasNext()) {
  +                    element = (Element)iterator.next();
  +                    if ( E_HREF.equals(element.getName()) && (element.getText() != 
null) ) {
  +                        element.setText(PropertyHelper.getAbsoluteURL(serverURL, 
contextPath, element.getText()));
  +                    }
  +                }
  +                convertedValue = xmlValue.toString();
  +            }
  +            catch (JDOMException e) {
  +            }
  +        }
  +        
  +        return convertedValue;
  +    }
       
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to