Package com.dotmarketing.viewtools.bean

Examples of com.dotmarketing.viewtools.bean.XSLTranformationDoc


        Logger.error(XsltTool.class, "XSLTTool user does not have scripting access ");
        return null;
      }
      String outputXML = null;
      Source xmlSource = null;
      XSLTranformationDoc doc = null;
      Host host = hostWebAPI.getCurrentHost(request);

      /*Validate if in cache exists a valid version*/
      doc = XSLTransformationCache.getXSLTranformationDocByXMLPath(XMLPath,XSLPath);

      if(doc == null){
        /*Get the XSL source*/
        java.io.File binFile = null;
        Identifier xslId = APILocator.getIdentifierAPI().find(host, XSLPath);
        if(xslId!=null && InodeUtils.isSet(xslId.getId()) && xslId.getAssetType().equals("contentlet")){
          Contentlet cont = APILocator.getContentletAPI().findContentletByIdentifier(xslId.getId(), true, APILocator.getLanguageAPI().getDefaultLanguage().getId(), userAPI.getSystemUser(),false);
          if(cont!=null && InodeUtils.isSet(cont.getInode())){
            binFile = cont.getBinary(FileAssetAPI.BINARY_FIELD);
          }
        }else{
          File xslFile = fileAPI.getFileByURI(XSLPath, host, true, userAPI.getSystemUser(),false);
          binFile = fileAPI.getAssetIOFile (xslFile);
        }
       
       
        /*Get the XML Source from file or from URL*/
        if(!XMLPath.startsWith("http")){
          Identifier xmlId = APILocator.getIdentifierAPI().find(host, XMLPath);
          if(xmlId!=null && InodeUtils.isSet(xmlId.getId()) && xmlId.getAssetType().equals("contentlet")){
            Contentlet cont = APILocator.getContentletAPI().findContentletByIdentifier(xmlId.getId(), true, APILocator.getLanguageAPI().getDefaultLanguage().getId(), userAPI.getSystemUser(),false);
            if(cont!=null && InodeUtils.isSet(cont.getInode())){
              xmlSource = new StreamSource(new InputStreamReader(new FileInputStream(cont.getBinary(FileAssetAPI.BINARY_FIELD)), "UTF8"));
            }
          }else{
            File xmlFile = fileAPI.getFileByURI(XMLPath, host, true,userAPI.getSystemUser(),false);
            xmlSource = new StreamSource(new InputStreamReader(new FileInputStream(fileAPI.getAssetIOFile(xmlFile)), "UTF8"));
          }

        }else{
          xmlSource = new StreamSource(XMLPath);
        }

        Source xsltSource = new StreamSource(new InputStreamReader(new FileInputStream(binFile), "UTF8"));

        // create an instance of TransformerFactory
        TransformerFactory transFact = TransformerFactory.newInstance();
        StreamResult result = new StreamResult(new ByteArrayOutputStream());
        Transformer trans = transFact.newTransformer(xsltSource);

        try{
          trans.transform(xmlSource, result);
        }catch(Exception e1){
          Logger.error(XsltTool.class, "Error in transformation. "+e1.getMessage());
          e1.printStackTrace();
        }

        outputXML = result.getOutputStream().toString();

        doc = new XSLTranformationDoc();
        doc.setIdentifier(xslId.getId());
        doc.setInode(xslId.getInode());
        doc.setXslPath(XSLPath);
        doc.setXmlPath(XMLPath);
        doc.setXmlTransformation(outputXML);
        doc.setTtl(new Date().getTime()+ttl);

        XSLTransformationCache.addXSLTranformationDoc(doc);

      }

View Full Code Here


        Logger.error(XsltTool.class, "XSLTTool user does not have scripting access ");
        return null;
      }
      String outputXML = null;
      Source xmlSource = null;
      XSLTranformationDoc doc = null;
      Host host = hostWebAPI.getCurrentHost(request);
     
      /*Get the XSL source*/
      File xslFile = fileAPI.getFileByURI(XSLPath, host, true, userAPI.getSystemUser(), false);
     
      if (doc == null) {
        xmlSource = new StreamSource(new ByteArrayInputStream(xmlString.getBytes("UTF-8")));
       
        Source xsltSource = new StreamSource(new InputStreamReader(new FileInputStream(fileAPI.getAssetIOFile (xslFile)), "UTF8"));
       
        // create an instance of TransformerFactory
        TransformerFactory transFact = TransformerFactory.newInstance();
        StreamResult result = new StreamResult(new ByteArrayOutputStream());
        Transformer trans = transFact.newTransformer(xsltSource);
       
        try {
          trans.transform(xmlSource, result);
        } catch (Exception e1) {
          Logger.error(XsltTool.class, "Error in transformation. " + e1.getMessage());
          e1.printStackTrace();
        }
       
        outputXML = result.getOutputStream().toString();
       
        doc = new XSLTranformationDoc();
        doc.setIdentifier(xslFile.getIdentifier());
        doc.setInode(xslFile.getInode());
        doc.setXslPath(XSLPath);
        doc.setXmlTransformation(outputXML);
      }
     
      return doc;
    } catch (Exception e) {
      Logger.error(XsltTool.class, "Error in transformation. " + e.getMessage());
View Full Code Here

   * @param XSLPath XSL path
   * @return XSLTranformationDoc
   */
  public static XSLTranformationDoc getXSLTranformationDocByXMLPath(String XMLPath,String XSLPath) {
    DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
    XSLTranformationDoc doc = null;
    try{
      doc = (XSLTranformationDoc) cache.get(getPrimaryGroup() + XMLPath+"_"+XSLPath, getPrimaryGroup());
    }catch (DotCacheException e) {
      Logger.debug(XSLTransformationCache.class,"Cache Entry not found", e);
    }

    if (doc != null) {
      try{

        /*validate if xsl file change*/
        Identifier xslIdentifier = APILocator.getIdentifierAPI().find(doc.getIdentifier());
        File xslFile = (File) versionableAPI.findWorkingVersion(xslIdentifier, userAPI.getSystemUser(), false);

        /*validate time to live*/
        long ttl = doc.getTtl() - new Date().getTime();

        if(ttl <= 0 || doc.getInode() != xslFile.getInode()){
          removeXSLTranformationDoc(doc);
          doc =null;
        }


View Full Code Here

TOP

Related Classes of com.dotmarketing.viewtools.bean.XSLTranformationDoc

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.