Search in sources :

Example 1 with MarkupWriterImpl

use of org.apache.tapestry5.internal.services.MarkupWriterImpl in project tapestry-5 by apache.

the class MarkupWriterFactoryImpl method constructMarkupWriter.

private MarkupWriter constructMarkupWriter(ContentType contentType, boolean partial, boolean HTML5) {
    final String mimeType = contentType.getMimeType();
    boolean isHTML = mimeType.equalsIgnoreCase("text/html");
    MarkupModel model;
    if (isHTML)
        model = HTML5 ? (partial ? html5PartialModel : html5Model) : (partial ? htmlPartialModel : htmlModel);
    else
        model = partial ? xmlPartialModel : xmlModel;
    return new MarkupWriterImpl(model, contentType.getCharset(), mimeType);
}
Also used : Html5MarkupModel(org.apache.tapestry5.dom.Html5MarkupModel) DefaultMarkupModel(org.apache.tapestry5.dom.DefaultMarkupModel) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) MarkupModel(org.apache.tapestry5.dom.MarkupModel)

Example 2 with MarkupWriterImpl

use of org.apache.tapestry5.internal.services.MarkupWriterImpl in project tapestry-5 by apache.

the class SelectTest method option_groups.

@Test
public void option_groups() throws Exception {
    ValidationTracker tracker = mockValidationTracker();
    OptionGroupModel husbands = new OptionGroupModelImpl("Husbands", false, TapestryInternalUtils.toOptionModels("Fred,Barney"));
    OptionGroupModel wives = new OptionGroupModelImpl("Wives", true, TapestryInternalUtils.toOptionModels("Wilma,Betty"));
    List<OptionGroupModel> groupModels = CollectionFactory.newList(husbands, wives);
    Select select = new Select();
    train_getInput(tracker, select, null);
    replay();
    select.setModel(new SelectModelImpl(groupModels, null));
    select.setValueEncoder(new StringValueEncoder());
    select.setValue("Fred");
    select.setValidationTracker(tracker);
    MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
    writer.element("select");
    select.options(writer);
    writer.end();
    assertEquals(writer.toString(), read("option_groups.txt"));
    verify();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) OptionGroupModelImpl(org.apache.tapestry5.internal.OptionGroupModelImpl) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) Test(org.testng.annotations.Test)

Example 3 with MarkupWriterImpl

use of org.apache.tapestry5.internal.services.MarkupWriterImpl in project tapestry-5 by apache.

the class SelectTest method just_options.

@Test
public void just_options() throws Exception {
    ValidationTracker tracker = mockValidationTracker();
    List<OptionModel> options = TapestryInternalUtils.toOptionModels("fred=Fred Flintstone,barney=Barney Rubble");
    Select select = new Select();
    train_getInput(tracker, select, null);
    replay();
    select.setModel(new SelectModelImpl(null, options));
    select.setValueEncoder(new StringValueEncoder());
    select.setValue("barney");
    select.setValidationTracker(tracker);
    MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
    writer.element("select");
    select.options(writer);
    writer.end();
    assertEquals(writer.toString(), read("just_options.txt"));
    verify();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) Test(org.testng.annotations.Test)

Example 4 with MarkupWriterImpl

use of org.apache.tapestry5.internal.services.MarkupWriterImpl in project tapestry-5 by apache.

the class SelectTest method option_attributes.

@Test
public void option_attributes() throws Exception {
    ValidationTracker tracker = mockValidationTracker();
    // Extra cast needed for Sun compiler, not Eclipse compiler.
    List<OptionModel> options = Arrays.asList((OptionModel) new OptionModelImpl("Fred", "fred") {

        @Override
        public Map<String, String> getAttributes() {
            return Collections.singletonMap("class", "pixie");
        }
    });
    Select select = new Select();
    train_getInput(tracker, select, null);
    replay();
    select.setModel(new SelectModelImpl(null, options));
    select.setValueEncoder(new StringValueEncoder());
    select.setValue("barney");
    select.setValidationTracker(tracker);
    MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
    writer.element("select");
    select.options(writer);
    writer.end();
    assertEquals(writer.toString(), read("option_attributes.txt"));
    verify();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) OptionModelImpl(org.apache.tapestry5.internal.OptionModelImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) Test(org.testng.annotations.Test)

Example 5 with MarkupWriterImpl

use of org.apache.tapestry5.internal.services.MarkupWriterImpl in project tapestry-5 by apache.

the class SelectTest method just_options_with_blank_label_enabled.

@Test
public void just_options_with_blank_label_enabled() throws Exception {
    ValidationTracker tracker = mockValidationTracker();
    List<OptionModel> options = TapestryInternalUtils.toOptionModels("fred=Fred Flintstone,barney=Barney Rubble");
    Select select = new Select();
    train_getInput(tracker, select, null);
    replay();
    select.setModel(new SelectModelImpl(null, options));
    select.setValueEncoder(new StringValueEncoder());
    select.setValue("barney");
    select.setValidationTracker(tracker);
    select.setBlankOption(BlankOption.ALWAYS, "Make a selection");
    MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
    writer.element("select");
    select.options(writer);
    writer.end();
    assertEquals(writer.toString(), read("blank_label.txt"));
    verify();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)40 MarkupWriter (org.apache.tapestry5.MarkupWriter)32 XMLMarkupModel (org.apache.tapestry5.dom.XMLMarkupModel)19 MarkupWriterImpl (org.apache.tapestry5.internal.services.MarkupWriterImpl)16 SelectModelImpl (org.apache.tapestry5.internal.SelectModelImpl)9 StringValueEncoder (org.apache.tapestry5.internal.services.StringValueEncoder)9 ComponentResources (org.apache.tapestry5.ComponentResources)4 Element (org.apache.tapestry5.dom.Element)4 DefaultMarkupModel (org.apache.tapestry5.dom.DefaultMarkupModel)3 OptionGroupModelImpl (org.apache.tapestry5.internal.OptionGroupModelImpl)3 Link (org.apache.tapestry5.http.Link)2 OptionModelImpl (org.apache.tapestry5.internal.OptionModelImpl)2 RenderCommand (org.apache.tapestry5.runtime.RenderCommand)2 JavaScriptSupport (org.apache.tapestry5.services.javascript.JavaScriptSupport)2 MarkupWriterListener (org.apache.tapestry5.MarkupWriterListener)1 Location (org.apache.tapestry5.commons.Location)1 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)1 Html5MarkupModel (org.apache.tapestry5.dom.Html5MarkupModel)1 MarkupModel (org.apache.tapestry5.dom.MarkupModel)1 AttributeToken (org.apache.tapestry5.internal.parser.AttributeToken)1