1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
|
/*
* $Id: ActionConfig.java 377805 2006-02-14 19:26:15Z niallp $
*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.struts.config;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
/**
* <p>A JavaBean representing the configuration information of an
* <code><action></code> element from a Struts
* module configuration file.</p>
*
* @version $Rev: 377805 $ $Date: 2006-02-14 19:26:15 +0000 (Tue, 14 Feb 2006) $
* @since Struts 1.1
*/
public class ActionConfig implements Serializable {
// ----------------------------------------------------- Instance Variables
/**
* Indicates if configuration of this component been completed.
*/
protected boolean configured = false;
/**
* The set of exception handling configurations for this
* action, if any, keyed by the <code>type</code> property.
*/
protected HashMap exceptions = new HashMap();
/**
* The set of local forward configurations for this action, if any,
* keyed by the <code>name</code> property.
*/
protected HashMap forwards = new HashMap();
// ------------------------------------------------------------- Properties
/**
* The module configuration with which we are associated.
*/
protected ModuleConfig moduleConfig = null;
/**
* The module configuration with which we are associated.
*/
public ModuleConfig getModuleConfig() {
return (this.moduleConfig);
}
/**
* The module configuration with which we are associated.
*/
public void setModuleConfig(ModuleConfig moduleConfig) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.moduleConfig = moduleConfig;
}
/**
* The request-scope or session-scope attribute name under which our
* form bean is accessed, if it is different from the form bean's
* specified <code>name</code>.
*/
protected String attribute = null;
/**
* Returns the request-scope or session-scope attribute name under which our
* form bean is accessed, if it is different from the form bean's
* specified <code>name</code>.
* @return attribute name under which our form bean is accessed.
*/
public String getAttribute() {
if (this.attribute == null) {
return (this.name);
} else {
return (this.attribute);
}
}
/**
* Set the request-scope or session-scope attribute name under which our
* form bean is accessed, if it is different from the form bean's
* specified <code>name</code>.
* @param attribute the request-scope or session-scope attribute name under which our
* form bean is access.
*/
public void setAttribute(String attribute) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.attribute = attribute;
}
/**
* Context-relative path of the web application resource that will process
* this request via RequestDispatcher.forward(), instead of instantiating
* and calling the <code>Action</code> class specified by "type".
* Exactly one of <code>forward</code>, <code>include</code>, or
* <code>type</code> must be specified.
*/
protected String forward = null;
/**
* Returns context-relative path of the web application resource that will process
* this request.
* @return context-relative path of the web application resource that will process
* this request.
*/
public String getForward() {
return (this.forward);
}
/**
* Set the context-relative path of the web application resource that will process
* this request.
* Exactly one of <code>forward</code>, <code>include</code>, or
* <code>type</code> must be specified.
* @param forward context-relative path of the web application resource that will process
* this request.
*/
public void setForward(String forward) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.forward = forward;
}
/**
* Context-relative path of the web application resource that will process
* this request via RequestDispatcher.include(), instead of instantiating
* and calling the <code>Action</code> class specified by "type".
* Exactly one of <code>forward</code>, <code>include</code>, or
* <code>type</code> must be specified.
*/
protected String include = null;
/**
* Context-relative path of the web application resource that will process
* this request.
* @return Context-relative path of the web application resource that will process
* this request.
*/
public String getInclude() {
return (this.include);
}
/**
* Set context-relative path of the web application resource that will process
* this request.
* Exactly one of <code>forward</code>, <code>include</code>, or
* <code>type</code> must be specified.
* @param include context-relative path of the web application resource that will process
* this request.
*/
public void setInclude(String include) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.include = include;
}
/**
* Context-relative path of the input form to which control should be
* returned if a validation error is encountered. Required if "name"
* is specified and the input bean returns validation errors.
*/
protected String input = null;
/**
* Get the context-relative path of the input form to which control should be
* returned if a validation error is encountered.
* @return context-relative path of the input form to which control should be
* returned if a validation error is encountered.
*/
public String getInput() {
return (this.input);
}
/**
* Set the context-relative path of the input form to which control should be
* returned if a validation error is encountered. Required if "name"
* is specified and the input bean returns validation errors.
* @param input context-relative path of the input form to which control should be
* returned if a validation error is encountered.
*/
public void setInput(String input) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.input = input;
}
/**
* Fully qualified Java class name of the
* <code>MultipartRequestHandler</code> implementation class used to
* process multi-part request data for this Action.
*/
protected String multipartClass = null;
/**
* Return the fully qualified Java class name of the
* <code>MultipartRequestHandler</code> implementation class used to
* process multi-part request data for this Action.
*/
public String getMultipartClass() {
return (this.multipartClass);
}
/**
* Set the fully qualified Java class name of the
* <code>MultipartRequestHandler</code> implementation class used to
* process multi-part request data for this Action.
* @param multipartClass fully qualified class name of the
* <code>MultipartRequestHandler</code> implementation class.
*/
public void setMultipartClass(String multipartClass) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.multipartClass = multipartClass;
}
/**
* Name of the form bean, if any, associated with this Action.
*/
protected String name = null;
/**
* Return name of the form bean, if any, associated with this Action.
*/
public String getName() {
return (this.name);
}
/**
* @param name name of the form bean associated with this Action.
*/
public void setName(String name) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.name = name;
}
/**
* General purpose configuration parameter that can be used to pass
* extra information to the Action instance selected by this Action.
* Struts does not itself use this value in any way.
*/
protected String parameter = null;
/**
* Return general purpose configuration parameter that can be used to pass
* extra information to the Action instance selected by this Action.
* Struts does not itself use this value in any way.
*/
public String getParameter() {
return (this.parameter);
}
/**
* General purpose configuration parameter that can be used to pass
* extra information to the Action instance selected by this Action.
* Struts does not itself use this value in any way.
* @param parameter General purpose configuration parameter.
*/
public void setParameter(String parameter) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.parameter = parameter;
}
/**
* Context-relative path of the submitted request, starting with a
* slash ("/") character, and omitting any filename extension if
* extension mapping is being used.
*/
protected String path = null;
/**
* Return context-relative path of the submitted request, starting with a
* slash ("/") character, and omitting any filename extension if
* extension mapping is being used.
*/
public String getPath() {
return (this.path);
}
/**
* Set context-relative path of the submitted request, starting with a
* slash ("/") character, and omitting any filename extension if
* extension mapping is being used.
* @param path context-relative path of the submitted request.
*/
public void setPath(String path) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.path = path;
}
/**
* Prefix used to match request parameter names to form bean property
* names, if any.
*/
protected String prefix = null;
/**
* Retruns prefix used to match request parameter names to form bean property
* names, if any.
*/
public String getPrefix() {
return (this.prefix);
}
/**
* @param prefix Prefix used to match request parameter names to
* form bean property names, if any.
*/
public void setPrefix(String prefix) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.prefix = prefix;
}
/**
* Comma-delimited list of security role names allowed to request
* this Action.
*/
protected String roles = null;
public String getRoles() {
return (this.roles);
}
public void setRoles(String roles) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.roles = roles;
if (roles == null) {
roleNames = new String[0];
return;
}
ArrayList list = new ArrayList();
while (true) {
int comma = roles.indexOf(',');
if (comma < 0)
break;
list.add(roles.substring(0, comma).trim());
roles = roles.substring(comma + 1);
}
roles = roles.trim();
if (roles.length() > 0)
list.add(roles);
roleNames = (String[]) list.toArray(new String[list.size()]);
}
/**
* The set of security role names used to authorize access to this
* Action, as an array for faster access.
*/
protected String[] roleNames = new String[0];
/**
* Get array of security role names used to authorize access to this
* Action.
*/
public String[] getRoleNames() {
return (this.roleNames);
}
/**
* Identifier of the scope ("request" or "session") within which
* our form bean is accessed, if any.
*/
protected String scope = "session";
/**
* Get the scope ("request" or "session") within which
* our form bean is accessed, if any.
*/
public String getScope() {
return (this.scope);
}
/**
* @param scope scope ("request" or "session") within which
* our form bean is accessed, if any.
*/
public void setScope(String scope) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.scope = scope;
}
/**
* Suffix used to match request parameter names to form bean property
* names, if any.
*/
protected String suffix = null;
/**
* Return suffix used to match request parameter names to form bean property
* names, if any.
*/
public String getSuffix() {
return (this.suffix);
}
/**
* @param suffix Suffix used to match request parameter names to form bean property
* names, if any.
*/
public void setSuffix(String suffix) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.suffix = suffix;
}
/**
* Fully qualified Java class name of the <code>Action</code> class
* to be used to process requests for this mapping if the
* <code>forward</code> and <code>include</code> properties are not set.
* Exactly one of <code>forward</code>, <code>include</code>, or
* <code>type</code> must be specified.
*/
protected String type = null;
public String getType() {
return (this.type);
}
public void setType(String type) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.type = type;
}
/**
* Indicates Action be configured as the default one for this
* module, when true.
*/
protected boolean unknown = false;
/**
* Determine whether Action is configured as the default one for this
* module.
*/
public boolean getUnknown() {
return (this.unknown);
}
/**
* @param unknown Indicates Action is configured as the default one for this
* module, when true.
*/
public void setUnknown(boolean unknown) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.unknown = unknown;
}
/**
* Should the <code>validate()</code> method of the form bean associated
* with this action be called?
*/
protected boolean validate = true;
public boolean getValidate() {
return (this.validate);
}
public void setValidate(boolean validate) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.validate = validate;
}
/**
* <p>Can this Action be cancelled? [false]</p> <p> By default, when an
* Action is cancelled, validation is bypassed and the Action should not
* execute the business operation. If a request tries to cancel an Action
* when cancellable is not set, a "InvalidCancelException" is thrown.</p>
* @since Struts 1.2.9
*/
protected boolean cancellable = false;
/**
* <p>Accessor for cancellable property</p>
*
* @return True if Action can be cancelled
* @since Struts 1.2.9
*/
public boolean getCancellable() {
return (this.cancellable);
}
/**
* <p>Mutator for for cancellable property</p>
*
* @param cancellable
* @since Struts 1.2.9
*/
public void setCancellable(boolean cancellable) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.cancellable = cancellable;
}
// 2014/07/02 - security problem patch.
// Author: NTT DATA Corporation
/**
* Accepted page value for multi-page validation.<br>
* If two or more page values are accepted, then acceptPage is set minimum of them.<br>
* If multi-page validation is not use, acceptPage is not set. Then multi-page validation is disabled.
* @since Struts 1.2.9-sp2
*/
protected Integer acceptPage = null;
/**
* Returns accepted page value for multi-page validation.
*
* @return Accepted page value for multi-page validation
* @since Struts 1.2.9-sp2
*/
public Integer getAcceptPage() {
return acceptPage;
}
/**
* Set accepted page value for multi-page validation.
*
* @param acceptPage Accepted page value for multi-page validation
* @since Struts 1.2.9-sp2
*/
public void setAcceptPage(Integer acceptPage) {
this.acceptPage = acceptPage;
}
// --------------------------------------------------------- Public Methods
/**
* Add a new <code>ExceptionConfig</code> instance to the set associated
* with this action.
*
* @param config The new configuration instance to be added
*
* @exception IllegalStateException if this module configuration
* has been frozen
*/
public void addExceptionConfig(ExceptionConfig config) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
exceptions.put(config.getType(), config);
}
/**
* Add a new <code>ForwardConfig</code> instance to the set of global
* forwards associated with this action.
*
* @param config The new configuration instance to be added
*
* @exception IllegalStateException if this module configuration
* has been frozen
*/
public void addForwardConfig(ForwardConfig config) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
forwards.put(config.getName(), config);
}
/**
* Return the exception configuration for the specified type, if any;
* otherwise return <code>null</code>.
*
* @param type Exception class name to find a configuration for
*/
public ExceptionConfig findExceptionConfig(String type) {
return ((ExceptionConfig) exceptions.get(type));
}
/**
* Return the exception configurations for this action. If there
* are none, a zero-length array is returned.
*/
public ExceptionConfig[] findExceptionConfigs() {
ExceptionConfig results[] = new ExceptionConfig[exceptions.size()];
return ((ExceptionConfig[]) exceptions.values().toArray(results));
}
/**
* <p>Find and return the <code>ExceptionConfig</code> instance defining
* how <code>Exceptions</code> of the specified type should be handled.
* This is performed by checking local and then global configurations for
* the specified exception's class, and then looking up the superclass chain
* (again checking local and then global configurations). If no handler
* configuration can be found, return <code>null</code>.</p>
*
* <p>Introduced in <code>ActionMapping</code> in Struts 1.1, but pushed
* up to <code>ActionConfig</code> in Struts 1.2.0.</p>
*
* @param type Exception class for which to find a handler
* @since Struts 1.2.0
*/
public ExceptionConfig findException(Class type) {
// Check through the entire superclass hierarchy as needed
ExceptionConfig config = null;
while (true) {
// Check for a locally defined handler
String name = type.getName();
config = findExceptionConfig(name);
if (config != null) {
return (config);
}
// Check for a globally defined handler
config = getModuleConfig().findExceptionConfig(name);
if (config != null) {
return (config);
}
// Loop again for our superclass (if any)
type = type.getSuperclass();
if (type == null) {
break;
}
}
return (null); // No handler has been configured
}
/**
* Return the forward configuration for the specified key, if any;
* otherwise return <code>null</code>.
*
* @param name Name of the forward configuration to return
*/
public ForwardConfig findForwardConfig(String name) {
return ((ForwardConfig) forwards.get(name));
}
/**
* Return all forward configurations for this module. If there
* are none, a zero-length array is returned.
*/
public ForwardConfig[] findForwardConfigs() {
ForwardConfig results[] = new ForwardConfig[forwards.size()];
return ((ForwardConfig[]) forwards.values().toArray(results));
}
/**
* Freeze the configuration of this action.
*/
public void freeze() {
configured = true;
ExceptionConfig[] econfigs = findExceptionConfigs();
for (int i = 0; i < econfigs.length; i++) {
econfigs[i].freeze();
}
ForwardConfig[] fconfigs = findForwardConfigs();
for (int i = 0; i < fconfigs.length; i++) {
fconfigs[i].freeze();
}
}
/**
* Remove the specified exception configuration instance.
*
* @param config ExceptionConfig instance to be removed
*
* @exception IllegalStateException if this module configuration
* has been frozen
*/
public void removeExceptionConfig(ExceptionConfig config) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
exceptions.remove(config.getType());
}
/**
* Remove the specified forward configuration instance.
*
* @param config ForwardConfig instance to be removed
*
* @exception IllegalStateException if this module configuration
* has been frozen
*/
public void removeForwardConfig(ForwardConfig config) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
forwards.remove(config.getName());
}
/**
* Return a String representation of this object.
*/
public String toString() {
StringBuffer sb = new StringBuffer("ActionConfig[");
sb.append("path=");
sb.append(path);
if (attribute != null) {
sb.append(",attribute=");
sb.append(attribute);
}
if (forward != null) {
sb.append(",forward=");
sb.append(forward);
}
if (include != null) {
sb.append(",include=");
sb.append(include);
}
if (input != null) {
sb.append(",input=");
sb.append(input);
}
if (multipartClass != null) {
sb.append(",multipartClass=");
sb.append(multipartClass);
}
if (name != null) {
sb.append(",name=");
sb.append(name);
}
if (parameter != null) {
sb.append(",parameter=");
sb.append(parameter);
}
if (prefix != null) {
sb.append(",prefix=");
sb.append(prefix);
}
if (roles != null) {
sb.append(",roles=");
sb.append(roles);
}
if (scope != null) {
sb.append(",scope=");
sb.append(scope);
}
if (suffix != null) {
sb.append(",suffix=");
sb.append(suffix);
}
if (type != null) {
sb.append(",type=");
sb.append(type);
}
sb.append(",validate=");
sb.append(validate);
sb.append(",cancellable=");
sb.append(cancellable);
return (sb.toString());
}
}
|