Search in sources :

Example 1 with SplitString

use of org.jaffa.util.SplitString in project jaffa-framework by jaffa-projects.

the class FormDefinitionViewerComponent method loadFormTemplate.

// .//GEN-END:_addListeners_1_be
// All the custom code goes here//GEN-FIRST:_custom
public File loadFormTemplate() throws FrameworkException, ApplicationExceptions, IOException {
    String formTemplate = getFormDefinitionViewerOutDto().getFormTemplate();
    if (formTemplate != null) {
        FormDefinitionViewerInDto inputDto = new FormDefinitionViewerInDto();
        inputDto.setFormId(m_formId);
        if (m_tx == null)
            m_tx = (IFormDefinitionViewer) Factory.createObject(IFormDefinitionViewer.class);
        byte[] formTemplateContents = m_tx.loadFormTemplate(inputDto);
        // int i = formTemplate.lastIndexOf(".pdf");
        // String prifix = i>0 ? formTemplate : formTemplate.substring(0,i);
        // File formTemplateFile=File.createTempFile(prifix,"pdf");
        SplitString ss = new SplitString(formTemplate, ".", false);
        String suffix = ss.getSuffix() != null ? "." + ss.getSuffix() : null;
        File formTemplateFile = File.createTempFile("jaffa", suffix);
        OutputStream outputStream = null;
        try {
            outputStream = new BufferedOutputStream(new FileOutputStream(formTemplateFile));
            outputStream.write(formTemplateContents);
            outputStream.flush();
        } finally {
            if (outputStream != null)
                outputStream.close();
        }
        return formTemplateFile;
    }
    return null;
}
Also used : SplitString(org.jaffa.util.SplitString) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) FormDefinitionViewerInDto(org.jaffa.modules.printing.components.formdefinitionviewer.dto.FormDefinitionViewerInDto) IFormDefinitionViewer(org.jaffa.modules.printing.components.formdefinitionviewer.IFormDefinitionViewer) SplitString(org.jaffa.util.SplitString) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with SplitString

use of org.jaffa.util.SplitString in project jaffa-framework by jaffa-projects.

the class MappingFilter method getFieldList.

private static void getFieldList(Class dao, List out, String prefix, boolean includeKeys) {
    String lastField = null;
    if (prefix != null) {
        SplitString ss = new SplitString(prefix, ".", false);
        if (ss.isValid())
            lastField = ss.getSuffix();
        else
            lastField = ss.getPrefix();
    }
    GraphMapping mapper = MappingFactory.getInstance(dao);
    if (mapper == null) {
        log.error("Can't find mapping for class " + dao.getName());
        return;
    }
    String[] fields = mapper.getDataFieldNames();
    if (fields != null) {
        for (int i = 0; i < fields.length; i++) {
            String name = fields[i];
            if (includeKeys || !mapper.isKeyField(name)) {
                String fullName = name;
                if (prefix != null)
                    fullName = prefix + name;
                PropertyDescriptor pd = mapper.getDataFieldDescriptor(name);
                if (pd != null && pd.getReadMethod() != null) {
                    Class c = pd.getReadMethod().getReturnType();
                    boolean array = c.isArray();
                    if (array)
                        c = c.getComponentType();
                    if (DomainDAO.class.isAssignableFrom(c)) {
                        if (lastField == null || !lastField.equals(name)) {
                            getFieldList(c, out, fullName + ".", array);
                            if (array)
                                fullName = "*" + fullName;
                            else
                                fullName = "+" + fullName;
                        } else {
                            log.debug("Stopped Recursion @ Path=" + fullName);
                            fullName = null;
                        }
                    }
                } else
                    log.debug("Can't introspect field " + name);
                if (// Don't add if nulled out to prevent recursion
                fullName != null)
                    out.add(fullName);
            }
        }
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) SplitString(org.jaffa.util.SplitString) SplitString(org.jaffa.util.SplitString)

Aggregations

SplitString (org.jaffa.util.SplitString)2 PropertyDescriptor (java.beans.PropertyDescriptor)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 IFormDefinitionViewer (org.jaffa.modules.printing.components.formdefinitionviewer.IFormDefinitionViewer)1 FormDefinitionViewerInDto (org.jaffa.modules.printing.components.formdefinitionviewer.dto.FormDefinitionViewerInDto)1