Module: Muml_Element

Defined in:
lib/ontomde-uml2-struts/form.rb,
lib/ontomde-uml2-struts/form.rb,
lib/ontomde-uml2-struts/action.rb,
lib/ontomde-uml2-struts/exceptionHandling.rb

Constant Summary collapse

STRUTS_LVB =

Struts LabelValueBean class qualified name.

'org.apache.struts.util.LabelValueBean'
NIL_LVB_KEY =

LVB used for null object

"nil"
NIL_LVB_RES_KEY =
"obj_nil"
STRUTS_FORM_HELPER =
"xmda.struts.FormHelper"
STRUTS_FORM_HELPER_ENUMTOLVB =
"enumToLvb"
STRUTS_DATE_FORMATER_INSTANCE =
STRUTS_FORM_HELPER+'.DfCalendar'
STRUTS_TIMESTAMP_FORMATER_INSTANCE =
STRUTS_FORM_HELPER+'.DfTimestamp'
STRUTS_FORM_HELPER_CODE =
<<ENDCODE
     public static final java.text.SimpleDateFormat DfTimestamp=new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm:ss",java.util.Locale.ENGLISH);
     public static final java.text.SimpleDateFormat DfCalendar=new java.text.SimpleDateFormat("yyyy/MM/dd",java.util.Locale.ENGLISH);

	/**
	 * Transform a timestamp date to its GMT equivalent date.
	 *
	 * @param fromTimeZone
	 * @param timestampToTransform
	 * @return date in GMT
	 */
	public static java.util.Date transformFromCurrentTZToGMT(final java.util.TimeZone fromTimeZone,final  java.util.Date timestampToTransform) {
		// the offset of this time zone from UTC.
		int offset = fromTimeZone.getRawOffset();

		java.util.GregorianCalendar gregCal = new java.util.GregorianCalendar();
		gregCal.setTime(timestampToTransform);
		gregCal.add(java.util.Calendar.HOUR_OF_DAY, (-offset / 3600000));

		return gregCal.getTime();
	}

public static java.util.Date transformFromGMTToCurrentTZ(final java.util.TimeZone currentTimeZone,final  java.util.Date timestampToTransform) {
		// the offset of this time zone from UTC.
		int offset = currentTimeZone.getRawOffset();

		java.util.GregorianCalendar gregorianCalendar = new java.util.GregorianCalendar();
		gregorianCalendar.setTime(timestampToTransform);
		gregorianCalendar.add(java.util.Calendar.HOUR_OF_DAY, (offset / 3600000));
		return gregorianCalendar.getTime();
	}

public static java.util.List<#{STRUTS_LVB}> #{STRUTS_FORM_HELPER_ENUMTOLVB}(final Class<?> enumType,final xmda.java.JavaEnumSig typeCheck, final java.util.List<?> enums) {
	return #{STRUTS_FORM_HELPER_ENUMTOLVB}(enumType,typeCheck,enums,false);
}
// addNullItem is used for example to add a "add element" in creator selection.
public static java.util.List<#{STRUTS_LVB}> #{STRUTS_FORM_HELPER_ENUMTOLVB}(final Class<?> enumType,final xmda.java.JavaEnumSig typeCheck, final java.util.List<?> enums,final boolean addNullItem) {
	try {
	java.util.List<#{STRUTS_LVB}> ret=new java.util.ArrayList<#{STRUTS_LVB}>();
	String prefix=enumType.getCanonicalName()+".";
	#{STRUTS_LVB} lvb=null;
	if(addNullItem) { ret.add(new #{STRUTS_LVB}(prefix+"obj_nil", "nil"));}
	for ( Object itemObj : enums) {
		xmda.java.JavaEnumSig item=(#{JAVA_ENUM_INTERFACE_QNAME})itemObj;
		if(item!=null) {
			//value is a localization resource key
			lvb=new #{STRUTS_LVB}(prefix+item.name(),item.name());
		} else {
			lvb=new #{STRUTS_LVB}(prefix+"obj_nil", "nil");
		}
		ret.add(lvb);
		}
	return ret;
	} catch (RuntimeException e) {
		log.error(e);
		throw(e);
	}
			}
ENDCODE
STRUTS_ACTION_HELPER =
"xmda.struts.ActionHelper"
STRUTS_FUNCTIONAL_EXCEPTION =
"xmda.struts.exceptions.FunctionalException"

Instance Method Summary collapse

Instance Method Details

#db_tx_none(java_code) ⇒ Object



706
707
708
# File 'lib/ontomde-uml2-struts/action.rb', line 706

def db_tx_none(java_code)
  return java_code
end

#struts_getActionHelperObject



712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
# File 'lib/ontomde-uml2-struts/action.rb', line 712

def struts_getActionHelper
  helper=umlx_getOrCreateClass(STRUTS_ACTION_HELPER)
  if(helper.java_customCode.empty?)
    helper.apaCom_addLogger!
    helper.umlx_external=RDF_FALSE
    #helper.java_import_add(STRUTS_LVB)
    helper.db_isTransient=RDF_TRUE
    helper.struts_isForm=RDF_FALSE
    helper.java_customCode= <<ENDCODE

public static final String STRUTS_INPUT_FWD="#{::Muml_Classifier::STRUTS_INPUT_FWD}";

public static void changeTimeZoneAction_s1(final #{::Muml_Classifier::STRUTS_FORM_INTERFACE} form,final org.apache.struts.action.ActionMapping mapping,final javax.servlet.http.HttpServletRequest request,final String newTimeZoneId) {
	String oldTimeZoneId = xmda.tags.helpers.XMDARequestUtils.getUserTimeZone(request, null).getID();
	//String newTimeZoneId = form.get#{Muml_Classifier::STRUTS_SETTIMEZONE_BEAN}();

	// we change the the timezone.
	xmda.struts.ActionHelper.changeTimeZone(mapping, java.util.TimeZone.getDefault(),request,newTimeZoneId);

	// We transform the current timestamp dates in the form to the GMT
	// format
	// using the old time zone id in the method "copyToReference".
	form.set#{Muml_Classifier::STRUTS_SETTIMEZONE_BEAN}(oldTimeZoneId);
	form.copyToReference();
}

public static org.apache.struts.action.ActionForward changeTimeZoneAction_s2(final #{::Muml_Classifier::STRUTS_FORM_INTERFACE} form,final org.apache.struts.action.ActionMapping mapping,final javax.servlet.http.HttpServletRequest request,final  String newTimeZoneId) {
	//String newTimeZoneId = form.get#{Muml_Classifier::STRUTS_SETTIMEZONE_BEAN}();
	form.set#{Muml_Classifier::STRUTS_SETTIMEZONE_BEAN}(newTimeZoneId);
	form.initFromReference();

	return mapping.findForward(STRUTS_INPUT_FWD);
	}


	public static void changeTimeZone(
	final org.apache.struts.action.ActionMapping mapping, java.util.TimeZone timeZone,
	final javax.servlet.http.HttpServletRequest request, final String timeZoneDisplayName) {

boolean isTimeZone = ((timeZoneDisplayName != null) && (timeZoneDisplayName.length() > 0));

if (isTimeZone) {
	timeZone = java.util.TimeZone.getTimeZone(timeZoneDisplayName);
}
request.getSession().setAttribute(xmda.tags.helpers.XMDAStrutsGlobals.TIMEZONE_KEY,
		timeZone);

log.debug("selected timeZone = " + timeZone.getDisplayName());
//		return mapping.findForward("inputfw");
}

public static String getCurrentTab(final org.apache.struts.action.ActionMapping mapping,final String bizClassName) {
	String path=mapping.findForward(STRUTS_INPUT_FWD).getPath();
	// path=/pages/comftpass/application/form/Applicationall.jsp
	String s=bizClassName;
	//int i=path.indexOf(s);
	int bi=path.indexOf(s)+s.length();
	int ei=path.indexOf(".jsp");

	String currentTab=path.substring(bi,ei);
	#{java_debug(%{"currentTab= >"+currentTab+"< path="+path})}
	return currentTab;
}

public static org.apache.struts.action.ActionForward changeLocaleAction(final org.apache.struts.action.ActionMapping mapping,java.util.Locale locale,final javax.servlet.http.HttpServletRequest request,final String language,final String country) {

      boolean isLanguage = ((language != null) && (language.length() > 0));
      boolean isCountry = ((country != null) && (country.length() > 0));

      if ((isLanguage) && (isCountry)) {
          locale = new java.util.Locale(language, country);
      } else if (isLanguage) {
          locale = new java.util.Locale(language, "");
      }
      request.getSession().setAttribute(org.apache.struts.Globals.LOCALE_KEY, locale);
	return mapping.findForward("#{Muml_Classifier::STRUTS_INPUT_FWD}");
	}

public static org.apache.struts.action.ActionForward transferToStartEditAction(final org.apache.struts.action.ActionMapping mapping,final javax.servlet.http.HttpServletRequest request,final Object alienElement,final String parentFwd) {
	javax.servlet.http.HttpSession session = request.getSession();
	String currentTab = getCurrentTab(mapping, parentFwd);
	// an extraneous "/" is added for forward (not needed for redirect)
	String returnTo = "/"+parentFwd + currentTab
+ "-submit.do?doWhat=#{Muml_Classifier::STRUTS_RESUME_ACTION}";

	session.setAttribute("#{Muml_Classifier::STRUTS_SESSION_KEY_EditAction}", alienElement);
	session.setAttribute( alienElement.getClass().getName() + "_returnTo", returnTo);
	return mapping.findForward(alienElement.getClass().getSimpleName()+"#{Muml_Class::STRUTS_EDIT_FWD_POSTFIX}");
	}

public static void checkNotNull(final Object elt, #{struts_getFunctionalException.java_qualifiedName} exceptionToFire) {
	if (elt == null) {
throw exceptionToFire;
}
	}
/*
* dump image contained in image variable to web browser.
* Forward to #{Muml_Class::NOGIF_FORWARD} if image is null.
*/
public static org.apache.struts.action.ActionForward writeGif(final org.apache.struts.action.ActionMapping  mapping,final javax.servlet.http.HttpServletResponse response, byte image[]) {
if (image != null) {
	response.setContentType("image/gif");
	try {
		response.getOutputStream().write(image);
	} catch (java.io.IOException ioe) {
		throw new RuntimeException(ioe);
	}
	return null;
} else {
	// image will display as text if loaded directly
	//       ie: not trough <img src=>
	response.setContentType("image/gif");
	return mapping.findForward("#{Muml_Class::NOGIF_FORWARD}");
}
	}

/*
* dump image contained in image variable to web browser.
* Forward to #{Muml_Class::NOGIF_FORWARD} if image is null.
*/
public static org.apache.struts.action.ActionForward writeGraphviz(final org.apache.struts.action.ActionMapping  mapping,final javax.servlet.http.HttpServletResponse response,final  String graphvizDotFile) {
if (graphvizDotFile!= null) {
	response.setContentType("image/gif");
	try {
		com.ft.cil.graphe.Graphe graphe=new com.ft.cil.graphe.Graphe(graphvizDotFile);
                              //note: function renaming : (Stream is a byte array)
		response.getOutputStream().write(graphe.getImageStream());
	} catch (java.io.IOException ioe) {
		throw new RuntimeException(ioe);
	}
	return null;
} else {
	// image will display as text if loaded directly
	//       ie: not trough <img src=>
	response.setContentType("image/gif");
	return mapping.findForward("#{Muml_Class::NOGIF_FORWARD}");
}
	}

/*
* dump image contained in image variable to web browser.
* Forward to #{Muml_Class::NOGIF_FORWARD} if image is null.
*/

public static org.apache.struts.action.ActionForward writeGraphvizMap(final org.apache.struts.action.ActionMapping  mapping,final javax.servlet.http.HttpServletResponse response,final  String graphvizDotFile) {
              response.setContentType("text/html");
if (graphvizDotFile!= null) {

	try {
		com.ft.cil.graphe.Graphe graphe=new com.ft.cil.graphe.Graphe(graphvizDotFile);
                              //note: function renaming : (Stream is a byte array)
		javax.servlet.ServletOutputStream out=response.getOutputStream();
		out.write("<html><head><title>usemap</title></head><body><map name=\\"myMap\\">\\n".getBytes());
		out.write(graphe.getImageMap());
		out.write("</map></body></html>\\n".getBytes());
	} catch (java.io.IOException ioe) {
		throw new RuntimeException(ioe);
	}
} else {

	// image will display as text if loaded directly
	//       ie: not trough <img src=>

}
              // do not forward to a jsp, output has already been written.
          return null;
	}

ENDCODE

  end
  return helper;
end

#struts_getExceptionHandlerClassObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ontomde-uml2-struts/exceptionHandling.rb', line 20

def struts_getExceptionHandlerClass
	m=umlx_getOrCreateClass("xmda.struts.exceptions.XMDAExceptionHandler")
	if(m.java_import.empty?)
		['org.apache.struts.Globals', 'org.apache.struts.action.ActionForm', 'org.apache.struts.action.ActionForward', 'org.apache.struts.action.ActionMapping', 'org.apache.struts.action.ActionMessage', 'org.apache.struts.action.ExceptionHandler', 'org.apache.struts.config.ExceptionConfig', 'org.apache.struts.util.ModuleException', 'javax.servlet.http.HttpServletResponse','javax.servlet.ServletException','javax.servlet.http.HttpServletRequest'].each { |c|
			m.java_import_add(c);
		}
		m.apaCom_addLogger!
		m.umlx_external=RDF_FALSE
		#m.java_import_add(STRUTS_LVB)
		m.db_isTransient=RDF_TRUE
		m.struts_isForm=RDF_FALSE
		m.java_extends_add(umlx_reserved_model.umlx_getOrCreateClass("org.apache.struts.action.ExceptionHandler"))

		m.java_customCode= <<ENDCODE

    /**
     * <p> Handle the Exception. Return the ActionForward instance (if any)
     * returned by the called ExceptionHandler. </p>
     *
     * @param ex           The exception to handle
     * @param ae           The ExceptionConfig corresponding to the exception
     * @param mapping      The ActionMapping we are processing
     * @param formInstance The ActionForm we are processing
     * @param request      The servlet request we are processing
     * @param response     The servlet response we are creating
     * @return The <code>ActionForward</code> instance (if any) returned by
     *         the called <code>ExceptionHandler</code>.
     * @throws ServletException if a servlet exception occurs
     * @since Struts 1.1
     */
    public ActionForward execute(Exception ex, ExceptionConfig ae,
        ActionMapping mapping, ActionForm formInstance,
        HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
        log.debug("ExceptionHandler executing for exception " + ex);

        ActionForward forward;
        ActionMessage error;
        String property;

        // Build the forward from the exception mapping if it exists
        // or from the form input
        if (ex instanceof FunctionalException && ((FunctionalException)ex).getFwPath()!= null) {
        	String fwPath = ((FunctionalException)ex).getFwPath();
        	forward = new ActionForward(fwPath);
        }
        else if (ae.getPath() != null) {
            forward = new ActionForward(ae.getPath());
        } else {
            forward = mapping.getInputForward();
        }

        // Figure out the error
        if (ex instanceof ModuleException) {
            error = ((ModuleException) ex).getActionMessage();
            property = ((ModuleException) ex).getProperty();
        } else {
            error = new ActionMessage(ae.getKey(), ex.getMessage());
            property = error.getKey();
        }

        this.logException(ex);

        // Store the exception
        request.setAttribute(Globals.EXCEPTION_KEY, ex);
        this.storeException(request, property, error, forward, ae.getScope());

        if (!response.isCommitted()) {
            return forward;
        }

        log.debug("Response is already committed, so forwarding will not work."
            + " Attempt alternate handling.");

        if (!silent(ae)) {
            handleCommittedResponse(ex, ae, mapping, formInstance, request,
                response, forward);
        } else {
            log.warn("ExceptionHandler configured with " + SILENT_IF_COMMITTED
                + " and response is committed.", ex);
        }

        return null;
    }


    /**
     * <p>Indicate whether this Handler has been configured to be silent.  In
     * the base implementation, this is done by specifying the value
     * <code>"true"</code> for the property "SILENT_IF_COMMITTED" in the
     * ExceptionConfig.</p>
     *
     * @param config The ExceptionConfiguration we are handling
     * @return True if Handler is silent
     * @since Struts 1.3
     */
    private boolean silent(ExceptionConfig config) {
        return "true".equals(config.getProperty(SILENT_IF_COMMITTED));
    }
ENDCODE
	end
	return m
end

#struts_getFormHelperObject



436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/ontomde-uml2-struts/form.rb', line 436

def struts_getFormHelper
	helper=umlx_getOrCreateClass(STRUTS_FORM_HELPER)
	if(helper.java_customCode.empty?)
		helper.apaCom_addLogger!
		helper.umlx_external=RDF_FALSE
		#helper.java_import_add(STRUTS_LVB)
		helper.db_isTransient=RDF_TRUE
		helper.struts_isForm=RDF_FALSE
		helper.java_customCode= STRUTS_FORM_HELPER_CODE
	end
	return helper;
end

#struts_getFunctionalExceptionObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/ontomde-uml2-struts/exceptionHandling.rb', line 125

def struts_getFunctionalException
	m=umlx_getOrCreateClass(STRUTS_FUNCTIONAL_EXCEPTION)
	if(m.java_customCode.empty?)
		m.java_annotation_add(%{@SuppressWarnings("serial")})
		m.apaCom_addLogger!
		m.umlx_external=RDF_FALSE
		#m.java_import_add(STRUTS_LVB)
		m.db_isTransient=RDF_TRUE
		m.struts_isForm=RDF_FALSE
		m.java_extends_add(umlx_getOrCreateClass("java.lang.RuntimeException"))

		m.java_customCode= <<ENDCODEend
	private String fwPath =null;
	public #{m.java_Name}() {
		super();
	}
	public #{m.java_Name}(String mesg) {
		super(mesg);
	}
	public #{m.java_Name}(String fwPath, String mesg) {
		super(mesg);
		this.fwPath = fwPath;
	}

	public #{m.java_Name}(String mesg, Throwable th) {
		super(mesg, th);
	}

	public String getFwPath() {
		return fwPath;
	}

	public void setFwPath(String fwPath) {
		this.fwPath = fwPath;
	}
ENDCODEend
	end
	return m
end