下面列出了javax.swing.text.SimpleAttributeSet#getAttribute ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void cacheLinkElements() {
this.linkCache = new ArrayList<HtmlLinkAddress>();
final View view = (View) this.getClientProperty("html");
if (view != null) {
final HTMLDocument doc = (HTMLDocument) view.getDocument();
final HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
while (it.isValid()) {
final SimpleAttributeSet s = (SimpleAttributeSet) it.getAttributes();
final String link = (String) s.getAttribute(HTML.Attribute.HREF);
if (link != null) {
this.linkCache.add(new HtmlLinkAddress(link, it.getStartOffset(), it.getEndOffset()));
}
it.next();
}
}
}
private void cacheLinkElements() {
this.linkCache = new ArrayList<HtmlLinkAddress>();
final View view = (View) this.getClientProperty("html");
if (view != null) {
final HTMLDocument doc = (HTMLDocument) view.getDocument();
final HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
while (it.isValid()) {
final SimpleAttributeSet s = (SimpleAttributeSet) it.getAttributes();
final String link = (String) s.getAttribute(HTML.Attribute.HREF);
if (link != null) {
this.linkCache.add(new HtmlLinkAddress(link, it.getStartOffset(), it.getEndOffset()));
}
it.next();
}
}
}
private void cacheLinkElements() {
this.linkCache = new ArrayList<>();
final View view = (View) this.getClientProperty("html"); //NOI18N
if (view != null) {
final HTMLDocument doc = (HTMLDocument) view.getDocument();
final HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
while (it.isValid()) {
final SimpleAttributeSet s = (SimpleAttributeSet) it.getAttributes();
final String link = (String) s.getAttribute(HTML.Attribute.HREF);
if (link != null) {
this.linkCache.add(new HtmlLinkAddress(link, it.getStartOffset(), it.getEndOffset()));
}
it.next();
}
}
}
/**
* Adds text to a string buffer as an html-formatted string, adding formatting information
* as specified.
* @param buffer the string buffer to add to
* @param string the string to add
* @param attributes the formatting instructions
*/
protected void insertHTMLString(StringBuilder buffer, String string,
SimpleAttributeSet attributes) {
if (string == null) {
return;
}
buffer.append("<FONT COLOR=\"");
Color foregroundColor = (Color) attributes.getAttribute(StyleConstants.Foreground);
buffer.append(HTMLUtilities.toHexString(foregroundColor));
buffer.append("\" FACE=\"");
buffer.append(attributes.getAttribute(StyleConstants.FontFamily).toString());
buffer.append("\">");
Boolean isBold = (Boolean) attributes.getAttribute(StyleConstants.Bold);
isBold = (isBold == null) ? Boolean.FALSE : isBold;
String text = HTMLUtilities.escapeHTML(string);
if (isBold) {
text = HTMLUtilities.bold(text);
}
buffer.append(text);
buffer.append("</FONT>");
}
@Override
public void hyperlinkUpdate(final HyperlinkEvent e) {
if (!HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
return;
}
BugTrackingAccessor accessor = Lookup.getDefault().lookup(BugTrackingAccessor.class);
if (accessor != null){
AttributeSet ats = e.getSourceElement().getAttributes();
Object attribute = ats.getAttribute(HTML.getTag("a"));
if (attribute instanceof SimpleAttributeSet) {
SimpleAttributeSet attributeSet = (SimpleAttributeSet) attribute;
Object bugId = attributeSet.getAttribute(HTML.getAttributeKey("id"));
if (bugId != null){
try{
Integer.parseInt(bugId.toString());
LOG.log(Level.FINE, "Open issue {0}", bugId);
accessor.openIssue(bugId.toString());
return;
}catch(NumberFormatException nfe){
LOG.log(Level.INFO, "Invalid id attribute", nfe);
}
}
}
} else {
LOG.log(Level.INFO, "Bugzilla Accessor not found");
}
RP.post(new Runnable(){
@Override
public void run() {
HtmlBrowser.URLDisplayer.getDefault().showURL(e.getURL());
}
});
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}
/**
* Stores the given {@link String} line for the next batch update. If the number of elements
* awaiting batch update are >= maxRows, will discard the oldest element. Call
* {@link #executeBatch(int)} or {@link #executeBatchAppend()} to execute the batch update.
* <p>
* <strong>Attention:</strong> Every {@link String} is considered as one line so a line
* separator will be added into the document after it.
* </p>
* <p>
* This method is thread safe.
* </p>
*
* @param str
* the {@link String} to add to the document.
* @param a
* the style formatting settings
*/
public void appendLineForBatch(String str, SimpleAttributeSet a) {
if (str == null || str.isEmpty()) {
throw new IllegalArgumentException("str must not be null or empty!");
}
if (!str.endsWith(System.lineSeparator())) {
str += System.lineSeparator();
}
char[] txt = str.toCharArray();
a = a != null ? (SimpleAttributeSet) a.copyAttributes() : new SimpleAttributeSet();
// set font family if not set
if (a.getAttribute(StyleConstants.FontFamily) == null) {
StyleConstants.setFontFamily(a, DEFAULT_FONT_FAMILY);
}
synchronized (LOCK) {
// make sure batch size does not exceed maxRows *3 (*3 because we add the str and 2 line
// separator tags)
if (maxRows > 0) {
while (listToInsert.size() >= maxRows * 3) {
// remove element itself and both line separator elements)
// we start at the beginning because we discard oldest first
listToInsert.removeFirst();
listToInsert.removeFirst();
listToInsert.removeFirst();
lineLength.removeFirst();
}
}
// close previous paragraph tag, start new one, add text
// yes the order is correct; no you cannot change to start/text/end
// if you do, linebreaks get messed up
listToInsert.add(new ElementSpec(new SimpleAttributeSet(), ElementSpec.EndTagType));
listToInsert.add(new ElementSpec(new SimpleAttributeSet(), ElementSpec.StartTagType));
listToInsert.add(new ElementSpec(a, ElementSpec.ContentType, txt, 0, txt.length));
// store length of each row we add
lineLength.add(txt.length);
}
}
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}