You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by th...@apache.org on 2014/05/28 16:14:17 UTC
git commit: Closes TAP5-2200 : Generating XML from pages and
templates is not possible anymore
Repository: tapestry-5
Updated Branches:
refs/heads/master ab66a31ea -> ff2fcd8a7
Closes TAP5-2200 : Generating XML from pages and templates is not possible anymore
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/ff2fcd8a
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/ff2fcd8a
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/ff2fcd8a
Branch: refs/heads/master
Commit: ff2fcd8a70aea2d10d1d9742f196acc25f24fb7f
Parents: ab66a31
Author: Thiago H. de Paula Figueiredo <th...@apache.org>
Authored: Wed May 28 11:14:00 2014 -0300
Committer: Thiago H. de Paula Figueiredo <th...@apache.org>
Committed: Wed May 28 11:14:00 2014 -0300
----------------------------------------------------------------------
.../java/org/apache/tapestry5/dom/Document.java | 39 ++++++++++++++++++--
.../internal/services/DocumentLinkerImpl.java | 12 ++++++
.../services/MarkupWriterFactoryImpl.java | 5 ++-
.../internal/services/MarkupWriterImpl.java | 6 +--
tapestry-core/src/test/app1/RawXML.tml | 1 +
.../integration/app1/pages/RawXML.java | 22 +++++++++++
6 files changed, 77 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ff2fcd8a/tapestry-core/src/main/java/org/apache/tapestry5/dom/Document.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/dom/Document.java b/tapestry-core/src/main/java/org/apache/tapestry5/dom/Document.java
index b31ed3a..a741fd0 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/dom/Document.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/dom/Document.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2010, 2014 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.
@@ -44,18 +44,39 @@ public final class Document extends Node
private final MarkupModel model;
private final String encoding;
+
+ private final String mimeType;
/**
* Non-element content that comes between the DOCTYPE and the root element.
*/
private List<Node> preamble;
- public Document(MarkupModel model)
+ /**
+ * Same as Document(model, null).
+ * @param model a {@link MarkupModel}.
+ */
+ public Document(final MarkupModel model)
{
this(model, null);
}
- public Document(MarkupModel model, String encoding)
+ /**
+ * Same as Document(model, encoding, null).
+ * @param model a {@link MarkupModel}.
+ */
+ public Document(final MarkupModel model, final String encoding) {
+ this(model, encoding, null);
+ }
+
+ /**
+ * Creates a document instance with a given markup model, encoding and MIME type.
+ * @param model a {@link MarkupModel}.
+ * @param encoding the encoding.
+ * @param mimeType the MIME type.
+ * @since 5.4
+ */
+ public Document(final MarkupModel model, final String encoding, final String mimeType)
{
super(null);
@@ -63,6 +84,7 @@ public final class Document extends Node
this.model = model;
this.encoding = encoding;
+ this.mimeType = mimeType;
}
@Override
@@ -282,4 +304,15 @@ public final class Document extends Node
{
return newChild(new CData(null, content));
}
+
+ /**
+ * Returns the MIME type of this document.
+ * @return the MIME type.
+ * @since 5.4
+ */
+ public String getMimeType()
+ {
+ return mimeType;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ff2fcd8a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
index cc11709..67d4dba 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
@@ -23,10 +23,15 @@ import org.apache.tapestry5.services.javascript.ModuleConfigurationCallback;
import org.apache.tapestry5.services.javascript.ModuleManager;
import org.apache.tapestry5.services.javascript.StylesheetLink;
+import java.util.Collections;
import java.util.List;
+import java.util.Set;
public class DocumentLinkerImpl implements DocumentLinker
{
+
+ private final static Set<String> HTML_MIME_TYPES = CollectionFactory.newSet("text/html", "application/xml+xhtml");
+
private final List<String> coreLibraryURLs = CollectionFactory.newList();
private final List<String> libraryURLs = CollectionFactory.newList();
@@ -110,6 +115,13 @@ public class DocumentLinkerImpl implements DocumentLinker
{
return;
}
+
+ // TAP5-2200: Generating XML from pages and templates is not possible anymore
+ // only add JavaScript and CSS if we're actually generating
+ final String mimeType = document.getMimeType();
+ if (mimeType != null && !HTML_MIME_TYPES.contains(mimeType)) {
+ return;
+ }
addStylesheetsToHead(root, includedStylesheets);
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ff2fcd8a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java
index 48edfe0..3a875c9 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java
@@ -75,7 +75,8 @@ public class MarkupWriterFactoryImpl implements MarkupWriterFactory
private MarkupWriter constructMarkupWriter(ContentType contentType, boolean partial, boolean HTML5)
{
- boolean isHTML = contentType.getMimeType().equalsIgnoreCase("text/html");
+ final String mimeType = contentType.getMimeType();
+ boolean isHTML = mimeType.equalsIgnoreCase("text/html");
MarkupModel model;
@@ -86,7 +87,7 @@ public class MarkupWriterFactoryImpl implements MarkupWriterFactory
// The charset parameter sets the encoding attribute of the XML declaration, if
// not null and if using the XML model.
- return new MarkupWriterImpl(model, contentType.getCharset());
+ return new MarkupWriterImpl(model, contentType.getCharset(), mimeType);
}
public MarkupWriter newMarkupWriter(String pageName)
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ff2fcd8a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterImpl.java
index e845f79..d0682a0 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterImpl.java
@@ -45,12 +45,12 @@ public class MarkupWriterImpl implements MarkupWriter
public MarkupWriterImpl(MarkupModel model)
{
- this(model, null);
+ this(model, null, null);
}
- public MarkupWriterImpl(MarkupModel model, String encoding)
+ public MarkupWriterImpl(MarkupModel model, String encoding, String mimeType)
{
- document = new Document(model, encoding);
+ document = new Document(model, encoding, mimeType);
}
public void toMarkup(PrintWriter writer)
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ff2fcd8a/tapestry-core/src/test/app1/RawXML.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/RawXML.tml b/tapestry-core/src/test/app1/RawXML.tml
new file mode 100644
index 0000000..9e4f2fe
--- /dev/null
+++ b/tapestry-core/src/test/app1/RawXML.tml
@@ -0,0 +1 @@
+<xml><xhtml/></xml>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ff2fcd8a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RawXML.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RawXML.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RawXML.java
new file mode 100644
index 0000000..17a0d40
--- /dev/null
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RawXML.java
@@ -0,0 +1,22 @@
+// Copyright 2014 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.tapestry5.integration.app1.pages;
+
+import org.apache.tapestry5.annotations.ContentType;
+
+@ContentType("text/xml")
+public class RawXML
+{
+
+}