@Override public void handleSimpleTag(final HTML.Tag t, final MutableAttributeSet a, final int pos) { if (t.toString().equalsIgnoreCase("afirma")) { //$NON-NLS-1$ if (!a.isDefined(HTML.Attribute.ENDTAG)) { final String type = (String) a.getAttribute(HTML.Attribute.TYPE); if (type != null && type.equals("file")) { //$NON-NLS-1$ final String uri = (String) a.getAttribute(HTML.Attribute.HREF); try { AFirmaWebSignHTMLDocument.addAttachment(new Attachment(URLDecoder.decode(uri, "UTF-8"))); //$NON-NLS-1$ } catch (final IOException e) { AFirmaWebSignHTMLDocument.addAttachment(new Attachment(uri)); } } } } else { super.handleSimpleTag(t, a, pos); } }
/** * Writes a start tag, prepending EOL. * * @param tag The tag. * @param id An id to add. * @param name The name (value) of the id. * @param attributeId An id identifying the attribute set. */ protected void writeStartTag( Tag tag, String id, String name, String attributeId ) { MutableAttributeSet att = config.getAttributeSet( attributeId ); // make sure we don't add it twice if ( att.isDefined( id ) ) { att.removeAttribute( id ); } att.addAttribute( id, name ); writeEOL(); writeStartTag( tag, att ); }
private void blockURLTyping(MutableAttributeSet inputAttr, int dot, int mark) { StyledDocument doc = getStyledDocument(); int begin = (dot < mark) ? dot - 1 : mark - 1; if(begin >= 0) { Element dotEl = doc.getCharacterElement(begin); Element markEl = doc.getCharacterElement((dot < mark) ? mark : dot); AttributeSet dotAttr = dotEl.getAttributes(); AttributeSet markAttr = markEl.getAttributes(); if(dotAttr.isDefined(HTML.Attribute.HREF)) // Ensure atleast one of them isn't null { if(dotAttr.getAttribute(HTML.Attribute.HREF) == markAttr.getAttribute(HTML.Attribute.HREF)) { inputAttr.addAttribute(HTML.Attribute.HREF, dotAttr.getAttribute(HTML.Attribute.HREF)); inputAttr.addAttribute(StyleConstants.Foreground, Color.BLUE); inputAttr.addAttribute(StyleConstants.Underline, true); return; } } } if(inputAttr.isDefined(HTML.Attribute.HREF)) // In all other cases => remove { inputAttr.removeAttribute(HTML.Attribute.HREF); inputAttr.removeAttribute(StyleConstants.Foreground); inputAttr.removeAttribute(StyleConstants.Underline); } }
if ( atts.isDefined( SinkEventAttributes.DECORATION ) )
/** * The default align is <code>center</code>. * * {@inheritDoc} * @see javax.swing.text.html.HTML.Tag#TABLE */ public void tableRows( int[] justification, boolean grid ) { // similar to super.tableRows( justification, grid ) but without class. this.tableRows = true; setCellJustif( justification ); if ( this.tableAttributes == null ) { this.tableAttributes = new SinkEventAttributeSet( 0 ); } MutableAttributeSet att = new SinkEventAttributeSet(); if ( !tableAttributes.isDefined( Attribute.BORDER.toString() ) ) { att.addAttribute( Attribute.BORDER, ( grid ? "1" : "0" ) ); } att.addAttributes( tableAttributes ); tableAttributes.removeAttributes( tableAttributes ); writeStartTag( TABLE, att ); }
/** {@inheritDoc} */ public void verbatim( SinkEventAttributes attributes ) { MutableAttributeSet atts = SinkUtils.filterAttributes( attributes, SinkUtils.SINK_VERBATIM_ATTRIBUTES ); if ( atts == null ) { atts = new SinkEventAttributeSet(); } boolean boxed = false; if ( atts.isDefined( SinkEventAttributes.DECORATION ) ) { boxed = "boxed".equals( atts.getAttribute( SinkEventAttributes.DECORATION ).toString() ); } if ( boxed ) { atts.addAttribute( Attribute.CLASS, "source" ); } atts.removeAttribute( SinkEventAttributes.DECORATION ); String width = (String) atts.getAttribute( Attribute.WIDTH.toString() ); atts.removeAttribute( Attribute.WIDTH.toString() ); writeStartTag( Tag.DIV, atts ); writeEOL( true ); if ( width != null ) { atts.addAttribute( Attribute.WIDTH.toString(), width ); } atts.removeAttribute( Attribute.ALIGN.toString() ); atts.removeAttribute( Attribute.CLASS.toString() ); writeStartTag( VERBATIM_TAG, atts ); }