weaver 2004/10/12 12:38:14
Modified: components/jetspeed project.xml
Added: components/jetspeed/src/java/org/apache/jetspeed/rewriter/html/neko
XMLAttributesWrapper.java URLRewriterFilter.java
CallbackElementRemover.java
NeckoHTMLParserAdapter.java
Log:
see: http://nagoya.apache.org/jira/browse/JS2-138#action_53952
Revision Changes Path
1.1
jakarta-jetspeed-2/components/jetspeed/src/java/org/apache/jetspeed/rewriter/html/neko/XMLAttributesWrapper.java
Index: XMLAttributesWrapper.java
===================================================================
/*
* Copyright 2000-2001,2004 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.
* 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.
*/
package org.apache.jetspeed.rewriter.html.neko;
import org.apache.jetspeed.rewriter.MutableAttributes;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
/**
* <p>
* XMLAttributesWrapper
* </p>
* <p>
*
* </p>
* @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
* @version $Id: XMLAttributesWrapper.java,v 1.1 2004/10/12 19:38:14 weaver Exp $
*
*/
public class XMLAttributesWrapper implements MutableAttributes
{
protected XMLAttributes attrs;
/**
*
*/
public XMLAttributesWrapper(XMLAttributes attrs)
{
super();
this.attrs = attrs;
}
/**
* <p>
* addAttribute
* </p>
*
* @param arg0
* @param arg1
* @param arg2
* @return
*/
public int addAttribute( QName arg0, String arg1, String arg2 )
{
return attrs.addAttribute(arg0, arg1, arg2);
}
/**
* <p>
* equals
* </p>
*
* @see java.lang.Object#equals(java.lang.Object)
* @param obj
* @return
*/
public boolean equals( Object obj )
{
return attrs.equals(obj);
}
/**
* <p>
* getAugmentations
* </p>
*
* @param arg0
* @return
*/
public Augmentations getAugmentations( int arg0 )
{
return attrs.getAugmentations(arg0);
}
/**
* <p>
* getAugmentations
* </p>
*
* @param arg0
* @return
*/
public Augmentations getAugmentations( String arg0 )
{
return attrs.getAugmentations(arg0);
}
/**
* <p>
* getAugmentations
* </p>
*
* @param arg0
* @param arg1
* @return
*/
public Augmentations getAugmentations( String arg0, String arg1 )
{
return attrs.getAugmentations(arg0, arg1);
}
/**
* <p>
* getIndex
* </p>
*
* @param arg0
* @return
*/
public int getIndex( String arg0 )
{
return attrs.getIndex(arg0);
}
/**
* <p>
* getIndex
* </p>
*
* @param arg0
* @param arg1
* @return
*/
public int getIndex( String arg0, String arg1 )
{
return attrs.getIndex(arg0, arg1);
}
/**
* <p>
* getLength
* </p>
*
* @return
*/
public int getLength()
{
return attrs.getLength();
}
/**
* <p>
* getLocalName
* </p>
*
* @param arg0
* @return
*/
public String getLocalName( int arg0 )
{
return attrs.getLocalName(arg0);
}
/**
* <p>
* getName
* </p>
*
* @param arg0
* @param arg1
*/
public void getName( int arg0, QName arg1 )
{
attrs.getName(arg0, arg1);
}
/**
* <p>
* getNonNormalizedValue
* </p>
*
* @param arg0
* @return
*/
public String getNonNormalizedValue( int arg0 )
{
return attrs.getNonNormalizedValue(arg0);
}
/**
* <p>
* getPrefix
* </p>
*
* @param arg0
* @return
*/
public String getPrefix( int arg0 )
{
return attrs.getPrefix(arg0);
}
/**
* <p>
* getQName
* </p>
*
* @param arg0
* @return
*/
public String getQName( int arg0 )
{
return attrs.getQName(arg0);
}
/**
* <p>
* getType
* </p>
*
* @param arg0
* @return
*/
public String getType( int arg0 )
{
return attrs.getType(arg0);
}
/**
* <p>
* getType
* </p>
*
* @param arg0
* @return
*/
public String getType( String arg0 )
{
return attrs.getType(arg0);
}
/**
* <p>
* getType
* </p>
*
* @param arg0
* @param arg1
* @return
*/
public String getType( String arg0, String arg1 )
{
return attrs.getType(arg0, arg1);
}
/**
* <p>
* getURI
* </p>
*
* @param arg0
* @return
*/
public String getURI( int arg0 )
{
return attrs.getURI(arg0);
}
/**
* <p>
* getValue
* </p>
*
* @param arg0
* @return
*/
public String getValue( int arg0 )
{
return attrs.getValue(arg0);
}
/**
* <p>
* getValue
* </p>
*
* @param arg0
* @return
*/
public String getValue( String arg0 )
{
return attrs.getValue(arg0);
}
/**
* <p>
* getValue
* </p>
*
* @param arg0
* @param arg1
* @return
*/
public String getValue( String arg0, String arg1 )
{
return attrs.getValue(arg0, arg1);
}
/**
* <p>
* hashCode
* </p>
*
* @see java.lang.Object#hashCode()
* @return
*/
public int hashCode()
{
return attrs.hashCode();
}
/**
* <p>
* isSpecified
* </p>
*
* @param arg0
* @return
*/
public boolean isSpecified( int arg0 )
{
return attrs.isSpecified(arg0);
}
/**
* <p>
* removeAllAttributes
* </p>
*
*
*/
public void removeAllAttributes()
{
attrs.removeAllAttributes();
}
/**
* <p>
* removeAttributeAt
* </p>
*
* @param arg0
*/
public void removeAttributeAt( int arg0 )
{
attrs.removeAttributeAt(arg0);
}
/**
* <p>
* setAugmentations
* </p>
*
* @param arg0
* @param arg1
*/
public void setAugmentations( int arg0, Augmentations arg1 )
{
attrs.setAugmentations(arg0, arg1);
}
/**
* <p>
* setName
* </p>
*
* @param arg0
* @param arg1
*/
public void setName( int arg0, QName arg1 )
{
attrs.setName(arg0, arg1);
}
/**
* <p>
* setNonNormalizedValue
* </p>
*
* @param arg0
* @param arg1
*/
public void setNonNormalizedValue( int arg0, String arg1 )
{
attrs.setNonNormalizedValue(arg0, arg1);
}
/**
* <p>
* setSpecified
* </p>
*
* @param arg0
* @param arg1
*/
public void setSpecified( int arg0, boolean arg1 )
{
attrs.setSpecified(arg0, arg1);
}
/**
* <p>
* setType
* </p>
*
* @param arg0
* @param arg1
*/
public void setType( int arg0, String arg1 )
{
attrs.setType(arg0, arg1);
}
/**
* <p>
* setValue
* </p>
*
* @param arg0
* @param arg1
*/
public void setValue( int arg0, String arg1 )
{
attrs.setValue(arg0, arg1);
}
/**
* <p>
* toString
* </p>
*
* @see java.lang.Object#toString()
* @return
*/
public String toString()
{
return attrs.toString();
}
/**
* <p>
* addAttribute
* </p>
*
* @see
org.apache.jetspeed.rewriter.MutableAttributes#addAttribute(java.lang.String,
java.lang.Object)
* @param name
* @param value
*/
public void addAttribute( String name, Object value )
{
addAttribute(new QName(null, name.toUpperCase(), name.toUpperCase(),
null),"CDATA", value.toString());
}
}
1.1
jakarta-jetspeed-2/components/jetspeed/src/java/org/apache/jetspeed/rewriter/html/neko/URLRewriterFilter.java
Index: URLRewriterFilter.java
===================================================================
/*
* Copyright 2000-2001,2004 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.
* 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.
*/
package org.apache.jetspeed.rewriter.html.neko;
import org.apache.jetspeed.rewriter.Rewriter;
import org.apache.jetspeed.rewriter.html.SwingAttributes;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.XMLString;
import org.apache.xerces.xni.XNIException;
import org.cyberneko.html.filters.DefaultFilter;
/**
* <p>
* URLRewriterFilter
* </p>
* <p>
*
* </p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver </a>
* @version $Id: URLRewriterFilter.java,v 1.1 2004/10/12 19:38:14 weaver Exp $
*
*/
public class URLRewriterFilter extends DefaultFilter
{
private Rewriter rewriter;
/**
*
*/
public URLRewriterFilter(Rewriter rewriter )
{
super();
this.rewriter = rewriter;
}
/**
* <p>
* startElement
* </p>
*
* @see
org.apache.xerces.xni.XMLDocumentHandler#startElement(org.apache.xerces.xni.QName,
* org.apache.xerces.xni.XMLAttributes,
* org.apache.xerces.xni.Augmentations)
* @param element
* @param attrs
* @param augs
* @throws org.apache.xerces.xni.XNIException
*/
public void startElement( QName element, XMLAttributes attrs, Augmentations augs
) throws XNIException
{
if (false == rewriter.enterSimpleTagEvent(element.rawname, new
XMLAttributesWrapper(attrs)))
{
doRewrite(element, attrs);
String appended = rewriter.exitSimpleTagEvent(element.rawname, new
XMLAttributesWrapper(attrs));
if (null != appended)
{
//TODO: implement this!
}
}
super.startElement(element, attrs, augs);
}
/**
* <p>
* doRewrite
* </p>
*
* @param element
* @param attrs
*/
protected void doRewrite( QName element, XMLAttributes attrs )
{
if (element.rawname.equals("A"))
{
rewriteAttribute("href", attrs);
}
else if (element.rawname.equals("FORM"))
{
rewriteAttribute("action", attrs);
}
}
protected void rewriteAttribute( String attrName, XMLAttributes attributes )
{
String uri = attributes.getValue(attrName);
if (uri != null)
{
// attributes.setValue(attributes.getIndex(attrName),
urlGenerator.createUrl(uri));
}
}
/**
* <p>
* emptyElement
* </p>
*
* @see
org.apache.xerces.xni.XMLDocumentHandler#emptyElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
* @param arg0
* @param arg1
* @param arg2
* @throws org.apache.xerces.xni.XNIException
*/
public void emptyElement( QName element, XMLAttributes attrs, Augmentations arg2
) throws XNIException
{
doRewrite(element, attrs);
super.emptyElement(element, attrs, arg2);
}
/**
* <p>
* comment
* </p>
*
* @see
org.apache.xerces.xni.XMLDocumentHandler#comment(org.apache.xerces.xni.XMLString,
org.apache.xerces.xni.Augmentations)
* @param comment
* @param augs
* @throws org.apache.xerces.xni.XNIException
*/
public void comment( XMLString comment, Augmentations augs ) throws XNIException
{
if (!rewriter.shouldRemoveComments())
{
super.comment(comment, augs);
}
}
/**
* <p>
* endElement
* </p>
*
* @see
org.apache.xerces.xni.XMLDocumentHandler#endElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.Augmentations)
* @param arg0
* @param arg1
* @throws org.apache.xerces.xni.XNIException
*/
public void endElement( QName element, Augmentations augs ) throws XNIException
{
String elementName = element.rawname;
super.endElement(element, augs);
}
/**
* <p>
* characters
* </p>
*
* @see
org.apache.xerces.xni.XMLDocumentHandler#characters(org.apache.xerces.xni.XMLString,
org.apache.xerces.xni.Augmentations)
* @param arg0
* @param arg1
* @throws org.apache.xerces.xni.XNIException
*/
public void characters( XMLString text, Augmentations arg1 ) throws XNIException
{
if (!(text.ch[0] == '>') && ! rewriter.enterText(text.ch, text.offset))
{
super.characters(text, arg1);
}
}
}
1.1
jakarta-jetspeed-2/components/jetspeed/src/java/org/apache/jetspeed/rewriter/html/neko/CallbackElementRemover.java
Index: CallbackElementRemover.java
===================================================================
/*
* Copyright 2000-2001,2004 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.
* 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.
*/
package org.apache.jetspeed.rewriter.html.neko;
import org.apache.jetspeed.rewriter.Rewriter;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.XNIException;
import org.cyberneko.html.filters.ElementRemover;
/**
* <p>
* CallbackElementRemover
* </p>
* <p>
* Extended version of the NekoHTML ElementRemover which provides
* tag stripping/removal based on Rewriter settings.
* </p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver </a>
* @version $Id: CallbackElementRemover.java,v 1.1 2004/10/12 19:38:14 weaver Exp $
*
*/
public class CallbackElementRemover extends ElementRemover
{
private Rewriter rewriter;
/**
*
*/
public CallbackElementRemover( Rewriter rewriter )
{
super();
}
/**
* <p>
* emptyElement
* </p>
*
* @see
org.apache.xerces.xni.XMLDocumentHandler#emptyElement(org.apache.xerces.xni.QName,
* org.apache.xerces.xni.XMLAttributes,
* org.apache.xerces.xni.Augmentations)
* @param element
* @param arg1
* @param arg2
* @throws org.apache.xerces.xni.XNIException
*/
public void emptyElement( QName element, XMLAttributes arg1, Augmentations arg2
) throws XNIException
{
processTag(element.rawname);
super.emptyElement(element, arg1, arg2);
}
/**
* <p>
* processTag
* </p>
*
* @param tag
*/
protected void processTag( String tag )
{
if (!fAcceptedElements.contains(tag.toLowerCase()) &&
!fRemovedElements.contains(tag.toLowerCase()))
{
if (!rewriter.shouldRemoveTag(tag) && !rewriter.shouldStripTag(tag))
{
acceptElement(tag, null);
}
else if (rewriter.shouldStripTag(tag))
{
removeElement(tag);
}
}
}
/**
* <p>
* startElement
* </p>
*
* @see
org.apache.xerces.xni.XMLDocumentHandler#startElement(org.apache.xerces.xni.QName,
* org.apache.xerces.xni.XMLAttributes,
* org.apache.xerces.xni.Augmentations)
* @param element
* @param arg1
* @param arg2
* @throws org.apache.xerces.xni.XNIException
*/
public void startElement( QName element, XMLAttributes arg1, Augmentations arg2
) throws XNIException
{
processTag(element.rawname);
super.startElement(element, arg1, arg2);
}
}
1.1
jakarta-jetspeed-2/components/jetspeed/src/java/org/apache/jetspeed/rewriter/html/neko/NeckoHTMLParserAdapter.java
Index: NeckoHTMLParserAdapter.java
===================================================================
/*
* Copyright 2000-2001,2004 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.
* 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.
*/
package org.apache.jetspeed.rewriter.html.neko;
import java.io.Reader;
import java.io.Writer;
import org.apache.jetspeed.rewriter.ParserAdaptor;
import org.apache.jetspeed.rewriter.Rewriter;
import org.apache.jetspeed.rewriter.RewriterException;
/**
* <p>
* NeckoHTMLParserAdapter
* </p>
* <p>
*
* </p>
* @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
* @version $Id: NeckoHTMLParserAdapter.java,v 1.1 2004/10/12 19:38:14 weaver Exp $
*
*/
public class NeckoHTMLParserAdapter implements ParserAdaptor
{
/**
* <p>
* parse
* </p>
*
* @see
org.apache.jetspeed.rewriter.ParserAdaptor#parse(org.apache.jetspeed.rewriter.Rewriter,
java.io.Reader)
* @param rewriter
* @param reader
* @throws RewriterException
*/
public void parse( Rewriter rewriter, Reader reader ) throws RewriterException
{
// TODO Auto-generated method stub
}
/**
* <p>
* rewrite
* </p>
*
* @see
org.apache.jetspeed.rewriter.ParserAdaptor#rewrite(org.apache.jetspeed.rewriter.Rewriter,
java.io.Reader, java.io.Writer)
* @param rewriter
* @param reader
* @param writer
* @throws RewriterException
*/
public void rewrite( Rewriter rewriter, Reader reader, Writer writer ) throws
RewriterException
{
// TODO Auto-generated method stub
}
}
1.12 +7 -0 jakarta-jetspeed-2/components/jetspeed/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/jetspeed/project.xml,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- project.xml 25 Sep 2004 23:01:20 -0000 1.11
+++ project.xml 12 Oct 2004 19:38:14 -0000 1.12
@@ -82,6 +82,13 @@
</properties>
</dependency>
<dependency>
+ <id>nekohtml</id>
+ <version>0.9.3</version>
+ <properties>
+ <war.bundle>true</war.bundle>
+ </properties>
+ </dependency>
+ <dependency>
<id>xerces</id>
<version>2.3.0</version>
<properties>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]