Class CommonsOperationsUtil


  • @API(type=INTERNAL,
         src=PUBLIC)
    public final class CommonsOperationsUtil
    extends java.lang.Object
    Util methods for common Author operations.
    • Method Detail

      • serializeAttributes

        public static java.lang.String serializeAttributes​(java.util.Map<java.lang.String,​java.lang.String> attributes,
                                                           java.util.Collection<java.lang.String> attributesToSkip)
        Serialize attributes with a space before.
        Parameters:
        attributes - The attributes to serialize.
        attributesToSkip - The names of the attributes to skip.
        Returns:
        The serialization.
      • unwrapTags

        public static void unwrapTags​(AuthorAccess authorAccess,
                                      AuthorNode nodeToUnwrap)
                               throws javax.swing.text.BadLocationException
        Unwrap node tags.
        Parameters:
        authorAccess - The Author access.
        nodeToUnwrap - The node to unwrap.
        Throws:
        javax.swing.text.BadLocationException
      • surroundWithFragment

        public static void surroundWithFragment​(AuthorAccess authorAccess,
                                                boolean schemaAware,
                                                java.lang.String xmlFragment)
                                         throws AuthorOperationException
        Surround selection with fragment.
        Parameters:
        authorAccess - Author access.
        schemaAware - true for schema aware operation
        xmlFragment - The xml fragment
        Throws:
        AuthorOperationException
      • surroundWithFragment

        public static int surroundWithFragment​(AuthorAccess authorAccess,
                                               java.lang.String xmlFragment,
                                               int start,
                                               int end)
                                        throws AuthorOperationException
        Surround the content between start and end offset with the given fragment.
        Parameters:
        authorAccess - Author access.
        xmlFragment - The xml fragment
        start - The start offset. Inclusive.
        end - The end offset. Inclusive.
        Returns:
        Insertion offset.
        Throws:
        AuthorOperationException
      • setAttributeValue

        public static java.lang.String setAttributeValue​(AuthorDocumentController ctrl,
                                                         AuthorElement targetElement,
                                                         javax.xml.namespace.QName attributeQName,
                                                         java.lang.String value,
                                                         boolean removeIfEmpty)
        Sets an attribute value. If the value is null the attribute will be removed from the element. If the value is the empty string and removeIfEmpty is true the attribute will also be removed.
        Parameters:
        ctrl - Attribute controller.
        targetElement - The target element.
        attributeQName - Attribute to edit.
        value - Current value. Illegal characters in the value WILL NOT be escaped.
        removeIfEmpty - true to remove the attribute when an empty value is set.
        Returns:
        The QName with which the attribute was committed. From the given attributeQName only the local name and namespace are taken into account.
      • setAttributeValue

        public static java.lang.String setAttributeValue​(AuthorDocumentController ctrl,
                                                         AuthorElement targetElement,
                                                         javax.xml.namespace.QName attributeQName,
                                                         java.lang.String value,
                                                         java.lang.String normalizedValue,
                                                         boolean removeIfEmpty)
        Sets an attribute value. If the value is null the attribute will be removed from the element. If the value is the empty string and removeIfEmpty is true the attribute will also be removed.
        Parameters:
        ctrl - Attribute controller.
        targetElement - The target element.
        attributeQName - Attribute to edit.
        value - Current value. Illegal characters in the value WILL NOT be escaped. All entities must be already escaped in this value. For example:
        ab&quot;c&amp;&#36;
        normalizedValue - The value with normalized whitespaces and expanded entities. For example:
        ab"c&$
        removeIfEmpty - true to remove the attribute when an empty value is set.
        Returns:
        The QName with which the attribute was committed. From the given attributeQName only the local name and namespace are taken into account.
      • buildFreshPrefix

        public static java.lang.String buildFreshPrefix​(NamespaceContext namespaceContext)
        Generates a prefix that is not yet bound to a namespace.
        Parameters:
        namespaceContext - Namespace context.
        Returns:
        A prefix not bound in the given context.
      • locateResourceInClasspath

        public static java.net.URL locateResourceInClasspath​(AuthorAccess authorAccess,
                                                             java.lang.String resourceFileName)
        Locate a certain resource in the classpath using its file name.
        Parameters:
        authorAccess - Author access.
        resourceFileName - The resource file name.
        Returns:
        The URL of the resource or null.
      • locateResourceInClasspathFolder

        public static java.net.URL locateResourceInClasspathFolder​(AuthorAccess authorAccess,
                                                                   java.lang.String folderName,
                                                                   java.lang.String resourceFileName)
        Locate a certain resource in the classpath using its file name.
        Parameters:
        authorAccess - Author access.
        folderName - The name of the folder.
        resourceFileName - The resource file name.
        Returns:
        The URL of the resource or null.
      • expandAndResolvePath

        public static java.net.URL expandAndResolvePath​(AuthorAccess authorAccess,
                                                        java.lang.String path)
        Resolves a path relative to the framework directory. Editor variables are also accepted and expanded. The path is also passed through the catalog mappings.
        Parameters:
        authorAccess - Author access.
        path - The path to resolve. Can be a file path, an URL path or a path relative to the framework directory. Editor variables are also accepted. The path is also passed through the catalog mappings.
        Returns:
        An URL or null if unable to expand the path to an URL.
      • getPrefix

        public static java.lang.String getPrefix​(java.lang.String qName)
        Get the proxy from an qualified element or attribute name.
        Parameters:
        qName - q name
        Returns:
        the proxy or an empty string. Null if the argument is null.
      • getLocalName

        public static java.lang.String getLocalName​(java.lang.String qName)
        Get the local name from an qualified element or attribute name.
        Parameters:
        qName - q name
        Returns:
        the local name, or null if the argument is null.
      • removeUnwantedAttributes

        public static void removeUnwantedAttributes​(java.lang.String[] skippedAttributes,
                                                    AuthorDocumentFragment fragment,
                                                    AuthorDocumentController controller)
        Remove unwanted attributes.
        Parameters:
        skippedAttributes - The attributes to be deleted.
        fragment - The author document fragment to be cleared.
        controller - The author document controller.
      • removeCurrentSelection

        public static java.util.List<javax.swing.text.Position> removeCurrentSelection​(AuthorAccess authorAccess)
        Remove current selection from Author.
        Parameters:
        authorAccess - Author access.
        Returns:
        A list with start positions for empty elements (after remove is done).
      • removeIntervals

        public static java.util.List<javax.swing.text.Position> removeIntervals​(AuthorAccess authorAccess,
                                                                                java.util.List<ContentInterval> selectionIntervals)
        Remove current selection from Author.
        Parameters:
        authorAccess - Author access.
        selectionIntervals - The intervals.
        Returns:
        A list with start positions for empty elements (after remove is done).
      • removeEmptyElements

        public static void removeEmptyElements​(AuthorAccess authorAccess,
                                               java.util.Collection<javax.swing.text.Position> emptyElementsPositions)
        Remove empty elements.
        Parameters:
        authorAccess - The Author access.
        emptyElementsPositions - Positions for empty elements
      • isAllowedElement

        public static boolean isAllowedElement​(java.lang.String elementLocalName,
                                               int offset,
                                               AuthorSchemaManager authorSchemaManager)
                                        throws javax.swing.text.BadLocationException
        Check if an element with the given local name is allowed at the caret offset.
        Parameters:
        elementLocalName - the local name of the element whose allowance we check.
        offset - the offset where the allowance of the element is checked.
        authorSchemaManager - the Author schema manager.
        Returns:
        true if an element with the given local name is allowed at the caret offset, false otherwise.
        Throws:
        javax.swing.text.BadLocationException - When the offset is below zero or greater than the content.