Class CommonsOperationsUtil
- java.lang.Object
-
- ro.sync.ecss.extensions.commons.operations.CommonsOperationsUtil
-
@API(type=INTERNAL, src=PUBLIC) public final class CommonsOperationsUtil extends java.lang.Object
Util methods for common Author operations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CommonsOperationsUtil.ConversionElementHelper
Interface used to check the elements that will be converted in other elements (table cells or list entries)static class
CommonsOperationsUtil.SelectedFragmentInfo
Class containing the new fragment and info about it.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
buildFreshPrefix(NamespaceContext namespaceContext)
Generates a prefix that is not yet bound to a namespace.static java.net.URL
expandAndResolvePath(AuthorAccess authorAccess, java.lang.String path)
Resolves a path relative to the framework directory.static java.util.List<CommonsOperationsUtil.SelectedFragmentInfo>
getFragmentsForConversions(AuthorAccess authorAccess, CommonsOperationsUtil.ConversionElementHelper helper, java.util.List<ContentInterval> intervals)
Get selected content fragments to be converted to cell or list entries fragments.static java.lang.String
getLocalName(java.lang.String qName)
Get the local name from an qualified element or attribute name.static java.lang.String
getPrefix(java.lang.String qName)
Get the proxy from an qualified element or attribute name.static java.util.List<CommonsOperationsUtil.SelectedFragmentInfo>
getSelectedFragmentsForConversions(AuthorAccess authorAccess, CommonsOperationsUtil.ConversionElementHelper helper)
Get selected content fragments to be converted to cell or list entries fragments.static boolean
isAllowedElement(java.lang.String elementLocalName, int offset, AuthorSchemaManager authorSchemaManager)
Check if an element with the given local name is allowed at the caret offset.static java.net.URL
locateResourceInClasspath(AuthorAccess authorAccess, java.lang.String resourceFileName)
Locate a certain resource in the classpath using its file name.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.static java.util.List<javax.swing.text.Position>
removeCurrentSelection(AuthorAccess authorAccess)
Remove current selection from Author.static void
removeEmptyElements(AuthorAccess authorAccess, java.util.Collection<javax.swing.text.Position> emptyElementsPositions)
Remove empty elements.static java.util.List<javax.swing.text.Position>
removeIntervals(AuthorAccess authorAccess, java.util.List<ContentInterval> selectionIntervals)
Remove current selection from Author.static void
removeUnwantedAttributes(java.lang.String[] skippedAttributes, AuthorDocumentFragment fragment, AuthorDocumentController controller)
Remove unwanted attributes.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.static java.lang.String
setAttributeValue(AuthorDocumentController ctrl, AuthorElement targetElement, javax.xml.namespace.QName attributeQName, java.lang.String value, boolean removeIfEmpty)
Sets an attribute value.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.static void
surroundWithFragment(AuthorAccess authorAccess, boolean schemaAware, java.lang.String xmlFragment)
Surround selection with fragment.static int
surroundWithFragment(AuthorAccess authorAccess, java.lang.String xmlFragment, int start, int end)
Surround the content between start and end offset with the given fragment.static void
unwrapTags(AuthorAccess authorAccess, AuthorNode nodeToUnwrap)
Unwrap node tags.
-
-
-
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 operationxmlFragment
- 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 fragmentstart
- 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 isnull
the attribute will be removed from the element. If the value is the empty string and removeIfEmpty istrue
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 isnull
the attribute will be removed from the element. If the value is the empty string and removeIfEmpty istrue
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"c&$
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).
-
getSelectedFragmentsForConversions
public static java.util.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
public static java.util.List<CommonsOperationsUtil.SelectedFragmentInfo> getFragmentsForConversions(AuthorAccess authorAccess, CommonsOperationsUtil.ConversionElementHelper helper, java.util.List<ContentInterval> intervals) throws javax.swing.text.BadLocationException, 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)intervals
- The intervals to convert.- Returns:
- The selected content fragments to be converted to cell fragments.
- Throws:
javax.swing.text.BadLocationException
AuthorOperationException
-
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.
-
-