You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/05/17 19:58:39 UTC

[GitHub] [maven] rfscholte commented on a diff in pull request #286: [MNG-6656] Introduce base for build/consumer process

rfscholte commented on code in PR #286:
URL: https://github.com/apache/maven/pull/286#discussion_r875212394


##########
maven-xml/src/main/java/org/apache/maven/xml/sax/filter/FastForwardFilter.java:
##########
@@ -0,0 +1,128 @@
+package org.apache.maven.xml.sax.filter;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLFilter;
+import org.xml.sax.XMLReader;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * This filter will skip all following filters and write directly to the output.
+ * Should be used in case of a DOM that should not be effected by other filters, even though the elements match 
+ * 
+ * @author Robert Scholte
+ * @since 3.7.0
+ */
+class FastForwardFilter extends AbstractSAXFilter
+{
+    /**
+     * DOM elements of pom
+     * 
+     * <ul>
+     *  <li>execution.configuration</li>
+     *  <li>plugin.configuration</li>
+     *  <li>plugin.goals</li>
+     *  <li>profile.reports</li>
+     *  <li>project.reports</li>
+     *  <li>reportSet.configuration</li>
+     * <ul>
+     */
+    private final Deque<String> state = new ArrayDeque<>();
+    
+    private int domDepth = 0;
+    
+    private ContentHandler originalHandler;
+    
+    FastForwardFilter()
+    {
+        super();
+    }
+
+    <T extends XMLReader & LexicalHandler> FastForwardFilter( T parent )
+    {
+        super( parent );
+    }
+
+    @Override
+    public void startElement( String uri, String localName, String qName, Attributes atts )
+        throws SAXException
+    {
+        super.startElement( uri, localName, qName, atts );
+        if ( domDepth > 0 )
+        {
+            domDepth++;
+        }
+        else
+        {
+            final String key = state.peek() + '.' + localName;
+            switch ( key )
+            {
+                case "execution.configuration":
+                case "plugin.configuration":
+                case "plugin.goals":
+                case "profile.reports":
+                case "project.reports":
+                case "reportSet.configuration":
+                    domDepth++;
+
+                    originalHandler = getContentHandler();
+
+                    ContentHandler outputContentHandler = getContentHandler();

Review Comment:
   @mthmulders here's the original code, where you'll see it doesn't write to its direct parent (which is another XMLFilter), but all the way up to the effective outputstream, to ensure these won't be part of the output manipulation. I don't know how @gnodet eventually solved this on an event based stream.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org