[jboss-svn-commits] JBL Code SVN: r8467 - labs/jbossesb/trunk/product/console/src/org/jboss/soa/esb/admin/console/transform

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Dec 20 17:57:56 EST 2006


Author: tfennelly
Date: 2006-12-20 17:57:54 -0500 (Wed, 20 Dec 2006)
New Revision: 8467

Added:
   labs/jbossesb/trunk/product/console/src/org/jboss/soa/esb/admin/console/transform/SmooksResourceListConverter.java
Log:
readded

Added: labs/jbossesb/trunk/product/console/src/org/jboss/soa/esb/admin/console/transform/SmooksResourceListConverter.java
===================================================================
--- labs/jbossesb/trunk/product/console/src/org/jboss/soa/esb/admin/console/transform/SmooksResourceListConverter.java	2006-12-20 22:47:05 UTC (rev 8466)
+++ labs/jbossesb/trunk/product/console/src/org/jboss/soa/esb/admin/console/transform/SmooksResourceListConverter.java	2006-12-20 22:57:54 UTC (rev 8467)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+
+package org.jboss.soa.esb.admin.console.transform;
+
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+
+import org.jboss.soa.esb.admin.console.SeamUtils;
+
+/**
+ * Faces converter for a list of transformation resource.
+ * <p/>
+ * Generates a Smooks XML config fragment.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class SmooksResourceListConverter implements Converter {
+
+	/* (non-Javadoc)
+	 * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String)
+	 */
+	public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String string) throws ConverterException {
+		throw new UnsupportedOperationException();
+	}
+
+	/* (non-Javadoc)
+	 * @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
+	 */
+	public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object object) throws ConverterException {
+		StringBuffer stringBuffer = new StringBuffer();
+		
+		if(object instanceof List) {
+			List resList = (List)object;
+			
+			for(int i = 0; i < resList.size(); i++) {
+				TransformationResource resource = (TransformationResource) resList.get(i);
+				
+				appendResource(resource, stringBuffer);
+			}
+		} else {
+			stringBuffer.append("<!-- No configurations found. -->");
+			SeamUtils.printContexts();
+		}
+		
+		return stringBuffer.toString();
+	}
+
+	private static void appendResource(TransformationResource resource, StringBuffer stringBuffer) {
+		
+		stringBuffer.append("\n\t<smooks-resource ");
+		if(resource.getSelector() != null && !resource.getSelector().trim().equals("")) {
+			stringBuffer.append("selector=\"").append(resource.getSelector()).append("\" ");
+		}
+		if(resource.getUseragent() != null && !resource.getUseragent().trim().equals("")) {
+			stringBuffer.append("useragent=\"").append(resource.getUseragent()).append("\" ");
+		}
+		if(resource.getNamespace() != null && !resource.getNamespace().trim().equals("")) {
+			stringBuffer.append("namespace=\"").append(resource.getNamespace()).append("\" ");
+		}
+		if(resource.getPath() != null && !resource.getPath().trim().equals("")) {
+			stringBuffer.append("path=\"").append(resource.getPath()).append("\" ");
+		}
+		stringBuffer.append(">");
+
+		List<TransformationResourceParameter> parameters = resource.getParameters();
+		if(parameters != null && !parameters.isEmpty()) {
+			appendParameters(resource, parameters, stringBuffer);
+		}
+	
+		stringBuffer.append("\n\t</smooks-resource>");
+	}
+
+	private static void appendParameters(TransformationResource resource, List<TransformationResourceParameter> parameters, StringBuffer stringBuffer) {
+		TransformationResourceParameter nameParameter = 
+			new TransformationResourceParameter(SmooksUtils.RESOURCE_NAME_PARAM, null, resource.getName());
+		
+		// Append the "Name" parameter.  This is not a "real" parameter.  It's just how we get over the fact that the SmooksResourceConfiguration
+		// class doesn't have "name" attribute like the TransformationResource class.  So, we import and export
+		// as a resource parameter.
+		appendParameter(stringBuffer, nameParameter);
+		for(TransformationResourceParameter param : parameters) {
+			appendParameter(stringBuffer, param);
+		}
+	}
+
+	private static void appendParameter(StringBuffer stringBuffer, TransformationResourceParameter param) {
+		stringBuffer.append("\n\t\t<param name=\"").append(param.getName()).append("\"");
+		if(param.getType() != null && !param.getType().trim().equals("")) {
+			stringBuffer.append(" type=\"").append(param.getType()).append("\"");
+		}
+		stringBuffer.append(">");
+		
+		stringBuffer.append("<![CDATA[");
+		stringBuffer.append(param.getValueAsString());
+		stringBuffer.append("]]>");
+		stringBuffer.append("</param>");
+	}
+}




More information about the jboss-svn-commits mailing list