CorePrintSession.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.client.info.FileInfo;
  21. import org.alfresco.jlan.client.info.PrintQueueEnumerator;
  22. import org.alfresco.jlan.smb.DataType;
  23. import org.alfresco.jlan.smb.PCShare;
  24. import org.alfresco.jlan.smb.PacketType;
  25. import org.alfresco.jlan.smb.SMBException;
  26. /**
  27. * SMB core protocol print session class.
  28. *
  29. * @author gkspencer
  30. */
  31. class CorePrintSession extends PrintSession {
  32. /**
  33. * Class constructor
  34. *
  35. * @param shr Remote server details.
  36. * @param dialect SMB dialect that this session is using
  37. */
  38. protected CorePrintSession(PCShare shr, int dialect) {
  39. super(shr, dialect);
  40. }
  41. /**
  42. * Return an SMBPrintQueue object that can be used to list the pending print jobs in the print
  43. * servers queue.
  44. *
  45. * @param idx Specifies the starting index of the first entry in the queue to be returned.
  46. * @param cnt Number of entries to return, may be a positive value for a forward search and
  47. * negative for a backward search.
  48. * @return SMBPrintQueue for this print queue.
  49. * @exception java.io.IOException If an I/O error occurs.
  50. * @exception SMBException If an SMB level error occurs
  51. */
  52. public PrintQueueEnumerator getPrintQueue(int idx, int cnt)
  53. throws java.io.IOException, SMBException {
  54. return null;
  55. }
  56. /**
  57. * Open a spool file on the remote print server.
  58. *
  59. * @param id Identifier string for this print request.
  60. * @param mode Print mode, either TextMode or GraphicsMode.
  61. * @param setuplen Length of data in the start of the spool file that is printer setup code.
  62. * @return SMBFile for the new spool file, else null.
  63. * @exception java.io.IOException If an I/O error occurs.
  64. * @exception SMBException If an SMB level error occurs
  65. */
  66. public SMBFile OpenSpoolFile(String id, int mode, int setuplen)
  67. throws java.io.IOException, SMBException {
  68. // Initialize the SMB requets to open a spool file
  69. m_pkt.setCommand(PacketType.OpenPrintFile);
  70. m_pkt.setFlags(0);
  71. // Set the parameter words
  72. m_pkt.setParameterCount(2);
  73. m_pkt.setParameter(0, setuplen);
  74. m_pkt.setParameter(1, mode);
  75. // Set the user id
  76. m_pkt.setUserId(this.getUserId());
  77. // Set the tree id
  78. m_pkt.setTreeId(this.getTreeId());
  79. // Build the spool file identifier
  80. StringBuffer idbuf = new StringBuffer();
  81. idbuf.append((char) DataType.ASCII);
  82. idbuf.append(id);
  83. idbuf.append((char) 0x00);
  84. m_pkt.setBytes(idbuf.toString().getBytes());
  85. // Send/receive the SMB open spool file packet
  86. m_pkt.ExchangeSMB(this, m_pkt);
  87. // Check if a valid response was received
  88. if ( m_pkt.isValidResponse()) {
  89. // Extract the file information from the received SMB packet
  90. int fid = m_pkt.getParameter(0);
  91. // Create a file information object
  92. FileInfo finfo = new FileInfo(id, 0, 0);
  93. // Create an SMB file object
  94. return new CoreFile(this, finfo, fid);
  95. }
  96. // Invalid SMB response
  97. return null;
  98. }
  99. }