Package com.sun.star.text

Examples of com.sun.star.text.XTextContent


    }

    void insertDocumentIndexMark(XTextCursor xCursor, String key)
        throws Exception
    {
        XTextContent xContent = makeDocumentIndexMark(key);
        xContent.attach(xCursor);
    }
View Full Code Here


    XTextContent makeDocumentIndexMark(String key) throws Exception
    {
        Object xMark =
            m_xDocFactory.createInstance("com.sun.star.text.DocumentIndexMark");
        XTextContent xContent = (XTextContent)
            UnoRuntime.queryInterface(XTextContent.class, xMark);
        XPropertySet xPropSet = (XPropertySet)
            UnoRuntime.queryInterface(XPropertySet.class, xMark);
        xPropSet.setPropertyValue("PrimaryKey", key);
        return xContent;
View Full Code Here

    }

    void insertMeta(XTextCursor xCursor, StringPair xmlid)
        throws Exception
    {
        XTextContent xContent = makeMeta();
        xContent.attach(xCursor);
        XMetadatable xMetadatable = (XMetadatable)
            UnoRuntime.queryInterface(XMetadatable.class, xContent);
        xMetadatable.setMetadataReference(xmlid);
    }
View Full Code Here

    XTextContent makeMeta() throws Exception
    {
        Object xMeta = m_xDocFactory.createInstance(
                "com.sun.star.text.InContentMetadata");
        XTextContent xContent = (XTextContent)
            UnoRuntime.queryInterface(XTextContent.class, xMeta);
        return xContent;
    }
View Full Code Here

    }

    void insertMetaField(XTextCursor xCursor, StringPair xmlid)
        throws Exception
    {
        XTextContent xContent = makeMetaField();
        xContent.attach(xCursor);
        XMetadatable xMetadatable = (XMetadatable)
            UnoRuntime.queryInterface(XMetadatable.class, xContent);
        xMetadatable.setMetadataReference(xmlid);
    }
View Full Code Here

        RangeInserter inserter = new RangeInserter(m_xDoc);
        TreeNode text = new TextNode("12AB6789");
        inserter.insertRange( new Range(0, 0, text) );
        MetaNode meta = new MetaNode( mkId("id") );
//        inserter.insertRange( new Range(3, 5, met2) );
        XTextContent xMeta = inserter.makeMeta();

        XText xDocText = m_xDoc.getText();
        XTextCursor xDocTextCursor = xDocText.createTextCursor();
        xDocTextCursor.goRight((short)3, false);
        xDocTextCursor.goRight((short)2, true);
        xDocText.insertTextContent(xDocTextCursor, xMeta, true);
//        xMeta.attach(xDocTextCursor);

        XMetadatable xMetadatable = (XMetadatable)
            UnoRuntime.queryInterface(XMetadatable.class, xMeta);
        xMetadatable.setMetadataReference(meta.getXmlId());
        XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta);

        XText xParentText = xText.getText();
        assure("getText(): no parent", xParentText != null);

        XTextRange xStart = xText.getStart();
        assure("getStart(): no start", xStart != null);

        XTextRange xEnd = xText.getEnd();
        assure("getEnd(): no end", xEnd != null);

        /*
        String string = xText.getString();
        assure("getString(): invalid string returned",
            string != null && "AB".equals(string) );
            */

        xText.setString("45");

        {
            String string = xText.getString();
            assure("getString(): invalid string returned: " + string,
                string != null && "45".equals(string) );
        }

        XTextCursor xTextCursor = xText.createTextCursor();
        assure("createTextCursor(): failed", xTextCursor != null);

        try {
            xText.createTextCursorByRange(null);
            assure("createTextCursorByRange(): null allowed?", false);
        } catch (RuntimeException e) { /* expected */ }

        XTextCursor xTextCursorStart = xText.createTextCursorByRange(xStart);
        assure("createTextCursorByRange(): failed for start",
                xTextCursorStart != null);

        XTextCursor xTextCursorEnd = xText.createTextCursorByRange(xEnd);
        assure("createTextCursorByRange(): failed for end",
                xTextCursorEnd != null);

        // move outside meta
        xDocTextCursor.gotoStart(false);

        try {
            xText.insertString(null, "foo", false);
            assure("insertString(): null allowed?", false);
        } catch (RuntimeException e) { /* expected */ }

        try {
            xText.insertString(xDocTextCursor, "foo", false);
            assure("insertString(): cursor outside allowed?", false);
        } catch (RuntimeException e) { /* expected */ }

        xStart = xText.getStart();
        xText.insertString(xStart, "A", false);
        {
            String string = xText.getString();
            assure("getString(): invalid string returned: " + string,
                string != null && "A45".equals(string) );
        }

        xText.insertString(xEnd, "B", false);
        {
            String string = xText.getString();
            assure("getString(): invalid string returned: " + string,
                string != null && "A45B".equals(string) );
        }

        try {
            xText.insertControlCharacter(null, HARD_HYPHEN, false);
            assure("insertControlCharacter(): null allowed?", false);
        } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }

        xStart = xText.getStart();
        try {
            xText.insertControlCharacter(xDocTextCursor, HARD_HYPHEN, false);
            assure("insertControlCharacter(): cursor outside allowed?", false);
        } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }

        xText.insertControlCharacter(xStart, HARD_HYPHEN, false);
        {
            String string = xText.getString();
            assure("getString(): invalid string returned: " + string,
                string != null && ('\u2011' + "A45B").equals(string) );
        }

        xText.insertControlCharacter(xEnd, HARD_HYPHEN, false);
        {
            String string = xText.getString();
            assure("getString(): invalid string returned: " + string,
                string != null &&
                ('\u2011' + "A45B" + '\u2011').equals(string) );
        }

        xText.setString("45");

        try {
            xText.insertTextContent(null, xMeta, false);
            assure("insertTextContent(): null range allowed?", false);
        } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }

        try {
            xText.insertTextContent(xStart, null, false);
            assure("insertTextContent(): null content allowed?", false);
        } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }

        try {
            xText.insertTextContent(xDocTextCursor, xMeta, false);
            assure("insertTextContent(): cursor outside allowed?", false);
        } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }

        TextFieldNode field1 = new TextFieldNode( "f1" );
        TextFieldNode field2 = new TextFieldNode( "f2" );
        XTextContent xField1 = inserter.makeTextField(field1.getContent());
        XTextContent xField2 = inserter.makeTextField(field2.getContent());

        xStart = xText.getStart();
        xText.insertTextContent(xStart, xField1, false);

        TreeNode root = new TreeNode()
View Full Code Here

    {
        RangeInserter inserter = new RangeInserter(m_xDoc);
        TreeNode text = new TextNode("Text. 12 More text here.");
        inserter.insertRange( new Range(0, 0, text) );
        MetaNode met1 = new MetaNode( mkId("id") );
        XTextContent xMeta = inserter.makeMeta();

        XText xDocText = m_xDoc.getText();
        XTextCursor xDocTextCursor = xDocText.createTextCursor();
        xDocTextCursor.goRight((short)7, false);
        xDocTextCursor.goRight((short)2, true);
View Full Code Here

    {
        RangeInserter inserter = new RangeInserter(m_xDoc);
        TreeNode text = new TextNode("12AB6789");
        inserter.insertRange( new Range(0, 0, text) );
        MetaNode met1 = new MetaNode( mkId("id") );
        XTextContent xMeta = inserter.makeMeta();

        XText xDocText = m_xDoc.getText();
        XTextCursor xDocTextCursor = xDocText.createTextCursor();
        xDocTextCursor.goRight((short)3, false);
        xDocTextCursor.goRight((short)2, true);
        xDocText.insertTextContent(xDocTextCursor, xMeta, true);

        XMetadatable xMetadatable = (XMetadatable)
            UnoRuntime.queryInterface(XMetadatable.class, xMeta);
        xMetadatable.setMetadataReference(met1.getXmlId());
        XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta);
        XTextRange xStart = null;
        XTextRange xEnd = null;

        {
            xStart = xText.getStart();
            xEnd = xText.getEnd();

            TreeNode nod1 = helper.mkTreeNode();
            TreeNode nod2 = helper.mkTreeNode();
            XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
            XTextContent xContent2 = helper.mkTextContent(inserter, nod2);

            // insertTextContent with meta getStart()/getEnd()
            xText.insertTextContent(xStart, xContent1, false);
            xText.insertTextContent(xEnd  , xContent2, false);

            helper.postInserted(nod1, xContent1);
            helper.postInserted(nod2, xContent2);

            TreeNode root = new TreeNode()
                .appendChild( new TextNode("12") )
                .appendChild( met1.dup()
                    .appendChild( nod1.dup() )
                    .appendChild( new TextNode("AB") )
                    .appendChild( nod2.dup() ) )
                .appendChild( new TextNode("6789") );
            doTest(root, false);
        }
        {
            xText.setString("AB");
            xStart = xText.getStart();
            xEnd = xText.getEnd();

            TreeNode nod1 = helper.mkTreeNode();
            TreeNode nod2 = helper.mkTreeNode();
            XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
            XTextContent xContent2 = helper.mkTextContent(inserter, nod2);

            XTextCursor xTextCursor = xText.createTextCursor();
            xTextCursor.gotoStart(false);

            // insertTextContent with meta cursor
            xText.insertTextContent(xTextCursor, xContent1, false);
            xTextCursor.gotoEnd(false);
            xText.insertTextContent(xTextCursor, xContent2, false);

            helper.postInserted(nod1, xContent1);
            helper.postInserted(nod2, xContent2);

            TreeNode root = new TreeNode()
                .appendChild( new TextNode("12") )
                .appendChild( met1.dup()
                    .appendChild( nod1.dup() )
                    .appendChild( new TextNode("AB") )
                    .appendChild( nod2.dup() ) )
                .appendChild( new TextNode("6789") );
            doTest(root, false);
        }
        if (!helper.isAttribute())
        {
//            xText.setString("AB");
            xStart = xText.getStart();
            xEnd = xText.getEnd();

            TreeNode nod1 = helper.mkTreeNode();
            TreeNode nod2 = helper.mkTreeNode();
            XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
            XTextContent xContent2 = helper.mkTextContent(inserter, nod2);

            XTextCursor xTextCursor = xText.createTextCursor();
            xTextCursor.gotoStart(false);
            xTextCursor.goRight((short)1, true);

            // insertTextContent with meta cursor and absorb
            xText.insertTextContent(xTextCursor, xContent1, true);
            xTextCursor.gotoEnd(false);
            xTextCursor.goLeft((short)1, true);
            xText.insertTextContent(xTextCursor, xContent2, true);

            helper.postInserted(nod1, xContent1);
            helper.postInserted(nod2, xContent2);

            TreeNode root = new TreeNode()
                .appendChild( new TextNode("12") )
                .appendChild( met1.dup()
                    .appendChild( nod1.dup() )
                    .appendChild( new TextNode("AB") )
                    .appendChild( nod2.dup() ) )
                .appendChild( new TextNode("6789") );
            doTest(root, false);
        }
        {
            xText.setString("AB");
            xStart = xText.getStart();
            xEnd = xText.getEnd();

            TreeNode nod1 = helper.mkTreeNode();
            TreeNode nod2 = helper.mkTreeNode();
            XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
            XTextContent xContent2 = helper.mkTextContent(inserter, nod2);

            xDocTextCursor.gotoRange(xStart, false);

            // insertTextContent with document cursor
            xText.insertTextContent(xDocTextCursor, xContent1, false);
            xDocTextCursor.gotoRange(xEnd, false);
            xText.insertTextContent(xDocTextCursor, xContent2, false);

            helper.postInserted(nod1, xContent1);
            helper.postInserted(nod2, xContent2);

            TreeNode root = new TreeNode()
                .appendChild( new TextNode("12") )
                .appendChild( met1.dup()
                    .appendChild( nod1.dup() )
                    .appendChild( new TextNode("AB") )
                    .appendChild( nod2.dup() ) )
                .appendChild( new TextNode("6789") );
            doTest(root, false);
        }
        if (!helper.isAttribute())
        {
//            xText.setString("AB");
            xStart = xText.getStart();
            xEnd = xText.getEnd();

            TreeNode nod1 = helper.mkTreeNode();
            TreeNode nod2 = helper.mkTreeNode();
            XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
            XTextContent xContent2 = helper.mkTextContent(inserter, nod2);

            xDocTextCursor.gotoRange(xStart, false);
            xDocTextCursor.goRight((short)1, true);

            // insertTextContent with document cursor and absorb
            xText.insertTextContent(xDocTextCursor, xContent1, true);
            xDocTextCursor.gotoRange(xEnd, false);
            xDocTextCursor.goLeft((short)1, true);
            xText.insertTextContent(xDocTextCursor, xContent2, true);

            helper.postInserted(nod1, xContent1);
            helper.postInserted(nod2, xContent2);

            TreeNode root = new TreeNode()
                .appendChild( new TextNode("12") )
                .appendChild( met1.dup()
                    .appendChild( nod1.dup() )
                    .appendChild( new TextNode("AB") )
                    .appendChild( nod2.dup() ) )
                .appendChild( new TextNode("6789") );
            doTest(root, false);
        }
        {
            xText.setString("AB");
            xStart = xText.getStart();
            xEnd = xText.getEnd();

            TreeNode nod1 = helper.mkTreeNode();
            TreeNode nod2 = helper.mkTreeNode();
            XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
            XTextContent xContent2 = helper.mkTextContent(inserter, nod2);

            // attach to range from meta getStart()/getEnd()
            xContent1.attach(xStart);
            xContent2.attach(xEnd);

            helper.postInserted(nod1, xContent1);
            helper.postInserted(nod2, xContent2);

            TreeNode root = new TreeNode()
                .appendChild( new TextNode("12") )
                .appendChild( met1.dup()
                    .appendChild( nod1.dup() )
                    .appendChild( new TextNode("AB") )
                    .appendChild( nod2.dup() ) )
                .appendChild( new TextNode("6789") );
            doTest(root, false);
        }
        {
            xText.setString("AB");
            xStart = xText.getStart();
            xEnd = xText.getEnd();

            TreeNode nod1 = helper.mkTreeNode();
            TreeNode nod2 = helper.mkTreeNode();
            XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
            XTextContent xContent2 = helper.mkTextContent(inserter, nod2);

            XTextCursor xTextCursor = xText.createTextCursor();
            xTextCursor.gotoStart(false);

            // attach to cursor from meta XText
            xContent1.attach(xTextCursor);
            xTextCursor.gotoEnd(false);
            xContent2.attach(xTextCursor);

            helper.postInserted(nod1, xContent1);
            helper.postInserted(nod2, xContent2);

            TreeNode root = new TreeNode()
View Full Code Here

       
        // find the bookmark named "Subscription"
        Object bookmark = xNamedBookmarks.getByName("Subscription");
        // we need its XTextRange which is available from getAnchor(),
        // so query for XTextContent
        XTextContent xBookmarkContent = (XTextContent)UnoRuntime.queryInterface(
            XTextContent.class, bookmark);
        // get the anchor of the bookmark (its XTextRange)
        XTextRange xBookmarkRange = xBookmarkContent.getAnchor();
        // set string at the bookmark position
        xBookmarkRange.setString("subscription for the Manatee Journal");
  
    }
View Full Code Here

            // Again, the Level property _must_ be set
            xIndex.setPropertyValue ( "Level", new Short ( (short) 10 ) );

            // Access the XTextContent interfaces of both the Index and the
            // IndexMark
            XTextContent xIndexContent = (XTextContent) UnoRuntime.queryInterface(
                XTextContent.class, xIndex );
            XTextContent xEntryContent = (XTextContent) UnoRuntime.queryInterface(
                XTextContent.class, xEntry );
           
            // Insert both in the document
            mxDocText.insertTextContent ( mxDocCursor, xEntryContent, false );
            mxDocText.insertTextContent ( mxDocCursor, xIndexContent, false );
View Full Code Here

TOP

Related Classes of com.sun.star.text.XTextContent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.