Custom html tags with JEditorPane

I'm trying, to use my own tags within html in the JEditorPane. An insert parses without exception but the html in the pane is missing the custom tags that I attempted to insert. I have tried to use the 'setPreservesUnknownTags' command on the html document, but it appears to have no affect. This is the code I have been trying to use:
edtHTML.insertHTML(docHTML, 0, "<p><my:link id=\"12\">ABC</my:link></p>", 0, 0, HTML.Tag.P);
I have also tried
edtHTML.insertHTML(docHTML, 0, "<my:link id=\"12\">ABC</my:link>", 0, 0, new HTML.UnknownTag("my:link"));
Can anyone help?
Thanks

I have no example for custom Tags but I found out that every tag is stored as an attribute.
You can access the attributes if you use a JTextPane. There is a method (i don't know the name yet I will find out tomorrow in the office) which gives you the AttributeSet of each Character at the Carent position. All characters have an attribute "name" and the value of this attribute should be the name of the tag you've inserted.
The only problem is that I had to read out every character so it's quit slow.
If you could find a better solution please let me know ([email protected]).
Thank you.
J&ouml;rn

Similar Messages

  • Problem Printing html page with JEditorPane...

    Hello All,
    I Have a problem in printin html file with JEditorPane...
    My Html file contains a Table on it..
    Problem is that JEditorPane displays the html file correctly but
    it prints the file without print that Table..
    So pls help me...
    Thanx in advance,..
    Amit
    [email protected]

    I think you would know how to retrieve content of an HTML page using the URL object. Just in case.
    My apology if this short note doesn't help you at all.

  • Inserting custom HTML tags into a HTMLDocument to be displayed in a JEditor

    Does anyone know how to insert custom tags into a HTMLDocument to be displayed in a JEditorPane?
    I have tried using the following code,
    kit.insertHTML( doc,
                    jep.getCaretPosition(),
                    "<testtag>FFFF</testtag>",
                    0,
                    0,
                    new HTML.UnknownTag("testtag") );When the above code is run the handleStartTag, handleEndTag and handleText methods are called on the HTMLReader but nothing is inserted into the document model? Can anyone help?
    I have created an instance of HTML.UnknownTag,
      public static HTML.Tag testTag = new HTML.UnknownTag("testtag");I have subclassed HTMLEditorKit and overridden the getParser() method,
      protected Parser getParser(){
        DTD dtd = null;
        try {
          dtd = createDTD( DTD.getDTD("html32"), "html32" );
        } catch ( Exception e ) {
          e.printStackTrace();
        dtd.getElement( "testtag" );
        Parser p = new ParserAdaptor( new DocumentParser( dtd ) );
        return p;
      }I have subclassed HTMLDocument and HTMLDocument.HTMLReader and created a TagAction for my new tag.
    The following code works fine, the custom tag is in the document model,
        String contents =    "<html>"
                           + "<body>"
                           + "<testtag>Here is some text</testtag>"
                           + "</body>"
                           + "</html>";
        ((HTMLDocument)jep.getDocument()).setPreservesUnknownTags(true);
        jep.setText( contents );

    I've been trying to get <blockquote> insert working in an editor but it seems to be a quite difficult task even if it's only about inserting a couple of tags into the right slot! This is the closest I got:
    HTMLDocument doc = (HTMLDocument)editor.getDocument();
    int start = editor.getCaretPosition()
    int paraStart = doc.getParagraphElement(start).getStartOffset();
    int paraEnd = doc.getParagraphElement(start).getEndOffset();
    String insideBlockQuotes = doc.getText(paraStart, paraEnd - paraStart);
    doc.setOuterHTML(doc.getParagraphElement(start),"<blockquote><p>"+insideBlockQuotes+"</p></blockquote>");
    This is how it works: Get the current paragraphs start and end positions, read the text between the start and end into a string, replace the paragrapElement with <blockquote><p>..the text from string..</p></blockquote>.
    This works 'in about' but it's far from perfect.. it has the following problems:
    1. It looses all formatting from the quoted paragraph (bold etc. tags from the quoted part)
    2. It assumes that the paragraphElement was a <p> (could have been another element too!)
    3. It's ugly
    Anybody come up with a better way to use blockquote?

  • How to get html tags from JEditorPane ??

    Hi All,
    I have a html page that i am displaying in a JEditorPane with all support to styles and images as i have set content type of pane to text/html.
    When a user selects some text in JEditorPane, i want to get the content of the selected text, but not from text, but from HTML tags. In short what i want to know how can i get the html tags of the selected text in JEditorPane.
    Please tell me how to solve this problem.
    Thanks in advance
    Kind regards
    Chetan Chandarana

    thats very correct, but things is that the tags which i displayed are not getting retrived back from the textpane, specially some new line characters are coming.....any reason ?
    thanks for the reply
    kind regards
    Chetan Chandarana

  • How to insert customized HTML tags?

    Hi
    I insert a lot of tags like <p class="foo"> or say <span onmouseover=”doAction(this);”>.
    Is it possible in Dreamweaver CS5 to extend a list of insertable tags with my customized tags and do steps like
    select some text (say “some text”),
    them choose a tag from the list (say <span onmouseover=”doAction(this);”>.)
    A fragment “<span onmouseover=”doAction(this);”> some text</span>” will be inserted into the file instead of  selected “some text”.
    Thank you in advance.

    Have you used the Snippets folder to store reusable code fragments?
    I use my snippets folder often. Go to an insertion point in your document and double click on the Snippet.
    http://webdesign.about.com/cs/dreamweaver/ht/htdwusesnip.htm
    Another option is to create and use commands from History steps:
    http://help.adobe.com/en_US/dreamweaver/cs/using/WSc78c5058ca073340dcda9110b1f693f21-7780a .html
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • Query to extract HTML tag with data

    Hi All,
    I have a string.
    '<HTML><HEAD>THIS IS HEAD.</HEAD><BODY>THIS IS BODY.<P>THIS IS P1.</P>NIMISH<P>THIS IS P2.</P></BODY></HTML>'
    I want to extract a html tag including its opening & closing tab with data as
    if i say P1
    then the output should be
    '<P>THIS IS P1.</P>'
    for P2
    then the output should be
    <P>THIS IS P2.</P>
    please help me in writing this query with regular expression
    i have tried it as following but it is not giving desired result:
    WITH T AS
    SELECT
        '<HTML><HEAD>THIS IS HEAD.</HEAD><BODY>THIS IS BODY.<P>THIS IS P1.</P>NIMISH<P>THIS IS P2.</P></BODY></HTML>' STR
    FROM   
        DUAL
    SELECT REGEXP_SUBSTR(STR, '<P>.+P2.+</P>') FROM T
    Thanks & Regards
    Nimish GargEdited by: Nimish Garg on May 7, 2012 5:49 PM

    Nimish Garg wrote:
    My requirement is to extract a <tag>data</tag> from a HTML/XML string
    where data contains any specified value.HTML is not XML.
    And that is a critical distinction to make. HTML parsing is horribly complex. XML is quite easy. For HTML you have to code your own parser in PL/SQL. XML can be parsed using the XMLTYPE class/data type in PL/SQL.
    So if you need to find a single specific tag in HTML - I would not try to treat it as XML. I may not even try to use regular expressions.
    I would do a basic substring search for the start of the tag. Read the data following the tag. Ensure that there are no nested or embedded tags in the data. Until the end tag is read. Because HTML is that much abused - and because that is an accepted norm as parsers used by browsers deals with that abuse without complaining.
    Proper HTML is mostly a myth in my experience of "screen scraping" web servers for data extraction as they do not have web services supplying the data.

  • How to set an attribute of a HTML tag with a value in the Servlet

    I have a HTML page and a Servlet.
    The HTML page sends a request to the Servlet.
    The Servlet has to read the contents of the HTML page. When the Servlet encounters the body tag it should set the bgcolor attribute of the body tag with a string(For eg.a string called color with a value blue) in the servlet.
    After doing this the Servlet has to update the original HTML page with the changes (in the body tag).
    I need a help on this.

    Hi sangee,
    you could get what you want to do by using a Java Server Page instead of both a HTML page and a Servlet.
    I should code something like this:
    <%Strung color="yourColor"%>
    <html><head><title></title></head>
    <body bgcolor="<%=color%>
    </body>
    </html>

  • Why do I get html tags with my Flash forms CGI-mailed input text?

    I'm using a Flash form to send input text to a cgi page
    (using load variable). The following text is on the CGI page.
    To: [email protected]
    From: [email]
    Errors-To: [email protected]
    Subject: [subject]
    Type of Project: [subject]
    Deadline: [details]
    Name: [realname]
    e-mail: [email]
    Phone: [phone]
    e-mails me results like this...
    Type of Project: <TEXTFORMAT LEADING="2"><P
    ALIGN="LEFT"><FONT
    FACE="_sans" SIZE="12" COLOR="#000000"
    LETTERSPACING="0" KERNING="0">by
    george</FONT></P></TEXTFORMAT>
    Deadline: <TEXTFORMAT LEADING="2"><P
    ALIGN="LEFT"><FONT
    FACE="_sans" SIZE="12" COLOR="#000000"
    LETTERSPACING="0"
    KERNING="0"></FONT></P></TEXTFORMAT><TEXTFORMAT
    LEADING="2"><P ALIGN="LEFT"><FONT FACE="_sans"
    SIZE="12" COLOR="#000000" LETTERSPACING="0"
    KERNING="0">it!!!</FONT></P></TEXTFORMAT>
    Name:
    e-mail: <TEXTFORMAT LEADING="2"><P
    ALIGN="LEFT"><FONT
    FACE="_sans" SIZE="12" COLOR="#000000"
    LETTERSPACING="0"
    KERNING="0">[email protected]</FONT></P></TEXTFORMAT>
    Phone: <TEXTFORMAT LEADING="2"><P
    ALIGN="LEFT"><FONT
    FACE="_sans" SIZE="12" COLOR="#000000"
    LETTERSPACING="0" KERNING="0">I&apos;ve
    got</FONT></P></TEXTFORMAT>
    anyone know how I can get it to drop all the extraneous html
    crap? - I just want the input text items.
    Also I can't figure out how to do a flash pulldown list as a
    form element... all tutorials I find on the sbject are for Flash 5
    and say to use Smartclips from the common librarirs tab - but there
    are no "smartclips" in my Flash CS3. I see other things in
    components (menu, list) - but cannot figure out how to add my items
    to the list.

    is there some way I could use an "expression" to subtract the
    unwanted text strings from the info being passed by the variables?
    If so, does anyone have an example of the context I would used to
    subtract 2 strings from that info...
    this string of html tags appears before the passed input text
    TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT
    FACE="_sans" SIZE="12" COLOR="#000000"
    LETTERSPACING="0" KERNING="0">
    and this appears affter it...
    </FONT></P></TEXTFORMAT>
    it's always the same.

  • Removing html tags with \n

    Hi all,
    I have the following html tag to remove:
    <a onClick="s_code_linktrack('Article-MultiPagePageNum2');"
                           title="Page 2"
                           href="?pagewanted=2&ei=5088&en=dea221a153307225&ex=1284955200&partner=rssnyt&emc=rss">2<a onClick="s_code_linktrack('Article-MultiPagePageNum3');"
                           title="Page 3"
                           href="?pagewanted=3&ei=5088&en=dea221a153307225&ex=1284955200&partner=rssnyt&emc=rss">3<a onClick="s_code_linktrack('Article-MultiPagePageNum4');"
                           title="Page 4"
                           href="?pagewanted=4&ei=5088&en=dea221a153307225&ex=1284955200&partner=rssnyt&emc=rss">4<a class="next" onClick="s_code_linktrack('Article-MultiPage-Next');"
                 title="Next Page"
                 href="?pagewanted=2&ei=5088&en=dea221a153307225&ex=1284955200&partner=rssnyt&emc=rss">I tried using
    bText = bText.replaceAll("\\<.*?\\>","");
    and
    bText = bText.replaceAll("\\<.*?m)\\>","");
    Niether work. Any thoughts?
    thanx in advance

    What is the difference between this thread and your previous thread on the topic?
    http://forum.java.sun.com/thread.jspa?threadID=665617

  • Custom HTML tags in JTextPane

    Hi all,
    I have seen this topic broached before but, in spite of many hours searching, haven't found the answer I'm looking for...
    I jave a JTextPane containing an HTMLDocument and want to render elements within my own custom tag 'Custom' outlined in red.
    I have subclassed HTMLEditorKit as follows:import javax.swing.text.ViewFactory;
    import javax.swing.text.html.HTMLEditorKit;
    public class HTMLEditorKitForCustom extends HTMLEditorKit{
         public ViewFactory getViewFactory(){
              return htmlFactoryForCustom;
        private static final ViewFactory htmlFactoryForCustom = new HTMLFactoryForCustom();
    }I have subclassed HTMLEditorKit.HTMLFactory as follows:import javax.swing.text.View;
    import javax.swing.text.Element;
    import javax.swing.text.html.HTMLEditorKit;
    import javax.swing.text.StyleConstants;
    public class HTMLFactoryForCustom extends HTMLEditorKit.HTMLFactory{
         public View create(Element element){
              Object object = element.getAttributes().getAttribute(StyleConstants.NameAttribute);
              if(CustomView.CUSTOM_KEY_TAG.equals(object)){
                   return new CustomView(element);
              return super.create(element);
    }And, I have subclassed LabelView as follows:public class CustomView extends LabelView{
         public CustomView(Element element){
              super(element);
         public void paint(Graphics g, Shape a){
              super.paint(g, a);
              Rectangle rectangle = a instanceof Rectangle ? (Rectangle)a : a.getBounds();
              Graphics2D g2d = (Graphics2D)g;
              g.setColor(Color.RED);
              g.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
         public static final String CUSTOM_KEY_TAG = "Custom";
         public static final String CUSTOM_TYPE_TAG = "ccVarType";
         public static final String CUSTOM_NUMERIC_TYPE_TAG_VALUE = "Numeric";
    }The JTextPane in question has its EditorKit set to my HTMLEditorKitForCustom throughtextPane.setEditorKit(new HTMLEditorKitForCustom();In combination, these classes ensure that when a <Custom>...</Custom> set of tags is encountered, the text between is rendered with a red outline.
    This works fine when the custom tags and text are inserted but, as soon as a change is made that affects the paragraph containing the custom tags (for example, change alignment, font size, etc.), the content disappears. However, the underlying HTML still shows the <Custom> tag, but with no closing tag and without the text the tags once contained.
    E.g. <Custom>Fred</Custom> becomes simply <Custom>.
    Any help in solving this problem will be greatly appreciated!
    Chris.

    Stas, thanks for your response!
    I did try registering the tag, and associating it with a SpecialAction then with a CharacterAction (I want the user to be able to change the font style, etc. of these Custom items).
    I did this by creating HTMLDocumentForCustom (original name, huh!), subclassing HTMLDocument and inner HTMLReaderForCustom:// (Within HTMLDocumentForCustom)
    public class HTMLReaderForCustom extends HTMLReader{
      public HTMLReaderForCustom(int pos){
        super(pos, 0, 0, null);
        registerTag(new HTML.UnknownTag(CustomView.CUSTOM_KEY_TAG), new SpecialAction());
    }Then I created a new HTMLDocumentForCustom and did textPane.setDocument(document). Now, when I inserted the text between Custom tags, I got this exception:javax.swing.text.BadLocationException: Invalid insert;
         at javax.swing.text.GapContent.insertString(GapContent.java:109);
         at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:722);I was using the following code to insert the text:SimpleAttributeSet attributes = new SimpleAttributeSet();
    attributes.addAttribute(StyleConstants.NameAttribute, CustomView.CUSTOM_KEY_TAG);
    try{
      document.insertString(1, "Custom Here!", attributes);
    catch(BadLocationException ble){
      ble.printStackTrace();
    }Inserting at position 1 was working fine before trying to subclass HTMLDocument and HTMLReader, and there's already text in the document before trying the insert -- in fact it didn't matter what the insert location was set to, the exception kept occurring.
    Can you see anything obvious I've missed or am I barking totally up the wrong tree?
    Chris.

  • Custom Views: Set style of text in custom HTML tags

    hi all, I'm using an extended JEditorPane to render HTML containing custom tags e.g. <mytag>Text</mytag>
    My ViewFactory dynamically loads a class based on the name of the tag to return the View for that tag. (The idea being you can add any tag, by just providing a View class to render it). It's working to the extent that I can use the View.paint() method to paint a square of text before and after the content element.
    What I need to do is set the style (attributes) of the text contained in the custom tags. Is this possible?
    A call to doc.setCharacterAttributes(startoffset, endoffset, attrs, true); from the View results in a "Attempt to mutate in notification", possibly because the HTMLDocument is locked at this time.
    Any help/advice would be greatly appreciated.
    Thanks.

    I'll rephrase. Is it possible to change the HTMLDocument from a View object. Forgive my lack of understanding.

  • HTML Printing with JEditorPane table borders is missing...

    Hi,
    My application prints HTML reports that was rendered on a JEditorPane,
    actually the printing is working fine (almost)...
    After reading a lot of posts and the Printing API i've found a very god aproach to print HTML documents... the DocumentRenderer:
    http://www.fawcette.com/javapro/2002_12/online/print_kgauthier_12_10_02/
    I'm having a strange problem that I was unable to figure out by myself...
    Table borders and table background images never get printed...
    ex: <TABLE BORDER=1 ...
    <td background="image.gif" ...
    On the JEditorPane it shows just fine but, when the page is printed there's no border or table background pictures...
    Everything else is printed ok including images, small fonts, etc...
    Does anyone else had the same problem ?
    Thanks for any help

    The borders present an interesting problem created by the way the DocumentRenderer class finds for printable Views in the HTML. DocumentRenderer searches recursively down the tree of Views starting with the Document's root view looking for leaf views, those with no children. The DocumentRenderer only paints these smallest chunks of text to the printer graphics context. This usually works because leaf views do not usually contain anything paintable.
    The problem with borders is that they represent paintable areas of branch views, those with children. When we only print leaf views, these areas get ignored.
    I see two logical solotions to the problem:
    I. Change the code of the recursive printView method of Document Renderer to print any border that intersects with the current printable clip rectangle.
    II. A much more elegant solution would be to print any view, branch or leaf, that fits within the current printable area, and cease the recursion there. This would include the borders.
    It would also increase efficiency by terminating the recursive method earlier by painting larger chunks of the HTML. A strange problem pops up when I try this, however. When the size of the chunk to be printed gets too big, nothing is printed at all. In the article this is mentioned in the area of large images. "Lastly, large icons do not print. Java simply refuses to render them on the page. Small icons work quite well, however." The same holds true for any large View.
    I have not been able to quantify the exact size where this failure occurs, nor what is causing it. If anyone can tell me what causes this problem, it should be fairly easy, depenging on the cause of the problem, to rewrite the class to print borders and also does lots of other good stuff. I have already coded the new and improved printView method, but this size limitation has made it unworkable.
    Simply stated, if I can figure out why the class does not print large icons, the rest should be easy.
    Any suggestions would be appreciated.
    Thanks,
    Kei Gauthier

  • Custom html file with pix and links as Mac desktop display?

    Hi, in Windows it is possible to select an html file to use as your desktop display...pictures, web links, and links to network and local folders, files, and applications can be written directly into the html page. It was actually really nice.
    How can this be done on a Mac?
    It would be great to have personal pictures, text (poems and to do lists) displayed as the desktop background...with links to files (inspirational .mov files, recently used files, even the html file for the desktop itself for quick changes), links to start applications, and links to favorite websites...all accessible from the desktop itself.
    Alternatively, would these links need to be placed in the dashboard or expose or ? Would the text over a background image in html need to be composited into a static image file?
    thanks

    I don't believe there is a way in the Mac world to specify anything but image files to be used as your desktop.
    I might suggest that you open the HTML fileof your choice in a browser, and take a screen shot of the output. Then you can assign that screen shot to be your desktop.
    Command-shift-4 will give you a crosshair cursor to drag around the area you wish to capture.

  • HTML editing with JEditorPane - HTMLEditorKit actions

    I am trying to make a component that will allow the user to edit styled text, use some buttons to change text properties - font/color settings, allow him to insert tables and so on.
    From reading through the Swing tutorial and searching around I came to a conclusion that JEditorPane(or JTextPane - I haven't chosen one yet) is the component I must use. I intend to use HTMLEditorKit with it. What worries me are some fields in HTMLEditorKit - some public static String members that are documented as action identifiers(like FONT_CHANGE_BIGGER, FONT_CHANGE_SMALLER...).
    How to use those actions? I saw an example from O'Reilly 'Java Swing' book where they took the actions out of the editorPane's action map, but I could not find actions with names like above in the ActionMap of the JTextPane after I installed HTMLEditorKit /calling setEditorKit(new HTMLEditorKit())/.
    I also want to know how to insert tables and stuff like this. I think I must use HTMLEditorKit.InsertHTMLTextAction class and pass it HTMLEditorKit.INSERT_TABLE_HTML, but I am not sure this is the way to go.
    Can someone lead me to a good resource where I can better understand the details about using the actions of the HTMLEditorKit?
    Thank you for your time
    Mike

    .

  • Filting html tags, css, and javascript with regex

    hi everyone,
    im writing a small application where a user types in a url, and the text of the webpage is displayed in a text area.
    ive got it to work, however it takes some time, and also alot of content i dont want is displayed - tags, scripts and sometimes css.
    initally i filtered out the html tags with a regular expression, but i still get alot of unwanted content.
    im not a confident java programmer, and the idea of parsing html, css and javascript is the scariest idea ever to me, so my next idea is to keep only everything between the <body> tags - everything above and below it is deleted - hopefully that should leave me only with the visible content on the site.
    ive messed around with regular expressions but i cant get it to work, can anyone help out?
    thanks alot,
    Torre

    Darryl.Burke wrote:
    I tried out the regexes I posted on the source of a forum page, which is not valid html (contains two each opening and closing body tags). With a bit of trial and error I was able to remove everything upto the first, and not the second, opening tag by using a reluctant qualifier, ^.*?, but couldn't for the life of me achieve removal of only the last closing tag, leaving the other, invalid one intact. How would you do that?Regexes always try to match the first occurrence of whatever they're looking for (the sentinel), and there's no way to change that behavior (but it would be handy if you could). What you have to do instead is make sure the rest of the regex can't match the sentinel. For that you need lookahead, and the simplest way to use it is to scan the rest of the text looking for the sentinel and, if it doesn't find one, go ahead and gobble up the remaining text: "(?is)</body>(?!.*</body).*$" However, if there are many occurrences of the sentinel, you could take a serious performance hit. Here's a much more efficient way: "(?is)</body>(?:[^<]++|<(?!/body>))*+$" After matching the sentinel, this regex gobbles up anything that's not the first character of the sentinel, or the first character as long as it isn't followed by the remaining characters of the sentinel. The advantages of this regex are that it never has to backtrack, and the lookahead is only applied when it's necessary, where the first regex applies it every time.

Maybe you are looking for

  • Function Based Index and ORA-01450

    The following DDL produces ORA-01450 (maximum key length (758) exceeded) : create index test_fn_ix1 on ausv_int_acc (test_package.test_function(intacc_username)); Here's the package : create or replace package test_package is function test_function (

  • ABAP Unicode issue...

    ABAP gurus, We are in the process of upgrading our SAP from 4.6C to ECC 6.0. I am trying to pass some of the programs from UCCHECK. I got following exceptions: "XK_HEX00" must be a character-type data object (data type C, N, D, T or STRING) "XK_HEX09

  • My iMac freezes up intermittly

    Just got a replacement hard drive and now it is freezing intermitenly.  Any ideas?

  • Subfolders in Map Files and Baggage?

    Using Robo 6 to create webhelp. This is one of many issues I'm seeing since inheriting this help project that had not been updated in 2+ years. Today's question is, why are the topic folder names that I use to organize my content being re-created und

  • Cvirte.dll and Windows Vista

    Hi everyone, I used to have .DLL compled in LabView 7.1 that worked just fine in Windows XP. Now, I have rebuild it for Windows Vista. I have installed LabView RuntimeEngine 8.51. It's not working. Can you point out why?!  However I was wondering wha