what should I make my package if my domain has a dash? - oop

The convention for packages is your domain name. Dashes are sometimes not allowed in package names. So if your domain name has a dash what should you use?

The "official" convention in Java is to replace it with an underscore.
From (an older version of) the spec:
In some cases, the internet domain name may not be a valid package
name. Here are some suggested conventions for dealing with these
situations:
If the domain name contains a hyphen, or any other special character
not allowed in an identifier (§3.8), convert it into an underscore. If
any of the resulting package name components are keywords (§3.9) then
append underscore to them. If any of the resulting package name
components start with a digit, or any other character that is not
allowed as an initial character of an identifier, have an underscore
prefixed to the component.

Underscore is an option I've used before, but otherwise, just concatenate.

Related

How to split on unicode whitespace in kotlin

In Kotlin if we use:
string.split(Regex("\\s+"))
Then we can split a string into words separated by whitespace. However the string:
val string = "a\u2000b"
doesn't split since the regex doesn't match unicode whitespace characters.
I there a way to split the string on all whitespace characters?
Since Java 7 Pattern allows to specify the UNICODE_CHARACTER_CLASS-flag which would basically also work for your current issue:
Pattern.compile("\\s+", Pattern.UNICODE_CHARACTER_CLASS)
Unfortunately this isn't directly supported via RegexOption with Kotlins Regex yet. There is a known issue that also describes a workaround (KT-21094):
string.split("""(?U)\s+""".toRegex())
You (most probably) require Java 7+ for that to actually work. Alternatives could be to use other predefined character classes instead. However, you need to lookup the appropriate Pattern-javadoc for your Java version to ensure that it is actually working (or do it in a trial-error-manner ;-)).
I've used the following regex to match Unicode whitespace:
Regex("[\\p{javaWhitespace}\u00A0\u2007\u202F]+")
This works because while \s matches only Latin-1 whitespace, \p{javaWhitespace} matches everything for which Character.isWhitespace() is true.  For some reason, this doesn't include a few particular characters, which I've listed separately.
More info in the docs for Pattern.
Related fact: although java.lang.String.trim() doesn't remove non-breaking spaces or figure spaces, kotlin.String.trim() does!

Error: runKubernetesJobAtomicOperationDescription.application.invalid (Must match ^[a-z0-9]+$)

If you face the same problem as follows:
runKubernetesJobAtomicOperationDescription.application.invalid (Must match ^[a-z0-9]+$)
Cause: Your spinnaker application name is wrong, for example sample-application is a wrong application name. Please remove the hyphen character like this sampleapplication.
it's telling you can't have hyphens in your application name as this is used as a separator

Xpath: whitespace encoding

I need to create an XPath query to select a JCR node whose name contains a whitespace character.
For instance: /jcr:root/foo bar/
But that results in an invalid query.
How should whitespaces be encoded in an XPath query?
Try using something like this XPath query:
/jcr:root/foo_x0020_bar/
The JSR-170 (JCR 1.0) specification defines how XPath can be used to query a JCR repository, and even though JSR-283 (or JCR 2.0) deprecated XPath as a query language, many of the implementations still support XPath along with the other query languages (including the more powerful JCR-SQL2).
Now, regarding the rules for escaping characters in XPath, JSR-170 states the following in Section 6.6.4.9:
The names of elements and attributes (corresponding to nodes and properties, respectively) within an XPath statement must correspond to the form in which they (notionally) appear in the document view. This means that spaces (and any other non-XML characters) within names must be encoded according to the rules described in 6.4.3 Escaping of Names.
Section 6.4.3 defines how such characters are escaped in names:
The escape character is the underscore (“_”). Any invalid character is escaped as _xHHHH_, where HHHH is the four-digit hexadecimal UTF-16 code for the character. When producing escape sequences the implementation should use lowercase letters for the hex digits a-f. When unescaping, however, both upper and lowercase alphabetic hexadecimal characters must be recognized.
Although you didn't ask about it, you can easily do the same query in JCR-SQL2:
SELECT * FROM [nt:base] WHERE ISSAMENODE('/foo_x0020_bar')

amazon simpledb attribute naming restrictions?

I want to know if there are any restriction to attribute names in amazons simpledb.
I tried the following attribute name
my.attribute.name
Running the following query
select * from mydomain where my.attribute.name is not null
results in an error: "The specified query expression syntax is not valid.".
Also surrounding 'my.attribute.name' results in an error because is invalid select syntax.
Changing point to underscore and everything works fine:
my_attribute_name
and the query runs fine
select * from mydomain where my_attribute_name is not null
Now my question: What are the allowed characters for attributes?
On the amazon developer manual the names are restricted to characters that are valid in xml documents. What exactly does this mean? The linked W3C documents seems not answering this. In domain names the dot "." is allowed.
Currently I use the sdbTool. I hope this doesnt affect the behaviour.
Inserting some other characters in attribute names is working, like this one: 'my:attribute-name.with other%20chars'.
Any ideas?
Can you please enclosed your attribute name in back-tick quotes and try again ?
Domain names & Attribute names need to be enclosed in back-tick quotes if they contains any special characters. Attribute and domain names may appear without quotes if they contain only letters, numbers, underscores (_), or dollar symbols ($). You must quote all other attribute and domain names with the back-tick (`) if they contains any special characters.

Special characters in Amazon S3 file name

Users are uploading files with names like "abc #1", "abc #2". I am uploading these files to S3. When I try to download these files I get an error like this
InvalidArgument
Header value contained an open quoted span.
I am creating the link by wrapping the file name using "Uri.EscapeUriString".
Any suggestions?
From AWS documentation:
The name for a key is a sequence of Unicode characters whose UTF-8 encoding is at most 1024 bytes long.
So the "abc #1" and "abc #2" are valid key names, the problem is then probably in your client code, check the documentation of your Http client.
AWS also warn about using special characters:
You can use any UTF-8 character in an object key name. However, using certain characters in key names may cause problems with some applications and protocols. The following guidelines help you maximize compliance with DNS, web-safe characters, XML parsers, and other APIs.
Alphanumeric characters: 0-9, a-z, A-Z
Special characters: !, -, _, ., *, ', (, )
So either restrict the set of available characters in your app to only allow the recommended ones, or fix the issue at your client level.
You should use Uri.EscapeDataString instead of Uri.EscapeUriString for 3 reasons:
Uri.EscapeUriString has been deprecated as of .NET 6 - https://learn.microsoft.com/en-us/dotnet/api/system.uri.escapeuristring?view=net-6.0
Uri.EscapeUriString can corrupt the Uri string in some cases
Uri.EscapeUriString only escapes the spaces - not the #
Uri.EscapeUriString("abc #1") returns "abc%20#1" whereas Uri.EscapeDataString("abc #1") returns "abc%20%231" which is preferable.