/** * Resets the configuration of the tags to preserve.<p> * * This is called from the constructor and only has to be called if this * instance is reused with a differen configuration (of tags to keep).<p> * */ public void reset() { m_nodeFactory = new CmsHtmlTagRemoveFactory(); }
/** * Adds a tag that will be preserved by <code>{@link #stripHtml(String)}</code>.<p> * * @param tagName the name of the tag to keep (case insensitive) * * @return true if the tagName was added correctly to the internal engine */ public boolean addPreserveTag(final String tagName) { Vector<Attribute> attributeList = new Vector<Attribute>(1); Attribute tagNameAttribute = new Attribute(); tagNameAttribute.setName(tagName.toLowerCase()); attributeList.add(tagNameAttribute); Tag keepTag = m_nodeFactory.createTagNode(null, 0, 0, attributeList); boolean result = m_nodeFactory.addTagPreserve(keepTag); return result; }
/** * Default constructor that turns echo on and uses the settings for replacing tags. * <p> * * @param settings the settings to use for tag replacement. */ public CmsTagReplaceParser(CmsTagReplaceSettings settings) { // echo on super(true); m_settings = settings; CmsHtmlTagRemoveFactory nodeFactory = new CmsHtmlTagRemoveFactory(); // add the removals of the settings to the tag factory: Iterator itDeleteTags = m_settings.getDeleteTags().iterator(); while (itDeleteTags.hasNext()) { nodeFactory.addTagRemoval((Tag)itDeleteTags.next()); } m_nodeFactory = nodeFactory; }
/** * @see org.htmlparser.PrototypicalNodeFactory#createTagNode(org.htmlparser.lexer.Page, int, * int, java.util.Vector) */ @SuppressWarnings("rawtypes") @Override public Tag createTagNode(Page arg0, int arg1, int arg2, Vector arg3) { try { String tagName = ((Attribute)arg3.get(0)).getName().toLowerCase(); // end tags have names like "/a".... if (tagName.charAt(0) == '/') { tagName = tagName.substring(1); } Tag result = super.createTagNode(arg0, arg1, arg2, arg3); if (!keepTag(tagName)) { result = new CmsInvisibleTag(result); } return result; } catch (RuntimeException rte) { if (LOG.isErrorEnabled()) { // log here, as htmlparser 1.5 did swallow exceptions from here and threw NPEs from // other places LOG.error(rte); } throw rte; } }
/** * Adds a tag that will be preserved by <code>{@link #stripHtml(String)}</code>.<p> * * @param tagName the name of the tag to keep (case insensitive) * * @return true if the tagName was added correctly to the internal engine */ public boolean addPreserveTag(final String tagName) { Vector attributeList = new Vector(1); Attribute tagNameAttribute = new Attribute(); tagNameAttribute.setName(tagName.toLowerCase()); attributeList.add(tagNameAttribute); Tag keepTag = m_nodeFactory.createTagNode(null, 0, 0, attributeList); boolean result = m_nodeFactory.addTagPreserve(keepTag); return result; }
/** * @see org.htmlparser.PrototypicalNodeFactory#createTagNode(org.htmlparser.lexer.Page, int, * int, java.util.Vector) */ @Override public Tag createTagNode(Page arg0, int arg1, int arg2, Vector arg3) { try { String tagName = ((Attribute)arg3.get(0)).getName().toLowerCase(); // end tags have names like "/a".... if (tagName.charAt(0) == '/') { tagName = tagName.substring(1); } Tag result = super.createTagNode(arg0, arg1, arg2, arg3); if (!keepTag(tagName)) { result = new CmsInvisibleTag(result); } return result; } catch (RuntimeException rte) { if (LOG.isErrorEnabled()) { // log here, as htmlparser 1.5 did swallow exceptions from here and threw NPEs from // other places LOG.error(rte); } throw rte; } }
/** * Resets the configuration of the tags to preserve.<p> * * This is called from the constructor and only has to be called if this * instance is reused with a differen configuration (of tags to keep).<p> * */ public void reset() { m_nodeFactory = new CmsHtmlTagRemoveFactory(); }