incubator-ooo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Brinzing <Oliver.Brinz...@gmx.de>
Subject Re: Is this a UNO API bug?
Date Tue, 21 Aug 2012 09:48:18 GMT
Hi,

> I found that if page is more than 2, it will has problem. Would you pls
> help try a 3 page exist odt sample for this issue?

are you sure? the following code gives me a new 6 pages document with string:

Page # 1
Page # 2
Page # 3
Page # 4
Page # 5

public class TextfieldProblem {

	public static void setTextfield(final XComponent component) {

		final XMultiServiceFactory serviceFactory = UnoRuntime.queryInterface(
				XMultiServiceFactory.class, component);

		final XTextDocument xDoc = UnoRuntime.queryInterface(
				XTextDocument.class, component);
		try {
			final XText xText = xDoc.getText();
			final XTextCursor xTextCursor = xText.createTextCursor();
			xTextCursor.gotoRange(xText.getStart(), false);

			for (int i = 0; i < 5; i++) {
				xText.insertString(xTextCursor, "Page # ", false);
				xText.insertTextContent(xTextCursor,
						TextfieldProblem.createTextfield(serviceFactory), false);
				TextfieldProblem.insertPageBreak(xText, xTextCursor);
			}
		} catch (final IllegalArgumentException e) {
			e.printStackTrace();
		} catch (final UnknownPropertyException e) {
			e.printStackTrace();
		} catch (final PropertyVetoException e) {
			e.printStackTrace();
		} catch (final WrappedTargetException e) {
			e.printStackTrace();
		}
		TextfieldProblem.getTextfield(xDoc);
	}

	private static XTextField createTextfield(
			final XMultiServiceFactory serviceFactory) {
		XTextField pageNumberFiled = null;
		try {
			pageNumberFiled = UnoRuntime
					.queryInterface(
							XTextField.class,
							serviceFactory
									.createInstance("com.sun.star.text.textfield.PageNumber"));

			final XPropertySet props = UnoRuntime.queryInterface(
					XPropertySet.class, pageNumberFiled);

			props.setPropertyValue("NumberingType", new Short(
					com.sun.star.style.NumberingType.ARABIC));

			props.setPropertyValue("SubType",
					com.sun.star.text.PageNumberType.CURRENT);

		} catch (final Exception e) {
			e.printStackTrace();
		}
		return pageNumberFiled;
	}

	private static void insertPageBreak(final XText xText,
			final XTextCursor xTextCursor) throws UnknownPropertyException,
			PropertyVetoException, IllegalArgumentException,
			WrappedTargetException {

		final XPropertySet xCursorProps = UnoRuntime.queryInterface(
				XPropertySet.class, xTextCursor);
		xCursorProps.setPropertyValue("BreakType", BreakType.PAGE_AFTER);
		xText.insertControlCharacter(xTextCursor,
				ControlCharacter.PARAGRAPH_BREAK, false);
		xTextCursor.gotoEnd(false);
	}

	public static void getTextfield(final XComponent xComponent) {
		final XTextDocument document = UnoRuntime.queryInterface(
				XTextDocument.class, xComponent);
		final String documentString = document.getText().getString();
		System.out.println(documentString);
	}
}


Regards

Oliver

--

GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45


Mime
View raw message