You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by da...@apache.org on 2005/10/23 22:10:15 UTC
svn commit: r327850 - in
/cocoon/trunk/src/java/org/apache/cocoon/components/blocks:
BlockContext.java BlockWiring.java
Author: danielf
Date: Sun Oct 23 13:10:10 2005
New Revision: 327850
URL: http://svn.apache.org/viewcvs?rev=327850&view=rev
Log:
Ongoing work, need a local context in each block to get the context: protocol and other things right.
Will extend it with some block specific methods and let it be the only connection from within a block
to the rest of the world.
Added:
cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockContext.java (with props)
Modified:
cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockWiring.java
Added: cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockContext.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockContext.java?rev=327850&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockContext.java (added)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockContext.java Sun Oct 23 13:10:10 2005
@@ -0,0 +1,127 @@
+/*
+ * Copyright 1999-2005 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.cocoon.components.blocks;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.cocoon.environment.impl.AbstractContext;
+
+/**
+* @version SVN $Id$
+*/
+public class BlockContext extends AbstractContext {
+
+ private Hashtable attributes;
+ private BlockWiring wiring;
+
+ public BlockContext(BlockWiring wiring) {
+ this.wiring = wiring;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Context#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String name) {
+ return this.attributes.get(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Context#setAttribute(java.lang.String, java.lang.Object)
+ */
+ public void setAttribute(String name, Object value) {
+ this.attributes.put(name, value);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Context#getAttributes()
+ */
+ public Map getAttributes() {
+ return this.attributes;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Context#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String name) {
+ this.attributes.remove(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Context#getAttributeNames()
+ */
+ public Enumeration getAttributeNames() {
+ return this.attributes.keys();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Context#getResource(java.lang.String)
+ */
+ public URL getResource(String path) throws MalformedURLException {
+ String contextURL = this.wiring.getContextURL().toExternalForm();
+ URL resolvedURL = null;
+ try {
+ resolvedURL = ((new URI(contextURL)).resolve(path)).toURL();
+ } catch (URISyntaxException e) {
+ throw new MalformedURLException("Couldn't resolve " + path + " relative " + contextURL +
+ " error " + e.getMessage());
+ }
+ return resolvedURL;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Context#getRealPath(java.lang.String)
+ */
+ public String getRealPath(String path) {
+ // We better don't assume that blocks are unpacked
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Context#getMimeType(java.lang.String)
+ */
+ public String getMimeType(String file) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Context#getInitParameter(java.lang.String)
+ */
+ public String getInitParameter(String name) {
+ return this.wiring.getProperty(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Context#getResourceAsStream(java.lang.String)
+ */
+ public InputStream getResourceAsStream(String path) {
+ try {
+ return this.getResource(path).openStream();
+ } catch (IOException e) {
+ // FIXME Error handling
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+}
Propchange: cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockContext.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockWiring.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockWiring.java?rev=327850&r1=327849&r2=327850&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockWiring.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockWiring.java Sun Oct 23 13:10:10 2005
@@ -16,6 +16,7 @@
package org.apache.cocoon.components.blocks;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
@@ -48,6 +49,7 @@
private ServiceManager serviceManager;
private Context context;
+ private URL contextRootURL;
private BlocksManager blocksManager;
private String id;
@@ -70,6 +72,7 @@
public void contextualize(Context context) throws ContextException {
this.context = context;
+ this.contextRootURL = (URL) this.context.get(ContextHelper.CONTEXT_ROOT_URL);
}
public void configure(Configuration config)
@@ -179,12 +182,16 @@
/**
* Get the URL of the root of the block
*/
- public String getContextURL() throws URISyntaxException, ContextException {
- String contextRootURL = ((URL) this.context.get(ContextHelper.CONTEXT_ROOT_URL)).toExternalForm();
- getLogger().debug("Root URL " + contextRootURL);
- String contextURL = ((new URI(contextRootURL)).resolve(this.location)).toString();
- getLogger().debug("Block Root URL " + contextURL);
-
+ public URL getContextURL() throws MalformedURLException {
+ URL contextURL = null;
+ try {
+ contextURL = ((new URI(this.contextRootURL.toExternalForm())).resolve(this.location)).toURL();
+ getLogger().debug("Root URL " + contextRootURL);
+ getLogger().debug("Block Root URL " + contextURL.toString());
+ } catch (URISyntaxException e) {
+ throw new MalformedURLException("Couldn't create context URL from " + this.contextRootURL.toExternalForm()) +
+ " and " + this.location + " error: " + e.getMessage());
+ }
return contextURL;
}