Class CommonsOperationsUtil

java.lang.Object
ro.sync.ecss.extensions.commons.operations.CommonsOperationsUtil

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

    • serializeAttributes

      public static String serializeAttributes(Map<String,String> attributes, Collection<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 BadLocationException
      Unwrap node tags.
      Parameters:
      authorAccess - The Author access.
      nodeToUnwrap - The node to unwrap.
      Throws:
      BadLocationException
    • surroundWithFragment

      public static void surroundWithFragment(AuthorAccess authorAccess, boolean schemaAware, 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, 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 String setAttributeValue(AuthorDocumentController ctrl, AuthorElement targetElement, QName attributeQName, 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 String setAttributeValue(AuthorDocumentController ctrl, AuthorElement targetElement, QName attributeQName, String value, 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 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 URL locateResourceInClasspath(AuthorAccess authorAccess, 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 URL locateResourceInClasspathFolder(AuthorAccess authorAccess, String folderName, 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 URL expandAndResolvePath(AuthorAccess authorAccess, 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 String getPrefix(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 String getLocalName(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(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 List<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 List<Position> removeIntervals(AuthorAccess authorAccess, 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).
    • getSelectedFragmentsForConversions

      public static List<CommonsOperationsUtil.SelectedFragmentInfo> getSelectedFragmentsForConversions(AuthorAccess authorAccess, CommonsOperationsUtil.ConversionElementHelper helper) throws AuthorOperationException
      Get selected content fragments to be converted to cell or list entries fragments.
      Parameters:
      authorAccess - The author access.
      helper - Used to check if the elements from selection can be converted in other elements (table cells or list entries)
      Returns:
      The selected content fragments to be converted to cell fragments.
      Throws:
      AuthorOperationException
    • getFragmentsForConversions

      Get selected content fragments to be converted to cell or list entries fragments.
      Parameters:
      authorAccess - The author access.
      helper - Used to check if the elements from selection can be converted in other elements (table cells or list entries)
      intervals - The intervals to convert.
      Returns:
      The selected content fragments to be converted to cell fragments.
      Throws:
      BadLocationException
      AuthorOperationException
    • removeEmptyElements

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

      public static boolean isAllowedElement(String elementLocalName, int offset, AuthorSchemaManager authorSchemaManager) throws 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:
      BadLocationException - When the offset is below zero or greater than the content.