Java Code Examples for javax.swing.text.html.HTML.Attribute

The following examples show how to use javax.swing.text.html.HTML.Attribute. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: marathonv5   Source File: JEditorPaneTagJavaElement.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String getAttribute(final String name) {
    if ("text".equals(name)) {
        return getText();
    }
    if ("hRefIndex".equals(name)) {
        return getHRefIndex() + "";
    }
    if ("textIndex".equals(name)) {
        return getTextIndex() + "";
    }
    return EventQueueWait.exec(new Callable<String>() {
        @Override
        public String call() throws Exception {
            Iterator iterator = findTag((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument());
            AttributeSet attributes = iterator.getAttributes();
            Attribute attr = findAttribute(name);
            if (attr != null && attributes.isDefined(attr)) {
                return attributes.getAttribute(attr).toString();
            }
            return null;
        }
    });
}
 
Example 2
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 6 votes vote down vote up
public static VectorX<Element> matchChild(Element e
			, Attribute ab, String regex){
    VectorX<Element> vE= new VectorX<Element>(Element.class);
    
    int count = e.getElementCount();
    for (int i = 0; i < count; i++) {
      Element c = e.getElement(i);
      AttributeSet mAb = c.getAttributes();
      String s = (String) mAb.getAttribute(ab);	      
      if (s==null)continue;
//    System.out.println(name+" "+ab+"="+s);
      if (s.matches(regex))
        	vE.add(c);

    }
		return vE;
	}
 
Example 3
Source Project: jitsi   Source File: ChatConversationPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param element
 * @param attrName
 * @param matchStrings
 * @return
 */
private Element findFirstElement(   Element element,
                                    HTML.Attribute attrName,
                                    String[] matchStrings)
{
    String attr = (String) element.getAttributes().getAttribute(attrName);

    if(attr != null)
        for (String matchString : matchStrings)
            if (attr.startsWith(matchString))
                return element;

    Element resultElement = null;

    // Count how many messages we have in the document.
    for (int i = 0; i < element.getElementCount(); i++)
    {
        resultElement = findFirstElement(element.getElement(i),
                                    attrName,
                                    matchStrings);
        if (resultElement != null)
            return resultElement;
    }

    return null;
}
 
Example 4
Source Project: jitsi   Source File: ChatConversationPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Inform view creation.
 * @param view the newly created view.
 */
protected void viewCreated(ViewFactory factory, View view)
{
    if(view instanceof ImageView)
    {
        Element e = findFirstElement(view.getElement(), "img");

        if(e == null)
            return;

        Object src = e.getAttributes().getAttribute(Attribute.SRC);
        if(src != null && src instanceof String
            && ((String)src).endsWith("gif"))
        {
            imageViews.add((ImageView)view);
        }
    }
}
 
Example 5
Source Project: marathonv5   Source File: JEditorPaneTagJavaElement.java    License: Apache License 2.0 5 votes vote down vote up
private Attribute findAttribute(String attrName) {
    for (Attribute attr : allAttributes) {
        if (attrName.toUpperCase().equals(attr.toString().toUpperCase())) {
            return attr;
        }
    }
    return null;
}
 
Example 6
Source Project: marathonv5   Source File: JEditorPaneTagJavaElement.java    License: Apache License 2.0 5 votes vote down vote up
public int getHRefIndex() {
    return EventQueueWait.exec(new Callable<Integer>() {
        @Override
        public Integer call() throws Exception {
            String href = getAttribute("href");
            int hRefIndex = 0;
            int current = 0;
            JEditorPane editor = (JEditorPane) parent.getComponent();
            HTMLDocument document = (HTMLDocument) editor.getDocument();
            Iterator iterator = document.getIterator(Tag.A);
            while (iterator.isValid()) {
                if (current++ >= index) {
                    return hRefIndex;
                }
                AttributeSet attributes = iterator.getAttributes();
                if (attributes != null) {
                    Object attributeObject = attributes.getAttribute(HTML.Attribute.HREF);
                    if (attributeObject != null) {
                        String attribute = attributeObject.toString();
                        if (attribute.equals(href)) {
                            hRefIndex++;
                        }
                    }
                }
                iterator.next();
            }
            return -1;
        }
    });
}
 
Example 7
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 5 votes vote down vote up
public static boolean hasAttribute(Element e, Attribute ab){
	AttributeSet mAb=e.getAttributes();
   for (Enumeration it = mAb.getAttributeNames() ; it.hasMoreElements() ;) {
   	Object s= it.nextElement();
     if (s.equals(ab))
     	return true;
   }
	return false;		
}
 
Example 8
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 5 votes vote down vote up
public static String getAttribute(Element e, Attribute ab){
	AttributeSet mAb=e.getAttributes();
   for (Enumeration it = mAb.getAttributeNames() ; it.hasMoreElements() ;) {
   	Object s= it.nextElement();
     if (s.equals(ab))
     	return (String) mAb.getAttribute(ab);
   }
	return null;
}
 
Example 9
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 5 votes vote down vote up
public static VectorX<Element> findChild(Element e
		, Attribute ab, String value){
   VectorX<Element> vE= new VectorX<Element>(Element.class);
   
   int count = e.getElementCount();
   for (int i = 0; i < count; i++) {
     Element c = e.getElement(i);
     AttributeSet mAb = c.getAttributes();
     if (mAb.containsAttribute(HTML.Attribute.ID, value))
     	vE.add(c);
   }
	return vE;
}
 
Example 10
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 5 votes vote down vote up
public static void extractAll(Element e
		, Attribute ab,  Attribute abExtract,VectorS vs){
	//VectorS vs=new VectorS();
	for (Element c: findDecendent(e,ab))
		vs.add(FSwingHtml.getAttribute(c, abExtract));
	//return vs;
}
 
Example 11
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 5 votes vote down vote up
public static Element findElement(HTMLDocument doc
		, Attribute ab, String value){
	
	return doc.getElement(doc.getDefaultRootElement(), ab, value);
	
   /*ElementIterator it = new ElementIterator(doc);
   Element e;
   while ((e = it.next()) != null) 
     if (hasAttribute(e,ab,value))return e;
	return null;*/	
}
 
Example 12
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 5 votes vote down vote up
public static VectorX<Element> findDecendent(Element e
		, Attribute ab, String value){
	VectorX<Element> vE= new VectorX<Element>(Element.class);
   ElementIterator it = new ElementIterator(e);
   Element c;
   while ((c = it.next()) != null){
   	System.out.println(ab+"="+FSwingHtml.getAttribute(c, ab));
     if (hasAttribute(c,ab,value))
     	vE.add(c);
   }
	return vE;	
}
 
Example 13
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 5 votes vote down vote up
public static VectorX<Element> findDecendent(Element e
		, Attribute ab){
	VectorX<Element> vE= new VectorX<Element>(Element.class);
   ElementIterator it = new ElementIterator(e);
   Element c;
   while ((c = it.next()) != null){
   	//System.out.println(ab+"="+FHtml.getAttribute(c, ab));
     if (hasAttribute(c,ab))  	vE.add(c);
   }
	return vE;	
}
 
Example 14
Source Project: jitsi   Source File: ChatConversationPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the contents of the sent message with the given ID.
 *
 * @param messageUID The ID of the message to retrieve.
 * @return The contents of the message, or null if the message is not found.
 */
public String getMessageContents(String messageUID)
{
    Element root = document.getDefaultRootElement();
    Element e = document.getElement(
        root,
        Attribute.ID,
        ChatHtmlUtils.MESSAGE_TEXT_ID + messageUID);
    if (e == null)
    {
        logger.warn("Could not find message with ID " + messageUID);
        return null;
    }

    Object original_message = e.getAttributes().getAttribute(
            ChatHtmlUtils.ORIGINAL_MESSAGE_ATTRIBUTE);
    if (original_message == null)
    {
        logger.warn("Message with ID " + messageUID +
                " does not have original_message attribute");
        return null;
    }

    String res = StringEscapeUtils.unescapeXml(original_message.toString());
    // Remove all newline characters that were inserted to make copying
    // newlines from the conversation panel work.
    // They shouldn't be in the write panel, because otherwise a newline
    // would consist of two chars, one of them invisible (the &#10;), but
    // both of them have to be deleted in order to remove it.
    // On the other hand this means that copying newlines from the write
    // area produces only spaces, but this seems like the better option.
    res = res.replace("&#10;", "");
    return res;
}
 
Example 15
Source Project: jitsi   Source File: ChatConversationPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that the document won't become too big. When the document reaches
 * a certain size the first message in the page is removed.
 */
private void ensureDocumentSize()
{
    if (document.getLength() > Chat.CHAT_BUFFER_SIZE)
    {
        String[] ids = new String[]
                                  {ChatHtmlUtils.MESSAGE_TEXT_ID,
                                   "statusMessage",
                                   "systemMessage",
                                   "actionMessage"};

        Element firstMsgElement = findElement(Attribute.ID, ids);

        int startIndex = firstMsgElement.getStartOffset();
        int endIndex = firstMsgElement.getEndOffset();

        try
        {
            // Remove the message.
            this.document.remove(startIndex, endIndex - startIndex);
        }
        catch (BadLocationException e)
        {
            logger.error("Error removing messages from chat: ", e);
        }

        if(firstMsgElement.getName().equals("table"))
        {
            // as we have removed a header for maybe several messages,
            // delete all messages without header
            deleteAllMessagesWithoutHeader();
        }
    }
}
 
Example 16
Source Project: jitsi   Source File: ChatConversationPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param attribute
 * @param matchStrings
 * @return
 */
private Element findElement(HTML.Attribute attribute,
                            String[] matchStrings)
{
    return findFirstElement(document.getDefaultRootElement(),
                            attribute,
                            matchStrings);
}
 
Example 17
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 4 votes vote down vote up
public static String getID(Element e){
	return getAttribute(e,HTML.Attribute.ID);
}
 
Example 18
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 4 votes vote down vote up
public static String getAlt(Element e){
	return getAttribute(e,HTML.Attribute.ALT);
}
 
Example 19
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 4 votes vote down vote up
public static String getClass(Element e){
	return getAttribute(e,HTML.Attribute.CLASS);
}
 
Example 20
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 4 votes vote down vote up
public static boolean withClass(Element e, String value){
	return e.getAttributes().containsAttribute(
			HTML.Attribute.class, value);
}
 
Example 21
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 4 votes vote down vote up
public static boolean withID(Element e, String value){
	return e.getAttributes().containsAttribute(
			HTML.Attribute.ID, value);
}
 
Example 22
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 4 votes vote down vote up
public static void extractAll(Element e	, Attribute ab, String value
		, Attribute abExtract,VectorS vs){
	for (Element c: findDecendent(e,ab, value))
		vs.add(FSwingHtml.getAttribute(c, abExtract));
	return;
}
 
Example 23
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 4 votes vote down vote up
public static void extractAll(Element e	, Attribute ab,  VectorS vs){
	extractAll(e,ab,ab,vs);
}
 
Example 24
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 4 votes vote down vote up
public static boolean hasAttribute(Element e, Attribute ab, String value){
	return e.getAttributes().containsAttribute(	ab,value);
}
 
Example 25
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 4 votes vote down vote up
public static boolean hasName(Element e, String name){
	return e.getAttributes().containsAttribute(Attribute.NAME,name);
}
 
Example 26
Source Project: pra   Source File: FSwingHtml.java    License: MIT License 4 votes vote down vote up
public static boolean hasID(Element e, String name){
	return e.getAttributes().containsAttribute(Attribute.NAME,name);
}
 
Example 27
Source Project: pra   Source File: TxtElementExtractor.java    License: MIT License 4 votes vote down vote up
public Node(Attribute ab, String value, CallBack f){
	this.ab=ab;
	this.value=value;
	this.f=f;
}
 
Example 28
Source Project: pra   Source File: TxtElementExtractor.java    License: MIT License 4 votes vote down vote up
public Node(Attribute ab, String value){
	this(ab,value,null);
}
 
Example 29
Source Project: pra   Source File: TxtElementExtractor.java    License: MIT License 4 votes vote down vote up
public Node newChild(Attribute ab, String value, CallBack f){
	Node n= new Node(ab,value,f);
	vnC.add(n);
	return n;
}
 
Example 30
Source Project: pra   Source File: TxtElementExtractor.java    License: MIT License 4 votes vote down vote up
public Node newChild(Attribute ab, String value){
	return newChild(ab,value,null);
}