View | Details | Raw Unified | Return to bug 39948
Collapse All | Expand All

(-)src/scratchpad/src/org/apache/poi/hslf/model/Slide.java (+24 lines)
Lines 143-148 Link Here
143
  }
143
  }
144
144
145
145
146
    /**
147
     * Return title of this slide or <code>null</code> if the slide does not have title.
148
     * <p>
149
     * The title is a run of text of type <code>TextHeaderAtom.CENTER_TITLE_TYPE</code> or
150
     * <code>TextHeaderAtom.TITLE_TYPE</code>
151
     * </p>
152
     *
153
     * @see TextHeaderAtom
154
     *
155
     * @return title of this slide
156
     */
157
    public String getTitle(){
158
        TextRun[] txt = getTextRuns();
159
        for (int i = 0; i < txt.length; i++) {
160
            int type = txt[i].getRunType();
161
            if (type == TextHeaderAtom.CENTER_TITLE_TYPE ||
162
                type == TextHeaderAtom.TITLE_TYPE ){
163
                String title = txt[i].getText();
164
                return title;
165
            }
166
        }
167
        return null;
168
    }
169
146
  // Accesser methods follow
170
  // Accesser methods follow
147
171
148
  /**
172
  /**
(-)src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSlideOrdering.java (+68 lines)
Lines 85-88 Link Here
85
    	assertEquals(firstTRs[1], s2.getTextRuns()[0].getText());
85
    	assertEquals(firstTRs[1], s2.getTextRuns()[0].getText());
86
    	assertEquals(firstTRs[2], s3.getTextRuns()[0].getText());
86
    	assertEquals(firstTRs[2], s3.getTextRuns()[0].getText());
87
    }
87
    }
88
89
    /**
90
     * Assert that the order of slides is correct.
91
     *
92
     * @param filename  file name of the slide show to assert
93
     * @param titles    array of reference slide titles
94
     */
95
    protected void assertSlideOrdering(String filename, String[] titles) throws Exception {
96
        SlideShow ppt = new SlideShow(new HSLFSlideShow(filename));
97
        Slide[] slide = ppt.getSlides();
98
99
        assertEquals(titles.length, slide.length);
100
        for (int i = 0; i < slide.length; i++) {
101
            String title = slide[i].getTitle();
102
            assertEquals("Wrong slide title in " + filename, titles[i], title);
103
        }
104
    }
105
106
    public void testTitles() throws Exception{
107
        String dirname = System.getProperty("HSLF.testdata.path");
108
109
        assertSlideOrdering(dirname + "/basic_test_ppt_file.ppt",
110
                new String[]{
111
                    "This is a test title",
112
                    "This is the title on page 2"
113
                });
114
115
        assertSlideOrdering(dirname + "/incorrect_slide_order.ppt",
116
                new String[]{
117
                    "Slide 1",
118
                    "Slide 2",
119
                    "Slide 3"
120
                });
121
122
        assertSlideOrdering(dirname + "/next_test_ppt_file.ppt",
123
                new String[]{
124
                    "This is a test title",
125
                    "This is the title on page 2"
126
                });
127
128
        assertSlideOrdering(dirname + "/Single_Coloured_Page.ppt",
129
                new String[]{
130
                    "This is a title, it’s in black"
131
                });
132
133
        assertSlideOrdering(dirname + "/Single_Coloured_Page_With_Fonts_and_Alignments.ppt",
134
                new String[]{
135
                    "This is a title, it’s in black"
136
                });
137
138
        assertSlideOrdering(dirname + "/ParagraphStylesShorterThanCharStyles.ppt",
139
                new String[]{
140
                    "ROMANCE: AN ANALYSIS",
141
                    "AGENDA",
142
                    "You are an important supplier of various items that I need",
143
                    (char)0x0B + "Although The Psycho set back my relationship process, recovery is luckily enough under way",
144
                    "Since the time that we seriously go out together, you rank highly among existing relationships",
145
                    "Although our personal interests are mostly compatible, the greatest gap exists in Sex and Shopping",
146
                    "Your physical characteristics are strong when compared with your competition",
147
                    "The combination of your high physical appearance and personality rank you highly, although your sister is also a top prospect",
148
                    "When people found out that we were going out, their responses have been mixed",
149
                    "The benchmark of relationship lifecycles, suggests that we are on schedule",
150
                    "In summary we can say that we are on the right track, but we must remain aware of possible roadblocks ",
151
                    "THE ANSWER",
152
                    "Unfortunately a huge disconnect exists between my needs and your existing service",
153
                    "SUMMARY",
154
                });
155
    }
88
}
156
}

Return to bug 39948