1 17 package org.alfresco.filesys.smb; 18 19 25 public final class PCShare 26 { 27 28 30 private String m_domain = null; 31 32 34 private String m_nodename = null; 35 36 38 private String m_shrname = null; 39 40 42 private String m_username = null; 43 44 46 private String m_password = null; 47 48 50 private String m_path = null; 51 52 54 private String m_fname = null; 55 56 58 private int m_primaryProto = Protocol.UseDefault; 59 private int m_secondaryProto = Protocol.UseDefault; 60 61 63 private int m_extendedSecFlags; 64 65 68 public PCShare() 69 { 70 } 71 72 78 public PCShare(String netpath) throws InvalidUNCPathException 79 { 80 setNetworkPath(netpath); 81 82 84 if (m_username == null) 85 setUserName("GUEST"); 86 } 87 88 96 public PCShare(String nname, String shr, String uname, String pwd) 97 { 98 setNodeName(nname); 99 setShareName(shr); 100 setUserName(uname); 101 setPassword(pwd); 102 } 103 104 111 public static String makePath(String workdir, String fname) 112 { 113 114 116 StringBuffer pathStr = new StringBuffer (); 117 118 120 if (!workdir.startsWith("\\")) 121 pathStr.append("\\"); 122 pathStr.append(workdir); 123 124 126 if (pathStr.charAt(pathStr.length() - 1) != '\\') 127 pathStr.append("\\"); 128 129 131 pathStr.append(fname); 132 133 135 return pathStr.toString(); 136 } 137 138 143 public final String getDomain() 144 { 145 return m_domain; 146 } 147 148 153 public final boolean hasExtendedSecurityFlags() 154 { 155 return m_extendedSecFlags != 0 ? true : false; 156 } 157 158 163 public final int getExtendedSecurityFlags() 164 { 165 return m_extendedSecFlags; 166 } 167 168 173 public final String getFileName() 174 { 175 return m_fname; 176 } 177 178 183 public final String getNetworkPath() 184 { 185 186 188 StringBuffer strBuf = new StringBuffer (128); 189 190 192 strBuf.append("\\\\"); 193 strBuf.append(getNodeName()); 194 strBuf.append("\\"); 195 strBuf.append(getShareName()); 196 197 199 if (getPath() != null && getPath().length() > 0) 200 { 201 if (getPath().charAt(0) != '\\') 202 { 203 strBuf.append("\\"); 204 } 205 strBuf.append(getPath()); 206 } 207 208 210 if (getFileName() != null && getFileName().length() > 0) 211 { 212 if (strBuf.charAt(strBuf.length() - 1) != '\\') 213 { 214 strBuf.append("\\"); 215 } 216 strBuf.append(getFileName()); 217 } 218 219 221 return strBuf.toString(); 222 } 223 224 229 public final String getNodeName() 230 { 231 return m_nodename; 232 } 233 234 239 public final String getPassword() 240 { 241 return m_password; 242 } 243 244 249 public final String getPath() 250 { 251 return m_path != null ? m_path : "\\"; 252 } 253 254 259 public final String getRelativePath() 260 { 261 262 264 StringBuffer strBuf = new StringBuffer (128); 265 266 268 if (getPath().length() > 0) 269 { 270 if (getPath().charAt(0) != '\\') 271 { 272 strBuf.append("\\"); 273 } 274 strBuf.append(getPath()); 275 } 276 277 279 if (getFileName().length() > 0) 280 { 281 if (strBuf.charAt(strBuf.length() - 1) != '\\') 282 { 283 strBuf.append("\\"); 284 } 285 strBuf.append(getFileName()); 286 } 287 288 290 return strBuf.toString(); 291 } 292 293 298 299 public final String getShareName() 300 { 301 return m_shrname; 302 } 303 304 309 310 public final String getUserName() 311 { 312 return m_username != null ? m_username : ""; 313 } 314 315 320 public final int getPrimaryProtocol() 321 { 322 return m_primaryProto; 323 } 324 325 330 public final int getSecondaryProtocol() 331 { 332 return m_secondaryProto; 333 } 334 335 340 public final boolean hasDomain() 341 { 342 return m_domain == null ? false : true; 343 } 344 345 350 public final void setDomain(String domain) 351 { 352 m_domain = domain; 353 if (m_domain != null) 354 m_domain = m_domain.toUpperCase(); 355 } 356 357 362 363 public final void setFileName(String fn) 364 { 365 m_fname = fn; 366 } 367 368 373 374 public final void setNetworkPath(String netpath) throws InvalidUNCPathException 375 { 376 377 379 StringBuffer path = new StringBuffer (netpath); 380 for (int i = 0; i < path.length(); i++) 381 { 382 383 385 if (path.charAt(i) == '/') 386 path.setCharAt(i, '\\'); 387 } 388 String npath = path.toString(); 389 390 392 if (!npath.startsWith("\\\\") || npath.length() < 5) 393 throw new InvalidUNCPathException(npath); 394 395 397 int pos = 2; 398 int endpos = npath.indexOf("\\", pos); 399 400 if (endpos == -1) 401 throw new InvalidUNCPathException(npath); 402 403 setNodeName(npath.substring(pos, endpos)); 404 pos = endpos + 1; 405 406 408 endpos = npath.indexOf("\\", pos); 409 410 if (endpos == -1) 411 { 412 413 415 setShareName(npath.substring(pos)); 416 417 419 setPath("\\"); 420 setFileName(""); 421 } 422 else 423 { 424 setShareName(npath.substring(pos, endpos)); 425 426 pos = endpos + 1; 427 428 430 endpos = npath.lastIndexOf("\\"); 431 432 if (endpos != -1 && endpos > pos) 433 { 434 435 437 setPath(npath.substring(pos, endpos)); 438 439 441 setFileName(npath.substring(endpos + 1)); 442 } 443 else 444 { 445 446 448 setPath("\\"); 449 450 452 if (npath.length() > pos) 453 setFileName(npath.substring(pos)); 454 else 455 setFileName(""); 456 } 457 } 458 459 461 pos = m_shrname.indexOf("%"); 462 if (pos != -1) 463 { 464 465 467 endpos = m_shrname.indexOf(":", pos); 468 if (endpos != -1) 469 { 470 471 473 setUserName(m_shrname.substring(pos + 1, endpos)); 474 setPassword(m_shrname.substring(endpos + 1)); 475 } 476 else 477 { 478 479 481 setUserName(m_shrname.substring(pos + 1)); 482 } 483 484 486 setShareName(m_shrname.substring(0, pos)); 487 } 488 489 491 if (m_path == null || m_path.length() == 0) 492 m_path = "\\"; 493 } 494 495 500 public final void setExtendedSecurityFlags(int extFlags) 501 { 502 m_extendedSecFlags = extFlags; 503 } 504 505 510 511 public final void setNodeName(String nname) 512 { 513 m_nodename = nname; 514 } 515 516 521 522 public final void setPassword(String pwd) 523 { 524 m_password = pwd; 525 } 526 527 532 533 public final void setPath(String pth) 534 { 535 m_path = pth; 536 } 537 538 543 544 public final void setShareName(String shr) 545 { 546 m_shrname = shr; 547 } 548 549 554 555 public final void setUserName(String uname) 556 { 557 m_username = uname; 558 } 559 560 566 public final void setProtocolOrder(int pri, int sec) 567 { 568 m_primaryProto = pri; 569 m_secondaryProto = sec; 570 } 571 572 577 578 public final String toString() 579 { 580 return getNetworkPath(); 581 } 582 } | Popular Tags |