Bugzilla – Attachment 133300 Details for
Bug 107829
Fatal exception: Signal 6 when using SDK to insert text
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Self contained test java app
OfficeTest.java (text/x-java), 8.46 KB, created by
kstenerud
on 2017-05-13 21:54:27 UTC
(
hide
)
Description:
Self contained test java app
Filename:
MIME Type:
Creator:
kstenerud
Created:
2017-05-13 21:54:27 UTC
Size:
8.46 KB
patch
obsolete
>/* Copyright Karl Stenerud, all rights reserved. >* Released under the terms of the Mozilla Public License v2 https://www.mozilla.org/en-US/MPL/2.0 >*/ >package org.testing; > >import com.sun.star.beans.PropertyValue; >import com.sun.star.beans.XPropertySet; >import com.sun.star.comp.helper.Bootstrap; >import com.sun.star.container.XNameAccess; >import com.sun.star.container.XNameContainer; >import com.sun.star.frame.XComponentLoader; >import com.sun.star.frame.XDesktop; >import com.sun.star.lang.XComponent; >import com.sun.star.lang.XMultiComponentFactory; >import com.sun.star.lang.XMultiServiceFactory; >import com.sun.star.style.BreakType; >import com.sun.star.style.LineSpacing; >import com.sun.star.style.LineSpacingMode; >import com.sun.star.style.ParagraphAdjust; >import com.sun.star.style.XStyle; >import com.sun.star.style.XStyleFamiliesSupplier; >import com.sun.star.text.ControlCharacter; >import com.sun.star.text.XText; >import com.sun.star.text.XTextCursor; >import com.sun.star.text.XTextDocument; >import com.sun.star.uno.UnoRuntime; >import com.sun.star.uno.XComponentContext; >import com.sun.star.uno.XInterface; > >public class OfficeTest { > > public static void main(String[] args) throws Exception { > new OfficeTest().testBigDocument(); > } > > public void testBigDocument() throws Exception { > XTextDocument document = newTextDocument(); > XText text = document.getText(); > XTextCursor cursor = text.createTextCursor(); > > setDocumentProperties(document, cursor); > buildTitleStyle(document); > buildTextStyle(document); > > for(int i=0; i < 30; i++) { > insertStory(text, cursor); > } > } > > public void buildTitleStyle(XTextDocument document) throws Exception { > String name = "Story Title"; > XMultiServiceFactory serviceFactory = UnoRuntime.queryInterface(XMultiServiceFactory.class, document); > XInterface style = (XInterface)serviceFactory.createInstance("com.sun.star.style.ParagraphStyle"); > XPropertySet properties = UnoRuntime.queryInterface(XPropertySet.class, style); > > properties.setPropertyValue("ParaAdjust", ParagraphAdjust.CENTER_value); > properties.setPropertyValue("CharHeight", (float)24.0); > properties.setPropertyValue("ParaTopMargin", 1000); > properties.setPropertyValue("ParaBottomMargin", 2000); > > XStyleFamiliesSupplier styleSupplier = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, document); > XNameAccess styleFamilies = styleSupplier.getStyleFamilies(); > XNameContainer xParaStyleCollection = UnoRuntime.queryInterface(XNameContainer.class, styleFamilies.getByName("ParagraphStyles")); > xParaStyleCollection.insertByName(name, style); > } > > public void buildTextStyle(XTextDocument document) throws Exception { > String name = "Story Text"; > XMultiServiceFactory serviceFactory = UnoRuntime.queryInterface(XMultiServiceFactory.class, document); > XInterface style = (XInterface)serviceFactory.createInstance("com.sun.star.style.ParagraphStyle"); > XPropertySet properties = UnoRuntime.queryInterface(XPropertySet.class, style); > > properties.setPropertyValue("ParaAdjust", ParagraphAdjust.BLOCK_value); > properties.setPropertyValue("ParaBottomMargin", 400); > LineSpacing lineSpacing = new LineSpacing(); > lineSpacing.Mode = LineSpacingMode.PROP; > lineSpacing.Height = (short)(1100); > properties.setPropertyValue("ParaLineSpacing", lineSpacing); > > XStyleFamiliesSupplier styleSupplier = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, document); > XNameAccess styleFamilies = styleSupplier.getStyleFamilies(); > XNameContainer xParaStyleCollection = UnoRuntime.queryInterface(XNameContainer.class, styleFamilies.getByName("ParagraphStyles")); > xParaStyleCollection.insertByName(name, style); > } > > public void applyTitleStyle(XTextCursor cursor) throws Exception { > String name = "Story Title"; > XPropertySet cursorProperties = UnoRuntime.queryInterface(XPropertySet.class, cursor); > cursorProperties.setPropertyValue("ParaStyleName", name); > } > > public void applyTextStyle(XTextCursor cursor) throws Exception { > String name = "Story Text"; > XPropertySet cursorProperties = UnoRuntime.queryInterface(XPropertySet.class, cursor); > cursorProperties.setPropertyValue("ParaStyleName", name); > } > > public void insertStory(XText text, XTextCursor cursor) throws Exception { > insertTitle(text, cursor); > > for(int i = 0; i < 20; i++) { > insertParagraph(text, cursor); > } > insertPageBreak(text, cursor); > } > > public void insertTitle(XText text, XTextCursor cursor) throws Exception { > String title = "Title of the story"; > applyTitleStyle(cursor); > text.insertString(cursor, title, false); > insertParagraphBreak(text, cursor); > } > > public void insertParagraph(XText text, XTextCursor cursor) throws Exception { > String paragraph = "âAs I must first inform you,â continued the captain, âMr. Clifford here is an antiquarian and traveler. He was some few weeks ago engaged in exploring the interior of Honduras. In the mountains he found the ruined city of an ancient race. In exploring the ruins he found a secret chamber which was completely walled up, save for one small opening large enough to put a hand through."; > applyTextStyle(cursor); > text.insertString(cursor, paragraph, false); > insertParagraphBreak(text, cursor); > } > > private void insertParagraphBreak(XText text, XTextCursor cursor) throws Exception { > text.insertControlCharacter(cursor, ControlCharacter.PARAGRAPH_BREAK, false); > } > > private void insertPageBreak(XText text, XTextCursor cursor) throws Exception { > XPropertySet cursorProperties = UnoRuntime.queryInterface(XPropertySet.class, cursor); > BreakType oldType = (BreakType)cursorProperties.getPropertyValue("BreakType"); > cursorProperties.setPropertyValue("BreakType", BreakType.PAGE_AFTER); > text.insertControlCharacter(cursor, ControlCharacter.PARAGRAPH_BREAK, false); > cursorProperties.setPropertyValue("BreakType", oldType); > } > > public void setDocumentProperties(XTextDocument document, XTextCursor cursor) throws Exception { > String styleName = "Book"; > XMultiServiceFactory serviceFactory = UnoRuntime.queryInterface(XMultiServiceFactory.class, document); > XStyle style = UnoRuntime.queryInterface(XStyle.class, serviceFactory.createInstance("com.sun.star.style.PageStyle")); > XPropertySet properties = UnoRuntime.queryInterface(XPropertySet.class, style); > > properties.setPropertyValue("Width", 15240); > properties.setPropertyValue("Height", 22860); > properties.setPropertyValue("LeftMargin", 1905); > properties.setPropertyValue("RightMargin", 1905); > properties.setPropertyValue("TopMargin", 1905); > properties.setPropertyValue("BottomMargin", 2159); > > XStyleFamiliesSupplier supplier = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, document); > XNameAccess styleFamilies = supplier.getStyleFamilies(); > XNameContainer family = UnoRuntime.queryInterface(XNameContainer.class, styleFamilies.getByName("PageStyles")); > family.insertByName (styleName, style); > > XPropertySet cursorProperties = UnoRuntime.queryInterface(XPropertySet.class, cursor); > cursorProperties.setPropertyValue("PageDescName", styleName); > } > > public XTextDocument newTextDocument() throws Exception { > return newDocument("swriter", XTextDocument.class); > } > > private <T extends Object> T newDocument(String documentType, Class<T> classType) throws Exception { > String url = "private:factory/" + documentType; > PropertyValue emptyArgs[] = new PropertyValue[0]; > XComponentLoader componentLoader = UnoRuntime.queryInterface(XComponentLoader.class, getDesktop()); > XComponent component = componentLoader.loadComponentFromURL(url, "_blank", 0, emptyArgs); > return UnoRuntime.queryInterface(classType, component); > } > > private XDesktop getDesktop() throws Exception { > XComponentContext componentContext = Bootstrap.bootstrap(); > XMultiComponentFactory componentFactory = componentContext.getServiceManager(); > Object desktopObject = componentFactory.createInstanceWithContext("com.sun.star.frame.Desktop", componentContext); > return UnoRuntime.queryInterface(XDesktop.class, desktopObject); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 107829
: 133300