Example usage for org.dom4j DocumentHelper parseText

List of usage examples for org.dom4j DocumentHelper parseText

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper parseText.

Prototype

public static Document parseText(String text) throws DocumentException 

Source Link

Document

parseText parses the given text as an XML document and returns the newly created Document.

Usage

From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java

License:Open Source License

/**
 * this function will return a boolean corresponding to the use or not the backup
 * server for FTP/*  w w  w. ja v  a 2s.  c  om*/
 * @param ingest
 * @param type
 * @return
 */
public static boolean useBackup(String ingest) {
    boolean use = false;

    Document doc = null;

    try {
        doc = DocumentHelper.parseText(ingest);
    } catch (DocumentException e) {
        logger.error("", e);
    }

    String xpath = "/fsxml/properties/image/ftp/backup";
    Element isEnabled = (Element) doc.selectSingleNode(xpath);

    if (isEnabled != null) {
        String enabled = isEnabled.getText();
        if (enabled.equals("true"))
            use = true;
    }
    return use;
}

From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java

License:Open Source License

/**
 * this function will get the value in the given xpath
 *
 * @param ingest/*  www. j a v  a2  s.  co  m*/
 * @param xpath
 * @return
 */
public static String getValueFromIngest(String ingest, String xpath) {
    Document doc = null;
    String value = "";

    try {
        doc = DocumentHelper.parseText(ingest);
    } catch (DocumentException e) {
        logger.error("", e);
    }

    Element elem = (Element) doc.selectSingleNode(xpath);

    if (elem != null)
        value = elem.getText();

    return value;
}

From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java

License:Open Source License

/**
 * this function will return a list with the raw elements for this type
 * @param ingest// w  w w  .ja v  a2 s .  c o m
 * @param type
 * @return
 */
public static List<Element> getRaws(String ingest, String type) {
    List<Element> elems = new ArrayList<Element>();

    Document doc = null;

    logger.debug("ingest: " + ingest);
    logger.debug("type: " + type);

    try {
        doc = DocumentHelper.parseText(ingest);
    } catch (DocumentException e) {
        logger.error("", e);
    }
    String xpath = "/fsxml/properties/" + type + "/raw" + type;

    elems = doc.selectNodes(xpath);

    return elems;
}

From source file:com.noterik.bart.fs.restlet.FSResource.java

License:Open Source License

/**
 * Post/* ww  w  .j a  v a  2  s  .c  o  m*/
 */
@Post
public void doPost(Representation representation) {
    if (httpblocked)
        return;
    logger.debug("POST: " + getResourceUri());

    String data = getRequestBodyData(representation);
    String response = null;
    if (!decisionEngine.decide(getRequest())) {
        String error = FSXMLBuilder.getErrorMessage("403", "Permission denied", "Please log in",
                "http://teamelements.noterik.com/team");
        Representation rep = new StringRepresentation(error, MediaType.TEXT_XML);
        getResponse().setEntity(rep);
        return;
    }
    if (data == null) {
        response = FSXMLBuilder.getErrorMessage("500", "The request data could not be found",
                "Please resend with the correct request data", "http://teamelements.noterik.com/team");
    } else {
        logger.debug("Post request: " + data);
        String uri = getResourceUri();
        MimeType mt = FSXMLHelper.getMimeTypeFromXml(data);
        if (mt == MimeType.MIMETYPE_FS_XML) {
            response = FSXMLRequestHandler.instance().handlePOST(uri, data);
        } else if (mt == MimeType.MIMETYPE_FS_COMMAND) {
            response = CommandRequestHandler.instance().handlePOST(uri, data);
        } else if (mt == MimeType.MIMETYPE_FS_SCRIPT) {
            response = FSScriptRequestHandler.instance().handlePOST(uri, data);
        } else {
            response = FSXMLBuilder.getErrorMessage("500", "Posting data of this mimetype is not supported",
                    "Please resend with the correct mimetype (application/fscommand or text/fsxml)",
                    "http://teamelements.noterik.com/team");
        }
    }
    logger.debug("returning response for POST request: " + response);

    // proper UTF-8 encoding of response
    DomRepresentation dr = null;
    try {
        dr = new DomRepresentation(MediaType.TEXT_XML);
        Document doc = DocumentHelper.parseText(response);
        dr.setDocument(XMLHelper.convert(doc));
    } catch (Exception e) {
        logger.error("", e);
        response = FSXMLBuilder.getErrorMessage("500", "Response data not valid", "",
                "http://teamelements.noterik.com/team");
        getResponse().setEntity(new StringRepresentation(response, MediaType.TEXT_XML));
    }
    getResponse().setEntity(dr);

    //set access control headers to allow cross domain communication
    Form responseHeaders = (Form) getResponse().getAttributes().get("org.restlet.http.headers");
    if (responseHeaders == null) {
        responseHeaders = new Form();
        getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
    }

    responseHeaders.add("Access-Control-Allow-Origin", "*");
    responseHeaders.add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
    responseHeaders.add("Access-Control-Allow-Headers", "Content-Type");
}

From source file:com.noterik.bart.fs.restlet.FSResource.java

License:Open Source License

/**
 * Put/* ww  w . j a v  a 2s  . c  om*/
 */
@Put
public void doPut(Representation representation) {
    if (httpblocked)
        return;
    logger.debug("PUT: " + getResourceUri());

    String data = getRequestBodyData(representation);
    String response = null;
    if (!decisionEngine.decide(getRequest())) {
        String error = FSXMLBuilder.getErrorMessage("403", "Permission denied", "Please log in",
                "http://teamelements.noterik.com/team");
        Representation rep = new StringRepresentation(error, MediaType.TEXT_XML);
        getResponse().setEntity(rep);
        return;
    }
    if (data == null) {
        response = FSXMLBuilder.getErrorMessage("500", "The request data could not be found",
                "Please resend with the correct request data", "http://teamelements.noterik.com/team");
    } else {
        logger.debug("Put request: " + data);
        MimeType mt = FSXMLHelper.getMimeTypeFromXml(data);
        if (mt == MimeType.MIMETYPE_FS_XML) {
            response = FSXMLRequestHandler.instance().handlePUT(getResourceUri(), data);
        } else if (mt == MimeType.MIMETYPE_FS_SCRIPT) {
            response = FSScriptRequestHandler.instance().handlePUT(getResourceUri(), data);
        } else {
            response = FSXMLBuilder.getErrorMessage("403", "You can only PUT data of the mimetype text/fsxml",
                    "Please resend with the correct mimetype", "http://teamelements.noterik.com/team");
        }
    }
    logger.debug("returning response for PUT request: " + response);

    // proper UTF-8 encoding of response
    DomRepresentation dr = null;
    try {
        dr = new DomRepresentation(MediaType.TEXT_XML);
        Document doc = DocumentHelper.parseText(response);
        dr.setDocument(XMLHelper.convert(doc));
    } catch (Exception e) {
        logger.error("", e);
        response = FSXMLBuilder.getErrorMessage("500", "Response data not valid", "",
                "http://teamelements.noterik.com/team");
        getResponse().setEntity(new StringRepresentation(response, MediaType.TEXT_XML));
    }
    getResponse().setEntity(dr);

    //set access control headers to allow cross domain communication
    Form responseHeaders = (Form) getResponse().getAttributes().get("org.restlet.http.headers");
    if (responseHeaders == null) {
        responseHeaders = new Form();
        getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
    }

    responseHeaders.add("Access-Control-Allow-Origin", "*");
    responseHeaders.add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
    responseHeaders.add("Access-Control-Allow-Headers", "Content-Type");
}

From source file:com.noterik.bart.fs.restlet.FSResource.java

License:Open Source License

/**
 * Delete/* w  w w.ja  v a  2s  .  c  o m*/
 */
@Delete
public void doDelete() {
    if (httpblocked)
        return;

    logger.debug("DELETE: " + getResourceUri());

    if (!decisionEngine.decide(getRequest())) {
        String error = FSXMLBuilder.getErrorMessage("403", "Permission denied", "Please log in",
                "http://teamelements.noterik.com/team");
        Representation rep = new StringRepresentation(error, MediaType.TEXT_XML);
        getResponse().setEntity(rep);
        return;
    }
    String data = getRequestBodyData(getRequest().getEntity());
    FSScriptRequestHandler.instance().handleDELETE(getResourceUri());
    String response = FSXMLRequestHandler.instance().handleDELETE(getResourceUri(), data);
    logger.debug("returning response for DELETE request: " + response);

    // proper UTF-8 encoding of response
    DomRepresentation dr = null;
    try {
        dr = new DomRepresentation(MediaType.TEXT_XML);
        Document doc = DocumentHelper.parseText(response);
        dr.setDocument(XMLHelper.convert(doc));
    } catch (Exception e) {
        logger.error("", e);
        response = FSXMLBuilder.getErrorMessage("500", "Response data not valid", "",
                "http://teamelements.noterik.com/team");
        getResponse().setEntity(new StringRepresentation(response, MediaType.TEXT_XML));
    }
    getResponse().setEntity(dr);

    //set access control headers to allow cross domain communication
    Form responseHeaders = (Form) getResponse().getAttributes().get("org.restlet.http.headers");
    if (responseHeaders == null) {
        responseHeaders = new Form();
        getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
    }

    responseHeaders.add("Access-Control-Allow-Origin", "*");
    responseHeaders.add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
    responseHeaders.add("Access-Control-Allow-Headers", "Content-Type");
}

From source file:com.noterik.bart.fs.script.ActionSet.java

License:Open Source License

/**
 * Parses xml into a ActionSet/*from  w w  w  .  j av  a2s. co  m*/
 *
 * @param xml
 * @throws DocumentException
 */
public ActionSet(FSScript script, String id, String xml) throws DocumentException {
    this(script, id, DocumentHelper.parseText(xml));
}

From source file:com.noterik.bart.fs.script.FSScript.java

License:Open Source License

/**
 * Parses xml into a FSScript/*from ww  w  .ja  v a2s  . co  m*/
 *
 * @param xml
 * @throws DocumentException
 */
public FSScript(String id, String xml) throws DocumentException {
    this(id, DocumentHelper.parseText(xml));
}

From source file:com.petpet.c3po.analysis.ProfileGenerator.java

License:Apache License

/**
 * writes the xml string to a local folder 'profiles' in a file called
 * output.xml.//from  www .  j a  v  a2 s  .  co  m
 *
 * @param xml
 *          the xml to write.
 */
public void write(final String xml) {
    try {
        final Document doc = DocumentHelper.parseText(xml);
        this.write(doc);

    } catch (final DocumentException e) {
        LOG.warn("An error occurred: {}", e.getMessage());
    }
}

From source file:com.plugin.UI.Windows.DesktopUI.java

/**
 * Instantiates a new desktop ui.//  w w  w . jav  a2 s .co m
 */
public DesktopUI() {
    super(Global.selectedLanguage + " " + Global.SOFTWARE_NAME + " " + Global.VERSION);
    this.setFont(new Font(Global.standardOtherLangFont, Font.PLAIN, Global.standardOtherLangFontSize));
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    this.addWindowListener(new WindowListener() {

        public void windowActivated(WindowEvent e) {
            // TODO Auto-generated method stub

        }

        public void windowClosed(WindowEvent e) {

        }

        public void windowClosing(WindowEvent e) {
            DB.closeConnection();
        }

        public void windowDeactivated(WindowEvent e) {
            // TODO Auto-generated method stub

        }

        public void windowDeiconified(WindowEvent e) {
            // TODO Auto-generated method stub

        }

        public void windowIconified(WindowEvent e) {
            // TODO Auto-generated method stub

        }

        public void windowOpened(WindowEvent e) {
            // TODO Auto-generated method stub

        }
    });

    Container content = getContentPane();
    content.setBackground(Color.white);
    _desktop = new JScrollableDesktopPane();
    // _desktop.setBackground(Color.WHITE);
    _desktop.setOpaque(false);

    // ///
    try {
        Image logo = ImageIO.read(new File(IconList.CHURCH_SOFTWARE_ICON));
        this.setIconImage(logo);
    } catch (IOException e2) {
    }
    content.add(_desktop, BorderLayout.CENTER);
    statusBar = new JLabel();
    statusBar.setText("Logged In User: " + Global.loggedInUser);
    statusBar.setBorder(new EtchedBorder());
    content.add(statusBar, BorderLayout.SOUTH);
    setSize(Global.SCREEN_X, Global.SCREEN_Y);
    Document doc;
    try {
        doc = DocumentHelper.parseText(Global.MENUS);
        Element root = doc.getRootElement();
        JMenuBar menuBar = new JMenuBar();
        traverseXML(root, menuBar);
        setJMenuBar(menuBar);
    } catch (DocumentException e) {
        System.out.println(e);
    }

    setExtendedState(JFrame.MAXIMIZED_BOTH);
    setVisible(true);
}