📄 cmshtmltagremovefactory.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/util/CmsHtmlTagRemoveFactory.java,v $
* Date : $Date: 2006/07/20 13:46:39 $
* Version: $Revision: 1.3 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2006 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.util;
import org.opencms.main.CmsLog;
import java.util.Hashtable;
import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;
import org.apache.commons.logging.Log;
import org.htmlparser.Attribute;
import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.PrototypicalNodeFactory;
import org.htmlparser.Tag;
import org.htmlparser.lexer.Page;
import org.htmlparser.scanners.Scanner;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;
import org.htmlparser.util.SimpleNodeIterator;
import org.htmlparser.visitors.NodeVisitor;
/**
*
* A tag factory for htmlparser that is able to "remove tags".
* <p>
*
* Create an instance, add the {@link org.htmlparser.Tag} instances to remove and assign this
* factory to the {@link org.htmlparser.Parser} before starting a visit. A demo usage is shown in
* {@link org.opencms.workplace.tools.content.CmsTagReplaceParser}.
* <p>
*
* The tags are not actually removed: They are linked in the document object model tree of the HTML
* that the parser generates. They just will not accept any {@link NodeVisitor} instances and
* therefore be invisible in any output a visitor will generate from the visited tree.
* <p>
*
* @author Achim Westermann
*
* @version $Revision: 1.3 $
*
* @since 6.1.8
*
*/
public final class CmsHtmlTagRemoveFactory extends PrototypicalNodeFactory {
/**
*
* A Tag implementation that will not accept any {@link NodeVisitor} stopping by.
* <p>
*
* When visiting the corresponding tree of tags, this tag will be there but the visitor will not
* see it as it is not accepted. This allows "elimination" of this tag in the output the visitor
* generates from the document object model (e.g. HTML code again).
* <p>
*
* Potential child tags will be visible to visitors (unless they are instances of this class).
* <p>
*
* @author Achim Westermann
*
* @version $Revision: 1.3 $
*
* @since 6.1.8
*
*/
private static final class CmsInvisibleTag implements Tag {
/** Generated serial version UID. */
private static final long serialVersionUID = -3397880117291165819L;
/** The real underlying tag. */
private Tag m_decorated;
/**
* Constructor with the delegate to wrap.
* <p>
*
* Every property is accessed transparently from the delegate, except that visitors are not
* welcome.
* <p>
*
* @param delegate the tag to hide.
*/
CmsInvisibleTag(Tag delegate) {
m_decorated = delegate;
}
/**
* @see org.htmlparser.nodes.TagNode#accept(org.htmlparser.visitors.NodeVisitor)
*/
public void accept(NodeVisitor visitor) {
// be invisible but show the children (if they like visits)
NodeList children = m_decorated.getChildren();
if (children == null) {
return;
}
SimpleNodeIterator itChildren = children.elements();
while (itChildren.hasMoreNodes()) {
itChildren.nextNode().accept(visitor);
}
}
/**
* @see org.htmlparser.Tag#breaksFlow()
*/
public boolean breaksFlow() {
return m_decorated.breaksFlow();
}
/**
* @see org.htmlparser.Node#clone()
*/
public Object clone() throws CloneNotSupportedException {
return m_decorated.clone();
}
/**
* @see org.htmlparser.Node#collectInto(org.htmlparser.util.NodeList,
* org.htmlparser.NodeFilter)
*/
public void collectInto(NodeList arg0, NodeFilter arg1) {
m_decorated.collectInto(arg0, arg1);
}
/**
* @see org.htmlparser.Node#doSemanticAction()
*/
public void doSemanticAction() throws ParserException {
m_decorated.doSemanticAction();
}
/**
* @see org.htmlparser.Tag#getAttribute(java.lang.String)
*/
public String getAttribute(String arg0) {
return m_decorated.getAttribute(arg0);
}
/**
* @see org.htmlparser.Tag#getAttributeEx(java.lang.String)
*/
public Attribute getAttributeEx(String arg0) {
return m_decorated.getAttributeEx(arg0);
}
/**
* @deprecated
* @see org.htmlparser.Tag#getAttributes()
*/
public Hashtable getAttributes() {
return m_decorated.getAttributes();
}
/**
* @see org.htmlparser.Tag#getAttributesEx()
*/
public Vector getAttributesEx() {
return m_decorated.getAttributesEx();
}
/**
* @see org.htmlparser.Node#getChildren()
*/
public NodeList getChildren() {
return m_decorated.getChildren();
}
/**
* @see org.htmlparser.Tag#getEnders()
*/
public String[] getEnders() {
return m_decorated.getEnders();
}
/**
* @see org.htmlparser.Tag#getEndingLineNumber()
*/
public int getEndingLineNumber() {
return m_decorated.getEndingLineNumber();
}
/**
* @see org.htmlparser.Node#getEndPosition()
*/
public int getEndPosition() {
return m_decorated.getEndPosition();
}
/**
* @see org.htmlparser.Tag#getEndTag()
*/
public Tag getEndTag() {
return m_decorated.getEndTag();
}
/**
* @see org.htmlparser.Tag#getEndTagEnders()
*/
public String[] getEndTagEnders() {
return m_decorated.getEndTagEnders();
}
/**
* @see org.htmlparser.Tag#getIds()
*/
public String[] getIds() {
return m_decorated.getIds();
}
/**
* @see org.htmlparser.Node#getPage()
*/
public Page getPage() {
return m_decorated.getPage();
}
/**
* @see org.htmlparser.Node#getParent()
*/
public Node getParent() {
return m_decorated.getParent();
}
/**
* @see org.htmlparser.Tag#getRawTagName()
*/
public String getRawTagName() {
return m_decorated.getRawTagName();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -