1 22 package org.netbeans.lib.cvsclient.command; 23 24 import org.netbeans.lib.cvsclient.*; 25 import org.netbeans.lib.cvsclient.connection.*; 26 import org.netbeans.lib.cvsclient.event.*; 27 28 import java.io.UnsupportedEncodingException ; 29 30 35 public abstract class BuildableCommand extends Command { 36 37 41 protected Builder builder; 42 43 private final StringBuffer taggedLineBuffer = new StringBuffer (); 44 45 48 private boolean builderSet; 49 50 62 public void execute(ClientServices client, EventManager eventManager) 63 throws CommandException, AuthenticationException { 64 super.execute(client, eventManager); 65 66 if (builder == null && !isBuilderSet()) { 67 builder = createBuilder(eventManager); 68 } 69 } 70 71 76 public Builder createBuilder(EventManager eventManager) { 77 return null; 78 } 79 80 public void messageSent(BinaryMessageEvent e) { 81 super.messageSent(e); 82 83 if (builder == null) { 84 return; 85 } 86 87 if (builder instanceof BinaryBuilder) { BinaryBuilder binaryBuilder = (BinaryBuilder) builder; 89 binaryBuilder.parseBytes(e.getMessage(), e.getMessageLength()); 90 } 91 } 92 93 public void messageSent(MessageEvent e) { 94 super.messageSent(e); 95 if (builder == null) { 96 return; 97 } 98 99 if (e instanceof EnhancedMessageEvent) { 100 EnhancedMessageEvent eEvent = (EnhancedMessageEvent)e; 101 builder.parseEnhancedMessage(eEvent.getKey(), eEvent.getValue()); 102 return; 103 } 104 105 if (e.isTagged()) { 106 String message = MessageEvent.parseTaggedMessage(taggedLineBuffer, e.getMessage()); 107 if (message != null) { 108 builder.parseLine(message, false); 109 taggedLineBuffer.setLength(0); 110 } 111 } 112 else { 113 if (taggedLineBuffer.length() > 0) { 114 builder.parseLine(taggedLineBuffer.toString(), false); 115 taggedLineBuffer.setLength(0); 116 } 117 if (builder instanceof PipedFilesBuilder && e.isError() == false) { 121 try { 122 String iso88591 = new String (e.getRawData(), "ISO-8859-1"); 123 builder.parseLine(iso88591, e.isError()); 124 } catch (UnsupportedEncodingException e1) { 125 assert false; 126 } 127 } else { 128 builder.parseLine(e.getMessage(), e.isError()); 129 } 130 } 131 } 132 133 136 protected boolean isBuilderSet() { 137 return builderSet; 138 } 139 140 145 public void setBuilder(Builder builder) { 146 this.builder = builder; 147 builderSet = true; 148 } 149 150 153 public void commandTerminated(TerminationEvent e) { 154 if (builder == null) { 155 return; 156 } 157 158 if (taggedLineBuffer.length() > 0) { 159 builder.parseLine(taggedLineBuffer.toString(), false); 160 taggedLineBuffer.setLength(0); 161 } 162 builder.outputDone(); 163 } 164 } 165 | Popular Tags |