| 509 | } |
| 510 | |
| 511 | func injectDocBase(xmlContent string, docBase string) string { |
| 512 | idx := strings.Index(xmlContent, "<Context") |
| 513 | if idx == -1 { |
| 514 | return xmlContent |
| 515 | } |
| 516 | |
| 517 | endIdx := strings.Index(xmlContent[idx:], ">") |
| 518 | if endIdx == -1 { |
| 519 | return xmlContent |
| 520 | } |
| 521 | endIdx += idx |
| 522 | |
| 523 | contextTag := xmlContent[idx:endIdx] |
| 524 | |
| 525 | for strings.Contains(contextTag, "docBase=") { |
| 526 | docBaseIdx := strings.Index(contextTag, "docBase=") |
| 527 | |
| 528 | if docBaseIdx+8 >= len(contextTag) { |
| 529 | break |
| 530 | } |
| 531 | quote := contextTag[docBaseIdx+8] |
| 532 | if quote != '"' && quote != '\'' { |
| 533 | break |
| 534 | } |
| 535 | |
| 536 | endQuoteIdx := strings.Index(contextTag[docBaseIdx+9:], string(quote)) |
| 537 | if endQuoteIdx == -1 { |
| 538 | break |
| 539 | } |
| 540 | endQuoteIdx += docBaseIdx + 9 |
| 541 | |
| 542 | before := strings.TrimSpace(contextTag[:docBaseIdx]) |
| 543 | after := strings.TrimSpace(contextTag[endQuoteIdx+1:]) |
| 544 | if before != "" && after != "" { |
| 545 | contextTag = before + " " + after |
| 546 | } else { |
| 547 | contextTag = before + after |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | newContextTag := strings.Replace(contextTag, "<Context", `<Context docBase="`+docBase+`"`, 1) |
| 552 | |
| 553 | return xmlContent[:idx] + newContextTag + xmlContent[endIdx:] |
| 554 | } |
| 555 | |
| 556 | // Finalize performs final Tomcat configuration |
| 557 | func (t *TomcatContainer) Finalize() error { |