Example usage for java.lang Helper Helper

List of usage examples for java.lang Helper Helper

Introduction

In this page you can find the example usage for java.lang Helper Helper.

Prototype

Helper

Source Link

Usage

From source file:migration.App.java

/**
 * The main method.//from  ww  w  . j  a v a2 s .c om
 * 
 * @param args
 *            the arguments
 */
@Autowired
public static void main(final String[] args) {

    // PREPARE
    final ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
            new String[] { "applicationContext.xml" });
    // of course, an ApplicationContext is just a BeanFactory
    final BeanFactory factory = appContext;

    // Initialize
    final Helper helper = new Helper();
    final JournalMigration jmigration = new JournalMigration(factory, helper);

    // /run
    jmigration.run();

}

From source file:com.bluexml.side.framework.facetmap.multimap.FacetMapCacheManager.java

public void update() throws Exception {
    File fileCacheRep = new Helper().getFileFromClassPath(cacheRep);
    if (fileCacheRep.exists()) {
        File[] l = fileCacheRep.listFiles();
        availableFacetMap.clear();/*w w w .  java  2 s  .c  o m*/
        for (File file : l) {
            try {
                InputStream finf = new FileInputStream(file);
                SimpleFacetMapX localMap = (SimpleFacetMapX) SimpleFacetMapX.createFromXml(finf);
                availableFacetMap.put(getMapKey(file), localMap);
                logger.debug("Registered Facet :" + getMapKey(file));
            } catch (Exception e) {
                logger.error("FacetMap " + getMapKey(file) + " not loaded :\n" + e.getMessage());
            }
        }
    }
    logger.debug("facetMaps :" + availableFacetMap.size());
}

From source file:Importers.ImportReportCompiler.java

@Override
public boolean isValid(File file) {

    try {/*from ww w .j a  va2  s  .c  o  m*/
        String valid_string = "<reportCompiler";
        boolean valid = new Helper().fileContainsString(file, valid_string);
        return valid;
    } catch (FileNotFoundException ex) {
        Logger.getLogger(NessusV2XMLImporter.class.getName()).log(Level.SEVERE, null, ex);
    }
    return false;
}

From source file:com.bluexml.side.framework.facetmap.multimap.FacetMapCacheManager.java

public void deleteAllFacets() throws Exception {
    availableFacetMap.clear();/*w  w w.ja va 2 s  .c  om*/
    // purge all facets (cache and files)
    File fileCacheRep = new Helper().getFileFromClassPath(cacheRep);
    if (fileCacheRep.exists()) {
        File[] l = fileCacheRep.listFiles();
        for (File file : l) {
            try {
                FileUtils.forceDelete(file);
                logger.debug("Erase Facet :" + getMapKey(file));
            } catch (Exception e) {
                logger.error("FacetMap " + getMapKey(file) + " not Erase :\n" + e.getMessage());
            }
        }
    }
    logger.debug("facetMaps :" + availableFacetMap.size());
}

From source file:org.ewicom.pps.unitinfo.TabAddressFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    unitDataSource = new UnitDataSource(getActivity());
    unitDataSource.open();/*from www  . ja  va 2s. co  m*/

    unit = unitDataSource.getUnitById(unitID);

    helper = new Helper();
    phonesGroup = (LinearLayout) getView().findViewById(R.id.group_phones);
    emailsGroup = (LinearLayout) getView().findViewById(R.id.group_emails);

    setUnitName();
    setUnitParent();
    setDescription();

    setLocation();
    new PreparePhoneButtons().execute();
    new PrepareEmailButtons().execute();

    if (unit.getSimg().isEmpty()) {
        showImage.setTextColor(Color.GRAY);
        showImage.setClickable(false);
        showImage.setEnabled(false);
    }

}

From source file:models.Template.java

public static String upload(String name, String description, File template, String userRegistered,
        Boolean isHidden) {//  w  w w .j  a va  2 s .  c om
    try {
        FileStringReader reader = new FileStringReader(template);
        String text = reader.read();

        if (!Helper.isUtf8(text)) {
            return "File must be in Plaintext (UTF 8).";
        }

        String author = userRegistered;

        Date now = new Date();
        Template temp = new Template(name, template.getName(), author, now, description, 4);
        temp.userRegistered = userRegistered;
        temp.isHidden = isHidden;
        temp.save();

        int dotPos = template.getName().lastIndexOf(".");
        String newName;
        String extension = null;

        if (dotPos != -1) {
            extension = template.getName().substring(dotPos);
            newName = temp.id + "_" + name + extension;
        } else {
            newName = temp.id + "_" + name;
        }

        File copy_to = new File(Play.applicationPath.getAbsolutePath() + "/public/templates/" + newName);

        //System.out.println(copy_to.getAbsolutePath());
        Helper.copy(template, copy_to);

        temp.filename_ = newName;
        temp.calculateForm();
        temp.save();

        Helper helper = new Helper();
        if (!extension.equals(".tex")) {
            helper.templateToImage(temp);
        } else {
            Substitution sub = new Substitution(temp.textFile);
            Map map = new HashMap(temp.templates_);
            Iterator it = map.keySet().iterator();

            while (it.hasNext()) {
                String key = (String) it.next();
                map.put(key, key);
            }
            sub.replace(map);
            File replaced_file = new File(
                    Play.applicationPath.getAbsolutePath() + "/public/tmp/" + temp.filename_);
            File destination = new File(replaced_file.getParent());
            FileStringWriter writer = new FileStringWriter(replaced_file);

            writer.write(sub.getText());

            helper.texToPdf(replaced_file, destination);

            String[] source_name = temp.filename_.split(".tex");

            File source = new File(destination + "/" + source_name[0] + ".pdf");
            destination = new File(
                    Play.applicationPath.getAbsolutePath() + "/template/" + source_name[0] + ".pdf.jpg");

            helper.pdfToImage(source, destination);

        }

        return null;
    } catch (Exception e) {
        System.out.println(e.toString());
        return e.toString();
    }
}

From source file:sernet.gs.ui.rcp.main.security.VeriniceSecurityProvider.java

private void setupSunPKCS11Provider() {
    // Prevents installing the provider twice.
    if (Security.getProvider("SunPKCS11-verinice") != null) {
        return;//w w w .  ja va  2s  .c  o m
    }
    // If the user enabled anything PKCS#11 related we need to lead the PKCS#11 library and add its
    // provider.
    String configFile = createPKCS11ConfigFile();
    if (configFile != null) {
        // The availability of this class in an OSGi environment depends on a system property. If
        // get errors of this class not being available check that you have
        // -Dosgi.parentClassloader=ext
        // in your VM arguments.
        if (LOG.isDebugEnabled()) {
            LOG.debug("Setup SunPKCS11 AuthProvider with config file: " + configFile);
        }
        SunPKCS11 p = new SunPKCS11(configFile);
        p.setCallbackHandler(new Helper() {
            @Override
            protected void handle(PasswordCallback cb) {
                cb.setPassword(getTokenPIN());
            }
        });
        Security.addProvider(p);
    }
}

From source file:com.contrastsecurity.ide.eclipse.ui.internal.model.EventLabelProvider.java

@Override
protected void paint(Event event, Object element) {
    if (element instanceof EventItem) {
        EventItem eventItem = (EventItem) element;
        Color background = event.gc.getBackground();
        Color foreground = event.gc.getForeground();
        Font font = event.gc.getFont();
        FontData[] fontData = font.getFontData();
        for (int i = 0; i < fontData.length; i++) {
            fontData[i].setStyle(SWT.BOLD);
            fontData[i].setHeight(fontData[i].getHeight() + 1);
        }/*  w ww  .j a  v a2s.co  m*/
        Font boldFont = null;
        try {
            boldFont = new Font(Display.getCurrent(), fontData);
            int x = event.x + 15;
            switch (eventItem.getType()) {
            case EventResource.RED:
                x = x + 15;
                event.gc.setForeground(Constants.CREATION_COLOR);
                break;
            case EventResource.CONTENT:
                x = x + 15;
                event.gc.setForeground(Constants.CONTENT_COLOR);
                break;
            case EventResource.CODE:
                x = x + 15;
                event.gc.setForeground(Constants.CODE_COLOR);
                break;
            case EventResource.BOLD:
                event.gc.setFont(boldFont);
                break;
            default:
                break;
            }
            event.gc.setBackground(Constants.ITEM_BACKGROUND_COLOR);
            //Rectangle clipping = event.gc.getClipping();
            //event.gc.setClipping(clipping.x, clipping.y, viewer.getTree().getColumn(0).getWidth(), clipping.height + 5);
            Rectangle bounds = event.getBounds();
            bounds.width = viewer.getTree().getColumn(0).getWidth();
            bounds.height += 5;
            event.gc.fillRectangle(bounds);
            //event.gc.setClipping(clipping.x, clipping.y, clipping.width, clipping.height);
            String value = eventItem.getValue();
            if (value != null) {
                //value = StringEscapeUtils.unescapeHtml(value);
                value = HtmlEscape.unescapeHtml(value);
            }
            event.gc.drawString(eventItem.getValue(), x, event.y);
        } finally {
            if (boldFont != null) {
                boldFont.dispose();
            }
        }
        event.gc.setBackground(background);
        event.gc.setForeground(foreground);
        event.gc.setFont(font);
    } else {
        if (element instanceof EventResource) {
            EventResource eventResource = (EventResource) element;
            Color background = event.gc.getBackground();
            Color foreground = event.gc.getForeground();
            Rectangle clipping = event.gc.getClipping();
            // event.gc.setLineWidth(1);
            Point size = event.gc.stringExtent(INTERESTING_SECURITY_EVENT_OCCURED_ON_DATA);
            Color color = getColor(eventResource.getType());
            if (color != null) {
                event.gc.setBackground(color);
            } else {
                event.gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            }
            event.gc.fillOval(event.x + 8, event.y + size.y / 2 - 2, 10, 10);
            event.gc.setBackground(background);
            //            if (color != null) {
            //               event.gc.setForeground(color);
            //            } else {
            //               event.gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
            //            }
            String type = eventResource.getTypeDescription().toUpperCase();
            event.gc.drawString(type, event.x + 30, event.y + 2);
            size = event.gc.stringExtent(INTERESTING_SECURITY_EVENT_OCCURED_ON_DATA);
            event.gc.setBackground(background);
            event.gc.setForeground(foreground);
            Font oldFont = event.gc.getFont();
            FontData[] fontData = oldFont.getFontData();
            for (int i = 0; i < fontData.length; i++) {
                fontData[i].setStyle(SWT.BOLD);
            }
            FontData[] fontDataItalic = oldFont.getFontData();
            for (int i = 0; i < fontDataItalic.length; i++) {
                fontDataItalic[i].setStyle(SWT.ITALIC);
            }
            //Font boldFont = null;
            Font italicFont = null;
            int x = event.x + 45 + size.x;
            int startX = x;
            try {
                //boldFont = new Font(Display.getCurrent(), fontData);
                italicFont = new Font(Display.getCurrent(), fontDataItalic);
                int maxWidth = getMaxWidth(event, oldFont);
                if (clipping.width > x + maxWidth) {
                    event.gc.setClipping(clipping.x, clipping.y, x + maxWidth, clipping.height);
                }
                String currentString = eventResource.getRawCodeRecreation();
                if (currentString != null) {
                    //currentString = StringEscapeUtils.unescapeHtml(currentString);
                    currentString = HtmlEscape.unescapeHtml(currentString);
                }
                Helper helper = new Helper();
                helper.currentString = currentString;
                helper.x = x;
                while (helper != null && !helper.currentString.isEmpty()) {
                    helper = parseString(event, helper, /*boldFont ,*/ oldFont, italicFont, foreground);
                }
                x = startX + maxWidth + 45;
                event.gc.setClipping(clipping.x, clipping.y, clipping.width, clipping.height);
                helper.currentString = eventResource.getHtmlDataSnapshot();
                helper.x = x;
                while (helper != null && !helper.currentString.isEmpty()) {
                    helper = parseString(event, helper, /*boldFont,*/ oldFont, italicFont, foreground);
                }
            } finally {
                //if (boldFont != null) {
                //   boldFont.dispose();
                //}
                if (italicFont != null) {
                    italicFont.dispose();
                }
                event.gc.setClipping(clipping.x, clipping.y, clipping.width, clipping.height);
            }

        }

    }
}

From source file:patientlinkage.Util.Util.java

public static Helper readAndEncodeWithProps(String FileName, int[][] lens) {
    Helper ret = new Helper();
    ArrayList<boolean[][]> retArrList = new ArrayList<>();
    int properties_num = lens[0].length;
    Soundex sdx = new Soundex();

    try (CSVReader reader = new CSVReader(new FileReader(FileName))) {
        String[] strs;//from  w  ww  . j av a2 s  . co m
        ret.pros = reader.readNext();
        ret.updatingrules(lens);
        while ((strs = reader.readNext()) != null) {
            ret.IDs.add(strs[0]);
            String[] coms_strs = new String[lens.length];
            Arrays.fill(coms_strs, "");
            for (int i = 0; i < properties_num; i++) {
                String temp = strs[i].replace("-", "").toLowerCase();
                for (int j = 0; j < coms_strs.length; j++) {
                    if (lens[j][i] > (Integer.MAX_VALUE / 2)) {
                        coms_strs[j] += sdx.soundex(temp) + resizeString(temp, Integer.MAX_VALUE - lens[j][i]);
                    } else {
                        coms_strs[j] += resizeString(temp, lens[j][i]);
                    }
                }
            }
            boolean[][] bool_arr = new boolean[coms_strs.length][];
            for (int j = 0; j < coms_strs.length; j++) {
                bool_arr[j] = bytes2boolean(coms_strs[j].getBytes(StandardCharsets.US_ASCII));
            }
            retArrList.add(bool_arr);
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PatientLinkageGadget.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PatientLinkageGadget.class.getName()).log(Level.SEVERE, null, ex);
    }

    ret.data_bin = new boolean[retArrList.size()][][];
    for (int i = 0; i < ret.data_bin.length; i++) {
        ret.data_bin[i] = retArrList.get(i);
    }

    return ret;
}

From source file:org.omnaest.utils.xml.XMLNestedMapConverter.java

/**
 * Template method for {@link #newNamespaceAwareMapFromXML(CharSequence)} and {@link #newMapFromXML(CharSequence)} which allows
 * to convert the {@link QName} based key values to other representations.
 * /*from  w w w.ja v  a  2 s .  c o  m*/
 * @param xmlContent
 * @return new (nested) {@link Map} instance
 */
protected <K> Map<K, Object> newMapFromXML(CharSequence xmlContent,
        final ElementConverter<QName, K> keyElementConverter) {
    //
    final Map<K, Object> retmap = new LinkedHashMap<K, Object>();

    //
    Assert.isNotNull(keyElementConverter, "keyElementConverter must not be null");

    //
    final ExceptionHandler exceptionHandler = this.exceptionHandler;

    //    
    try {
        //
        final XMLInputFactory xmlInputFactory = this.xmlInstanceContextFactory.newXmlInputFactory();
        Assert.isNotNull(xmlInputFactory, "xmlInputFactory must not be null");

        //
        final Reader reader = new CharSequenceReader(xmlContent);
        final XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(reader);

        //
        final class Helper {
            /* ********************************************** Variables ********************************************** */
            private List<TupleTwo<QName, Object>> stackList = new ArrayList<TupleTwo<QName, Object>>();

            /* ********************************************** Methods ********************************************** */

            /**
             * Manifests a single tag node recursively
             * 
             * @return
             * @throws XMLStreamException
             */
            @SuppressWarnings("unchecked")
            public TupleTwo<QName, Object> manifest() throws XMLStreamException {
                //
                TupleTwo<QName, Object> retval = null;

                //          
                while (xmlEventReader.hasNext()) {
                    //
                    final XMLEvent xmlEvent = xmlEventReader.nextEvent();

                    //
                    if (xmlEvent.isStartElement()) {
                        //
                        final StartElement startElement = xmlEvent.asStartElement();
                        final QName name = startElement.getName();

                        //
                        this.addNewStackElement().setValueFirst(name);

                        //
                        final Iterator<Attribute> attributeIterator = startElement.getAttributes();
                        if (attributeIterator.hasNext()) {
                            //
                            final Map<QName, Object> map = new LinkedHashMap<QName, Object>();
                            for (Attribute attribute : IterableUtils.valueOf(attributeIterator)) {
                                map.put(attribute.getName(), attribute.getValue());
                            }

                            //
                            this.updateCurrentStackValue(map);
                        }
                    } else if (xmlEvent.isEndElement()) {
                        //
                        retval = this.removeStackElement();

                        //
                        final Object manifestation = retval.getValueSecond();
                        final QName tagname = retval.getValueFirst();

                        //
                        updateCurrentStackValue(manifestation, tagname);
                    } else if (xmlEvent.isCharacters()) {
                        //
                        final Characters characters = xmlEvent.asCharacters();
                        if (!characters.isWhiteSpace()) {
                            //
                            final TupleTwo<QName, Object> currentStackValue = this.getCurrentStackValue();
                            currentStackValue.setValueSecond(
                                    ObjectUtils.defaultIfNull(currentStackValue.getValueSecond(), "")
                                            + characters.getData());

                        }
                    }

                }

                //
                return retval;
            }

            /**
             * Updates the current stack value
             * 
             * @param manifestation
             * @param tagname
             */
            private void updateCurrentStackValue(Object manifestation, QName tagname) {
                //
                final Map<QName, Object> tagNameToManifestationMap = new LinkedHashMap<QName, Object>();
                tagNameToManifestationMap.put(tagname, manifestation);
                this.updateCurrentStackValue(tagNameToManifestationMap);
            }

            @SuppressWarnings("unchecked")
            private void updateCurrentStackValue(Map<QName, Object> tagNameToManifestationMap) {
                //
                final TupleTwo<QName, Object> currentStackValue = this.getCurrentStackValue();

                //
                if (currentStackValue != null) {
                    //
                    Map<K, Object> map = null;
                    {
                        //
                        final Object valueSecond = currentStackValue.getValueSecond();
                        if (valueSecond instanceof Map) {
                            map = (Map<K, Object>) valueSecond;
                        } else {
                            //
                            map = new LinkedHashMap<K, Object>();
                            if (valueSecond instanceof String) {
                                map.put(keyElementConverter.convert(new QName("")), valueSecond);
                            }
                        }
                    }

                    //
                    for (Entry<QName, Object> tagNameToManifestationEntry : tagNameToManifestationMap
                            .entrySet()) {
                        //
                        final K tagname = keyElementConverter.convert(tagNameToManifestationEntry.getKey());
                        final Object manifestation = tagNameToManifestationEntry.getValue();

                        //
                        if (!map.containsKey(tagname)) {
                            map.put(tagname, manifestation);
                        } else {
                            //
                            final Object object = map.get(tagname);
                            if (object instanceof List) {
                                //
                                final List<Object> list = (List<Object>) object;
                                list.add(manifestation);
                            } else {
                                //
                                final List<Object> list = new ArrayList<Object>();
                                list.add(object);
                                list.add(manifestation);
                                map.put(tagname, list);
                            }
                        }
                    }

                    //
                    currentStackValue.setValueSecond(map);
                }
            }

            private TupleTwo<QName, Object> getCurrentStackValue() {
                return ListUtils.firstElement(this.stackList);
            }

            private TupleTwo<QName, Object> removeStackElement() {
                return ListUtils.removeFirst(this.stackList);
            }

            private TupleTwo<QName, Object> addNewStackElement() {
                //
                final TupleTwo<QName, Object> retval = new TupleTwo<QName, Object>();
                this.stackList.add(0, retval);
                return retval;
            }
        }

        //  
        try {
            final Helper helper = new Helper();
            final TupleTwo<QName, Object> result = helper.manifest();
            retmap.put(keyElementConverter.convert(result.getValueFirst()), result.getValueSecond());
        } catch (Exception e) {
            if (exceptionHandler != null) {
                exceptionHandler.handleException(e);
            }
        }

        //
        xmlEventReader.close();
        reader.close();

    } catch (Exception e) {
        if (exceptionHandler != null) {
            exceptionHandler.handleException(e);
        }
    }

    //
    return retmap;
}