@Override protected Element narrow(ElementMetadata<?, ?> meta, ValidationContext vc) { // Don't create a new instance if type is already narrow. if (!Content.class.equals(this.getClass())) { return this; } URI src = getSrc(); if (src == null) { String type = getAttributeValue(TYPE); if (type == null || type.equals("text") || type.equals("html") || type.equals("xhtml")) { // In-line text content return adapt(this, meta, TextContent.KIND); } else { // Other in-line content return adapt(this, meta, OtherContent.KIND); } } else { // Out-of-line content return adapt(this, meta, OutOfLineContent.KIND); } } }
/** Sets the human language that this content was is written in. */ public void setLang(String lang) { setAttributeValue(Content.XML_LANG, lang); }
/** Returns the human language that this content is written in */ public String getLang() { return getAttributeValue(XML_LANG); }
/** * Registers the metadata for this element. */ public static void registerMetadata(MetadataRegistry registry) { if (registry.isRegistered(KEY)) { return; } Content.registerMetadata(registry); ElementCreator builder = registry.build(KEY); builder.addElement(Feed.KEY); builder.addElement(Entry.KEY); registry.adapt(Content.KEY, KIND, KEY); }
@Override protected void validate(ElementMetadata<?, ?> metadata, ValidationContext vc) { super.validate(metadata, vc); int maximumChildren = hasTextValue() ? 0 : 1; if (getElementCount() > maximumChildren) { vc.addError(this, "Content cannot contain more than " + maximumChildren + " child elements, but contains " + getElementCount()); } } }
/** * {@inheritDoc} * * In the case of plain text or html content, we resolve a null content body * to an empty string. */ @Override public Element resolve(ElementMetadata<?,?> metadata, ValidationContext vc) { int type = getType(); if (type == IContent.Type.TEXT && Service.getVersion().isBefore(Service.Versions.V2) && getAttributeValue(Content.TYPE) == null) { setAttributeValue(Content.TYPE, "text"); } if (type == IContent.Type.TEXT || type == IContent.Type.HTML) { if (getTextValue() == null) { setTextValue(""); } } return super.resolve(metadata, vc); }
/** Returns the human language that this content is written in */ public String getLang() { return getAttributeValue(XML_LANG); }
/** * Registers the metadata for this element. */ public static void registerMetadata(MetadataRegistry registry) { if (registry.isRegistered(KEY)) { return; } Content.registerMetadata(registry); ElementCreator builder = registry.build(KEY); builder.addElement(Feed.KEY); builder.addElement(Entry.KEY); registry.adapt(Content.KEY, KIND, KEY); }
@Override protected void validate(ElementMetadata<?, ?> metadata, ValidationContext vc) { super.validate(metadata, vc); int maximumChildren = hasTextValue() ? 0 : 1; if (getElementCount() > maximumChildren) { vc.addError(this, "Content cannot contain more than " + maximumChildren + " child elements, but contains " + getElementCount()); } } }
/** * {@inheritDoc} * * In the case of plain text or html content, we resolve a null content body * to an empty string. */ @Override public Element resolve(ElementMetadata<?,?> metadata, ValidationContext vc) { int type = getType(); if (type == IContent.Type.TEXT && Service.getVersion().isBefore(Service.Versions.V2) && getAttributeValue(Content.TYPE) == null) { setAttributeValue(Content.TYPE, "text"); } if (type == IContent.Type.TEXT || type == IContent.Type.HTML) { if (getTextValue() == null) { setTextValue(""); } } return super.resolve(metadata, vc); }
@Override protected Element narrow(ElementMetadata<?, ?> meta, ValidationContext vc) { // Don't create a new instance if type is already narrow. if (!Content.class.equals(this.getClass())) { return this; } URI src = getSrc(); if (src == null) { String type = getAttributeValue(TYPE); if (type == null || type.equals("text") || type.equals("html") || type.equals("xhtml")) { // In-line text content return adapt(this, meta, TextContent.KIND); } else { // Other in-line content return adapt(this, meta, OtherContent.KIND); } } else { // Out-of-line content return adapt(this, meta, OutOfLineContent.KIND); } } }
/** Returns the human language that this content is written in */ public String getLang() { return getAttributeValue(XML_LANG); }
/** * Registers the metadata for this element. */ public static void registerMetadata(MetadataRegistry registry) { if (registry.isRegistered(KEY)) { return; } Content.registerMetadata(registry); ElementCreator builder = registry.build(KEY); builder.addElement(Feed.KEY); builder.addElement(Entry.KEY); registry.adapt(Content.KEY, KIND, KEY); }
@Override protected void validate(ElementMetadata<?, ?> metadata, ValidationContext vc) { super.validate(metadata, vc); int maximumChildren = hasTextValue() ? 0 : 1; if (getElementCount() > maximumChildren) { vc.addError(this, "Content cannot contain more than " + maximumChildren + " child elements, but contains " + getElementCount()); } } }
/** Sets the human language that this content was is written in. */ public void setLang(String lang) { setAttributeValue(Content.XML_LANG, lang); }
/** * {@inheritDoc} * * In the case of plain text or html content, we resolve a null content body * to an empty string. */ @Override public Element resolve(ElementMetadata<?,?> metadata, ValidationContext vc) { int type = getType(); if (type == IContent.Type.TEXT && Service.getVersion().isBefore(Service.Versions.V2) && getAttributeValue(Content.TYPE) == null) { setAttributeValue(Content.TYPE, "text"); } if (type == IContent.Type.TEXT || type == IContent.Type.HTML) { if (getTextValue() == null) { setTextValue(""); } } return super.resolve(metadata, vc); }
@Override protected Element narrow(ElementMetadata<?, ?> meta, ValidationContext vc) { // Don't create a new instance if type is already narrow. if (!Content.class.equals(this.getClass())) { return this; } URI src = getSrc(); if (src == null) { String type = getAttributeValue(TYPE); if (type == null || type.equals("text") || type.equals("html") || type.equals("xhtml")) { // In-line text content return adapt(this, meta, TextContent.KIND); } else { // Other in-line content return adapt(this, meta, OtherContent.KIND); } } else { // Out-of-line content return adapt(this, meta, OutOfLineContent.KIND); } } }
/** @return the external URI, or {@code null} if none exists */ public URI getSrc() { return getAttributeValue(SRC); }
/** * Registers the metadata for this element. */ public static void registerMetadata(MetadataRegistry registry) { if (registry.isRegistered(CONSTRUCT)) { return; } Content.registerMetadata(registry); ElementCreator constructBuilder = registry.build(CONSTRUCT) .setValidator(new TextContentValidator()); constructBuilder.addElement(DIV); ElementCreator builder = registry.build(KEY); registry.adapt(Content.KEY, KIND, KEY); }
/** Sets the human language that this content was is written in. */ public void setLang(String lang) { setAttributeValue(Content.XML_LANG, lang); }