Class KStringTag<TARGET>

  • All Implemented Interfaces:
    java.lang.Cloneable
    Direct Known Subclasses:
    KStringHTMLTag, KStringPLAINTag

    public abstract class KStringTag<TARGET>
    extends java.lang.Object
    implements java.lang.Cloneable
    Base class for Tags (HTMLTag and PlainTag) in KString.
    Author:
    Christopher Mindus
    • Nested Class Summary

      Nested Classes 
      Modifier and TypeClassDescription
      static class KStringTag.Type
      The types.
    • Constructor Summary

      Constructors 
      ConstructorDescription
      KStringTag​(KStringTag.Type type, int position, java.util.LinkedHashMap<java.lang.String,​java.lang.String> attributes)
      Constructs a tag.
    • Constructor Detail

      • KStringTag

        public KStringTag​(KStringTag.Type type,
                          int position,
                          java.util.LinkedHashMap<java.lang.String,​java.lang.String> attributes)
        Constructs a tag.
        Parameters:
        type - The connector type.
        position - The position in the character based and parsed string.
        attributes - The attributes for the tag.
    • Method Detail

      • disposeTagReference

        protected void disposeTagReference()
        Disposes of the tag reference, used in the Editor for references.
      • setSourceLocation

        public final void setSourceLocation​(int startPos,
                                            int endPos)
                                     throws java.lang.IllegalArgumentException
        Sets the source position for the tag. This can only be done once, next time an IllegalArgumentException is thrown.
        Parameters:
        startPos - The start position in the source string.
        endPos - The end position in the source string.
        Throws:
        java.lang.IllegalArgumentException
      • getSourcePosition

        public final int getSourcePosition()
        Gets the source position of this tag in the source string.
        Returns:
        The start position of the tag.
      • getSourceEndPosition

        public final int getSourceEndPosition()
        Gets the ending position of this tag in the source string.
        Returns:
        The end position of the tag.
      • getSourceLength

        public final int getSourceLength()
        Gets the length of this tag in the source string.
        Returns:
        The length in characters of the tag.
      • isReferenceTag

        public abstract boolean isReferenceTag()
        Checks if this tag is of reference type, i.e. for HTML, the tags A, IMG, IZ. For PLAIN KString type, this method always returns true.
      • getReference

        public java.lang.String getReference()
        Gets the reference of this tag.
        Returns:
        The reference, or null for none.
      • setReference

        public abstract boolean setReference​(java.lang.String ref)
        Updates the tag reference.
        Parameters:
        ref - The new reference.
        Returns:
        true if changed, false for no change.
      • getReferenceClass

        public java.lang.Class<?> getReferenceClass()
        Returns the reference class used by this tag, e.g. KStringProp for text table, or the image class IImageTarget.class.
        Returns:
        The class, or null for no references.
      • appendPLAINAttributes

        public final void appendPLAINAttributes​(java.lang.StringBuilder useme)
        Appends the attributes for PLAIN raw format.
      • appendPLAINValue

        public static void appendPLAINValue​(java.lang.StringBuilder useme,
                                            java.lang.String value)
        Appends a string as quoted value. The chosen quote can be either single- or double-quote, whichever is shortest.
      • appendHTMLAttributes

        public final void appendHTMLAttributes​(java.lang.StringBuilder useme,
                                               IKStringInfoProvider provider)
        Appends the attributes for HTML raw format.
      • appendHTMLAttributesSkip

        public final void appendHTMLAttributesSkip​(java.lang.StringBuilder useme,
                                                   IKStringInfoProvider provider,
                                                   java.lang.String... skipAttributes)
        Appends the attributes for HTML raw format.
      • appendHTMLAttributes

        public final void appendHTMLAttributes​(java.lang.StringBuilder useme,
                                               IKStringInfoProvider provider,
                                               java.lang.String... possibleAttributeList)
        Appends the attributes for HTML raw format that are present in the "possibleAttributeList".
      • getAttribute

        public final java.lang.String getAttribute​(java.lang.String attributeName)
        Gets the attribute value.
        Parameters:
        attributeName - The name of the attribute.
        Returns:
        The value, or null if the attribute is not present.
      • setAttribute

        public final boolean setAttribute​(java.lang.String attributeName,
                                          java.lang.String value)
        Updates an attribute value or removes it.
        Parameters:
        attributeName - The attribute name.
        value - The value to set, or null to remove the attribute.
        Returns:
        true if changed, false otherwise.
      • willLoseFormatting

        public abstract boolean willLoseFormatting()
        Checks if this string will lose formatting when translated to PLAIN. Note that translating PLAIN to HTML never loses formatting.
      • getPLAINTagText

        public abstract java.lang.String getPLAINTagText​(java.lang.StringBuilder useme)
        Gets the "unparsed" string representation of this tag in the PLAIN format, i.e. a HTML tag will reformat or translate itself for PLAIN, or vice versa.
      • getHTMLTagText

        public abstract java.lang.String getHTMLTagText​(java.lang.StringBuilder useme,
                                                        IKStringInfoProvider provider)
        Gets the "unparsed" string representation of this tag in the HTML format, i.e. a PLAIN tag will reformat or translate itself for HTML, or vice versa.
        Parameters:
        useme - Temporary StringBuilder for any use.
        provider - The information provider or null for none.
      • getPLAINString

        public abstract java.lang.String getPLAINString​(java.lang.StringBuilder useme,
                                                        IKStringInfoProvider provider)
        Gets the string representation of this tag in the PLAIN format, i.e. a HTML tag will reformat or translate itself for PLAIN, or vice versa.
        Parameters:
        useme - Temporary StringBuilder for any use.
        provider - The information provider or null for none.
      • getHTMLString

        public abstract java.lang.String getHTMLString​(java.lang.StringBuilder useme,
                                                       IKStringInfoProvider provider)
        Gets the string representation of this tag in the HTML format, i.e. a PLAIN tag will reformat or translate itself for HTML, or vice versa.
        Parameters:
        useme - Temporary StringBuilder for any use.
        provider - The information provider or null for none.
      • equals

        public boolean equals​(java.lang.Object obj)
        Equality check: tags must be of same class (i.e. exactly same type) and have the same attributes.
        Overrides:
        equals in class java.lang.Object
      • equalsName

        public boolean equalsName​(KStringTag<?> kst)
        Checks for the same "name" (tag ordinal and closing tag for HTML, tag name for PLAIN).
      • clone

        protected KStringTag<TARGET> clone()
        Cloneable.
        Overrides:
        clone in class java.lang.Object
      • getReferenceDescription

        public final java.lang.String getReferenceDescription()
        Gets the reference description.
        Returns:
        The description shown for reference view in the Designer.
      • isReferenceValid

        public boolean isReferenceValid​(KStringHolder holder,
                                        GProp<?> gp)
        Validates a reference.
        Parameters:
        holder - The KString holder.
        gp - The reference found.
        Returns:
        Validates the reference.
      • getReferenceError

        public java.lang.String getReferenceError()
        Gets the validation error.
        Returns:
        null for OK, otherwise the error text.
      • resolve

        public void resolve​(KStringHolder holder,
                            boolean doReCheck,
                            GEvent triggerEvent)
        Resolves the reference.
        Parameters:
        holder - The KString holder.
        doReCheck - Rechecks the references.
        triggerEvent - The trigger event.
      • verify

        public void verify​(KStringHolder holder,
                           PropVerification verification,
                           java.lang.String location,
                           int id)
        Verifies the KString for a KString holder.
        Parameters:
        holder - The KString holder.
        verification - The property verification class.
        location - The location.
        id - The tag ID.
      • isRefreshRequired

        public boolean isRefreshRequired​(RefreshEvent event)
        Returns whether the tags needs a refresh for the specified refresh type.
        Parameters:
        event - The refresh event.
        Returns:
        true for refresh needed, false otherwise.
      • isRefreshRequired

        public boolean isRefreshRequired​(GEvent event,
                                         TARGET target)
        Upon a property event received on the target reference property (or its children), this method verifies if the event would affect the KString contents needing to be refreshed.
        Parameters:
        event - The event.
        target - The target property for the tag.
        Returns:
        true to refresh the KString, false not to.