You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2009/07/29 17:41:10 UTC
svn commit: r798956 - in /tiles/framework/trunk:
tiles-core/src/main/java/org/apache/tiles/util/URLUtil.java
tiles-test/src/main/java/org/apache/tiles/test/factory/TestTilesContainerFactory.java
Author: apetrelli
Date: Wed Jul 29 15:41:10 2009
New Revision: 798956
URL: http://svn.apache.org/viewvc?rev=798956&view=rev
Log:
TILES-452
Created URLUtil class and one method.
Modified TestTilesContainerFactory accordingly.
Added:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/URLUtil.java (with props)
Modified:
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/factory/TestTilesContainerFactory.java
Added: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/URLUtil.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/URLUtil.java?rev=798956&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/URLUtil.java (added)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/URLUtil.java Wed Jul 29 15:41:10 2009
@@ -0,0 +1,61 @@
+/*
+ * $Id$
+ *
+ * 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.tiles.util;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Utilities to manage URLs in the Tiles environment.
+ *
+ * @version $Rev$ $Date$
+ * @since 2.2.0
+ */
+public final class URLUtil {
+
+ /**
+ * Private constructor to avoid instantiation.
+ */
+ private URLUtil() { }
+
+ /**
+ * Filters a collection of URLs and removes all that have an underscore in
+ * their name (not in their path).
+ *
+ * @param urlSet The set of URLs to filter.
+ * @return A new list containing only those URLs that does not have an
+ * underscore in their name.
+ * @since 2.2.0
+ */
+ public static List<URL> getBaseTilesDefinitionURLs(Collection<? extends URL> urlSet) {
+ List<URL> filteredUrls = new ArrayList<URL>();
+ for (URL url : urlSet) {
+ String externalForm = url.toExternalForm();
+ if (externalForm.indexOf('_', externalForm.lastIndexOf("/")) < 0) {
+ filteredUrls.add(url);
+ }
+ }
+ return filteredUrls;
+ }
+}
Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/URLUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/URLUtil.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/factory/TestTilesContainerFactory.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/factory/TestTilesContainerFactory.java?rev=798956&r1=798955&r2=798956&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/factory/TestTilesContainerFactory.java (original)
+++ tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/factory/TestTilesContainerFactory.java Wed Jul 29 15:41:10 2009
@@ -22,7 +22,6 @@
import java.io.IOException;
import java.net.URL;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -75,6 +74,7 @@
import org.apache.tiles.renderer.impl.BasicRendererFactory;
import org.apache.tiles.test.exception.TilesTestRuntimeException;
import org.apache.tiles.test.renderer.ReverseStringAttributeRenderer;
+import org.apache.tiles.util.URLUtil;
import org.apache.tiles.velocity.context.VelocityTilesRequestContextFactory;
import org.apache.tiles.velocity.renderer.VelocityAttributeRenderer;
import org.mvel2.integration.VariableResolverFactory;
@@ -87,11 +87,6 @@
*/
public class TestTilesContainerFactory extends BasicTilesContainerFactory {
- /**
- * The number of URLs to load..
- */
- private static final int URL_COUNT = 7;
-
/** {@inheritDoc} */
@Override
protected BasicTilesContainer instantiateContainer(
@@ -251,27 +246,22 @@
@Override
protected List<URL> getSourceURLs(TilesApplicationContext applicationContext,
TilesRequestContextFactory contextFactory) {
- List<URL> urls = new ArrayList<URL>(URL_COUNT);
try {
+ List<URL> urls;
Set<URL> urlSet = applicationContext
.getResources("/WEB-INF/**/tiles-defs*.xml");
- for (URL url : urlSet) {
- String externalForm = url.toExternalForm();
- if (externalForm.indexOf('_', externalForm.lastIndexOf("/")) < 0) {
- urls.add(url);
- }
- }
+ urls = URLUtil.getBaseTilesDefinitionURLs(urlSet);
urls.add(applicationContext.getResource(
"classpath:/org/apache/tiles/classpath-defs.xml"));
urls.add(applicationContext.getResource(
"classpath:/org/apache/tiles/freemarker-classpath-defs.xml"));
urls.add(applicationContext.getResource(
"classpath:/org/apache/tiles/velocity-classpath-defs.xml"));
+ return urls;
} catch (IOException e) {
throw new DefinitionsFactoryException(
"Cannot load definition URLs", e);
}
- return urls;
}
/** {@inheritDoc} */