Author: markt Date: Tue Aug 30 16:59:06 2016 New Revision: 1758430 URL: http://svn.apache.org/viewvc?rev=1758430&view=rev Log: Reduce code duplication
Added: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/XmlEncodingBase.java (with props) Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FilterMap.java tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/JspPropertyGroup.java tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityConstraint.java tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FilterMap.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FilterMap.java?rev=1758430&r1=1758429&r2=1758430&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FilterMap.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FilterMap.java Tue Aug 30 16:59:06 2016 @@ -32,7 +32,7 @@ import org.apache.tomcat.util.buf.UDecod * * @author Craig R. McClanahan */ -public class FilterMap implements Serializable { +public class FilterMap extends XmlEncodingBase implements Serializable { // ------------------------------------------------------------- Properties @@ -57,24 +57,6 @@ public class FilterMap implements Serial private int dispatcherMapping = NOT_SET; - private String encoding = null; - public void setEncoding(String encoding) { - this.encoding = encoding; - } - /** - * Obtain the encoding of the XML source that was used to populated this - * object. - * - * @return The encoding of the associated XML source or <code>UTF-8</code> - * if the encoding could not be determined - */ - public String getEncoding() { - if (encoding == null || encoding.length() == 0) { - return "UTF-8"; - } - return encoding; - } - private String filterName = null; public String getFilterName() { Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/JspPropertyGroup.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/JspPropertyGroup.java?rev=1758430&r1=1758429&r2=1758430&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/JspPropertyGroup.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/JspPropertyGroup.java Tue Aug 30 16:59:06 2016 @@ -26,25 +26,7 @@ import org.apache.tomcat.util.buf.UDecod /** * Representation of a jsp-property-group element in web.xml. */ -public class JspPropertyGroup { - - private String encoding = null; - public void setEncoding(String encoding) { - this.encoding = encoding; - } - /** - * Obtain the encoding of the XML source that was used to populated this - * object. - * - * @return The encoding of the associated XML source or <code>UTF-8</code> - * if the encoding could not be determined - */ - public String getEncoding() { - if (encoding == null || encoding.length() == 0) { - return "UTF-8"; - } - return encoding; - } +public class JspPropertyGroup extends XmlEncodingBase { private Boolean deferredSyntax = null; public void setDeferredSyntax(String deferredSyntax) { Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityConstraint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityConstraint.java?rev=1758430&r1=1758429&r2=1758430&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityConstraint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityConstraint.java Tue Aug 30 16:59:06 2016 @@ -50,7 +50,7 @@ import org.apache.tomcat.util.res.String * * @author Craig R. McClanahan */ -public class SecurityConstraint implements Serializable { +public class SecurityConstraint extends XmlEncodingBase implements Serializable { private static final long serialVersionUID = 1L; @@ -61,25 +61,6 @@ public class SecurityConstraint implemen StringManager.getManager(Constants.PACKAGE_NAME); - private String encoding = null; - public void setEncoding(String encoding) { - this.encoding = encoding; - } - /** - * Obtain the encoding of the XML source that was used to populated this - * object. - * - * @return The encoding of the associated XML source or <code>UTF-8</code> - * if the encoding could not be determined - */ - public String getEncoding() { - if (encoding == null || encoding.length() == 0) { - return "UTF-8"; - } - return encoding; - } - - // ----------------------------------------------------------- Constructors /** Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java?rev=1758430&r1=1758429&r2=1758430&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java Tue Aug 30 16:59:06 2016 @@ -54,7 +54,7 @@ import org.apache.tomcat.util.res.String * This class checks for invalid duplicates (eg filter/servlet names) * StandardContext will check validity of values (eg URL formats etc) */ -public class WebXml implements DocumentProperties.Encoding { +public class WebXml extends XmlEncodingBase implements DocumentProperties.Encoding { protected static final String ORDER_OTHERS = "org.apache.catalina.order.others"; @@ -130,25 +130,6 @@ public class WebXml implements DocumentP public Set<String> getBeforeOrdering() { return before; } // Common elements and attributes - private String encoding = null; - @Override - public void setEncoding(String encoding) { - this.encoding = encoding; - } - /** - * Obtain the encoding of the XML source that was used to populated this - * object. - * - * @return The encoding of the associated XML source or <code>UTF-8</code> - * if the encoding could not be determined - */ - public String getEncoding() { - if (encoding == null || encoding.length() == 0) { - return "UTF-8"; - } - return encoding; - } - // Required attribute of web-app element public String getVersion() { StringBuilder sb = new StringBuilder(3); Added: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/XmlEncodingBase.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/XmlEncodingBase.java?rev=1758430&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/XmlEncodingBase.java (added) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/XmlEncodingBase.java Tue Aug 30 16:59:06 2016 @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.tomcat.util.descriptor.web; + +/** + * Base class for those elements that need to track the encoding used in the + * source XML. + */ +public abstract class XmlEncodingBase { + + private String encoding = null; + + + public void setEncoding(String encoding) { + this.encoding = encoding; + } + + + /** + * Obtain the encoding of the XML source that was used to populated this + * object. + * + * @return The encoding of the associated XML source or <code>UTF-8</code> + * if the encoding could not be determined + */ + public String getEncoding() { + if (encoding == null || encoding.length() == 0) { + return "UTF-8"; + } + return encoding; + } +} Propchange: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/XmlEncodingBase.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org