1 package com.openedit.store; 2 3 11 public class SegmentedProductPathFinder implements ProductPathFinder 12 { 13 protected int fSegmentLength = 0; 14 protected String fieldPrefix; 15 protected boolean fieldReverse; 16 public boolean isReverse() 17 { 18 return fieldReverse; 19 } 20 21 public void setReverse(boolean inReverse) 22 { 23 fieldReverse = inReverse; 24 } 25 26 30 public SegmentedProductPathFinder() 31 { 32 } 33 34 44 public SegmentedProductPathFinder( int inSegmentLength ) 45 { 46 fSegmentLength = inSegmentLength; 47 } 48 49 public int getSegmentLength() 50 { 51 return fSegmentLength; 52 } 53 54 public void setSegmentLength( int inSegmentLength ) 55 { 56 fSegmentLength = inSegmentLength; 57 } 58 59 public String idToPath( String inProductId ) 60 { 61 if ( inProductId == null ) 62 { 63 return null; 64 } 65 66 if( getSegmentLength() == 0 && getPrefix() == null) 67 { 68 return inProductId; 69 } 70 71 StringBuffer sb = new StringBuffer (); 72 if( getPrefix() != null) 73 { 74 sb.append(getPrefix()); 75 } 76 if( getSegmentLength() > 0) 77 { 78 if( isReverse()) 79 { 80 sb.append( inProductId.substring(inProductId.length() - getSegmentLength() ) ); 81 } 82 else 83 { 84 sb.append( inProductId.substring(0,getSegmentLength() ) ); 85 } 86 sb.append( "/" ); 87 } 88 89 101 sb.append( inProductId ); 102 103 return sb.toString(); 104 } 105 106 public String getPrefix() 107 { 108 return fieldPrefix; 109 } 110 111 public void setPrefix(String inPrefix) 112 { 113 fieldPrefix = inPrefix; 114 } 115 } 116 | Popular Tags |