You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PaintTarget.java 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server;
  17. import java.io.Serializable;
  18. import java.util.Map;
  19. import com.vaadin.server.StreamVariable.StreamingStartEvent;
  20. import com.vaadin.ui.Component;
  21. /**
  22. * This interface defines the methods for painting XML to the UIDL stream.
  23. *
  24. * @author Vaadin Ltd.
  25. * @since 3.0
  26. */
  27. public interface PaintTarget extends Serializable {
  28. /**
  29. * Prints single XMLsection.
  30. *
  31. * Prints full XML section. The section data is escaped from XML tags and
  32. * surrounded by XML start and end-tags.
  33. *
  34. * @param sectionTagName
  35. * the name of the tag.
  36. * @param sectionData
  37. * the section data.
  38. * @throws PaintException
  39. * if the paint operation failed.
  40. */
  41. public void addSection(String sectionTagName, String sectionData)
  42. throws PaintException;
  43. /**
  44. * Result of starting to paint a Component (
  45. * {@link PaintTarget#startPaintable(Component, String)}).
  46. *
  47. * @since 7.0
  48. */
  49. public enum PaintStatus {
  50. /**
  51. * Painting started, addVariable() and addAttribute() etc. methods may
  52. * be called.
  53. */
  54. PAINTING,
  55. /**
  56. * A previously unpainted or painted {@link Component} has been queued
  57. * be created/update later in a separate change in the same set of
  58. * changes.
  59. */
  60. CACHED
  61. }
  62. /**
  63. * Prints element start tag of a paintable section. Starts a paintable
  64. * section using the given tag. The PaintTarget may implement a caching
  65. * scheme, that checks the paintable has actually changed or can a cached
  66. * version be used instead. This method should call the startTag method.
  67. * <p>
  68. * If the {@link Component} is found in cache and this function returns true
  69. * it may omit the content and close the tag, in which case cached content
  70. * should be used.
  71. * </p>
  72. * <p>
  73. * This method may also add only a reference to the paintable and queue the
  74. * paintable to be painted separately.
  75. * </p>
  76. * <p>
  77. * Each paintable being painted should be closed by a matching
  78. * {@link #endPaintable(Component)} regardless of the {@link PaintStatus}
  79. * returned.
  80. * </p>
  81. *
  82. * @param paintable
  83. * the paintable to start.
  84. * @param tag
  85. * the name of the start tag.
  86. * @return {@link PaintStatus} - ready to paint or already cached on the
  87. * client (also used for sub paintables that are painted later
  88. * separately)
  89. * @throws PaintException
  90. * if the paint operation failed.
  91. * @see #startTag(String)
  92. * @since 7.0 (previously using startTag(Paintable, String))
  93. */
  94. public PaintStatus startPaintable(Component paintable, String tag)
  95. throws PaintException;
  96. /**
  97. * Prints paintable element end tag.
  98. *
  99. * Calls to {@link #startPaintable(Component, String)}should be matched by
  100. * {@link #endPaintable(Component)}. If the parent tag is closed before
  101. * every child tag is closed a PaintException is raised.
  102. *
  103. * @param paintable
  104. * the paintable to close.
  105. * @throws PaintException
  106. * if the paint operation failed.
  107. * @since 7.0 (previously using engTag(String))
  108. */
  109. public void endPaintable(Component paintable) throws PaintException;
  110. /**
  111. * Prints element start tag.
  112. *
  113. * <pre>
  114. * Todo:
  115. * Checking of input values
  116. * </pre>
  117. *
  118. * @param tagName
  119. * the name of the start tag.
  120. * @throws PaintException
  121. * if the paint operation failed.
  122. */
  123. public void startTag(String tagName) throws PaintException;
  124. /**
  125. * Prints element end tag.
  126. *
  127. * If the parent tag is closed before every child tag is closed an
  128. * PaintException is raised.
  129. *
  130. * @param tagName
  131. * the name of the end tag.
  132. * @throws PaintException
  133. * if the paint operation failed.
  134. */
  135. public void endTag(String tagName) throws PaintException;
  136. /**
  137. * Adds a boolean attribute to component. Attributes must be added before
  138. * any content is written.
  139. *
  140. * @param name
  141. * the Attribute name.
  142. * @param value
  143. * the Attribute value.
  144. *
  145. * @throws PaintException
  146. * if the paint operation failed.
  147. */
  148. public void addAttribute(String name, boolean value) throws PaintException;
  149. /**
  150. * Adds a integer attribute to component. Attributes must be added before
  151. * any content is written.
  152. *
  153. * @param name
  154. * the Attribute name.
  155. * @param value
  156. * the Attribute value.
  157. *
  158. * @throws PaintException
  159. * if the paint operation failed.
  160. */
  161. public void addAttribute(String name, int value) throws PaintException;
  162. /**
  163. * Adds a resource attribute to component. Attributes must be added before
  164. * any content is written.
  165. *
  166. * @param name
  167. * the Attribute name
  168. * @param value
  169. * the Attribute value
  170. *
  171. * @throws PaintException
  172. * if the paint operation failed.
  173. */
  174. public void addAttribute(String name, Resource value) throws PaintException;
  175. /**
  176. * Adds details about {@link StreamVariable} to the UIDL stream. E.g. in web
  177. * terminals Receivers are typically rendered for the client side as URLs,
  178. * where the client side implementation can do an http post request.
  179. * <p>
  180. * The urls in UIDL message may use Vaadin specific protocol. Before
  181. * actually using the urls on the client side, they should be passed via
  182. * {@link com.vaadin.client.ApplicationConnection#translateVaadinUri(String)}.
  183. * <p>
  184. * Note that in current terminal implementation StreamVariables are cleaned
  185. * from the terminal only when:
  186. * <ul>
  187. * <li>a StreamVariable with same name replaces an old one
  188. * <li>the variable owner is no more attached
  189. * <li>the developer signals this by calling
  190. * {@link StreamingStartEvent#disposeStreamVariable()}
  191. * </ul>
  192. * Most commonly a component developer can just ignore this issue, but with
  193. * strict memory requirements and lots of StreamVariables implementations
  194. * that reserve a lot of memory this may be a critical issue.
  195. *
  196. * @param owner
  197. * the ReceiverOwner that can track the progress of streaming to
  198. * the given StreamVariable
  199. * @param name
  200. * an identifying name for the StreamVariable
  201. * @param value
  202. * the StreamVariable to paint
  203. *
  204. * @throws PaintException
  205. * if the paint operation failed.
  206. */
  207. public void addVariable(VariableOwner owner, String name,
  208. StreamVariable value) throws PaintException;
  209. /**
  210. * Adds a long attribute to component. Attributes must be added before any
  211. * content is written.
  212. *
  213. * @param name
  214. * the Attribute name.
  215. * @param value
  216. * the Attribute value.
  217. *
  218. * @throws PaintException
  219. * if the paint operation failed.
  220. */
  221. public void addAttribute(String name, long value) throws PaintException;
  222. /**
  223. * Adds a float attribute to component. Attributes must be added before any
  224. * content is written.
  225. *
  226. * @param name
  227. * the Attribute name.
  228. * @param value
  229. * the Attribute value.
  230. *
  231. * @throws PaintException
  232. * if the paint operation failed.
  233. */
  234. public void addAttribute(String name, float value) throws PaintException;
  235. /**
  236. * Adds a double attribute to component. Attributes must be added before any
  237. * content is written.
  238. *
  239. * @param name
  240. * the Attribute name.
  241. * @param value
  242. * the Attribute value.
  243. *
  244. * @throws PaintException
  245. * if the paint operation failed.
  246. */
  247. public void addAttribute(String name, double value) throws PaintException;
  248. /**
  249. * Adds a string attribute to component. Attributes must be added before any
  250. * content is written.
  251. *
  252. * @param name
  253. * the Boolean attribute name.
  254. * @param value
  255. * the Boolean attribute value.
  256. *
  257. * @throws PaintException
  258. * if the paint operation failed.
  259. */
  260. public void addAttribute(String name, String value) throws PaintException;
  261. /**
  262. * Adds a {@link Map} attribute to the component. Attributes must be added
  263. * before any content is written.
  264. *
  265. * TODO: specify how the map is added
  266. *
  267. * @param name
  268. * @param value
  269. * @throws PaintException
  270. */
  271. public void addAttribute(String name, Map<?, ?> value)
  272. throws PaintException;
  273. /**
  274. * Adds a Component type attribute. On client side the value will be a
  275. * terminal specific reference to corresponding component on client side
  276. * implementation.
  277. *
  278. * @param name
  279. * the name of the attribute
  280. * @param value
  281. * the Component to be referenced on client side
  282. * @throws PaintException
  283. */
  284. public void addAttribute(String name, Component value)
  285. throws PaintException;
  286. /**
  287. * Adds a string type variable.
  288. *
  289. * @param owner
  290. * the Listener for variable changes.
  291. * @param name
  292. * the Variable name.
  293. * @param value
  294. * the Variable initial value.
  295. *
  296. * @throws PaintException
  297. * if the paint operation failed.
  298. */
  299. public void addVariable(VariableOwner owner, String name, String value)
  300. throws PaintException;
  301. /**
  302. * Adds an int type variable.
  303. *
  304. * @param owner
  305. * the Listener for variable changes.
  306. * @param name
  307. * the Variable name.
  308. * @param value
  309. * the Variable initial value.
  310. *
  311. * @throws PaintException
  312. * if the paint operation failed.
  313. */
  314. public void addVariable(VariableOwner owner, String name, int value)
  315. throws PaintException;
  316. /**
  317. * Adds a long type variable.
  318. *
  319. * @param owner
  320. * the Listener for variable changes.
  321. * @param name
  322. * the Variable name.
  323. * @param value
  324. * the Variable initial value.
  325. *
  326. * @throws PaintException
  327. * if the paint operation failed.
  328. */
  329. public void addVariable(VariableOwner owner, String name, long value)
  330. throws PaintException;
  331. /**
  332. * Adds a float type variable.
  333. *
  334. * @param owner
  335. * the Listener for variable changes.
  336. * @param name
  337. * the Variable name.
  338. * @param value
  339. * the Variable initial value.
  340. *
  341. * @throws PaintException
  342. * if the paint operation failed.
  343. */
  344. public void addVariable(VariableOwner owner, String name, float value)
  345. throws PaintException;
  346. /**
  347. * Adds a double type variable.
  348. *
  349. * @param owner
  350. * the Listener for variable changes.
  351. * @param name
  352. * the Variable name.
  353. * @param value
  354. * the Variable initial value.
  355. *
  356. * @throws PaintException
  357. * if the paint operation failed.
  358. */
  359. public void addVariable(VariableOwner owner, String name, double value)
  360. throws PaintException;
  361. /**
  362. * Adds a boolean type variable.
  363. *
  364. * @param owner
  365. * the Listener for variable changes.
  366. * @param name
  367. * the Variable name.
  368. * @param value
  369. * the Variable initial value.
  370. *
  371. * @throws PaintException
  372. * if the paint operation failed.
  373. */
  374. public void addVariable(VariableOwner owner, String name, boolean value)
  375. throws PaintException;
  376. /**
  377. * Adds a string array type variable.
  378. *
  379. * @param owner
  380. * the Listener for variable changes.
  381. * @param name
  382. * the Variable name.
  383. * @param value
  384. * the Variable initial value.
  385. *
  386. * @throws PaintException
  387. * if the paint operation failed.
  388. */
  389. public void addVariable(VariableOwner owner, String name, String[] value)
  390. throws PaintException;
  391. /**
  392. * Adds a Component type variable. On client side the variable value will be
  393. * a terminal specific reference to corresponding component on client side
  394. * implementation. When updated from client side, terminal will map the
  395. * client side component reference back to a corresponding server side
  396. * reference.
  397. *
  398. * @param owner
  399. * the Listener for variable changes
  400. * @param name
  401. * the name of the variable
  402. * @param value
  403. * the initial value of the variable
  404. *
  405. * @throws PaintException
  406. * if the paint oparation fails
  407. */
  408. public void addVariable(VariableOwner owner, String name, Component value)
  409. throws PaintException;
  410. /**
  411. * Adds an upload stream type variable.
  412. *
  413. * @param owner
  414. * the Listener for variable changes.
  415. * @param name
  416. * the Variable name.
  417. *
  418. * @throws PaintException
  419. * if the paint operation failed.
  420. */
  421. public void addUploadStreamVariable(VariableOwner owner, String name)
  422. throws PaintException;
  423. /**
  424. * Prints single XML section.
  425. * <p>
  426. * Prints full XML section. The section data must be XML and it is
  427. * surrounded by XML start and end-tags.
  428. * </p>
  429. *
  430. * @param sectionTagName
  431. * the tag name.
  432. * @param sectionData
  433. * the section data to be printed.
  434. * @param namespace
  435. * the namespace.
  436. * @throws PaintException
  437. * if the paint operation failed.
  438. */
  439. public void addXMLSection(String sectionTagName, String sectionData,
  440. String namespace) throws PaintException;
  441. /**
  442. * Adds UIDL directly. The UIDL must be valid in accordance with the
  443. * UIDL.dtd
  444. *
  445. * @param uidl
  446. * the UIDL to be added.
  447. * @throws PaintException
  448. * if the paint operation failed.
  449. */
  450. public void addUIDL(String uidl) throws PaintException;
  451. /**
  452. * Adds text node. All the contents of the text are XML-escaped.
  453. *
  454. * @param text
  455. * the Text to add
  456. * @throws PaintException
  457. * if the paint operation failed.
  458. */
  459. void addText(String text) throws PaintException;
  460. /**
  461. * Adds CDATA node to target UIDL-tree.
  462. *
  463. * @param text
  464. * the Character data to add
  465. * @throws PaintException
  466. * if the paint operation failed.
  467. * @since 3.1
  468. */
  469. void addCharacterData(String text) throws PaintException;
  470. public void addAttribute(String string, Object[] keys);
  471. /**
  472. * @return the "tag" string used in communication to present given
  473. * {@link ClientConnector} type. Terminal may define how to present
  474. * the connector.
  475. */
  476. public String getTag(ClientConnector paintable);
  477. /**
  478. * @return true if a full repaint has been requested. E.g. refresh in a
  479. * browser window or such.
  480. */
  481. public boolean isFullRepaint();
  482. }