custom node types and namespaces (MAGNOLIA-1364)

[MAGNOLIA-1506] ids and names used for HTML elements and JavaScript variables and functions Created: 03/May/07  Updated: 11/Mar/10  Resolved: 11/Mar/10

Status: Closed
Project: Magnolia
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Sub-task Priority: Major
Reporter: Oliver Lietz Assignee: Oliver Lietz
Resolution: Outdated Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Date of First Response:

 Comments   
Comment by Oliver Lietz [ 03/May/07 ]

The controlType name is used to generate names and ids for HTML and JavaScript. When using custom node types and namespaces, the prefix is separated by a colon from the node/property name (e.g. jcr:mimeType). This leads to illegal names/ids.

broken:

  • multiselect control
Comment by Oliver Lietz [ 15/Jun/07 ]

(from dev-list@)
The sanitize function from StringUtils[SU] fixes most of the problems replacing
illegal characters with an underscore and prefixing the name with mgnl_ (when
it doesn't start already with mgnl, see comment in StringUtils).

This method is not 100% save. Think we have similar property names:
prÖperty and prÜperty*, both result in mgnl_pr_perty. It might be a rare case
but I don't want to rely on it. It will break sooner or later.

I know the gui prevents entering/saving special chars. But what's about
import/export or exchange with other (content management) systems?

A better solution would be to hex-encode the names. It's saver but leads to
unreadable names which makes it harder to debug.
We could swap implementations of sanitize when debugging - not optimal because
we also slightly change the system behaviour (another potential cause for
bugs).

I have to review the JS and check if they make use of the property name to
construct the id/names of HTML elements for accessing them.
If it's the case, sanitize has also to be implemented in JS.

[SU] http://svn.magnolia.info/view/magnolia/branches/custom-experimental/magnolia-core/src/main/java/info/magnolia/util/StringUtils.java

Comment by Oliver Lietz [ 15/Jun/07 ]

There is indeed JS which makes use of the property name (id/name) to construct the id/names of HTML elements for accessing them. This forces us to use a bi-directional en-/decoding of the ids/names.

hexencoding/hexdecoding looks best for that purpose.

HTML:

use StringUtils.hexencode(string) for ids and names

JS:

use StringUtils.hexencode(string) when constructing function names or paramter values when they are (final) HTML ids/names

DON'T use hexencode for parameter values in JS functions when it's the pure id/name, the JS has to encode the id/name itself when it's used for accessing HTML elements

Comment by Philipp Bracher [ 22/Jun/07 ]

I don't like this hexencoding of former readable strings.

What is about to url encode the srtings (only special characters are encoded)?

Comment by Oliver Lietz [ 22/Jun/07 ]

> What is about to url encode the srtings (only special characters are encoded)?

Doesn't work for several reasons:

  • not all characters which are illegal as id/name are encoded
  • encoding works only for ASCII characters (or hex/url results are of different length, 2 or 4 digits)
  • encoding is done in hex prefixed with a % (percent sign), which is illegal as id/name character

There are lots of cases where ids/names are prefixed or suffixed, e.g. btn_ or _fileNameExtension - only the id/name should be encoded and the prefix/suffix should be let as is.

Comment by Oliver Lietz [ 23/Jun/07 ]

make it more consistent and separate all prefixes and suffixes from id/name with _ (underscore)

Comment by Oliver Lietz [ 23/Jun/07 ]

we can use the universal title attribute for human readable (unencoded) names

Comment by Oliver Lietz [ 25/Jun/07 ]
  • review use of id and name
  • create id/name prefix and suffix variables and setters/getters

http://www.theajaxworkshop.com/index.php/Element_Name_vs_Id

Comment by Oliver Lietz [ 01/Jul/07 ]
  • replace getElementById with getElementsByName when used for grouped elements (e.g. button sets)
Comment by Oliver Lietz [ 12/Jul/07 ]

> - replace getElementById with getElementsByName when used for grouped elements (e.g. button sets)

reviewed: name attribute is deprecated, see MAGNOLIA-1620

Comment by Oliver Lietz [ 01/Aug/07 ]

> There are lots of cases where ids/names are prefixed or suffixed, e.g. btn_ or _fileNameExtension - only the id/name should be
> encoded and the prefix/suffix should be let as is.

makes encoding/decoding to complex, hence complete id has to be encoded

> we can use the universal title attribute for human readable (unencoded) names

ugly hack and normally human readable id is not needed

Comment by Magnolia International [ 11/Mar/10 ]

the "custom-experimental" branch referred to in this issue was moved to http://svn.magnolia-cms.com/svn/community/graveyard/namespace-and-cnd-support-experiment/
(a relevant name to start with, and since the branch is inactive, it's now considered "dead", hence the new location)

Comment by Magnolia International [ 11/Mar/10 ]

The work in this branch is outdated; with 5.0, this issue will not be present and/or be fixed in a different way.

Generated at Mon Feb 12 03:27:34 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.