Replacing HTML tags using HTMLEditorKit etc.
Hi
Not sure if this is the best place to ask this. I've searched without finding much.
Basically I am trying to create a HTML template system for output. User's can change the templates to change the program output.
The templates are basic HTML with custom tags inserted, that reside in a templates directory. For example, a simple template might be:
<html><body>
<table width="100%"><tr><td width="25%">Here is the output:</td>
<td> <insertOutputHere> </td>
</tr></table>
</body></html>
^^ Users would be able to edit these template .htm files to affect the output .htm files. For instance, changing where the <insertOutputHere> tag is, or formatting the table it is output to.
I am using the Swing HTMLDocument, HTMLWriter, HTMLEditorKit classes to load and parse the .htm files, iterate the tags and replace any custom tags (defined in code) with the program output. I have been able to locate these custom tags no problem, but I don't know how to replace this tag entirely with my output (Which will be formatted HTML string). I have been trying to use the insertBefore, insertAfter methods with limited success. In particular I have an 'include' custom tag which includes other files by recursion - it works except the <include> tag is not removed, and depending on which insert method I use, it usually goes into an infinite loop of parsing the <include> tag WITHOUT removing it, then picking it up again when its done.
Basically I'm looking for any advice as to how to go about COMPLETELY REPLACING these tags with a well structured HTML string. I can post some code if need be but I barely comprehend what I've done, LOL.
TIA
I've looked over my mess of comments :)
setOuterHTML is what I was previously using and it was quite unpredictable at times, as far as I could tell it is very strict with it's requirements for structured HTML (EG no floating line breaks, everything must be "paragraph-ised" which b0rks up the layout) and I can't rely on anyone using/extending these classes to write well structured HTML.
I remember the problems being quite odd, such as the output for one custom tag being displayed twice for some and not at all for others, and while it isn't critical data, it was still displayed in a way that it could be interpreted as correct - I just knew it wasn't.
So I dropped setOuterHTML to try insertAfterEnd - this leaves the tags in there and, like roughly explained above, it would pick up tags infinitely because they were not being replaced.
Here is a relevant method to give a better idea of what I've done:
public HTMLDocument parseHTMLfile(String filename, Custom_HTML_Tag tags[]) {
//create a document
HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
fileDepth++;
try {
//read in the file
BufferedReader rd = new BufferedReader(new FileReader(filename));
kit.read(rd, doc, 0);
if (tags != null) {
//replace tags with page content
ElementIterator it = new ElementIterator(doc);
Element e;
while ((e = it.next()) != null) {
//look for includes
if (e.getName().equals("include")) {
if (fileDepth >= 5){
//WARNING:
System.out.println("fileDepth has reached 5, include may be recursive. aborting.");
continue;
String href = (String)e.getAttributes().getAttribute(HTML.Attribute.HREF);
//grab parent of current file (IE the folder in which it sits)
File f = new File(filename);
String include = f.getParent() + sep + href;
f = new File(include);
if (f.exists()) {
HTMLDocument htmld = parseHTMLfile(include, tags);
StringWriter sw = new StringWriter();
HTMLWriter w = new HTMLWriter(sw, htmld);
w.write();
doc.setOuterHTML(e, sw.toString());
else {
//couldnt find include file - warning
for (int i=0; i < tags.length; i++) {
if (e.getName().equals(tags.getName())) {
//doc.setOuterHTML(e, tags[i].getText());
doc.insertAfterEnd(e, tags[i].getText());
//System.out.println("found tag: " + tags[i].getName() + ": " + tags[i].getText());
catch (BadLocationException ble) {// cant happen?
System.err.println("ERROR (" + 999 + "): Could not parse document " + filename + "; BadLocationException");
System.err.println(ble);
catch (FileNotFoundException fnf) {
System.err.println("ERROR (" + 999 + "): Could not parse document " + filename + "; File not found");
//System.err.println(fnf);
catch (IOException ioe) {
System.err.println("ERROR (" + 999 + "): Could not parse document " + filename + "; I/O Error:");
System.err.println(ioe);
fileDepth--;
return doc;
setInnerHTML kills it with the 'Can not set inner HTML of a leaf' error
Thanks
Similar Messages
-
APEX 3.1 replaces HTML tags in error message automatically
Hello!
I have a problem: we use sometimes HTML links or even JavaScript in error messages. In older versions of APEX it works, but now we upgraded to 3.1 and in all those messages HTML tags are replaced so instead of link we get a plain HTML in a message.
Are there any possibilities to turn this option off or what can we do to solve this problem?
Regards,
MaksimIn a page process we use raise_application_error(-20547, 'Go to GOOGLE') and in a Process Error Message
we use constuction Error: #SQLERRM#. Then on an standard error page we see instead of Error: Go to Google html source. Thats it. In template in Error Page Template Control section we use substitution #MESSAGE# -
How to change inner content of HTML tag using HTMLDocument?
I want to change the inner content of an HTML tag from a HTMLDocument. The tag is like
<span id ="id1">Replace me</span>.
So I want to change the text "Replace me" inside the span tag and replace it with an other text.
I can get the span element using
HTMLDocument.getElement("id1")
I have tried many things with the Element instance i got from getElement. But I find no way to change the inner content of the HTML element. Any ideas?If I use JDK 1.5 the SPAN tag works, so I checked the core of the problem which is inserting HTML code in an HTML tag.
setInnerHTML works fine for block tags like DIV but not if the tag is a leaf element like the SPAN tag. I have tried to use the following code for leaf elements:
Element elem = m_htmlDocument.getElement(id);
int nStartOffest = elem.getStartOffset();
int nEndOffset = elem.getEndOffset();
int nLength = nEndOffset - nStartOffest;
m_htmlDocument.replace(nStartOffest, nLength, html, elem.getAttributes());
This works, but only if the new HTML string does not contain HTML tags like a link <href..... >. If the string contains HTML tags the replace method masks all characters like < or >. So the link is not shown as link in the HTML page but as HTML text.
The next thing I have tried is using
m_htmlDocument.setOuterHTML(elem, html);
This works too but it replaces the whole original HTML element like the SPAN tag.
So there is still the question how to insert HTML text into a leaf Element in a HTMLDocument. -
Hi All,
I've requirement that I need to replace the html tags in RTE, I checked find and replace plugin, which only replace the text not the tags. The CQ.form.rte.SearchableDocument returns the plain text. Can anybody tell me how to replace the tags?, is there any existing plugin's available ?
Thanks in advance
GaneshHi Ganesh,
You can configure the rich text editor to use semantic markup, so that the bold=strong and italic=em will be modified in the html out. Not sure it applies for other tags. Give a try.
http://forums.adobe.com/message/4652639#4652639
Thanks,
Sham -
Replacing html tags in a htmldocument
Hi Java Gurus
I have a htmldocument which has the bacjground set to black and foreground to white.
When i print the document i see the text in white color ( rather invisible).
I thought the foreground color of the document needs to be changed.
How can i do this ?
Thanks in advance
Naveenrest_in_peace wrote:
You'll get a faster, more effective response to your questions by including as much relevant information as possible upfront. This should include:
<li>Full APEX version
<li>Full DB version and edition
<li>Web server architecture (EPG, OHS or APEX listener)
<li>Browser(s) and version(s) used
<li>Theme
<li>Template(s)
<li>Region/item type(s)
Read the FAQ and forum sticky threads for more information on using the forum effectively.
With APEX we're fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues.
I have created a form on a table. Now one of the fields in the form is a display only field and its datatype is varchar2.There are a number of different ways of "creating a form on a table" and of making "display only fields". Describe exactly what you mean using actual APEX terminology of regions, items, and their attributes.
The data in the database column of the field contains html tags which is getting displayed as it is without being parsed. It is not possible for me to edit the data in the table itself since there are thousands of data. So I need a way to display the data with the html tags parsed and not displayed as it is. Please any help would be grealy appreciated. How this is achieved is version-dependent: provide the full APEX version. -
Replace HTML tags within column values
Hi Gurus,
I have a requirement where I have some text which has HTML tags inserted within it and I need to insert either Presentation variable or a GO URL replacing that tag. Problem is that this text is value of a column from table. It is not something which I type( because the text can change dynamically). e.g
Column header: Main Text
Row1: <<COMPANY_NAME>>
Row2: As of <<AF_OF_DATE>>
instead of <<COMPANY_NAME>> and <<AS_OF_DATE>>, I need to insert amounts from another table which have this unique tags and associated amounts. Can this be done?
I have to these columns in different places throughout the report in narrative views. e.g
1st narrative view will have only column 1 and row 1 and row 2.. 2nd narrative view will have only column 3 and row1...
This is really really important part of a report. So please help me out with ideas.
Thanks,
DanI tried calling the column in a narrative view and the result looks like :
As of <<AS_OF_DATE>>. how can I replace "<<AS_OF_DATE>>" with a value? -
Html tags using javax.jws.WebService
Hi,
I am using javax.jws.WebService and I met a problem for html tags.
In a String containing "<" and ">", the javax.jws.WebService implmentation of IBM transfered the String with "<" and ">" in the XML reply. How could this translation be avoided?
Regards.
PengyouThe XML content in the soap request looks like this:
<myXml>
<tagWithCdata><![CDATA[<test>123</test>]]></tagWithCdata>
</myXml> The String "tagWithCdata" in the Java object looks like this: "<test>123</test>"
And the marshalled XML in the soap response looks like this:
<myXml>
<tagWithCdata><test>123<test></tagWithCdata>
</myXml>But I expect to have the same format as the soap request, i.e.
<myXml>
<tagWithCdata><![CDATA[<test>123</test>]]></tagWithCdata>
</myXml> -
Search and Replace XML TAG using JAVA
Hi All,
I have an XML file, say RESULT.XML Which has about 30000 Lines (yes Thirty Thousand ). For some reason i need to replace an existing tag with a different tag(not the value inside the tag, But the tag itself) . I am facing a challenge. I will explain it as below.
I have a csv file which has 2 values as given below
<VALUE A> , <VALUE B>
where <VALUE A> is an existing node in the RESULT.XML and <VALUE B> is the node that should replace <VALUE A> in the RESULT.XML
i have 500 such entries in the file.
Now i need to write a program to read the csv file, Search <VALUE A> in the RESULT.XML and Replace it with <VALUE B> of the csv file.
please let me know how do i start with this.
I really want to fix this issue.
Existing Node = <Product ID="role (contact) 3" UserTypeID="Product Number">_
To be changed to = <Product ID= role (contact)3" UserTypeID="Product Number">_
please reply if you need any further information
Thanks in Advance
ManzoorSounds like a job for XSLT or Perl not Java though it can be done in Java. In Java I would initially try
1) Read the csv file using one of the many free CSV parsers and build a Map<String,String>.
2) Create a Rewriter using the map keys as targets and use the map values as replacements.
3) Read the XML file line by line and process each line with the Rewriter.
4) Save each line to an output file.
For a one-off task this would probably serve but it could prove very slow if you need to run this on a daily basis. -
How to use Microsoft Word's Find and Replace with HTML tags?
Hello to all!
I'm trying to figure out how to use the find and replace function in Word to replace html tags. I'd like to be able to change something like this:
<span class="B01-K-ITAL">random text</span>
To something like this:
<em>random text</em>
I want to replace the open and close tags without changing or interfering with the text between the tags. I'm pretty sure I should use wildcards, but I can't figure out how to use them properly.
Anyone able to lend a hand?Here is my latest regular expression with Perl. I think it matches the spirit of the request in the original post.
Note, this isn't as easy as you think. You need to code up the complete set of html rules in you implementation. You need to allow for a certain amount of mal-formed html.
perl -0660pe 's^<[sS][pP][aA][nN]\s+class="B01-K-ITAL"\s*>(.*?)</[sS][pP][aA][nN]>^<em>$1</em>^gs' i.html >|o.html
input text
<html> <head>...</head> <body>I'd like to be able to change something like this: <span class="B01-K-ITAL">#1 one line</span> I want to replace the open and close tags without changing or interfering with the text between the tags. I'm pretty sure I should use wildcards, but I can't figure out how to use them properly. <p>note, this isn't as easy as you think. You need to code up the complete set of html rules in you implementation. You need to allow for a certain amount of mal-formed html.</p> <span class="B01-K-ITAL">#2 don't be greedy</span> <span class="B01-K-ITAL">$3 multiline text</span> <span class="B01-K-ITAL">#4 multiline tag. I believe html allow a carriage return in white space of tags</span> <span class="B01-K-ITAL">#5 split after the class tag. optional white space</span> <sPan class="B01-K-ITAL">#6 mixed case tag</Span> <p>no text #7</p><span class="B01-K-ITAL"></span> <!-- Apparently, this is valid http://www.positioniseverything.net/articles/cc-plus.html --> <!--[if IE]> <div id="IEroot"> <![endif]--> <p id="IE">This browser is IE.</p> <p id="notIE">This browser is not IE.</p><!--[if IE]> </div> <![endif]--></body> </html>
output text
<html> <head>...</head> <body>I'd like to be able to change something like this: <em>#1 one line</em> I want to replace the open and close tags without changing or interfering with the text between the tags. I'm pretty sure I should use wildcards, but I can't figure out how to use them properly. <p>note, this isn't as easy as you think. You need to code up the complete set of html rules in you implementation. You need to allow for a certain amount of mal-formed html.</p> <em>#2 don't be greedy</em> <em>$3 multiline text</em> <em>#4 multiline tag. I believe html allow a carriage return in white space of tags</em> <em>#5 split after the class tag. optional white space</em> <em>#6 mixed case tag</em> <p>no text #7</p><em></em> <!-- Apparently, this is valid http://www.positioniseverything.net/articles/cc-plus.html --> <!--[if IE]> <div id="IEroot"> <![endif]--> <p id="IE">This browser is IE.</p> <p id="notIE">This browser is not IE.</p><!--[if IE]> </div> <![endif]--></body> </html> -
How to Read a program with HTML tags from SO10
Hi All,
I have a html program in Standard text (SO10).But when I am trying read the program content using FM: READ_TEXT, the html tags <b> </p> etc are creating problem.
They are retrieved as <(><<)>b>.
What should we do to get same/original text as in SO10? Is there any other FM for that? Any other way to achieve this?
Thanks & Regards,
Vimalan Ramhere is the code sample.
after reading the text using READ_TEXT you have to use CONVERT_ITF_TO_ASCII to convert the contents.
DATA: itf_tab TYPE STANDARD TABLE OF tline ,
wa_itf TYPE tline .
DATA: c_datatab TYPE tdtab_c132 .
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = 'ST'
language = sy-langu
name = 'Y_RAJA_HTML'
object = 'TEXT'
* ARCHIVE_HANDLE = 0
* LOCAL_CAT = ' '
* IMPORTING
* HEADER = HEADER
TABLES
lines = itf_tab
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'CONVERT_ITF_TO_ASCII'
EXPORTING
* CODEPAGE = '0000'
* FORMATWIDTH = 72
language = sy-langu
tabletype = 'ASC'
* TAB_SUBSTITUTE = ' '
* LF_SUBSTITUTE = ' '
* REPLACE_SYMBOLS = 'X'
* REPLACE_SAPCHARS = 'X'
IMPORTING
* FORMATWIDTH_E = FORMATWIDTH_E
* X_DATATAB = X_DATATAB
c_datatab = c_datatab
* X_SIZE = X_SIZE
TABLES
itf_lines = itf_tab
EXCEPTIONS
invalid_tabletype = 1
OTHERS = 2
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Regards
Raja
Message was edited by: Durairaj Athavan Raja -
Displaying content in JSP page, want BR but not other Html tags
I have a page and am reading files and displaying the contents of the files onto the page in a <div> Oneissue is that in the file the end of line are \n or \r\n whichever operation system. I replaced those with <BR> no problem. Now my issue is that I display that in the JSP page:
<c:out value="${filecontents}" escapeXml="false" />I use escapeXml so that <BR> will add the line breaks. Now my issue is that the file might contains other HTML tags that I want to display simply as text - I don't want the browser to render the other HTML tags.
Is there a way to do that? Would I have to replace HTML tags with something special?Hmm... your file contains HTML tags, but you don't want the browser to interpret them as HTML tags, right? So the way to do that is to use escapeXml="true" in your c:out element.
But then that also escapes the <BR> tags that you carefully put in there. And you don't want that. You want the browser to interpret those as HTML tags.
I guess you can't have it both ways. Can you do something like outputting one line of the file at a time with <c:out ... escapeXml="true"> followed by <br>? -
Hi Forum ,
I need to do cleanup on a column to display clean data by eliminating the various <HTML> in the source. I would like to do a replace using the charindex, but my query becomes too big and i might miss some tags. What would be the best approach removing
the <tags> or formating them to display in correct format? .
Please give me some example if we can format data according to the tags using SSIS components.
<p><font face="Times New Roman"><span style="font-size: 11pt; ">DAVID BACKER, JR
</span><span style="font-size: 11pt; color: navy; ">L
</span></font><span style="font-size: 11pt; ">
<font face="Times New Roman"> 11111 Erwin 185th Ter <br />Jersey Gardens, NJ 10156/* Microsoft SQL Server Integration Services Script Component
* Write scripts using Microsoft Visual C# 2008.
* ScriptMain is the entry point class of the script.*/
// C# code
using System;
using System.Data;
using System.Text.RegularExpressions; // Added
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
// Method that will be executed for each row.
public override void Input0_ProcessInputRow(Input0Buffer Row)
// Replace the value of the message column
Row.Notes = RemoveHtml(Row.Notes).Replace(" ", " ")
.Replace("&", " ").Replace("-->", "
").Replace(""", "\"")
.Replace("<", "<").Replace(":
YES", ": YES ").Replace(": NO", ": NO ");
// A string method that removes html tags
// with a regex pattern
public String RemoveHtml(String message)
// The pattern for a html tag
String htmlTagPattern = "<(.|\n)+?>";
/// ///"<(.|\n)+?>"
/// ///"(?<=<[^>]*) "
// Create a regex object with the pattern
Regex objRegExp = new Regex(htmlTagPattern);
// Replace html tag by an empty string
message = objRegExp.Replace(message, String.Empty);
// Return the message without html tags
return message;
Ntext Source DataType
I convert the columns to convert(varchar(max),jr.NOTES) as Notes -
Using robohelp 10 on win 7
Is there a way to change or set the HTML tag used by WYSIWYG "formatting" toolbar?
For example, when i click "bold" using the formatting toolbar it creates a span tag <span style="font-weight: bold;">
instead of simply using <b> tag.
I would like to change this attribute so the <b> tag is applied instead of <span>.Hi there
Sorry, but no way I'm aware of to influence this behavior.
Cheers... Rick -
How to embed image in html when using JTextPane, HTMLEditorKit, JavaMail
I am developing a specialized e-mail client that has to be able to send e-mail messages (in html format with images and attachments) that can be read by standard e-mail clients, and receive similar messages from standard e-mail clients.
I have everything working except for embedding images.
Images are to appear in the document mixed in with the text, but that's not what I mean by "embed". By "embed" I mean that the image itself is encoded within the html.
Here's a bit of code to set the context.
JTextPane bodyPane = new JTextPane();
bodyPane.setEditorKit(htmlEditorKit);
bodyPane.setTransferHandler(new DropHandler());
bodyPane.setDocument(new HTMLDocument());
In the DropHandler I have the following:
HTMLDocument htmlDoc = (HTMLDocument) bodyPane.getDocument();
HTMLEditorKit htmlKit = (HTMLEditorKit) bodyPane.getEditorKit();
int caretPos = bodyPane.getCaretPosition();
At this point get "filename", the full path to an image file that has been dropped onto bodyPane.
String htmlString = "<img src=\"file:///" + filename.replace("\\","/") + "\">";
htmlKit.insertHTML(htmlDoc, caretPos, htmlString, 0, 0, HTML.Tag.IMG);
This works just fine. The image is displayed in the document at the point of insertion.
However, the image itself is an external file. I need to send an e-mail with this image and could send the image file as an attachment, but I obviously can't assume that the recipient of the email is going to save the attachment into the proper location.
What is the best way to do this?
There is a technique for embedding the actual image in the html, using this syntax:
String htmlString = "<a href=\"data:image/png;base64,---mimed png image here--\" alt=\"Red dot\"></a>";
I can't get this to work in JTextPane, so perhaps it's not supported. Also, there may be limitations on the size of an image. And apparently Internet Explorer doesn't support this.
From what I read, using a "content identifier", that is, "cid:" and adding the image as another part of the e-mail message is probably the thing to do. I haven't taken the time to explore this yet.
Does JTextPane support cid? Is that a nonsense question? I suspect what I need to do when the message is being composed is use absolute paths to local files with the images, and then when assembling the e-mail, attach the files and rewrite the html to build in the cid linkage. Similarly, when reading a message with cid's, the thing to do is save the body parts as files and rewrite the cid to point to the actual file.
I have seen others ask similar questions, one as recently as last December, and the reply was to refer to a Sun tutorial. But that tutorial doesn't address the full problem of 1) inserting an image into a document (instead of attaching an image to a component) and 2) sending it as an e-mail message.
I have yet to see an example that shows the complete package.
Am I right that the data option I mentioned is not going to work?
Am I right that cid is the best approach, and do I understand how to use it?
Is there something else?
Thanks
JohnHi Rocky,
Are you using the DC?
if yes then you need to put the image inside the component folder. after that close the application
& reopen. You will get the image.
In case this does not work then try refreshing the portal through server side. Once the cache is cleared, it will be up to view.
Also check the Activity list you have created. It should be added to the dtr properly or else it wont be reflected once reimported the configurations.
Regards
Chander Kararia -
Sending an email with html tags in it using apex_mail.send
Hello,
I am using APEX_MAIL.SEND to send emails from my apex applications.
now I need the email body to have html features: bold, underline, colors etc.
If I use regular html tags, they show up in the email.
How can this be done?
Thanks
RaniHi, try
p_body_html
and it should display just fine :)
Maybe you are looking for
-
I have a keynote presentation with a hyperlink to a web site, with keynote in one space and Safari in another space(Leopard). When the l select the link and it opens the web site in another space it works fine but when I return to the previous space
-
like I said b4, a pop-up says to update firefox and change my browser to theirs, this pop-up did not ID itself in any manner Tylerdowner says my version is old but I just wiped the old one and got the latest one less than a month ago. Just to be sure
-
How to reduce illustrator CS4 file size
Hi, How to reduce illustrator CS4 file size, the file size is alots bigger compare to art work done in indesign?
-
Query erroring out with lack of temp space?
I have 2 databases. One was cloned from the other on to another server. On one server the query takes 5 seconds to run on the other server the query errors lack with lack of disk space. The init files are the same. The Oracle memory is the same. The
-
Hi, How are SD invoices posted to FICA? Could any one explain me abt this with basic configuration? Thx in adv surya fin