Logo Search packages:      
Sourcecode: jabref-plugin-oo version File versions  Download package

static void net::sf::jabref::oo::OOUtil::insertOOFormattedTextAtCurrentLocation ( XText  text,
XTextCursor  cursor,
String  lText,
String  parStyle 
) throws UndefinedParagraphFormatException, Exception [inline, static]

Insert a text with formatting indicated by HTML-like tags, into a text at the position given by a cursor.

Parameters:
text The text to insert in.
cursor The cursor giving the insert location.
lText The marked-up text to insert.
parStyle The name of the paragraph style to use.
Exceptions:
Exception 

Definition at line 72 of file OOUtil.java.

Referenced by insertFullReferenceAtCurrentLocation().

                                                                                                 {

        XParagraphCursor parCursor = (XParagraphCursor)UnoRuntime.queryInterface(
            XParagraphCursor.class, cursor);
        XPropertySet props = (XPropertySet) UnoRuntime.queryInterface(
            XPropertySet.class, parCursor);

        try {
            props.setPropertyValue("ParaStyleName", parStyle);
        } catch (com.sun.star.lang.IllegalArgumentException ex) {
            throw new UndefinedParagraphFormatException(parStyle);
        }
        
        // We need to extract formatting. Use a simple regexp search iteration:
        int piv = 0;
        int italic = 0, bold = 0, sup = 0, sub = 0, mono = 0, smallCaps = 0;
        //insertTextAtCurrentLocation(text, cursor, "_",
        //    false, false, false, false, false, false);
        //cursor.goLeft((short)1, true);
        Matcher m = htmlTag.matcher(lText);
        while (m.find()) {
            String ss = lText.substring(piv, m.start());
            if (ss.length() > 0) {
                insertTextAtCurrentLocation(text, cursor, ss, (bold % 2) > 0, (italic % 2) > 0,
                        mono > 0, smallCaps > 0, sup > 0, sub > 0);
            }
            String tag = m.group();
            // Handle tags:
            if (tag.equals("<b>"))
                bold++;
            else if (tag.equals("</b>"))
                bold--;
            else if (tag.equals("<i>") || tag.equals("<em>"))
                italic++;
            else if (tag.equals("</i>") || tag.equals("</em>"))
                italic--;
            else if (tag.equals("</monospace>"))
                mono = 0;
            else if (tag.equals("<monospace>"))
                mono = 1;
            else if (tag.equals("</smallcaps>"))
                smallCaps = 0;
            else if (tag.equals("<smallcaps>"))
                smallCaps = 1;
            else if (tag.equals("</sup>"))
                sup = 0;
            else if (tag.equals("<sup>"))
                sup = 1;
            else if (tag.equals("</sub>"))
                sub = 0;
            else if (tag.equals("<sub>"))
                sub = 1;

            piv = m.end();
            
        }

        if (piv < lText.length())
            insertTextAtCurrentLocation(text, cursor,lText.substring(piv),
                    (bold % 2) > 0, (italic % 2) > 0, mono > 0, smallCaps > 0, sup > 0, sub > 0);



        cursor.collapseToEnd();
    }


Generated by  Doxygen 1.6.0   Back to index