1 package com.teamkonzept.field; 2 3 import com.teamkonzept.lib.*; 4 import com.teamkonzept.publishing.markups.*; 5 import com.teamkonzept.web.*; 6 import com.teamkonzept.field.db.*; 7 import org.w3c.dom.*; 8 9 18 public abstract class TKAtomField 19 extends TKBaseField 20 { 21 23 protected StringBuffer paramClasses = new StringBuffer (); 24 25 protected TKAtomField() {}; 26 protected TKAtomField( String fieldType, String fieldName, String showName ) 27 { 28 initAtomField( fieldType, fieldName, showName ); 29 } 30 31 public final void initAtomField( String fieldType, String fieldName, String showName ) 32 { 33 initBaseField( fieldType, fieldName, showName ); 34 } 35 36 public void addClass( String newClass ) 37 { 38 if( (newClass == null) || (newClass.length() == 0) ) return; 39 40 paramClasses.append( ";"+newClass ); 41 } 42 43 public Object compileData( String prefix, TKHashtable data, TKHashtable context ) 44 { 45 Object result = data.get( prefix+fieldName ); 46 if( result == null ) return getDefault(); 47 return result; 48 } 49 50 public Object compileData( String prefix, TKMarkupNode data, TKHashtable context ) 51 { 52 TKXmlMarkup markup = data == null ? null : (TKXmlMarkup) data.markup; 53 if (markup == null) { return null;} 54 55 if (!markup.name.equals (getName())) { 56 return null; 57 } 58 59 String val = TKMarkupParam.paramValue (markup.params,"VALUE"); 60 61 if (val == null) return getDefault(); 62 else return val; 63 } 64 65 public void fillIntoTemplate( TKHTMLTemplate t, Object value, String prefix ) 66 { 67 super.fillIntoTemplate( t, value, prefix ); 68 t.set( "CLASSES", paramClasses ); 69 if( value != null ) t.set( "VALUE", value ); 70 } 71 72 public void fillIntoPresentation( TKHTMLTemplate t, Object data, String scope ) 73 { 74 String scopedName = scope+"."+getName(); 75 TKVector realData; 76 if( data instanceof TKVector ) { 77 realData = (TKVector) data; 78 } 79 else { 80 realData = new TKVector(1); 81 realData.addElement( data ); 82 } 83 84 t.set( scopedName, data.toString() ); 85 t.set( scopedName+".SIZE", String.valueOf( realData.size() ) ); 86 t.setListIterator( new TKAtomFieldShowIterator( 88 realData, 89 t.getListIterator(), 90 scopedName 91 ) ); 92 } 93 94 99 public void fillIntoDOM(Document doc, Element node, Object data) throws DOMException 100 { 101 Element me = doc.createElement(getInternationalName()); 102 node.appendChild(me); 103 fillAttributesIntoNode(me, data); 104 fillDataIntoNode(doc, me, data); 105 } 106 107 110 protected void fillDataIntoNode(Document doc, Element node, Object data) throws DOMException 111 { 112 if (data != null) 113 { 114 TKVector realData; 115 if( data instanceof TKVector ) { 116 realData = (TKVector) data; 117 node.setAttribute(MULTIPLE, Boolean.TRUE.toString()); 118 } 119 else { 120 realData = new TKVector(); 121 realData.addElement( data ); 122 node.setAttribute(MULTIPLE, Boolean.FALSE.toString()); 123 } 124 for (int i = 0; i < realData.size(); i++) 125 { 126 createValueNode(doc, node, realData.elementAt(i).toString()); 127 } 128 } 129 } 130 131 protected void createValueNode(Document doc, Element node, String data) throws DOMException 132 { 133 Element me = doc.createElement(VALUE_NODE_NAME); 134 node.appendChild(me); 135 Text txt = doc.createTextNode(data); 136 me.appendChild(txt); 137 } 138 139 public int insertDataIntoDB( TKContentDBData db, Object data, int contentId, int leftNr ) 140 { 141 TKContentNodeTableData node = insertNewContentNode( db, contentId, leftNr ); 142 int newNodeId = node.content_node_id; 143 if( data instanceof TKVector ) { 144 TKVector values = (TKVector) data; 145 for( int i=0; i<values.size(); i++ ) { 146 insertNewContentValue( db, contentId, newNodeId, i, (String ) values.get(i) ); 147 } 148 } 149 else if( data != null ) { 150 insertNewContentValue( db, contentId, newNodeId, 0, (String ) data ); 151 } 152 return leftNr+1; 153 } 154 155 public Object getDataFromDB( TKContentDBData db ) 156 { 157 TKContentNodeTableData node = getContentNodeFromDB( db ); 158 TKContentValueTableData value; 159 boolean done = false; 160 TKVector result = new TKVector(); 161 do { 162 try { 163 value = getContentNodeValueFromDB( db, node ); 164 result.addElement( value.value ); 165 } 166 catch( Throwable e ) { 167 done = true; 168 } 169 } while( !done ); 170 171 int size = result.size(); 172 if( size == 0 ) return null; 173 if( size == 1 ) return result.elementAt(0); 174 return result; 175 } 176 177 } 178 | Popular Tags |