Example usage for javax.xml.parsers DocumentBuilder reset

List of usage examples for javax.xml.parsers DocumentBuilder reset

Introduction

In this page you can find the example usage for javax.xml.parsers DocumentBuilder reset.

Prototype

public void reset() 

Source Link

Document

Reset this DocumentBuilder to its original configuration.

DocumentBuilder is reset to the same state as when it was created with DocumentBuilderFactory#newDocumentBuilder() .

Usage

From source file:org.soapfromhttp.service.CallSOAP.java

/**
 * Contruction dynamique de la requte SOAP
 *
 * @param pBody//ww w.ja  v a2s.  c  om
 * @param method
 * @return SOAPMessage
 * @throws SOAPException
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
private SOAPMessage createSOAPRequest(final String pBody, final String method)
        throws SOAPException, IOException, SAXException, ParserConfigurationException {

    // Prcise la version du protocole SOAP  utiliser (ncessaire pour les appels de WS Externe)
    MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);

    SOAPMessage soapMessage = messageFactory.createMessage();

    MimeHeaders headers = soapMessage.getMimeHeaders();

    // Prcise la mthode du WSDL  interroger
    headers.addHeader("SOAPAction", method);
    // Encodage UTF-8
    headers.addHeader("Content-Type", "text/xml;charset=UTF-8");

    final SOAPBody soapBody = soapMessage.getSOAPBody();

    // convert String into InputStream - traitement des caracres escaps > < ... (contraintes de l'affichage IHM)
    //InputStream is = new ByteArrayInputStream(HtmlUtils.htmlUnescape(pBody).getBytes());
    InputStream is = new ByteArrayInputStream(pBody.getBytes());
    DocumentBuilder builder = null;

    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();

    // Important  laisser sinon KO
    builderFactory.setNamespaceAware(true);
    try {
        builder = builderFactory.newDocumentBuilder();

        Document document = builder.parse(is);

        soapBody.addDocument(document);
    } catch (ParserConfigurationException e) {
        MyLogger.log(CallSOAP.class.getName(), Level.ERROR, e.toString());
    } finally {
        is.close();
        if (builder != null) {
            builder.reset();
        }
    }
    soapMessage.saveChanges();

    return soapMessage;
}

From source file:OpenProdocServ.ImpElemF.java

/**
 *
 * @param Req//from w w w .  j  a  v  a 2  s .com
 * @throws Exception
 */
@Override
protected void ProcessPage(HttpServletRequest Req, PrintWriter out) throws Exception {
    String FileName = null;
    InputStream FileData = null;
    try {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        factory.setSizeThreshold(1000000);
        ServletFileUpload upload = new ServletFileUpload(factory);
        boolean isMultipart = ServletFileUpload.isMultipartContent(Req);
        List items = upload.parseRequest(Req);
        Iterator iter = items.iterator();
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            if (!item.isFormField()) {
                FileName = item.getName();
                FileData = item.getInputStream();
                break;
            }
        }
        DriverGeneric PDSession = SParent.getSessOPD(Req);
        DocumentBuilder DB = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document XMLObjects = DB.parse(FileData);
        NodeList OPDObjectList = XMLObjects.getElementsByTagName(ObjPD.XML_OPDObject);
        Node OPDObject;
        ObjPD Obj2Build;
        int Tot = 0;
        for (int i = 0; i < OPDObjectList.getLength(); i++) {
            OPDObject = OPDObjectList.item(i);
            Obj2Build = PDSession.BuildObj(OPDObject);
            Obj2Build.ProcesXMLNode(OPDObject);
            Tot++;
        }
        DB.reset();
        out.println(UpFileStatus.SetResultOk(Req, "Total=" + Tot));
        FileData.close();
    } catch (Exception e) {
        out.println(UpFileStatus.SetResultKo(Req, e.getLocalizedMessage()));
        throw e;
    }
}

From source file:OpenProdocServ.Oper.java

/**
 * //from   ww w.  j  a  v  a2 s.c o  m
 * @param Req
 * @param out
 * @throws Exception
 */
protected void ProcessPage(HttpServletRequest Req, PrintWriter out) throws Exception {
    String Order = Req.getParameter(DriverRemote.ORDER);
    String Param = Req.getParameter(DriverRemote.PARAM);
    if (PDLog.isDebug()) {
        PDLog.Debug("From:" + Req.getRemoteHost() + "/" + Req.getRemoteHost() + ":" + Req.getRemoteUser());
        PDLog.Debug("Order:" + Order);
        PDLog.Debug("Param:" + Param);
    }
    DocumentBuilder DB = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document XMLObjects = DB.parse(new ByteArrayInputStream(Param.getBytes("UTF-8")));
    if (Order.equals(DriverGeneric.S_LOGIN)) {
        NodeList OPDObjectList = XMLObjects.getElementsByTagName("U");
        Node OPDObject = OPDObjectList.item(0);
        String User = OPDObject.getTextContent();
        OPDObjectList = XMLObjects.getElementsByTagName("C");
        OPDObject = OPDObjectList.item(0);
        String Pass = OPDObject.getTextContent();
        DriverGeneric D = ProdocFW.getSession("PD", User, Pass);
        Req.getSession().setAttribute("PRODOC_SESS", D);
        Answer(Req, out, true, null, null);
        return;
    } else if (Order.equals(DriverGeneric.S_UNLOCK)) {
        getSessOPD(Req).UnLock();
        Req.getSession().setAttribute("PRODOC_SESS", null);
        Answer(Req, out, true, null, null);
        return;
    }
    DriverGeneric D = getSessOPD(Req);
    String Results = D.RemoteOrder(Order, XMLObjects);
    Answer(Req, out, Results);
    XMLObjects = null;
    DB.reset();
}

From source file:OpenProdocServ.Oper.java

private void SendFile(HttpServletRequest Req, HttpServletResponse response) throws Exception {
    String Param = Req.getParameter(DriverRemote.PARAM);
    if (PDLog.isDebug())
        PDLog.Debug("SendFile Param:" + Param);
    DocumentBuilder DB = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document XMLObjects = DB.parse(new ByteArrayInputStream(Param.getBytes("UTF-8")));
    NodeList OPDObjectList = XMLObjects.getElementsByTagName("Id");
    Node OPDObject = OPDObjectList.item(0);
    String Id = OPDObject.getTextContent();
    OPDObjectList = XMLObjects.getElementsByTagName("Ver");
    OPDObject = OPDObjectList.item(0);// w w w .  j av a  2  s  .c  o m
    String Ver = OPDObject.getTextContent();
    DB.reset();
    PDDocs doc = new PDDocs(getSessOPD(Req));
    doc.setPDId(Id);
    if (Ver != null && Ver.length() != 0)
        doc.LoadVersion(Id, Ver);
    else
        doc.LoadCurrent(Id);
    ServletOutputStream out = response.getOutputStream();
    PDMimeType mt = new PDMimeType(getSessOPD(Req));
    mt.Load(doc.getMimeType());
    response.setContentType(mt.getMimeCode());
    response.setHeader("Content-disposition", "inline; filename=" + doc.getName());
    try {
        if (Ver != null && Ver.length() != 0)
            doc.getStreamVer(out);
        else
            doc.getStream(out);
    } catch (Exception e) {
        out.close();
        throw e;
    }
    out.close();
}