PrintSession.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2006-2010 Alfresco Software Limited.
  3. *
  4. * This file is part of Alfresco
  5. *
  6. * Alfresco is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Alfresco is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package org.alfresco.jlan.client;
  20. import org.alfresco.jlan.smb.PCShare;
  21. import org.alfresco.jlan.smb.SMBDeviceType;
  22. import org.alfresco.jlan.smb.SMBException;
  23. /**
  24. * SMB print session class
  25. *
  26. * <p>The print session allows a new print job to be created, using the SMBFile
  27. * class or as an SMBOutputStream.
  28. *
  29. * <p>When the SMBFile/SMBOutputStream is closed the print job will be queued to
  30. * the remote printer.
  31. *
  32. * <p>A print session is created using the SessionFactory.OpenPrinter() method. The
  33. * SessionFactory negotiates the appropriate SMB dialect and creates the appropriate
  34. * PrintSession derived object.
  35. *
  36. * @see SessionFactory
  37. *
  38. * @author gkspencer
  39. */
  40. public abstract class PrintSession extends Session {
  41. // Print modes
  42. public static final int TextMode = 0;
  43. public static final int GraphicsMode = 1;
  44. // Default number of print queue entries to return
  45. public static final int DefaultEntryCount = 20;
  46. /**
  47. * Construct an SMB print session
  48. *
  49. * @param shr Remote server details
  50. * @param dialect SMB dialect that this session is using
  51. */
  52. protected PrintSession(PCShare shr, int dialect) {
  53. super(shr, dialect, null);
  54. // Set the device type
  55. this.setDeviceType(SMBDeviceType.Printer);
  56. }
  57. /**
  58. * Determine if the print session has been closed.
  59. *
  60. * @return true if the print session has been closed, else false.
  61. */
  62. protected final boolean isClosed() {
  63. return m_treeid == Closed ? true : false;
  64. }
  65. /**
  66. * Open a spool file on the remote print server.
  67. *
  68. * @param id Identifier string for this print request.
  69. * @param mode Print mode, either TextMode or GraphicsMode.
  70. * @param setuplen Length of data in the start of the spool file that is printer setup code.
  71. * @return SMBFile for the new spool file, else null.
  72. * @exception java.io.IOException If an I/O error occurs.
  73. * @exception SMBException If an SMB level error occurs
  74. */
  75. public abstract SMBFile OpenSpoolFile(String id, int mode, int setuplen)
  76. throws java.io.IOException, SMBException;
  77. /**
  78. * Open a spool file as an output stream.
  79. *
  80. * @param id Identifier string for this print request.
  81. * @param mode Print mode, either TextMode or GraphicsMode.
  82. * @param setuplen Length of data in the start of the spool file that is printer setup code.
  83. * @return SMBOutputStream for the spool file, else null.
  84. * @exception java.io.IOException If an I/O error occurs.
  85. * @exception SMBException If an SMB level error occurs
  86. */
  87. public SMBOutputStream OpenSpoolStream(String id, int mode, int setuplen)
  88. throws java.io.IOException, SMBException {
  89. // Open an SMBFile first
  90. SMBFile sfile = OpenSpoolFile(id, mode, setuplen);
  91. if ( sfile == null)
  92. return null;
  93. // Create an output stream attached to the SMBFile
  94. return new SMBOutputStream(sfile);
  95. }
  96. }