mirror of
				https://github.com/lacerta-doc/Lacerta.git
				synced 2025-11-04 00:40:49 +00:00 
			
		
		
		
	Merge pull request #60 from lacerta-doc/model/public_path
PublicPathの追加
This commit is contained in:
		
						commit
						385f2f327d
					
				
							
								
								
									
										68
									
								
								model/src/main/java/one/nem/lacerta/model/PublicPath.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								model/src/main/java/one/nem/lacerta/model/PublicPath.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,68 @@
 | 
			
		||||
package one.nem.lacerta.model;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class PublicPath {
 | 
			
		||||
    /*
 | 
			
		||||
     * ユーザーが扱うパス(内部パスの代替)
 | 
			
		||||
     * (時間がないのでInjectされることは考慮しない)
 | 
			
		||||
     *
 | 
			
		||||
     * TODO-rca:
 | 
			
		||||
     *  - こわれたパスを検知する
 | 
			
		||||
     *  - バリデーション
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    List<String> path = new ArrayList<String>();
 | 
			
		||||
 | 
			
		||||
    public PublicPath() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public PublicPath(List<String> path) {
 | 
			
		||||
        this.path = path;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void add(String path) {
 | 
			
		||||
        this.path.add(path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void resolveInternal(String path) {
 | 
			
		||||
        if (path.equals("..")) {
 | 
			
		||||
            this.path.remove(this.path.size() - 1);
 | 
			
		||||
        } else {
 | 
			
		||||
            add(path);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public PublicPath resolve(String path) {
 | 
			
		||||
        resolveInternal(path);
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public PublicPath resolve(List<String> path) {
 | 
			
		||||
        for (String p : path) {
 | 
			
		||||
            resolveInternal(p);
 | 
			
		||||
        }
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public PublicPath resolve(PublicPath path) {
 | 
			
		||||
        for (String p : path.getPath()) {
 | 
			
		||||
            resolveInternal(p);
 | 
			
		||||
        }
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public PublicPath parent() {
 | 
			
		||||
        this.path.remove(this.path.size() - 1);
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<String> getPath() {
 | 
			
		||||
        return path;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getStringPath() {
 | 
			
		||||
        return String.join("/", path);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user