*/
package com.vaadin.ui;
+import java.util.Collection;
+
+import org.jsoup.nodes.Element;
+
import com.vaadin.server.Resource;
import com.vaadin.shared.ui.AbstractEmbeddedState;
+import com.vaadin.ui.declarative.DesignAttributeHandler;
+import com.vaadin.ui.declarative.DesignContext;
/**
* Abstract base for embedding components.
return getState(false).alternateText;
}
+ @Override
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
+ if (design.hasAttr("alt")) {
+ setAlternateText(DesignAttributeHandler.readAttribute("alt",
+ design.attributes(), String.class));
+ }
+ }
+
+ @Override
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
+ AbstractEmbedded def = designContext.getDefaultInstance(this);
+ DesignAttributeHandler.writeAttribute("alt", design.attributes(),
+ getAlternateText(), def.getAlternateText(), String.class);
+ }
+
+ @Override
+ protected Collection<String> getCustomAttributes() {
+ Collection<String> c = super.getCustomAttributes();
+ c.add("alternate-text");
+ return c;
+ }
}
*/
package com.vaadin.ui;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.Map;
+
+import org.jsoup.nodes.Element;
import com.vaadin.server.Resource;
import com.vaadin.shared.ui.flash.FlashState;
+import com.vaadin.ui.declarative.DesignContext;
/**
* A component for displaying Adobe® Flash® content.
}
}
+ /**
+ * Returns the codebase.
+ *
+ * @see #setCodebase(String)
+ * @since 7.4
+ * @return Current codebase.
+ */
+ public String getCodebase() {
+ return getState(false).codebase;
+ }
+
/**
* This attribute specifies the content type of data expected when
* downloading the object specified by classid. This attribute is optional
}
}
+ /**
+ * Returns the current codetype.
+ *
+ * @see #setCodetype(String)
+ * @since 7.4
+ * @return Current codetype.
+ */
+ public String getCodetype() {
+ return getState(false).codetype;
+ }
+
/**
* This attribute may be used to specify a space-separated list of URIs for
* archives containing resources relevant to the object, which may include
}
}
+ /**
+ * Returns current archive.
+ *
+ * @see #setArchive(String)
+ * @since 7.4
+ * @return Current archive.
+ */
+ public String getArchive() {
+ return getState(false).archive;
+ }
+
+ /**
+ * Sets standby.
+ *
+ * @param standby
+ * Standby string.
+ */
public void setStandby(String standby) {
if (standby != getState().standby
|| (standby != null && !standby.equals(getState().standby))) {
}
}
+ /**
+ * Returns standby.
+ *
+ * @since
+ * @return Standby string.
+ */
+ public String getStandby() {
+ return getState(false).standby;
+ }
+
/**
* Sets an object parameter. Parameters are optional information, and they
* are passed to the instantiated object. Parameters are are stored as name
requestRepaint();
}
+ @Override
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
+ for (String param : getParameterNames()) {
+ design.appendElement("parameter").attr("name", param)
+ .attr("value", getParameter(param));
+ }
+ }
+
+ /**
+ * Returns an iterable with declared parameter names.
+ *
+ * @see #setParameter(String, String)
+ * @see #getParameter(String)
+ * @since 7.4
+ * @return An iterable with declared parameter names.
+ */
+ public Iterable<String> getParameterNames() {
+ Map<String, String> map = getState(false).embedParams;
+ if (map == null) {
+ return Collections.emptySet();
+ } else {
+ return Collections.unmodifiableSet(map.keySet());
+ }
+ }
+
+ @Override
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
+ for (Element paramElement : design.getElementsByTag("parameter")) {
+ setParameter(paramElement.attr("name"), paramElement.attr("value"));
+ }
+ }
+
}
import org.junit.Assert;
import com.vaadin.ui.Component;
+import com.vaadin.ui.Flash;
public abstract class DeclarativeTestBase<T extends Component> extends
DeclarativeTestBaseBase<T> {
}
}
+ {
+ comparators.put(Flash.class, new IntrospectorEqualsAsserter<Flash>(
+ Flash.class) {
+ @Override
+ public void assertObjectEquals(Flash o1, Flash o2) {
+ super.assertObjectEquals(o1, o2);
+ assertEquals("parameterNames", o1.getParameterNames(),
+ o2.getParameterNames());
+ for (String name : o1.getParameterNames()) {
+ assertEquals("Parameter " + name, o1.getParameter(name),
+ o2.getParameter(name));
+ }
+ }
+ });
+
+ }
+
@Override
protected EqualsAsserter getComparator(Class c) {
com.vaadin.tests.design.DeclarativeTestBaseBase.EqualsAsserter<?> comp = comparators
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * 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 com.vaadin.tests.design;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import org.junit.Test;
+
+import com.vaadin.server.ExternalResource;
+import com.vaadin.shared.util.SharedUtil;
+import com.vaadin.ui.AbstractEmbedded;
+import com.vaadin.ui.BrowserFrame;
+import com.vaadin.ui.Embedded;
+import com.vaadin.ui.Flash;
+import com.vaadin.ui.Image;
+import com.vaadin.ui.declarative.Design;
+
+/**
+ * Tests declarative support for implementations of {@link AbstractEmbedded} and
+ * {@link Embedded}.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+public class EmbeddedsTest {
+
+ public static final boolean equals(ExternalResource obj,
+ ExternalResource other) {
+ return SharedUtil.equals(obj.getURL(), other.getURL())
+ && SharedUtil.equals(obj.getMIMEType(), other.getMIMEType());
+ }
+
+ @Test
+ public void testAbstractEmbeddedsToFromDesign() throws Exception {
+ for (AbstractEmbedded ae : new AbstractEmbedded[] { new Image(),
+ new Flash(), new BrowserFrame() }) {
+ ae.setSource(new ExternalResource("http://www.example.org"));
+ ae.setAlternateText("some alternate text");
+ ae.setCaption("some <b>caption</b>");
+ ae.setCaptionAsHtml(true);
+ ae.setDescription("some description");
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ Design.write(ae, bos);
+ AbstractEmbedded result = (AbstractEmbedded) Design
+ .read(new ByteArrayInputStream(bos.toByteArray()));
+ assertTrue(equals((ExternalResource) ae.getSource(),
+ (ExternalResource) result.getSource()));
+ assertEquals(ae.getAlternateText(), result.getAlternateText());
+ assertEquals(ae.getCaption(), result.getCaption());
+ assertEquals(ae.isCaptionAsHtml(), result.isCaptionAsHtml());
+ assertEquals(ae.getDescription(), result.getDescription());
+ }
+ }
+
+ @Test
+ public void testFlashToFromDesign() throws Exception {
+ Flash ae = new Flash();
+ ae.setSource(new ExternalResource("http://www.example.org"));
+ ae.setAlternateText("some alternate text");
+ ae.setCaption("some <b>caption</b>");
+ ae.setCaptionAsHtml(true);
+ ae.setDescription("some description");
+ ae.setCodebase("codebase");
+ ae.setArchive("archive");
+ ae.setCodetype("codetype");
+ ae.setParameter("foo", "bar");
+ ae.setParameter("something", "else");
+ ae.setStandby("foobar");
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ Design.write(ae, bos);
+ Flash result = (Flash) Design.read(new ByteArrayInputStream(bos
+ .toByteArray()));
+ assertTrue(equals((ExternalResource) ae.getSource(),
+ (ExternalResource) result.getSource()));
+ assertEquals(ae.getAlternateText(), result.getAlternateText());
+ assertEquals(ae.getCaption(), result.getCaption());
+ assertEquals(ae.isCaptionAsHtml(), result.isCaptionAsHtml());
+ assertEquals(ae.getDescription(), result.getDescription());
+ assertEquals(ae.getCodebase(), result.getCodebase());
+ assertEquals(ae.getArchive(), result.getArchive());
+ assertEquals(ae.getCodetype(), result.getCodetype());
+ assertEquals(ae.getParameter("foo"), result.getParameter("foo"));
+ assertEquals(ae.getParameter("something"),
+ result.getParameter("something"));
+ assertEquals(ae.getStandby(), result.getStandby());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * 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 com.vaadin.tests.server.component.browserframe;
+
+import org.junit.Test;
+
+import com.vaadin.server.ExternalResource;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.BrowserFrame;
+
+/**
+ * Tests declarative support for implementations of {@link BrowserFrame}.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+public class BrowserFrameDeclarativeTest extends
+ DeclarativeTestBase<BrowserFrame> {
+
+ protected String getDesign() {
+ return "<v-browser-frame source='http://foo.bar/some.html' />";
+ }
+
+ protected BrowserFrame getExpectedResult() {
+ BrowserFrame i = new BrowserFrame();
+ i.setSource(new ExternalResource("http://foo.bar/some.html"));
+ return i;
+ };
+
+ @Test
+ public void read() {
+ testRead(getDesign(), getExpectedResult());
+ }
+
+ @Test
+ public void write() {
+ testWrite(getDesign(), getExpectedResult());
+ }
+
+ @Test
+ public void testEmpty() {
+ testRead("<v-browser-frame/>", new BrowserFrame());
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * 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 com.vaadin.tests.server.component.flash;
+
+import org.junit.Test;
+
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.AbstractEmbedded;
+import com.vaadin.ui.Embedded;
+import com.vaadin.ui.Flash;
+
+/**
+ * Tests declarative support for implementations of {@link AbstractEmbedded} and
+ * {@link Embedded}.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class FlashDeclarativeTest extends DeclarativeTestBase<Flash> {
+
+ protected Flash getExpectedResult() {
+ Flash f = new Flash();
+ f.setArchive("arch");
+ f.setCodebase("foo");
+ f.setCodetype("bar");
+ f.setStandby("Please wait");
+ f.setParameter("foo", "bar");
+ f.setParameter("baz", "foo");
+ return f;
+ };
+
+ protected String getDesign() {
+ return "<v-flash standby='Please wait' archive='arch' codebase='foo' codetype='bar' >"
+ + " <parameter name='baz' value='foo' />\n" //
+ + " <parameter name='foo' value='bar' />\n" //
+ + "</v-flash>"; //
+ }
+
+ @Test
+ public void read() {
+ testRead(getDesign(), getExpectedResult());
+ }
+
+ @Test
+ public void write() {
+ testWrite(getDesign(), getExpectedResult());
+ }
+
+ @Test
+ public void testEmpty() {
+ testRead("<v-flash />", new Flash());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * 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 com.vaadin.tests.server.component.image;
+
+import org.junit.Test;
+
+import com.vaadin.server.ExternalResource;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.Image;
+
+/**
+ * Tests declarative support for implementations of {@link Image}.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class ImageDeclarativeTest extends DeclarativeTestBase<Image> {
+
+ protected String getDesign() {
+ return "<v-image source='http://foo.bar/img.png' alt='Some random image from the theme'></v-image>";
+ }
+
+ protected Image getExpectedResult() {
+ Image i = new Image();
+ i.setSource(new ExternalResource("http://foo.bar/img.png"));
+ i.setAlternateText("Some random image from the theme");
+ return i;
+ };
+
+ @Test
+ public void read() {
+ testRead(getDesign(), getExpectedResult());
+ }
+
+ @Test
+ public void write() {
+ testWrite(getDesign(), getExpectedResult());
+ }
+
+ @Test
+ public void testEmpty() {
+ testRead("<v-image />", new Image());
+ }
+
+}