How do I modify a Html tag attribute?

Hi.
I tryed to modify the witdth and height attributes of <applet> tag but I have not obtained it. I run this:
import java.io.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax.swing.text.html.parser.*;
class OtraPrueba{
     public static void main(String[] args){
          String infile = "c:\\Page1.htm";
          String outfile = "c:\\outPage1.htm";
          String applethtml = "<applet code=\"class1.class\" codebase=\"v_10\" width=\"100\" height=\"100\" archive=\"class1.zip\"";
          Reader r;
          Writer w;
          HTMLDocument htmldoc;
          HTMLEditorKit kit = new HTMLEditorKit();
          HTMLEditorKit.ParserCallback callback =          
               new HTMLEditorKit.ParserCallback(){
                    public void handleText(char[] data, int pos){
                         for(int i=0;i<data.length;i++)
                              System.out.println ("data[" + i + "]" + data);
                    public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos){
     System.out.println ("handleStartTag " + t);
     if (t == HTML.Tag.APPLET){
          a.removeAttribute(HTML.Attribute.WIDTH);
          a.addAttribute(HTML.Attribute.WIDTH, "100");
          try{
               r = new FileReader(infile);
               w = new FileWriter(outfile);
               System.out.println ("antes del parser");
               new ParserDelegator().parse(r, callback, false);               
Can you help me?
Thanks.

Hello uhilger.
I do it what you tell me last week but I get a NullPointerException at write the document extends HTMLDocument. It seems tries to write a empty tag. this is the exception text:
_______________________exception text_____________________________
java.lang.NullPointerException
at javax.swing.text.AbstractWriter.write(AbstractWriter.java:489)
at javax.swing.text.html.HTMLWriter.emptyTag(HTMLWriter.java:315)
at javax.swing.text.html.HTMLWriter.write(HTMLWriter.java:187)
at javax.swing.text.html.HTMLEditorKit.write(HTMLEditorKit.java:289)
at Editor.setAppletAttributes(Editor.java:1017)
at Editor.saveMenuItemActionPerformed(Editor.java:535)
at Editor.access$13(Editor.java:24)
at Editor$14.actionPerformed(Editor.java:421)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
67)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
ctButton.java:1820)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:419)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257
at javax.swing.AbstractButton.doClick(AbstractButton.java:289)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1
092)
at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseRelease
d(BasicMenuItemUI.java:932)
at java.awt.Component.processMouseEvent(Component.java:5021)
at java.awt.Component.processEvent(Component.java:4818)
at java.awt.Container.processEvent(Container.java:1380)
at java.awt.Component.dispatchEventImpl(Component.java:3526)
at java.awt.Container.dispatchEventImpl(Container.java:1437)
at java.awt.Component.dispatchEvent(Component.java:3367)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3214
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2929)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2859)
at java.awt.Container.dispatchEventImpl(Container.java:1423)
at java.awt.Window.dispatchEventImpl(Window.java:1566)
at java.awt.Component.dispatchEvent(Component.java:3367)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:190)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)
___________________end_exception text_____________________________
I make a subclass of HTMLDocument with name EditableHTMLDocument :
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.text.html.HTMLDocument;
class EditableHTMLDocument extends HTMLDocument{
     public void addAttributes(Element e, AttributeSet a) {
          if ((e != null) && (a != null)) {
               try {
                    writeLock();
                    System.out.println("SHTMLDocument addAttributes e=" + e);
                    System.out.println("SHTMLDocument addAttributes a=" + a);
                    int start = e.getStartOffset();
                    javax.swing.text.AbstractDocument.DefaultDocumentEvent changes =
                    new javax.swing.text.AbstractDocument.DefaultDocumentEvent(start, e.getEndOffset() - start,
                         DocumentEvent.EventType.CHANGE);
                    AttributeSet sCopy = a.copyAttributes();
                    MutableAttributeSet attr = (MutableAttributeSet) e.getAttributes();
                    changes.addEdit(new AttributeUndoableEdit(e, sCopy, false));
                    attr.addAttributes(a);
                    changes.end();
                    fireChangedUpdate(changes);
                    fireUndoableEditUpdate(new UndoableEditEvent(this, changes));
               }finally {
                    writeUnlock();
And this is the method of program main class than call you addAttributes method:
     private void setAppletAttributes(){
          BufferedReader br;
          BufferedWriter bw;
          HTMLDocument htmlDoc;
          EditableHTMLDocument editHtmlDoc;
          HTMLEditorKit kit = new HTMLEditorKit();
          try{          
               br = new BufferedReader( new FileReader( jTxtHtmlFile.getText() ) );
               //htmlDoc = (HTMLDocument)kit.createDefaultDocument ();
               editHtmlDoc = new EditableHTMLDocument();
               kit.read (br, editHtmlDoc, 0);
               br.close ();
               javax.swing.text.Element rootElem = editHtmlDoc.getDefaultRootElement ();
               javax.swing.text.Element elem =
                    editHtmlDoc.getElement (rootElem, HTML.Attribute.CODEBASE, jTxtCodebase.getText ());
               SimpleAttributeSet sas = new SimpleAttributeSet();
               sas.addAttribute ( HTML.Attribute.CODE, jTxtCode.getText () );
               sas.addAttribute ( HTML.Attribute.CODEBASE, jTxtCodebase.getText () );
               sas.addAttribute ( HTML.Attribute.ARCHIVE, jTxtArchive.getText () );
               sas.addAttribute ( HTML.Attribute.WIDTH, jTxtAnchoApplet.getText () );
               sas.addAttribute ( HTML.Attribute.HEIGHT, jTxtAltoApplet.getText () );
               editHtmlDoc.addAttributes (elem, sas);
               editHtmlDoc.dump (System.out);
               bw = new BufferedWriter( new FileWriter( jTxtHtmlFile.getText() ) );
               System.out.println ("length " + editHtmlDoc.getLength ());
               kit.write (bw, editHtmlDoc, 0, editHtmlDoc.getLength ());
               bw.flush ();
               bw.close ();
          }catch(BadLocationException ble){
               System.out.println ("BadLocationException " + ble.getMessage());     
}catch(FileNotFoundException fnfe){
               System.out.println ("FileNotFoundException " + fnfe.getMessage());     
          }catch(IOException ioe){
               System.out.println ("IOException " + ioe.getMessage());
Which you think that it is the problem?
Thank you.
Sergio Mart�n
I visited your great page and download your SimplyHTML. I'll probe later.

Similar Messages

  • Insert HTML.Tag attributes?

    Hey,
    How would I insert html attributes? I am making a HTML Editor.
    The following are some valid java html attributes. How would I insert it properly?
    HTML.Tag.P, HTML.Tag.BLOCKQUOTE, HTML.Tag.CENTER,
    HTML.Tag.CITE, HTML.Tag.CODE, HTML.Tag.H1, HTML.Tag.H2,
    HTML.Tag.H3, HTML.Tag.H4, HTML.Tag.H5, HTML.Tag.H6,
    HTML.Tag.PRE
    Like for example, to make text bold, you would do
    MutableAttributeSet attr = new SimpleAttributeSet();
    StyleConstants.setBold(attr, true);
    textpane.setCharacterAttributes(attr,false);
    Is there similar code like the one above to add HTML.Tags like the ones I listed above in my post?
    Thanks in advance

    Hi,
    sorry about the delay, couldn't find this thread last night.
    Useful docs:
    http://java.sun.com/products/jfc/tsc/articles/text/element_interface/index.html
    and
    http://java.sun.com/products/jfc/tsc/articles/text/attributes/
    Those methods are in javax.swing.text.html.HTMLDocument and take the form insertBeforeStart(Element, String). As I said yesterday, as soon as you have text then the caret is in a character Element and a Paragraph element. So for e.g. if you're in a P element and you want to create an H1 element, how do you do it? If the user clicks your H1 button then you create an empty heading, easy enough. But if they have some text selected then you have a choice. You could just create an empty H1 or you could assume that they have typed the H1 content and have highlighted it so that it becomes an H1. You then have to change the existing element so that is no longer has the (now H1) text in it.
    That's where the other two methods (setInnerHTML and setOuterHTML) come into play.
    The other problemette that I'm working on is reseting text back to normal after it has been formatted.
    Suppose you have a P paragraph. The user highlights a single word, clicks Bold. That's easy. Then they decide that they don't want it bold, so they click the Normal button. Taking bold off is easy, but should you. What if the paragraph element was actually an H1 element. If you turn bold off now then that word no longer matches the H1 style.
    You could check at the caret position just before the start of the element that the user has selected and see what the style is there. BUt then waht if the user has the word before perhaps underlined. Again it's unreliable.
    Also I'm finding then when I remove the bold formatting that the element isn't being reabsorbed into it's parent. In a paragraph if I go through and make each word formatted (B, i, u) and then switch the formatting off word at a time I end up with each word as an element.
    Still working on these, so I'll post a solution when I have one.
    regards
    sjl

  • How to get and set custom tag attributes

    How do i get and set custom tag attributes from a jsp page?

    Not sure if this is what your looking for, but....
    example...
    < taglibprefix:testtag attribute1="x" attribute2="y">
    ...of course, the attributes have to be defined in your taglib (.tld) file

  • How to put String with html tags as it is into xml

    I am using apache dom API to create xml from java.
    I have a string with html tags in it .when I add the string to xml, its replacing all the "<"; with &lt and ">" with > I would like the html tags to look as it is instead of the > and & lt;. How can I acheive that
    this is the code snippet of what I am doing
    In java class
    String titleString = "<font color=red>This Is an Example of a Red Subject</font>"
    Document doc = new DocumentImpl();
    Element root = doc.createElement("bulletin");
    Element item = doc.createElement("title");
    item.appendChild(doc.createTextNode(titleString));
    In Xml it looks like below
    <title><font color=red>This Is an Example of a Red Subject</font></title>
    but I would like to have the xml like below
    <title><font color="red">This Is an Example of a Red Subject</font></title>
    Can you please suggest me whats the best way to acheive this.
    I appreciate all your help
    Thank you
    Suma

    One problem is that you don't understand escaping. If you re-read what you posted you'll see that what you say you get, and what you say you want, are identical. That's because you didn't escape one of the two properly. So your first step should be to find the section about escaping in Chapter 1 of your XML book and read it carefully. Figure out what you should have done here (yes, the same rules apply).
    However, to attempt to answer what I think your question is: if you have a String which contains markup, and you want to convert that String to XML elements, then you have to feed the String into an XML parser.

  • How to remove HTML tags from a String ?

    Hello,
    How can I remove all HTML Tags from a String ?
    Would you please to give me a simple example ?
    Best regards,
    Eric

    Here's some code I cooked up. I have created an object that processes code so that it can be incorporated directly into a project. There is some redundancy so that the it can be used in more than one way. Depending on your situation you might have to make the condition statement a little more sophisticated to catch stray ">" tags.
    I have also included a Tester application.
    //This removes Html tags from a String either by submitting the String during construction and then
    // calling getProcessedString() or
    // by simply calling " stringwithoutTags=removeHtmlTags(stringWithTagsSubmission); "
    //Note: This code assumes that all"<" tags are accompanied by a ">" tag in the proper order.
    public class HtmlTagRemover
         private String stringSubmission,processedString,stringBeingProcessed;
         private int indexOfTagStart,indexOfTagEnd;
         public HtmlTagRemover()
         public HtmlTagRemover(String s)
              removeHtmlTags(s);          
         public String removeHtmlTags(String s)
              stringSubmission=s;
              stringBeingProcessed=stringSubmission;
              removeNextTag();
              return processedString;
         private void removeNextTag()
              checkForNextTag();
              while((!(indexOfTagStart==-1||indexOfTagEnd==-1))&<indexOfTagEnd)
                   removeTag();
                   checkForNextTag();
              processedString=stringBeingProcessed;
         private void checkForNextTag()
              indexOfTagStart=stringBeingProcessed.indexOf("<");
              indexOfTagEnd=stringBeingProcessed.indexOf(">");
         private void removeTag()
              StringBuffer sb=new StringBuffer("");
              sb.append(stringBeingProcessed);
              sb.delete(indexOfTagStart,indexOfTagEnd+1);
              stringBeingProcessed=sb.toString();
         public String getProcessedString()
              return processedString;
         public String getLastStringSubmission()
              return stringSubmission;
    public class HtmlRemovalTester
         static void main(String[] args)
              String output;
              HtmlTagRemover h=new HtmlTagRemover();
              output="The processed String: "+h.removeHtmlTags("<Html tag>This is a test<another Html tag> string<yet another Html tag>.");
              output=output+"\n"+" The original string:"+h.getLastStringSubmission();
              System.out.print(output);

  • 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

  • Help needed in adding effects of certain HTML tags in Flex spark Richtext

    I want to apply the effects of the following HTML tags/ attributes, in my HTML text rendered in Flex Spark Richtext Component.
    Superscript - <sup>
    Subscript - <sub>
    Blockquotes - <blockquotes>
    Ordered Lists - <ol><li>
    Unordered List - <ul><li>
    Horizontal Rule - <hr>
    Direction Attribute for <p> - <p dir="rtl">Hello</p>
    Background Color for <font>
    I have observed that the above tags have no effect in RichText. Is this a limitation?
    Any solutions, tweaks and tricks will be appreciated...
    Thanks,
    Mangirish

    check this out . this should be able to answer you question.
    http://livedocs.adobe.com/flex/3/html/help.html?content=textcontrols_04.html
    Miguel

  • HTML tags in RTF--- Urgent pls help

    i have a field in answers with the name comments which returns the data in html tags like <~a>abcd <~/a>, it has to dispaly as a link but it is displying as <~a>abcd</~a>
    the same with html tags in it... how can i parse the HTML tags in BI publisher, can any one help me here pls
    pls remove the ~ code as it is not displaying those HTML tags in forum
    Edited by: user10744081 on Feb 5, 2010 9:48 PM
    Edited by: user10744081 on Feb 5, 2010 9:49 PM

    Hi Experts,
    to be precise, i have a column in my oracle DB has XHTML tags as a data in it, when i use this column in BIP report i am getting tha XHTML tags as my data in my output.how can i parse those and get only the required data to be displayed in RTF ?
    Any update on this? i am out of ideas on this.. can any one help me on this

  • HTML Tags search using TREX

    Hi All,
    Using following 2 documents I had tried to configure TREX to search HLTM tags. After following all the steps when I tired to search I don't get any results.
    1) How to set up web repository and crawling it for indexing.pdf
    2) How-to-guide for searchable HTML tags.pdf
    Any buddies please help?
    Thanks in advance.
    Mahesh

    Hi Suman,
    I am Manu's Colleague. We have the Hierarchy of Objects like this.
    Cubes --> Multiprovider -- > Aggregation level.
    We had two tranport requests one for the Planning objects Including Aggregation levels and the other for data model objects including cubes , DSO's and multiproviders. All deletion Requests.
    We moved the First transport request to production and we checked using Normal Find objectsand found no results for the aggregation Levels.We assumed all the objects were deleted.
    Then we moved the Datamodel transport request to Quasltiy and it failed stating that the Multiproviders are used in Aggregation Level. (this happened in Q)
    Then when we checked the aggreation Level in Planning Modeller we found it in there (this in both Q and P) and not in RSA1 transaction until we used TREX to retreive the result. (This in P as we dont have TREX in D and Q systems)
    This is the issues and beacuse of this we are not able to delete the Data models in the system.
    Thanks for all your previous replies and will be helpful if you have any idea ont his.
    Regards.
    Shafi.

  • Storing HTML TAG content in StringBuffer Problem..

    respected sir...
    currently i am working with one project in that i want to put whole table content in StringBuffer that goes for image creation .....and finally image is created for whole table
    how can i put the HTML tags in imageBuffer.... i have tried with this...
    StringBuffer ImageContent=new StringBuffer();
    ImageContent.append(out.print("<table>"));
    ImageContent.append(out.print("</table>"));
    ImageContent.append(out.print("<tr>"));
    ImageContent.append(out.print("</tr>"));
    but not working is there any way to build table using StringBuffer that has whole Table Content With Data....
    thanks in advance......regards.....

    Hi.
    Some remarks (no offence though...):
    1) StringBuffer is synchronized. In case your object instance will not be used by other threads concurrently, you should use StringBuilder class instead (which offers the same methods)
    2) when posting code samples, formatting them as code makes them easier for others to read
    3) variable names are written with a lower case first letter by convention
    4) shouldn't the "tr"s be between the opening and the closing "table"-tags?
    5) it would be helpful to have an indication on what type "out" is and why you are using it...
    For your problem: why do you pass your Strings to "out.print()"? StringBuffer directly takes Strings as arguments (among others).
    Without having tried your sample, I would suggest you try somthing like the following:
    StringBuffer imageContent=new StringBuffer();
    imageContent.append("<table>");
    imageContent.append("<tr>");
    imageContent.append("</tr>");
    imageContent.append("</table>");Bye.

  • Remove HTML tags in text

    Hi,
    I have to read some text from a text editor, that can be formatted for example with Bold, which means that when I execute the function to read its content, it returns something like this:
    Do you know how can I remove these HTML tags from the text?
    Thanks in advance.
    Regards,
    Sónia Gonçalves

    Hi,
    Something like this should do the trick.
    report  ztag.
    data: v_data type char30 value '<H>blablabla</H>'.
    if v_data(1) = '<' and
      v_data cs '>'.
    * Remove the HTML opening header
      shift v_data left up to '>'.
      shift v_data left.
    * Remove the HTML closing header
      shift v_data right up to '<'.
      shift v_data right.
      shift v_data left deleting leading space.
    endif.
    write: / v_data.
    Regards,
    Darren

  • Oracle Reports: Print HTML tags

    I am reading data from DB that contains HTML tags and would like the tags to be interpreted when the PDF report is displayed. Currently, the HTML tags are being displayed in the report.
    When I output the report as a HTML is tags are interpreted and looks ok.
    How do I convert the HTML tags in the report is displayed as PDF?
    Thanks for your response.

    Ramakrishnan Srinivasan (guest) wrote:
    : I have a requirement to transport a print file created by
    Oracle
    : Reports to a print shop and print the document at this
    facility.
    : I know the type of printer this shop has.
    : The print file I like to create is a Form Letter. I will like
    to
    : know how to achieve this using Oracle Reports.
    : The letter I like to print is a standard letter with some
    custom
    : information on it. I will also like to know if I can create a
    : file consisting of Name, address and other specific information
    : that I want in the letter and merge it at the other end with
    : Word/Word perfect Letter using a WINDOWS 95 supplied batch
    : program.
    : Any other feasible solutions are also welcome.
    : Ram
    Hi Ram,
    You can create a postscript file or a PDF file and give that
    to the print shop for printing. It's pretty easy. Go to the File
    menu, choose Generate to File, and then choose Postscript or PDF.
    Note that Reports will use the driver for the printer to which
    you are connected at the time you generate the file. You may have
    to do some tests to make sure that that printer driver is
    compatible with that of the print shop. I would generate a test
    file from Reports and see if it works with their printer.
    Regards
    The Oracle Reports Team
    null

  • How to get the "link" HTML.attribute

    What are the HTML.attribute that could contain a link ?
    The most common are
    HREF and
    SRC
    but there are too : ACTION, BGCOLOR ...
    and attribute that doesn't contain links like width ...
    Is there anyway to know the attributes that can contain links, or if someone knows the full list.
    Thanks

    Hmm.. got your meaning.. maybe its kind of weird to say but how about trying to see which similiar html tags can = "url" ? If the similiar html tags can, sure can the attribute.
    Just my cents..

  • Why there is a difference in a "class" attribute value of html tag when viewed in "Page Source" and using "Inspector", I am refering to new Microsoft site?

    While inspecting the new Microsoft site source, I observed that the "class" attribute value of the "html" tag when seen in Page Source the value given by Tools/Web Developer/Inspect tool. Value with the tool indicates class="en-in js no-flexbox canvas no-touch backgroundsize cssanimations csstransforms csstransforms3d csstransitions fontface video audio svg inlinesvg" while that is given in Page Source is class="en-us no-js"
    The question is why different values are shown?

    Inspector is showing you the source after it's been modified by Javascript and such.
    To see the same thing in the source viewer, press '''Ctrl+A''' to select everything on the page, then right-click the selection and choose '''View Selection Source'''.

  • How to add html tag in c:set value

    If i put the html tag around, like this <c:set var="test" value="This is a <b>nice</b> page." /> , the <c:out value="${test}" /> will print the bold tag around "nice" . How to get the actually string "nice" to be bold instead? Thank you!

    Set the 'escapeXml' attribute of c:out to false so that it doesn't escape XML (and so also HTML) entities.

Maybe you are looking for

  • Lock ups and sound looping!

    I remember reading something here about people having trouble with their systems locking up and then getting a loud static noise then a sound loop when playing games.    I am getting this about 2-3 times a night now and it is driving me nuts, I do no

  • How can I put current date and time in Photo Info (Print module)?

    I often use the Photo Info option in the Print Module to caption my proofs with File Number plus the date and time the print is made.  This allows me to match up the print to the History state for the image, so I know which print version I'm looking

  • Document not opening in /sap/bc/contentserver

    I am having this issue when i try to to to open the document which i stored "/sap/bc/contentserver" , it takes me to a webpage. here is the detail. 1. Able to check in the Document 2. Initially when i clicked the document i was getting this error "/s

  • Why does iPhoto keep asking me to confirm faces after they are already confirmed?

    Why does iPhoto keep asking me to confirm faces after they are already confirmed? Once it searches for photos containing (insert name) and says "(insert name) maybe found in 1,750 photos". I click to confirm the said person and it highlights the phot

  • Summing specified elements in 2D array.

    Hi! I have a little problem with summing elements in 2D array- I have signal from 64 sources in the 2D array - 64 colums and (time*sampling) rows. I have to add some deley to every signal (different for each)  and then sum signals from all of the sou