Skip to content

Very small patch for visibility in NodeResource#76

Open
baszero wants to merge 1 commit into
wyona:masterfrom
baszero:balzpatch2
Open

Very small patch for visibility in NodeResource#76
baszero wants to merge 1 commit into
wyona:masterfrom
baszero:balzpatch2

Conversation

@baszero

@baszero baszero commented May 20, 2016

Copy link
Copy Markdown
Contributor

important methods should be made protected instead of private so that inheritation becomes easy.

@baszero

baszero commented May 24, 2016

Copy link
Copy Markdown
Contributor Author

I found a workaround so I don't need get getNode() to be protected.

@baszero baszero closed this May 24, 2016
@baszero baszero reopened this May 26, 2016
@baszero

baszero commented May 26, 2016

Copy link
Copy Markdown
Contributor Author

I reopened this pull request as I really think that making those two methods protected makes fully sense and is really required.

Use Case / Reason:

  • Let's say you have static files, located at /static/**
  • In your XSL files, you reference those static files like <img src="/static/1.jpg"/>
  • Using the NodeResource in order to serve those files, the files must be physically stored under /static
  • Now you want to hide the physical location, so you want to map /static to /internal-static, means: you still reference the static files via /static , but physically they are stored at /internal-static...
  • The easiest way to achieve this is to overwrite the NodeResource method getRepoPath() where you do the URL to Yarep-Path translation.

Example of overridden method in subclassed NodeResource class:

    protected String getRepositoryPath() throws Exception {
        String pathPrefix = getResourceConfigProperty("path-prefix");
        String path = getPath();
        if (pathPrefix == null) {
            return path;
        }
        int index = path.indexOf(pathPrefix);
        if (index != 0) {
            throw new IllegalArgumentException("Path <"+path+"> should start with <"+pathPrefix+">!");
        }
        String repositoryPath = path.substring(index + pathPrefix.length());
        return repositoryPath;
    }

Today you can not reuse the NodeResource and just override the getRepositoryPath() method because it is private.

I think that both getNode() and getRepoPath() should be made protected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant