Author: yradtsevich
Date: 2009-02-03 11:05:44 -0500 (Tue, 03 Feb 2009)
New Revision: 13450
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSF.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFMediaOutput.java
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/mediaOutput.xhtml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/mediaOutput.xhtml.xml
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java
Log:
RESOLVED - issue JBIDE-3717: Some attrs of a4j:mediaOutput don't work.
https://jira.jboss.org/jira/browse/JBIDE-3717
- Support of attributes 'align', 'border', 'dir',
'hspace', 'vspace', 'id', 'style', 'styleClass',
'element', 'uriAttribute' has been added
- JUnit test has been rewritten
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSF.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSF.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSF.java 2009-02-03
16:05:44 UTC (rev 13450)
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.vpe.ajax4jsf.template;
+
+/**
+ * Contains Ajax4JSF tags and attributes names
+ *
+ * @author yradtsevich
+ */
+public final class Ajax4JSF {
+ public static final String ATTR_ELEMENT = "element"; //$NON-NLS-1$
+ public static final String ATTR_URI_ATTRIBUTE = "uriAttribute"; //$NON-NLS-1$
+ public static final String ATTR_STYLE_CLASS = "styleClass"; //$NON-NLS-1$
+}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFMediaOutput.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFMediaOutput.java 2009-02-03
14:09:04 UTC (rev 13449)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFMediaOutput.java 2009-02-03
16:05:44 UTC (rev 13450)
@@ -7,10 +7,12 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.jsf.vpe.ajax4jsf.template;
import java.io.File;
+import java.util.Arrays;
+import java.util.List;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@@ -18,49 +20,63 @@
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.util.HTML;
+import org.jboss.tools.vpe.editor.util.VisualDomUtil;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+/**
+ * The template for {@code <a4j:mediaOutput>} tag.
+ *
+ * @author dmaliarevich
+ * @author dsakovich
+ * @author yradtsevich
+ */
public class Ajax4JSFMediaOutput extends VpeAbstractTemplate {
+ private static final String IMG_PATH = "mediaOutput/mediaOutput.jpg";
//$NON-NLS-1$
+
+ private static final List<String> SAME_ATTRIBUTES_LIST;
+ static {
+ String []sameAttributes = {HTML.ATTR_ALIGN, HTML.ATTR_BORDER, HTML.ATTR_DIR,
+ HTML.ATTR_HSPACE, HTML.ATTR_ID, HTML.ATTR_STYLE, HTML.ATTR_VSPACE};
+ for (int i = 0; i < sameAttributes.length; i++) {
+ sameAttributes[i] = sameAttributes[i].toLowerCase();
+ }
+ SAME_ATTRIBUTES_LIST = Arrays.asList(sameAttributes);
+ }
- public static final String ALT_MEDIA_OTPUT = " mediaOutput";
-
- public static final String HTML_TAG_DIV = "DIV";
- public static final String HTML_TAG_IMG = "IMG";
-
- public static final String ATTR_WIDTH = "WIDTH";
- public static final String ATTR_HEIGHT = "HEIGHT";
- public static final String ATTR_SRC = "src";
- public static final String ATTR_ALT = "alt";
-
- public static final String IMG_PATH = "mediaOutput/mediaOutput.jpg";
-
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
-
- nsIDOMElement mainDiv = visualDocument
- .createElement(HTML_TAG_DIV);
- nsIDOMElement img = visualDocument
- .createElement(HTML_TAG_IMG);
-
- img.setAttribute(ATTR_SRC, "file:///" +
getAbsoluteResourcePath(IMG_PATH).replace('\\', '/'));
- img.setAttribute(ATTR_ALT, ALT_MEDIA_OTPUT);
- img.setAttribute(ATTR_WIDTH, "100");
- img.setAttribute(ATTR_HEIGHT, "50");
-
- mainDiv.appendChild(img);
-
- return new VpeCreationData(mainDiv);
+
+ Element sourceElement = (Element) sourceNode;
+ nsIDOMElement mainTag = createMainTag(visualDocument, sourceElement);
+
+ String uriAttribute = sourceElement.getAttribute(Ajax4JSF.ATTR_URI_ATTRIBUTE);
+ if (uriAttribute == null || "".equals(uriAttribute)) { //$NON-NLS-1$
+ uriAttribute = HTML.ATTR_SRC;
+ }
+
+ mainTag.setAttribute(uriAttribute, "file:///" +
getAbsoluteResourcePath(IMG_PATH).replace('\\', '/')); //$NON-NLS-1$
+
+ VisualDomUtil.copyAttributes(sourceElement, SAME_ATTRIBUTES_LIST, mainTag);
+
+ String styleClass = sourceElement.getAttribute(Ajax4JSF.ATTR_STYLE_CLASS);
+ if (styleClass != null) {
+ mainTag.setAttribute(HTML.ATTR_CLASS, styleClass);
+ }
+
+ return new VpeCreationData(mainTag);
}
-
+
+ @Override
public boolean isRecreateAtAttrChange(VpePageContext pageContext,
Element sourceElement, nsIDOMDocument visualDocument,
nsIDOMElement visualNode, Object data, String name, String value) {
return true;
}
-
+
public static String getAbsoluteResourcePath(String resourcePathInPlugin) {
String pluginPath = Activator.getPluginResourcePath();
IPath pluginFile = new Path(pluginPath);
@@ -68,9 +84,23 @@
if (file.exists()) {
return file.getAbsolutePath();
} else {
- throw new RuntimeException("Can't get path for "
- + resourcePathInPlugin);
+ throw new RuntimeException("Can't get path for " +
resourcePathInPlugin); //$NON-NLS-1$
}
}
-
+
+ /**
+ * Creates HTML element with tag-name specified in {@code element} attribute of
+ * {@code sourceElement}, or if the attribute is not present {@code 'img'} is
used.
+ */
+ private static nsIDOMElement createMainTag(nsIDOMDocument visualDocument,
+ Element sourceElement) {
+ String element = sourceElement.getAttribute(Ajax4JSF.ATTR_ELEMENT);
+
+ if (element == null || "".equals(element)) { //$NON-NLS-1$
+ element = HTML.TAG_IMG;
+ }
+
+ nsIDOMElement mainTag = visualDocument.createElement(element);
+ return mainTag;
+ }
}
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/mediaOutput.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/mediaOutput.xhtml.xml
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/mediaOutput.xhtml.xml 2009-02-03
14:09:04 UTC (rev 13449)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/mediaOutput.xhtml.xml 2009-02-03
16:05:44 UTC (rev 13450)
@@ -1,9 +1,18 @@
<tests>
- <test id="mediaOutput">
- <DIV>
- <IMG WIDTH="100" HEIGHT="50"
+ <test id="mediaOutput1">
+ <IMG SRC="/.*resources/mediaOutput/mediaOutput.jpg/"
ID="mediaOutput1"/>
+ </test>
+ <test id="mediaOutput2">
+ <IMG BORDER="20" ALIGN="right"
SRC="/.*resources/mediaOutput/mediaOutput.jpg/"
- ALT=" mediaOutput"/>
- </DIV>
+ ID="mediaOutput2"
+ STYLE="background-color: green;"
+ CLASS="dotted-border"/>
</test>
+ <test id="mediaOutput3">
+ <A HREF="/.*resources/mediaOutput/mediaOutput.jpg/"
+ ID="mediaOutput3"
+ STYLE="background-color: green;"
+ CLASS="dotted-border"/>
+ </test>
</tests>
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java 2009-02-03
14:09:04 UTC (rev 13449)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/HTML.java 2009-02-03
16:05:44 UTC (rev 13450)
@@ -83,6 +83,8 @@
public static final String ATTR_CELLPADDING = "cellpadding"; //$NON-NLS-1$
public static final String ATTR_WIDTH = "width"; //$NON-NLS-1$
public static final String ATTR_HEIGHT = "height"; //$NON-NLS-1$
+ public static final String ATTR_HSPACE = "hspace"; //$NON-NLS-1$
+ public static final String ATTR_VSPACE = "vspace"; //$NON-NLS-1$
public static final String ATTR_BORDER = "border"; //$NON-NLS-1$
public static final String ATTR_FOR = "FOR"; //$NON-NLS-1$
public static final String ATTR_DIR = "dir"; //$NON-NLS-1$