MS Word OLE Implementation
Hello Gurus,
We are creating a new MS word document via SAP and typing some datas and values in it, We could capture those datas into an internal table.But the challenge what we are facing is that, the data which we captured into the internal table is in RAW Format.
We even tried converting them into CHAR format.
In Both the cases(RAW and CHAR) the internal table data is like encryped data.
How can we capture the same data what we type?
Here we are referring SAPRDEMOOFFICEINTEGRATION standard program and using "i_oi_document_proxy" interface.
Waiting for your replies...
Hi Clemens,
Please let us know where we are going wrong.
The necessary coding part is pasted below.
Here the internal table DOC_TABLE contains RAW records of what we fetch from MS Word.
We tried using RRXWS_RAW_TO_CHAR function module to convert RAW format to CHAR format.
But the data is coming in encrypted format nothing understandable.
CLEAR: DOC_URL.
CALL FUNCTION 'SAP_OI_GET_UNIQUE_URL'
IMPORTING
UNIQUE_URL = DOC_URL
EXCEPTIONS
OTHERS = 0.
CALL METHOD DOCUMENT->SAVE_DOCUMENT_TO_URL
EXPORTING
URL = DOC_URL
IMPORTING
RETCODE = RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
EXPORTING
TYPE = 'E'.
CALL FUNCTION 'DP_GET_STREAM_FROM_URL'
EXPORTING
URL = DOC_URL
IMPORTING
SIZE = DOC_SIZE
TABLES
DATA = DOC_TABLE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
EXPORTING
TYPE = 'E'.
waiting for your replies.....
Similar Messages
-
I would like to create a custom datagridview column containing text images and MS Word OLE objects
I am an old time LabView programmer going back to 2.0. But moved on with my career several years ago. But here I am back attempting a custom column in dataviewgrid control. .NET is hard. My goal is to read in an MS Word document and parse it out to a custom column. The column will contain regular old text, images and MS Word objects, sometimes called OLE objects.
There is scant information on creating .NET and labview when it comes to form manipulation. I have stuggled through the learning curve and now able to insert a text box column into a datagridview and add it to the form container and actually size it to the datagridview control. I've added a menu, but still figuring out the layout class. Did I say .NET is hard?
I know there must be a custom column created and even found a C# example, sorta. Trouble is the example uses easy stuff like override and private. It will take me another 3 weeks for that, darnit I'm getting lazy.
Does anybody out there have some example of a custom column in the datagridview?
If you ask to post code. I have nothing I would be proud to show.
The sorta go by: http://www.codeproject.com/Articles/31823/RichTextBox-Cell-in-a-DataGridViewThis is what the progress looks like so far. I broke the tasks down in sub VIs. One to create a custom cell so I can add it to the column CellTemplate. The other to add the column to the control. My limited knowledge of .NET and the implementation in LV causes me to question the value of LV .NET.
The coding to create a TextBoxCell override with ImageCell CellTemplate. Honestly I'm guessing what to do, because the LV documentation on inheritance and overriding is poor at best.
The column coding to add the cell to the custom column.
Probe 19 always comes up with an error. The error is the standard 1172 with no clue what is causing it. The "index" will work on 0 or 1, I suspect bc the two cell types are 0 and 1 but nothing tells me that, just guessing. -
Interaction between Excel and Word OLE
I am using Office 2007 to write procedures but a problem is apparent only when run on Office 2013.
A procedure in a workbook that records Sales information runs to transfer data to another workbook that stores Invoice information, and then opens Word to generate a mail merge document from a template (dotm) which has an event procedure (on Open) to merge
data from the Invoice spreadsheet into a document to produce an invoice. This procedure works without problem on the Office 2007 (Vista) machine and until recently likewise ran without problem on the Office 2013 (Windows 8.1) machine. However,
apparently following an automatic update to the Office 2013 machine, when the Word document is generated the procedure "hangs" at the point of reading the data from the Invoice workbook, and after a longish delay a message is generated along the
lines of the program awaiting an OLE action. The only way to stop the whole process is via task manager.
After much research I have found that on the Office 2013 machine, the mail merge of data from the Invoice workbook will not now work if the Invoice workbook is open, bot works OK if it is closed.
I have therefore programmatically closed the Invoice workbook, and the procedure now works on the Office 2013 machine (and on the Office 2007 machine). However, I would like the Invoice workbook to be open when the Word document has been generated.
I therefore inserted a few seconds wait into the procedure to allow the mail merge to be completed, then tried to reopen the Invoice workbook. I now get the message that the Invoice workbook is locked for editing, and asking if I want to open a read
only copy (which I don't). The Invoice workbook does not appear on the task bar, nor does it appear in task manager. I have tried code to make it active and I then get "subscript out of range", and I have tried code to make it visible
and I again get "subscript out of range". However, if I close down the word documents generated with the data from the Invoice workbook, I can then open it; presumably the merge process is treated as still being in progress while the
documents are open, and the Invoice workbook is "released" when the documents are closed.
Has anyone any advice to offer on how to deal with this problem of not being able to open the Invoice workbook while the mail merge documents are open. The problem is apparent in both Office 2007 and 2013.Hi Caillen
Thanks for looking at this. I should explain that I do all my work on an Office 2007 machine for a family member who lives elsewhere, so I don't have direct access to the Office 2013 machine. However, they are reasonably computer literate and
report faults accurately. To deal with your queries:
1. Their Office (and Windows) updates are installed automatically. Basically, their systems are kept up to date. It is only a guess that an update may have caused the problem, for the procedure worked as expected for some months and no
other changes have been made. The problem does not occur on my Office 2007 machine.
2. For the initial problem there was no error message initially; the little circle just kept going round for a minute or so, then a message appeared on the Office 2013 machine saying that Excel was waiting for another program to complete an OLE
action. That message no longer appears because I have cured the problem by closing the workbook that is the data source for the mail merge.
3. I do indeed mean VBA code by procedure (Sub xxx()). The code in the Word Template on which the procedure originally hung up was the third line below - i,e, the line starting ActiveDocument.MailMerge.OpenDataSource Name:= _
Sub ctPrintInvoice()
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:= _
ThisDocument.Path & "\ColTarInvoices.xlsm", _
LinkToSource:=True, _
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="DETAILS", _
SQLStatement:="SELECT * FROM `'Print Invoice$'`", SQLStatement1:=""
"DETAILS" is a named range within the workbook that is the data source for the mail merge. "Print Invoice" is the name of the worksheet that holds the data. This code runs as an event on opening the document, which is done
automatically within the code in the workbook. The code in the Sales workbook to open the document is:
Set objWord = CreateObject("Word.Application")
If strSourceSheet = "Sales" Then
Set objctMergeDoc = objWord.Documents.Add(ThisWorkbook.Path & "\ctInvoice1.dotm")
ElseIf strSourceSheet = "Euro Sales" Then
Set objctMergeDoc = objWord.Documents.Add(ThisWorkbook.Path & "\ctEuroInvoice1.dotm")
End If
objWord.Visible = True
Set objWord = Nothing
Set objctMergeDoc = Nothing
However, the procedure also hung in the same place on the Office 2013 machine if the document was opened manually.
4. The code in the Sales workbook to close the Invoice workbook is:
Workbooks("ColTarInvoices.xlsm").Close
The code to reopen it is:
Workbooks.Open (ThisWorkbook.Path & "\ColtarInvoices.xlsm")
This generates the message that the workbook is locked for editing. The same message is generated if I try to open the workbook manually while the merged documents are still open.
(The files are all in the same folder)
With thanks
Andy C -
I've just olegen'd Word, 97 and I have got myself a project that won't
compile
because GetProperty is used with the wrong argument signatures. I used
the
3.0.G.2 olegen, because that is what we are using of the desktop.
However, on the
server we are still 3.0.E.? I think, and I see that a problem with
OleGen & Word 97
was fixed in 3.0.F.2 (Bug 32391). Are we stuck with this until we
upgrade the server?
I also wonder why the Word project that is currently there is
significantly different
from my Word project (oddly enough the things that don't compile aren't
in the old
project, so I'm guessing that someone before me found this problem too).
Is there a solution out there?
Thanks
Jamie Anstice
Programmer / Analyst
University of Canterbury
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>Can't you open it using the same mechanism you use for retrieving Word docs ?
If the "OLE Class" item property is blank then you can insert any type of document into your OLE container.
If your OLE container is a base table item then "OLE Activation Style" item property is "Double click" or Focus IN" then you can view the item by navigating or double clicking on the OLE container.
Does your OLE Container show anything, e.g. a PDF icon when you have inserted the PDF file ?
If PDFs are still not loading then check the list of OLE classes that Forms is showing in the drop down list for the OLE CLass property. All the ADOBE ones start with "ADO" or "adobe". -
Hello
(sorry for my english)
My question is :
I use Ole with Forms 6 and Word 2000
But sometimes when I open a document, it happen that this document has already openend by another user
and so Word make appear a popup window (Read Only, Notified or Cancel)
I would like that Word doesn't display this popup window.
How to do ?
please, contact me if you know at [email protected]
ThanksHi,
Please Help. This is very urgent.
I modified the above program in this manner:
loop at IOBJ. (selection-screen variable)
loop at it_RSZSELECT.
it_result-iobj = iobj.
it_result-iobjnm = it_RSZSELECT-iobjnm.
select * from rszeltxref
where teltuid = it_RSZSELECT-eltuid
and objvers = 'A'.
IF rszeltxref-laytp = 'FIX'.
UPDATE rszeltxref SET laytp = 'AGG'.
ENDIF.
endselect.
endloop.
endloop.
Rollback Work.
Inclusion of this statement did not help in any way.
Regards -
Hi All,
I have the below scenario.Can any one please suggest a solution.
I created a variable for OLE object , iole_word_application, and started MS Word with it.
iole_word_application.ConnectToNewObject("Word.Application")
Lets say I closed this MS Word instance accidenally, not through automation but manually.
Now how can I validate through my OLE object variable, iole_word_application,if MS word is still open?
If MS word is no longer open, I will not try the rest of the automation but will re start MS word.
Best Regards,
KiranThanks a lot for your suggestion Jacob, it helped.
Now I have the below question as well.
I have been enhancing my PB application by migrating the DDE operations to OLE operations.
I could translate most of the DDE commands to OLE but the below.
We have a DDE call like below.
ExecRemote("[n=MSWordMacro("Argument to Macro")]", DDE Channel Handle, Window Handle)
I know how to call the "MSWordMacro" with "Argument to Macro" using OLE.
iole_word_application.Run("MSWordMacro", "Argument to Macro" )
But I dont know what "n=" means in the original DDE command and how to convert it to OLE.
The "MSWordMacro" does not have any return values.
Can any one help please. -
MS Word OLE integration i new UI??
Hi Folks
We are in the middle of an upgrade from CRM 3.1 to CRM2007. And the new WEB UI.
In our old SAP gui, we have developped a ABAP Report program that collects a lot of data, and then via OLE integrated to a Word document. We didn't use the DOI, but just called a lot of methods in Word.
I have tried to execute our old ABAP Report via the Transaction Launcer in the new UI. And the first part of
it - collecting all the data - works fine. But the integration to word does not work.
Does anyone have an idea how to make this integration. The result of the progam is a nice formatted Word Document with a lot of fixed texts combined wit data from the CRM system!
Best regards
Carsten<b>word_document</b> = location of the existing document in which you want to change the val (d:\Documents and Settings\user\Desktop\Doc1.doc)
<b>File_name</b> = File name to which the modified file to be saved (just give the same file name you opened - Doc1.doc - just the file name and not the whole path)
<b>Download_path</b>
path for downloading (d:\Documents and Settings\user\Desktop\)
<b>Data_tab</b> = any internal table
<b>filednames</b> = field names of the internal table in a table . for example if your itab has fielda, fieldb and fieldc , then this table first record value should be fielda and second record value should be fieldb, etc.
Hope this is clear.
Regards
Raja -
Trie or Directed acyclic word graph Implementation
Hello all!
I currently have implemented a wordlist for an application i have written using a HashSet. It holds around 120,000 words and takes up 12mb in memory.
I would like to reduce the size of memory taken up by this list as it is for an app on a mobile device. I have been advised to use a Trie for this. I had a go using the code found [http://forums.sun.com/thread.jspa?threadID=5295936] and it seems to take up approx 3 times the amount of space as the hashSet, at around 30mb, which is not the desired behaviour.
I also came across the Directed_acyclic_word_graph (DAWG) [http://en.wikipedia.org/wiki/Directed_acyclic_word_graph] info while looking at the Trie, which seems perfect for my purposes.
I want to know, 1) any idea why the Trie increased the size of the word list? 2) Anyone know know of any open source Trie or DAWG code i could use?
Thanks for any help![cross-posted|http://stackoverflow.com/questions/3228075/hashset-of-strings-taking-up-too-much-memory-suggestions].
-
CREATE DOCUMENTO IN WORD - OLE
Hi to all
I have the following issue:
I have this code (this is a piece of code), and I need create the document in word (I need that word open it inside of SAP dynpro ) but I need create it with information. With this code, the document is created empty.
data document type ref to i_oi_document_proxy.
CALL METHOD DOCUMENT->Create_document
EXPORTING OPEN_INPLACE = 'X'
DOCUMENT_title = 'Documento en word'
NO_FLUSH = ' '
CREATE_VIEW_DATA = ' '.
*CALL METHOD DOCUMENT->open_document
EXPORTING
Este metodo permite grabar el documento sin intervencion del usuario
CALL METHOD DOCUMENT->save_as
exporting FILE_NAME = 'C:\test.doc'.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
Can somebody say me, wich is the method or FM, that I can use by create the document, and insert information of the itab or fix information ??
Thanks and regards
DarioJorge, thank you for that kind offer. I rebooted my PC and tried again, and now everything is working fine. I suppose that something in the add-in wasn't working properly. But the problem isn't repeating.
-
Download classical report to MS word with OLE
hi experts,
I have a Classical HR Report that contains profile information of the employee.Now I have to Download the Report to Ms word through OLE . I tried some threads but they were just displaying the static text.I have to download the data for the following format.could some one help me on this?
WRITE : 'Salary Information '.
SKIP 1.
WRITE : 1 SY-ULINE(83).
WRITE : /1'|',2 'Period Ending On 31ST',25'|',26'Rating(If Any)',42'|',43'Basic Salary',57'|',58'Gpm',70'|',71'CTC',83'|'.
WRITE : /1 SY-ULINE(83).
CLEAR YEARSAL.CLEAR CURRENT.
CLEAR GROSS.CLEAR GROSS1.CLEAR CTC1.
LOOP AT ISAL INTO WSAL WHERE PERNR = WP01-PERNR AND ENDDA = '99991231' ."AND CURRENT BETWEEN WSAL-BEGDA AND WSAL-ENDDA.
GROSS = WSAL-BET01 + WSAL-BET02 + WSAL-BET03 + WSAL-BET04.
GROSS1 = GROSS.CONDENSE GROSS1.
CTC1 = WSAL-BET10.CONDENSE CTC1.
WRITE : /1'|',2 'Current' ,25'|',26 WSAL-RTEXT,42'|',43 WSAL-BET01 ,57'|',58 GROSS1,70'|',71 CTC1,83'|'.
WRITE : /1 SY-ULINE(83).
ENDLOOP.
"need to download such information as above to ms word
"ole format
CREATE OBJECT gs_word 'WORD.APPLICATION' .
IF sy-subrc NE 0 .
MESSAGE s000(su) WITH 'Error while creating OLE object!'.
LEAVE PROGRAM .
ENDIF .
*--Setting object's visibility property
SET PROPERTY OF gs_word 'Visible' = '1' .
*--Opening a new document
GET PROPERTY OF gs_word 'Documents' = gs_documents .
CALL METHOD OF GS_DOCUMENTS 'ADD' = V_DOCUMENTS.
CALL METHOD OF gs_selection 'TypeText'
EXPORTING
#1 = 'Overview Of The Employee'.
"the output format would be like this .
pernr | year | salary | .......
Edited by: SYED_ibbu on Feb 23, 2011 11:07 AM
Edited by: SYED_ibbu on Feb 24, 2011 5:57 AMhi experts,
i Have to display multiple tables in the word document . i am displaying the first table but when i try to display the second table it is getting displayed inside the first table. When i debugged , i found that that the cursor is still in the first row of the first table even after the first table is displayed and the second table is displayed from that cursor position. How to get the cursor position after the end of the table ie outside the table to the main document.could some one help me on this. Below is the code i have used.
GET PROPERTY OF GS_WORD 'ActiveDocument' = gs_actdoc.
GET PROPERTY OF gs_actdoc 'Tables' = gs_tables .
GET PROPERTY OF gs_selection 'Range' = gs_range .
CALL METHOD OF gs_tables 'Add' = gs_table
EXPORTING
#1 = gs_range
#2 = LINES
#3 = '7'.
GET PROPERTY OF gs_table 'Borders' = gs_table_border .
SET PROPERTY OF gs_table_border 'Enable' = '1' .
GET PROPERTY OF gs_cell 'Range' = gs_range .
SET PROPERTY OF gs_range 'Text' = value .
CALL METHOD OF gs_table 'Cell' = gs_cell
EXPORTING
#1 = P_TABIX1
#2 = CNT.
GET PROPERTY OF GS_WORD 'ActiveDocument' = gs_actdoc1.
GET PROPERTY OF gs_actdoc1 'Tables' = gs_tables1 .
GET PROPERTY OF gs_selection 'Range' = gs_range1 .
CALL METHOD OF gs_tables1 'Add' = gs_table1
EXPORTING
#1 = gs_range1
#2 = '2'
#3 = '4'.
with thanks in advance,
syed
Edited by: SYED_ibbu on Feb 25, 2011 5:39 AM -
Poor image quality when displaying OLE Word doc stored in BLOB
Hello,
I am migrating some CR Reports from VB6 to VB.NET 2008.
The reports retrieves Word documents that is stored in BLOB column on SQL Server 2005.
If CR.NET (same behaviour with 2005 and 2008 versions) renders the word document, the quality is really bad. Looks like an ugly moire effect. The characters below 8pt font size are hardly readable. I have already set the option "use full color-depth" in the report options.
If the same word doc is rendered with CR that's included in VB6, it shows a clear and sharp output - the same as displayed in word.
Where is the difference in handling Word OLE between those two CR versions?
Is there anything I can do to improve the quality with CR.NET?
Regards,
StefanHello, Stefan;
Is this a Windows or Web application?
Visual Basic 6.0 shipped with Crystal Reports 4.6 Visual Studio .NET 2005 ships with Crystal Reports 10.2 and VS .NET 2008 with version 10.5.
The Crystal Reports application was rewritten in versions 5.0 and 9.0 and a great many changes were made - among them different options for including OLE Objects. See the [Note 1218374|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_erq/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes.do] for useful new functionality. I tested a report with a linked Word document and it viewed well through Visual Studio .NET 2008.
Is it possible support for the the Word format as a BLOB field in MS SQL Server has changed over time. What method is used to create the document as a BLOB field?
Are you using the bundled version included with Visual Studio .NET? In the article recommending the property 'Retain Original Image Color Depth', there is a note:
Note: This option only functions with the full version of Crystal Reports 9 or 10. This option does not function with the .NET Report Designer.
Originally the issue was fixed but only in a full versions of Crystal Reports Developer, not in the versions bundled with Visual Studio .NET.
I tested with a linked Word document and see some degradation when there is an image in the Word Document but not in the text itself.
Elaine -
Error in the PC editor. Continue with the line editor. Word 2010
We have just completed upgrade to ECC6.0 eph4.
We are evaluating new workstion build to depoly windows 7 and office 2010. We are installing SAP GUI 7.2 patch 1 on the workstations. While testing the build, we are finding that when creating/changing texts in VD02 and IW52 long text. That the editor defaults to the line editor. How can we change editor to call Word 2010? From reading SAP notes, SAP 7.20 supports windows 7 and office 2010. Is there a parameter or transaction that needs to be set for the user?
Please advise.
Thanks
Tony Romain
IT System Analyst
Steps:
We open IW52 to service notification, click on long text icon. Screen opens with line editor. When select "Change Editor" in menu, we then see this message.
Error in the PC editor. Continue with the line editor
Message no. TD754
Diagnosis
An internal error occurred in the PC editor accessing the text (data
transport with the data provider).
System Response
The operation could not be executed in the PC editor.
Procedure
Contact your PC system administrator.For MS Word 2010
Implement the code corrections of the note 1452849.
Upload the latest word template from the attachments of note 1091389.
For MS Word 2013
Implement the code corrections of the note 1829008.
Upload the latest word template from the attachments of note 1091389. -
Convert Adobe form (PDF file) to Word file
Hi,
my need is in the title, i would like to convert a Adobe Form, in fact a pdf file to word file. What is the best way ? And of course is it possible ?
Thanks for your help.
Cheers.Hello,
nothing like this cannot be done. You can generate interactive form if you need your user to fill in some more details. You can generate Word for example using OLE. There is a nice SDN contribution on generating MS Word using SAP Word OLE. Regards, Otto -
Has anyone successfully used WEBUTIL CLIENT_OLE to run acrobat reader?
We want to be able to print PDF files to the local printer on the client. We can get the PDF file to the client, but printing it is another problem.
Using CLIENT_HOST("acrord32 /t <pdf_file>"); leaves the reader running and we want it to close when the print job is finished.
I go Word working fine, but I can't even get Acrobat reader to launch!
Please provide Code!I've looked at both options.
OraRRP opens the Adobe window, prints the report, then closes the window. This causes (and I quote) "the screen to flash". It also requires that we manually install OraRRP on every client (unless I've missed something in the documentation).
AcroRd32 is a problem because it leaves the window open and you have to know the full path to the executable (wich changes with each version) and again "causes the screen to flash".
OLE (apparently) will allow us to print documents and has a "HIDE" property which we can use to ensure that there is not screen flashing.
The problem is, I can get word OLE to work, but not Acrobat OLE. -
Display JTree in browser using JSP
i have a program that converts xml file in to tree structure(using Swing). When i run this using eclipse then it is working. Swing is an extension of applet , right. I want to embed this in an HTML page(JSP). so that i can display the tree structure. Its gives class not foung error.
It is not posiible to embed it. I think if it extends an Applet then it will display. But i don't know how to convert that. It gives error if i convert.
pls help
CODE:
package TreeGen;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import java.io.IOException;
import org.w3c.dom.Document;
// Basic GUI components
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
// GUI components for right-hand side
import javax.swing.JSplitPane;
import javax.swing.JEditorPane;
// GUI support classes
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
// For creating borders
import javax.swing.border.EmptyBorder;
import javax.swing.border.BevelBorder;
import javax.swing.border.CompoundBorder;
// For creating a TreeModel
import javax.swing.tree.*;
import javax.swing.event.*;
import java.util.*;
public class TreeGen extends JPanel
static Document document;
boolean compress = false;
static final int windowHeight = 660;
static final int leftWidth = 300;
static final int rightWidth = 640;
static final int windowWidth = leftWidth + rightWidth;
public TreeGen()
EmptyBorder eb = new EmptyBorder(5,5,5,5);
BevelBorder bb = new BevelBorder(BevelBorder.LOWERED);
CompoundBorder cb = new CompoundBorder(eb,bb);
this.setBorder(new CompoundBorder(cb,eb));
JTree tree = new JTree(new DomToTreeModelAdapter());
JScrollPane treeView = new JScrollPane(tree);
treeView.setPreferredSize(
new Dimension( leftWidth, windowHeight ));
final
JEditorPane htmlPane = new JEditorPane("text/html","");
htmlPane.setEditable(true);
JScrollPane htmlView = new JScrollPane(htmlPane);
htmlView.setPreferredSize(
new Dimension( rightWidth, windowHeight ));
tree.addTreeSelectionListener(
new TreeSelectionListener()
public void valueChanged(TreeSelectionEvent e)
TreePath p = e.getNewLeadSelectionPath();
if (p != null)
AdapterNode adpNode =
(AdapterNode) p.getLastPathComponent();
htmlPane.setText(adpNode.content());
JSplitPane splitPane =
new JSplitPane( JSplitPane.HORIZONTAL_SPLIT,
treeView,
htmlView );
splitPane.setContinuousLayout( false );
splitPane.setDividerLocation( leftWidth );
splitPane.setDividerSize(1);
splitPane.setPreferredSize(
new Dimension( windowWidth + 10, windowHeight+10 ));
this.setLayout(new BorderLayout());
this.add("Center", splitPane );
//return menuBar;
} // constructor
public static void main(String argv[])
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse("C:/Program Files/Apache Software Foundation/Tomcat 5.0/webapps/parser1/sample.xml");
makeFrame();
} catch (SAXException sxe){
System.out.println("ERROR");
Exception x = sxe;
if (sxe.getException() != null)
x = sxe.getException();
x.printStackTrace();
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} // main
public static void makeFrame()
JFrame frame = new JFrame("DOM Echo");
frame.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
final TreeGen echoPanel =
new TreeGen();
frame.getContentPane().add("Center", echoPanel );
frame.pack();
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
int w = windowWidth + 10;
int h = windowHeight + 10;
frame.setSize(w, h);
frame.setVisible(true);
} // makeFrame
static final String[] typeName = {
"none",
"Element",
"Attr",
"Text",
"CDATA",
"EntityRef",
"Entity",
"ProcInstr",
"Comment",
"Document",
"DocType",
"DocFragment",
"Notation",
static final int ELEMENT_TYPE = 1;
static final int ATTR_TYPE = 2;
static final int TEXT_TYPE = 3;
static final int CDATA_TYPE = 4;
static final int ENTITYREF_TYPE = 5;
static final int ENTITY_TYPE = 6;
static final int PROCINSTR_TYPE = 7;
static final int COMMENT_TYPE = 8;
static final int DOCUMENT_TYPE = 9;
static final int DOCTYPE_TYPE = 10;
static final int DOCFRAG_TYPE = 11;
static final int NOTATION_TYPE = 12;
static String[] treeElementNames = {
"slideshow",
"slide",
"title", // For slideshow #1
"slide-title", // For slideshow #10
"item",
boolean treeElement(String elementName) {
for (int i=0; i<treeElementNames.length; i++) {
//System.out.println(treeElementNames);
if ( elementName.equals(treeElementNames[i]) )
return true;
return false;
public class AdapterNode
org.w3c.dom.Node domNode;
public AdapterNode(org.w3c.dom.Node node)
domNode = node;
public String toString()
String s = typeName[domNode.getNodeType()];
String nodeName = domNode.getNodeName();
if (! nodeName.startsWith("#"))
s += ": " + nodeName;
if (compress)
String t = content().trim();
int x = t.indexOf("\n");
if (x >= 0) t = t.substring(0, x);
s += " " + t;
return s;
if (domNode.getNodeValue() != null)
if (s.startsWith("ProcInstr"))
s += ", ";
else
s += ": ";
// Trim the value to get rid of NL's at the front
String t = domNode.getNodeValue().trim();
int x = t.indexOf("\n");
if (x >= 0) t = t.substring(0, x);
s += t;
return s;
public String content()
String s = "";
org.w3c.dom.NodeList nodeList = domNode.getChildNodes();
for (int i=0; i<nodeList.getLength(); i++)
org.w3c.dom.Node node = nodeList.item(i);
int type = node.getNodeType();
//System.out.println(type);
AdapterNode adpNode = new AdapterNode(node); //inefficient, but works
if (type == ELEMENT_TYPE)
if ( treeElement(node.getNodeName()) ) continue;
s += "<" + node.getNodeName() + ">";
s += adpNode.content();
s += "</" + node.getNodeName() + ">";
else if (type == TEXT_TYPE)
s += node.getNodeValue();
else if (type == ENTITYREF_TYPE)
s += adpNode.content();
else if (type == CDATA_TYPE)
StringBuffer sb = new StringBuffer( node.getNodeValue() );
for (int j=0; j<sb.length(); j++)
if (sb.charAt(j) == '<')
sb.setCharAt(j, '&');
sb.insert(j+1, "lt;");
j += 3;
else if (sb.charAt(j) == '&')
sb.setCharAt(j, '&');
sb.insert(j+1, "amp;");
j += 4;
s += "<pre>" + sb + "\n</pre>";
return s;
public int index(AdapterNode child)
int count = childCount();
for (int i=0; i<count; i++)
AdapterNode n = this.child(i);
if (child.domNode == n.domNode) return i;
return -1; // Should never get here.
public AdapterNode child(int searchIndex)
org.w3c.dom.Node node =
domNode.getChildNodes().item(searchIndex);
if (compress)
int elementNodeIndex = 0;
for (int i=0; i<domNode.getChildNodes().getLength(); i++)
node = domNode.getChildNodes().item(i);
if (node.getNodeType() == ELEMENT_TYPE
&& treeElement( node.getNodeName() )
&& elementNodeIndex++ == searchIndex)
break;
return new AdapterNode(node);
public int childCount()
if (!compress)
return domNode.getChildNodes().getLength();
int count = 0;
for (int i=0; i<domNode.getChildNodes().getLength(); i++)
org.w3c.dom.Node node = domNode.getChildNodes().item(i);
if (node.getNodeType() == ELEMENT_TYPE
&& treeElement( node.getNodeName() ))
++count;
return count;
public class DomToTreeModelAdapter
implements javax.swing.tree.TreeModel
public Object getRoot()
return new AdapterNode(document);
public boolean isLeaf(Object aNode)
AdapterNode node = (AdapterNode) aNode;
if (node.childCount() > 0) return false;
return true;
public int getChildCount(Object parent)
AdapterNode node = (AdapterNode) parent;
return node.childCount();
public Object getChild(Object parent, int index)
AdapterNode node = (AdapterNode) parent;
return node.child(index);
public int getIndexOfChild(Object parent, Object child)
AdapterNode node = (AdapterNode) parent;
return node.index((AdapterNode) child);
public void valueForPathChanged(TreePath path, Object newValue)
private Vector listenerList = new Vector();
public void addTreeModelListener(TreeModelListener listener)
if ( listener != null
&& ! listenerList.contains( listener ) )
listenerList.addElement( listener );
public void removeTreeModelListener(TreeModelListener listener)
if ( listener != null )
listenerList.removeElement( listener );
public void fireTreeNodesChanged( TreeModelEvent e )
Enumeration listeners = listenerList.elements();
while ( listeners.hasMoreElements() )
TreeModelListener listener =
(TreeModelListener) listeners.nextElement();
listener.treeNodesChanged( e );
public void fireTreeNodesInserted( TreeModelEvent e )
Enumeration listeners = listenerList.elements();
while ( listeners.hasMoreElements() )
TreeModelListener listener =
(TreeModelListener) listeners.nextElement();
listener.treeNodesInserted( e );
public void fireTreeNodesRemoved( TreeModelEvent e )
Enumeration listeners = listenerList.elements();
while ( listeners.hasMoreElements() )
TreeModelListener listener =
(TreeModelListener) listeners.nextElement();
listener.treeNodesRemoved( e );
public void fireTreeStructureChanged( TreeModelEvent e )
Enumeration listeners = listenerList.elements();
while ( listeners.hasMoreElements() )
TreeModelListener listener =
(TreeModelListener) listeners.nextElement();
listener.treeStructureChanged( e );I actually had to do this a few months ago. There are ways to perform this kind display using various distributed object (i.e., using MS Word OLE objects to "interpret" the byte for you, etc.). But this soon got extremely difficult to manage (and I actually had to use Perl/CGI for the majority of it).
The solution I went with was to implement a "cache" directory on the web server. Basically, the JSP/Servlet can simply check the cache and if file not there, create it from the database. Then send a redirect back to the browser to this newly-created file. The browser will then appropriately open the document. I tested this with both Netscape and IE browsers and common MIME types such as text files, MS Office docs, zip files, PDFs, RTFs.
Not ideal, but unfortunately the best I came up with.
Maybe you are looking for
-
Setting the layer name from a format plugin with CS2 and before
Hello, I wrote a new format plugin and the name of the layer shown in PS , when I read a file, does not seem to be consistent on all computers for versions CS2 and before : some times I get "Background" and some times I get "Layer 0" . When the laye
-
i have an apple cinema display that hasnt been tested, before i go out n by an adc adapter for it, i wanted to know if the apple store could test it
-
OK..so now I've learned that for my large panorama filesI wont get a thumbnail in the Organizer. Just some Blue Triangle warning with a exclamation point. I do allot of golf course work where I stitch phototos and print 38 x 11 inches @ 300dpi. So wh
-
Windows installer missing??? Satellit A505-S6960
Have had the computer since late August. Used constantly. Yesterday when I turn it on it gave me an error message loading the webcam as well as my malware sweep program. says itunes is not installed correctly. Also can't access microsoft word
-
How to format the URI for Human task worklist UI project?
This information is not easily found, so I am posting it here: When you click on the Administration Tab of the Human workflow component in EM, It allows you to enter an URI for the TaskDetail page. If you Auto-generate the taskdetail page, the URI fo