2010년 3월 31일 수요일

Spring 에서 Velocity DatasourceResourceLoader 쓰기.

환경: spring 2.5, velocity 1.5

화면 커스터마이징 요구는 많은데, 건건이 받아서 올리고 배포하고 하려니 골치 아파서 찾아본 해결책.
기존 파일로 존재하는 vm 파일도 그대로 쓰고, 없으면 db에서 가져오게 하는게 요점.


<bean id="dsVelocityEngine"
    class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
    <property name="resourceLoaderPath" value="/WEB-INF/vm"></property>
    <property name="velocityPropertiesMap">
        <map>
            <entry key="resource.loader" value="file,ds"></entry>                   
            <entry key="ds.resource.loader.instance">
                <ref bean="templateLoader"/>
            </entry>
            <entry key="ds.resource.loader.resource.table">
                <value>vm_templates</value>
            </entry>
            <entry key="ds.resource.loader.resource.keycolumn">
                <value>name</value>
            </entry>
            <entry key="ds.resource.loader.resource.templatecolumn">
                <value>content</value>
            </entry>
            <entry key="ds.resource.loader.resource.timestampcolumn">
                <value>updated</value>
            </entry>
            <entry key="input.encoding" value="utf-8"></entry>
            <entry key="output.encoding" value="utf-8"></entry>
            <entry key="directive.foreach.counter.name" value="velocityCount"></entry>
            <entry key="directive.foreach.counter.initial.value" value="0"></entry>
        </map>
    </property>
</bean>

<!-- Velocity Database Template Loader -->
<!-- dataSource bean은 이미 정의되어 있음 -->
<bean id="templateLoader"
    class="org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader">
    <property name="dataSource" ref="dataSource"></property>
</bean>
   

    <!-- Velocity Configurer -->
<!--
configurer 에서 velocityEngine 을 잡을 경우,
resourceLoaderPath나 기타 velocity property 는 여기가 아닌 velocityEngine 에서 설정해줘야 된다.
-->
    <bean id="velocityConfigurer"
        class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="velocityEngine" ref="dsVelocityEngine"></property>       
    </bean>

    <!-- Velocity Resolver -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
        <property name="exposeRequestAttributes" value="true" />
        <property name="exposeSessionAttributes" value="true" />
        <property name="contentType" value="text/html; charset=UTF-8" />
        <property name="cache" value="true" />    
        <property name="suffix" value=".vm" />
        <property name="viewClass" value="org.springframework.web.servlet.view.velocity.VelocityView" />
    </bean>


UIView 의 Tag

To search for a tagged view, use the viewWithTag: method of UIView. This method searches the receiver ’s
subviews using a depth-first search, starting with the receiver itself.

- iPhoneAppProgrammingGuide

for loop 를 돌릴 필요가 없구나.

대충 이런 코드?
// ViewController 에서.
UView *v = [self.view viewWithTag:tag];


2010년 3월 16일 화요일

rails type 필드명 읽기.

legacy table에 type 필드명 있을 때.

  class Thing < ActiveRecord::Base
def type
read_attribute :type
end

def type=( new_type )
write_attribute :type, new_type
end
end

Single Table Inheritance 의 inheritance column 명도 바꿔줌.

 @inheritance_column = "sti_type"

참고
http://lists.rubyonrails.org/pipermail/rails/2006-January/009209.html

중궈 IT 애들은 구글 없어지면 어떻게 일하려나.
난 사표 써야할 거 같은데...

2010년 3월 12일 금요일

core data migration

Remember to clean all your targets before trying again, to avoid the can’t merge models with two different entities named ‘Person’. error

Core Data migration 설정 후에 실행했는데

"avoid the can’t merge models with two different entities named 어쩌구" 에러 났을 때.

Clean 후 다시 실행하면 된다.

참고
* http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CoreDataVersioning/Introduction/Introduction.html
* http://www.timisted.net/blog/archive/core-data-migration/