PageRenderTime 39ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 1ms

/components/forks/poi/src/loci/poi/hpsf/DocumentSummaryInformation.java

http://github.com/openmicroscopy/bioformats
Java | 700 lines | 295 code | 101 blank | 304 comment | 14 complexity | c2188c129ae22690bf1bc62c31e01c84 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /* ====================================================================
  24. Licensed to the Apache Software Foundation (ASF) under one or more
  25. contributor license agreements. See the NOTICE file distributed with
  26. this work for additional information regarding copyright ownership.
  27. The ASF licenses this file to You under the Apache License, Version 2.0
  28. (the "License"); you may not use this file except in compliance with
  29. the License. You may obtain a copy of the License at
  30. http://www.apache.org/licenses/LICENSE-2.0
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. ==================================================================== */
  37. package loci.poi.hpsf;
  38. import java.util.Iterator;
  39. import java.util.Map;
  40. import loci.poi.hpsf.wellknown.PropertyIDMap;
  41. import loci.poi.hpsf.wellknown.SectionIDMap;
  42. /**
  43. * <p>Convenience class representing a DocumentSummary Information stream in a
  44. * Microsoft Office document.</p>
  45. *
  46. * @author Rainer Klute <a
  47. * href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
  48. * @author Drew Varner (Drew.Varner closeTo sc.edu)
  49. * @author robert_flaherty@hyperion.com
  50. * @see SummaryInformation
  51. * @version $Id: DocumentSummaryInformation.java 489730 2006-12-22 19:18:16Z bayard $
  52. * @since 2002-02-09
  53. */
  54. public class DocumentSummaryInformation extends SpecialPropertySet
  55. {
  56. /**
  57. * <p>The document name a document summary information stream
  58. * usually has in a POIFS filesystem.</p>
  59. */
  60. public static final String DEFAULT_STREAM_NAME =
  61. "\005DocumentSummaryInformation";
  62. /**
  63. * <p>Creates a {@link DocumentSummaryInformation} from a given
  64. * {@link PropertySet}.</p>
  65. *
  66. * @param ps A property set which should be created from a
  67. * document summary information stream.
  68. * @throws UnexpectedPropertySetTypeException if <var>ps</var>
  69. * does not contain a document summary information stream.
  70. */
  71. public DocumentSummaryInformation(final PropertySet ps)
  72. throws UnexpectedPropertySetTypeException
  73. {
  74. super(ps);
  75. if (!isDocumentSummaryInformation())
  76. throw new UnexpectedPropertySetTypeException
  77. ("Not a " + getClass().getName());
  78. }
  79. /**
  80. * <p>Returns the category (or <code>null</code>).</p>
  81. *
  82. * @return The category value
  83. */
  84. public String getCategory()
  85. {
  86. return (String) getProperty(PropertyIDMap.PID_CATEGORY);
  87. }
  88. /**
  89. * <p>Sets the category.</p>
  90. *
  91. * @param category The category to set.
  92. */
  93. public void setCategory(final String category)
  94. {
  95. final MutableSection s = (MutableSection) getFirstSection();
  96. s.setProperty(PropertyIDMap.PID_CATEGORY, category);
  97. }
  98. /**
  99. * <p>Removes the category.</p>
  100. */
  101. public void removeCategory()
  102. {
  103. final MutableSection s = (MutableSection) getFirstSection();
  104. s.removeProperty(PropertyIDMap.PID_CATEGORY);
  105. }
  106. /**
  107. * <p>Returns the presentation format (or
  108. * <code>null</code>).</p>
  109. *
  110. * @return The presentation format value
  111. */
  112. public String getPresentationFormat()
  113. {
  114. return (String) getProperty(PropertyIDMap.PID_PRESFORMAT);
  115. }
  116. /**
  117. * <p>Sets the presentation format.</p>
  118. *
  119. * @param presentationFormat The presentation format to set.
  120. */
  121. public void setPresentationFormat(final String presentationFormat)
  122. {
  123. final MutableSection s = (MutableSection) getFirstSection();
  124. s.setProperty(PropertyIDMap.PID_PRESFORMAT, presentationFormat);
  125. }
  126. /**
  127. * <p>Removes the presentation format.</p>
  128. */
  129. public void removePresentationFormat()
  130. {
  131. final MutableSection s = (MutableSection) getFirstSection();
  132. s.removeProperty(PropertyIDMap.PID_PRESFORMAT);
  133. }
  134. /**
  135. * <p>Returns the byte count or 0 if the {@link
  136. * DocumentSummaryInformation} does not contain a byte count.</p>
  137. *
  138. * @return The byteCount value
  139. */
  140. public int getByteCount()
  141. {
  142. return getPropertyIntValue(PropertyIDMap.PID_BYTECOUNT);
  143. }
  144. /**
  145. * <p>Sets the byte count.</p>
  146. *
  147. * @param byteCount The byte count to set.
  148. */
  149. public void setByteCount(final int byteCount)
  150. {
  151. final MutableSection s = (MutableSection) getFirstSection();
  152. s.setProperty(PropertyIDMap.PID_BYTECOUNT, byteCount);
  153. }
  154. /**
  155. * <p>Removes the byte count.</p>
  156. */
  157. public void removeByteCount()
  158. {
  159. final MutableSection s = (MutableSection) getFirstSection();
  160. s.removeProperty(PropertyIDMap.PID_BYTECOUNT);
  161. }
  162. /**
  163. * <p>Returns the line count or 0 if the {@link
  164. * DocumentSummaryInformation} does not contain a line count.</p>
  165. *
  166. * @return The line count value
  167. */
  168. public int getLineCount()
  169. {
  170. return getPropertyIntValue(PropertyIDMap.PID_LINECOUNT);
  171. }
  172. /**
  173. * <p>Sets the line count.</p>
  174. *
  175. * @param lineCount The line count to set.
  176. */
  177. public void setLineCount(final int lineCount)
  178. {
  179. final MutableSection s = (MutableSection) getFirstSection();
  180. s.setProperty(PropertyIDMap.PID_LINECOUNT, lineCount);
  181. }
  182. /**
  183. * <p>Removes the line count.</p>
  184. */
  185. public void removeLineCount()
  186. {
  187. final MutableSection s = (MutableSection) getFirstSection();
  188. s.removeProperty(PropertyIDMap.PID_LINECOUNT);
  189. }
  190. /**
  191. * <p>Returns the par count or 0 if the {@link
  192. * DocumentSummaryInformation} does not contain a par count.</p>
  193. *
  194. * @return The par count value
  195. */
  196. public int getParCount()
  197. {
  198. return getPropertyIntValue(PropertyIDMap.PID_PARCOUNT);
  199. }
  200. /**
  201. * <p>Sets the par count.</p>
  202. *
  203. * @param parCount The par count to set.
  204. */
  205. public void setParCount(final int parCount)
  206. {
  207. final MutableSection s = (MutableSection) getFirstSection();
  208. s.setProperty(PropertyIDMap.PID_PARCOUNT, parCount);
  209. }
  210. /**
  211. * <p>Removes the par count.</p>
  212. */
  213. public void removeParCount()
  214. {
  215. final MutableSection s = (MutableSection) getFirstSection();
  216. s.removeProperty(PropertyIDMap.PID_PARCOUNT);
  217. }
  218. /**
  219. * <p>Returns the slide count or 0 if the {@link
  220. * DocumentSummaryInformation} does not contain a slide count.</p>
  221. *
  222. * @return The slide count value
  223. */
  224. public int getSlideCount()
  225. {
  226. return getPropertyIntValue(PropertyIDMap.PID_SLIDECOUNT);
  227. }
  228. /**
  229. * <p>Sets the slideCount.</p>
  230. *
  231. * @param slideCount The slide count to set.
  232. */
  233. public void setSlideCount(final int slideCount)
  234. {
  235. final MutableSection s = (MutableSection) getFirstSection();
  236. s.setProperty(PropertyIDMap.PID_SLIDECOUNT, slideCount);
  237. }
  238. /**
  239. * <p>Removes the slide count.</p>
  240. */
  241. public void removeSlideCount()
  242. {
  243. final MutableSection s = (MutableSection) getFirstSection();
  244. s.removeProperty(PropertyIDMap.PID_SLIDECOUNT);
  245. }
  246. /**
  247. * <p>Returns the note count or 0 if the {@link
  248. * DocumentSummaryInformation} does not contain a note count.</p>
  249. *
  250. * @return The note count value
  251. */
  252. public int getNoteCount()
  253. {
  254. return getPropertyIntValue(PropertyIDMap.PID_NOTECOUNT);
  255. }
  256. /**
  257. * <p>Sets the note count.</p>
  258. *
  259. * @param noteCount The note count to set.
  260. */
  261. public void setNoteCount(final int noteCount)
  262. {
  263. final MutableSection s = (MutableSection) getFirstSection();
  264. s.setProperty(PropertyIDMap.PID_NOTECOUNT, noteCount);
  265. }
  266. /**
  267. * <p>Removes the noteCount.</p>
  268. */
  269. public void removeNoteCount()
  270. {
  271. final MutableSection s = (MutableSection) getFirstSection();
  272. s.removeProperty(PropertyIDMap.PID_NOTECOUNT);
  273. }
  274. /**
  275. * <p>Returns the hidden count or 0 if the {@link
  276. * DocumentSummaryInformation} does not contain a hidden
  277. * count.</p>
  278. *
  279. * @return The hidden count value
  280. */
  281. public int getHiddenCount()
  282. {
  283. return getPropertyIntValue(PropertyIDMap.PID_HIDDENCOUNT);
  284. }
  285. /**
  286. * <p>Sets the hidden count.</p>
  287. *
  288. * @param hiddenCount The hidden count to set.
  289. */
  290. public void setHiddenCount(final int hiddenCount)
  291. {
  292. final MutableSection s = (MutableSection) getSections().get(0);
  293. s.setProperty(PropertyIDMap.PID_HIDDENCOUNT, hiddenCount);
  294. }
  295. /**
  296. * <p>Removes the hidden count.</p>
  297. */
  298. public void removeHiddenCount()
  299. {
  300. final MutableSection s = (MutableSection) getFirstSection();
  301. s.removeProperty(PropertyIDMap.PID_HIDDENCOUNT);
  302. }
  303. /**
  304. * <p>Returns the mmclip count or 0 if the {@link
  305. * DocumentSummaryInformation} does not contain a mmclip
  306. * count.</p>
  307. *
  308. * @return The mmclip count value
  309. */
  310. public int getMMClipCount()
  311. {
  312. return getPropertyIntValue(PropertyIDMap.PID_MMCLIPCOUNT);
  313. }
  314. /**
  315. * <p>Sets the mmclip count.</p>
  316. *
  317. * @param mmClipCount The mmclip count to set.
  318. */
  319. public void setMMClipCount(final int mmClipCount)
  320. {
  321. final MutableSection s = (MutableSection) getFirstSection();
  322. s.setProperty(PropertyIDMap.PID_MMCLIPCOUNT, mmClipCount);
  323. }
  324. /**
  325. * <p>Removes the mmclip count.</p>
  326. */
  327. public void removeMMClipCount()
  328. {
  329. final MutableSection s = (MutableSection) getFirstSection();
  330. s.removeProperty(PropertyIDMap.PID_MMCLIPCOUNT);
  331. }
  332. /**
  333. * <p>Returns <code>true</code> when scaling of the thumbnail is
  334. * desired, <code>false</code> if cropping is desired.</p>
  335. *
  336. * @return The scale value
  337. */
  338. public boolean getScale()
  339. {
  340. return getPropertyBooleanValue(PropertyIDMap.PID_SCALE);
  341. }
  342. /**
  343. * <p>Sets the scale.</p>
  344. *
  345. * @param scale The scale to set.
  346. */
  347. public void setScale(final boolean scale)
  348. {
  349. final MutableSection s = (MutableSection) getFirstSection();
  350. s.setProperty(PropertyIDMap.PID_SCALE, scale);
  351. }
  352. /**
  353. * <p>Removes the scale.</p>
  354. */
  355. public void removeScale()
  356. {
  357. final MutableSection s = (MutableSection) getFirstSection();
  358. s.removeProperty(PropertyIDMap.PID_SCALE);
  359. }
  360. /**
  361. * <p>Returns the heading pair (or <code>null</code>)
  362. * <strong>when this method is implemented. Please note that the
  363. * return type is likely to change!</strong>
  364. *
  365. * @return The heading pair value
  366. */
  367. public byte[] getHeadingPair()
  368. {
  369. notYetImplemented("Reading byte arrays ");
  370. return (byte[]) getProperty(PropertyIDMap.PID_HEADINGPAIR);
  371. }
  372. /**
  373. * <p>Sets the heading pair.</p>
  374. *
  375. * @param headingPair The heading pair to set.
  376. */
  377. public void setHeadingPair(final byte[] headingPair)
  378. {
  379. notYetImplemented("Writing byte arrays ");
  380. }
  381. /**
  382. * <p>Removes the heading pair.</p>
  383. */
  384. public void removeHeadingPair()
  385. {
  386. final MutableSection s = (MutableSection) getFirstSection();
  387. s.removeProperty(PropertyIDMap.PID_HEADINGPAIR);
  388. }
  389. /**
  390. * <p>Returns the doc parts (or <code>null</code>)
  391. * <strong>when this method is implemented. Please note that the
  392. * return type is likely to change!</strong>
  393. *
  394. * @return The doc parts value
  395. */
  396. public byte[] getDocparts()
  397. {
  398. notYetImplemented("Reading byte arrays");
  399. return (byte[]) getProperty(PropertyIDMap.PID_DOCPARTS);
  400. }
  401. /**
  402. * <p>Sets the doc parts.</p>
  403. *
  404. * @param docparts The doc parts to set.
  405. */
  406. public void setDocparts(final byte[] docparts)
  407. {
  408. notYetImplemented("Writing byte arrays");
  409. }
  410. /**
  411. * <p>Removes the doc parts.</p>
  412. */
  413. public void removeDocparts()
  414. {
  415. final MutableSection s = (MutableSection) getFirstSection();
  416. s.removeProperty(PropertyIDMap.PID_DOCPARTS);
  417. }
  418. /**
  419. * <p>Returns the manager (or <code>null</code>).</p>
  420. *
  421. * @return The manager value
  422. */
  423. public String getManager()
  424. {
  425. return (String) getProperty(PropertyIDMap.PID_MANAGER);
  426. }
  427. /**
  428. * <p>Sets the manager.</p>
  429. *
  430. * @param manager The manager to set.
  431. */
  432. public void setManager(final String manager)
  433. {
  434. final MutableSection s = (MutableSection) getFirstSection();
  435. s.setProperty(PropertyIDMap.PID_MANAGER, manager);
  436. }
  437. /**
  438. * <p>Removes the manager.</p>
  439. */
  440. public void removeManager()
  441. {
  442. final MutableSection s = (MutableSection) getFirstSection();
  443. s.removeProperty(PropertyIDMap.PID_MANAGER);
  444. }
  445. /**
  446. * <p>Returns the company (or <code>null</code>).</p>
  447. *
  448. * @return The company value
  449. */
  450. public String getCompany()
  451. {
  452. return (String) getProperty(PropertyIDMap.PID_COMPANY);
  453. }
  454. /**
  455. * <p>Sets the company.</p>
  456. *
  457. * @param company The company to set.
  458. */
  459. public void setCompany(final String company)
  460. {
  461. final MutableSection s = (MutableSection) getFirstSection();
  462. s.setProperty(PropertyIDMap.PID_COMPANY, company);
  463. }
  464. /**
  465. * <p>Removes the company.</p>
  466. */
  467. public void removeCompany()
  468. {
  469. final MutableSection s = (MutableSection) getFirstSection();
  470. s.removeProperty(PropertyIDMap.PID_COMPANY);
  471. }
  472. /**
  473. * <p>Returns <code>true</code> if the custom links are dirty.</p> <p>
  474. *
  475. * @return The links dirty value
  476. */
  477. public boolean getLinksDirty()
  478. {
  479. return getPropertyBooleanValue(PropertyIDMap.PID_LINKSDIRTY);
  480. }
  481. /**
  482. * <p>Sets the linksDirty.</p>
  483. *
  484. * @param linksDirty The links dirty value to set.
  485. */
  486. public void setLinksDirty(final boolean linksDirty)
  487. {
  488. final MutableSection s = (MutableSection) getFirstSection();
  489. s.setProperty(PropertyIDMap.PID_LINKSDIRTY, linksDirty);
  490. }
  491. /**
  492. * <p>Removes the links dirty.</p>
  493. */
  494. public void removeLinksDirty()
  495. {
  496. final MutableSection s = (MutableSection) getFirstSection();
  497. s.removeProperty(PropertyIDMap.PID_LINKSDIRTY);
  498. }
  499. /**
  500. * <p>Gets the custom properties.</p>
  501. *
  502. * @return The custom properties.
  503. * @since 2006-02-09
  504. */
  505. public CustomProperties getCustomProperties()
  506. {
  507. CustomProperties cps = null;
  508. if (getSectionCount() >= 2)
  509. {
  510. cps = new CustomProperties();
  511. final Section section = (Section) getSections().get(1);
  512. final Map dictionary = section.getDictionary();
  513. final Property[] properties = section.getProperties();
  514. int propertyCount = 0;
  515. for (int i = 0; i < properties.length; i++)
  516. {
  517. final Property p = properties[i];
  518. final long id = p.getID();
  519. if (id != 0 && id != 1)
  520. {
  521. propertyCount++;
  522. final CustomProperty cp = new CustomProperty(p,
  523. (String) dictionary.get(new Long(id)));
  524. cps.put(cp.getName(), cp);
  525. }
  526. }
  527. if (cps.size() != propertyCount)
  528. cps.setPure(false);
  529. }
  530. return cps;
  531. }
  532. /**
  533. * <p>Sets the custom properties.</p>
  534. *
  535. * @param customProperties The custom properties
  536. * @since 2006-02-07
  537. */
  538. public void setCustomProperties(final CustomProperties customProperties)
  539. {
  540. ensureSection2();
  541. final MutableSection section = (MutableSection) getSections().get(1);
  542. final Map dictionary = customProperties.getDictionary();
  543. section.clear();
  544. /* Set the codepage. If both custom properties and section have a
  545. * codepage, the codepage from the custom properties wins, else take the
  546. * one that is defined. If none is defined, take Unicode. */
  547. int cpCodepage = customProperties.getCodepage();
  548. if (cpCodepage < 0)
  549. cpCodepage = section.getCodepage();
  550. if (cpCodepage < 0)
  551. cpCodepage = Constants.CP_UNICODE;
  552. customProperties.setCodepage(cpCodepage);
  553. section.setCodepage(cpCodepage);
  554. section.setDictionary(dictionary);
  555. for (final Iterator i = customProperties.values().iterator(); i.hasNext();)
  556. {
  557. final Property p = (Property) i.next();
  558. section.setProperty(p);
  559. }
  560. }
  561. /**
  562. * <p>Creates section 2 if it is not already present.</p>
  563. *
  564. */
  565. private void ensureSection2()
  566. {
  567. if (getSectionCount() < 2)
  568. {
  569. MutableSection s2 = new MutableSection();
  570. s2.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[1]);
  571. addSection(s2);
  572. }
  573. }
  574. /**
  575. * <p>Removes the custom properties.</p>
  576. *
  577. * @since 2006-02-08
  578. */
  579. public void removeCustomProperties()
  580. {
  581. if (getSectionCount() >= 2)
  582. getSections().remove(1);
  583. else
  584. throw new HPSFRuntimeException("Illegal internal format of Document SummaryInformation stream: second section is missing.");
  585. }
  586. /**
  587. * <p>Throws an {@link UnsupportedOperationException} with a message text
  588. * telling which functionality is not yet implemented.</p>
  589. *
  590. * @param msg text telling was leaves to be implemented, e.g.
  591. * "Reading byte arrays".
  592. */
  593. private void notYetImplemented(final String msg)
  594. {
  595. throw new UnsupportedOperationException(msg + " is not yet implemented.");
  596. }
  597. }