Example #1
0
  private static InputSource getConfigSource(File pAppFile) throws FileNotFoundException {
    InputSource retSource = null;
    String uri = FileUtils.createFileURL(pAppFile);

    FileInputStream fileInputStream = new FileInputStream(pAppFile);
    retSource = new InputSource(fileInputStream);
    retSource.setSystemId(uri);
    return (retSource);
  }
Example #2
0
 public static void readerToSAX(
     Reader reader,
     String systemId,
     XMLReceiver xmlReceiver,
     XMLUtils.ParserConfiguration parserConfiguration,
     boolean handleLexical) {
   final InputSource inputSource = new InputSource(reader);
   inputSource.setSystemId(systemId);
   inputSourceToSAX(inputSource, xmlReceiver, parserConfiguration, handleLexical);
 }
Example #3
0
 private static InputSource getConfigSource(Class pAppClass) throws DataNotFoundException {
   URL resource = pAppClass.getResource(CONFIG_FILE_NAME);
   String resourceFileName = resource.toExternalForm();
   File resourceFile = new File(resourceFileName);
   InputStream configResourceStream = pAppClass.getResourceAsStream(CONFIG_FILE_NAME);
   if (null == configResourceStream) {
     throw new DataNotFoundException(
         "unable to find XML configuration file resource: "
             + CONFIG_FILE_NAME
             + " for class: "
             + pAppClass.getName());
   }
   InputSource inputSource = new InputSource(configResourceStream);
   if (!resourceFile.exists()) {
     inputSource.setSystemId(resourceFileName);
   }
   return (inputSource);
 }
Example #4
0
  public static void parse(String fileNameOrURL, RDFParser parser, Model model)
      throws IOException, SAXException, MalformedURLException, ModelException {

    URL url = new URL(normalizeURI(fileNameOrURL));

    // maybe this model is loaded as schema...
    //    Model model = factory.registry().get(url.toString());
    //    if(model != null)
    //      return model;

    // Prepare input source
    model.setSourceURI(url.toString());
    InputStream in = url.openStream();
    InputSource source = new InputSource(in);
    source.setSystemId(url.toString());

    parser.parse(source, new ModelConsumer(model));
    in.close();
  }
Example #5
0
 /**
  * Read a URL into SAX events.
  *
  * @param systemId system id of the document
  * @param xmlReceiver receiver to output to
  * @param parserConfiguration parser configuration
  * @param handleLexical whether the XML parser must output SAX LexicalHandler events, including
  *     comments
  */
 public static void urlToSAX(
     String systemId,
     XMLReceiver xmlReceiver,
     XMLUtils.ParserConfiguration parserConfiguration,
     boolean handleLexical) {
   try {
     final URL url = URLFactory.createURL(systemId);
     final InputStream is = url.openStream();
     final InputSource inputSource = new InputSource(is);
     inputSource.setSystemId(systemId);
     try {
       inputSourceToSAX(inputSource, xmlReceiver, parserConfiguration, handleLexical);
     } finally {
       is.close();
     }
   } catch (IOException e) {
     throw new OXFException(e);
   }
 }
Example #6
0
    public InputSource resolveEntity(String publicId, String systemId)
        throws SAXException, IOException {
      final InputSource is = new InputSource();
      is.setSystemId(systemId);
      is.setPublicId(publicId);
      final URL url = URLFactory.createURL(systemId);

      // Would be nice to support XML Catalogs or similar here. See:
      // http://xerces.apache.org/xerces2-j/faq-xcatalogs.html
      if (url.getProtocol().equals("http")) {
        logger.warn(
            "XML entity resolver for public id: "
                + publicId
                + " is accessing external entity via HTTP: "
                + url.toExternalForm());
      }

      is.setByteStream(url.openConnection().getInputStream());
      return is;
    }
Example #7
0
  public static MiningResult importFile(InputStream input) throws IOException {
    try {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      Document doc;
      // NodeList netNodes;
      dbf.setValidating(false);
      dbf.setIgnoringComments(true);
      dbf.setIgnoringElementContentWhitespace(true);
      // dbf.setExpandEntityReferences(false);
      // dbf.setNamespaceAware(false);

      DocumentBuilder db = dbf.newDocumentBuilder();

      db.setEntityResolver(
          new EntityResolver() {
            public InputSource resolveEntity(String publicId, String systemId) {
              if (systemId.indexOf("ARIS-Export") != -1) {
                return new InputSource("file:" + About.EXTLIBLOCATION() + "ARIS-Export101.dtd");
              } else {
                return null;
              }
            }
          });

      InputSource inpStream = new InputSource(input);
      inpStream.setSystemId("file:" + System.getProperty("user.dir", ""));
      doc = db.parse(inpStream);

      // check if root element is a aml tag
      Message.add("parsing done" + doc, Message.DEBUG);
      if (!(doc.getDocumentElement().getNodeName().equals("AML"))) {
        Message.add("aml tag not found", Message.ERROR);
        throw new Exception("aml tag not found");
      } else {
        Message.add("aml root element found");
      }

      EPCResult result = new EPCResult(null, (EPC) null);
      HashMap ObjDef_LinkId = new HashMap();
      HashMap modelid_net = new HashMap();
      HashMap ObjDef_Name = new HashMap();
      HashMap function_LinkId = new HashMap();
      HashMap ModelId_ModelType = new HashMap();
      traverseAMLforObjectNames(
          ObjDef_Name, doc.getDocumentElement(), ObjDef_LinkId, ModelId_ModelType);
      Iterator findLinkToEpc = ObjDef_LinkId.keySet().iterator();
      while (findLinkToEpc.hasNext()) {
        String currentObjDef = (String) findLinkToEpc.next();
        String Links = (String) ObjDef_LinkId.get(currentObjDef);
        StringTokenizer linkSet = new StringTokenizer(Links);
        String realEpcLink = "";
        while (linkSet.hasMoreTokens()) {
          String currentLink = linkSet.nextToken();
          if (ModelId_ModelType.get(currentLink).equals("MT_EEPC")) {
            realEpcLink = currentLink;
            break;
          }
        }
        if (realEpcLink.equals(" ")) {
          ObjDef_LinkId.remove(currentObjDef);
        } else {
          ObjDef_LinkId.put(currentObjDef, realEpcLink);
        }
      }
      result =
          traverseAML(
              result,
              doc.getDocumentElement(),
              null,
              ObjDef_Name,
              ObjDef_LinkId,
              modelid_net,
              function_LinkId);
      Iterator hierarchicalFunctions = function_LinkId.keySet().iterator();
      while (hierarchicalFunctions.hasNext()) {
        EPCSubstFunction f = (EPCSubstFunction) hierarchicalFunctions.next();
        f.setSubstitutedEPC((EPC) modelid_net.get(function_LinkId.get(f)));
        // Message.add(f.getSubstitutedEPC().getName());
      }

      return result;

    } catch (Throwable x) {
      Message.add(x.toString());
      throw new IOException(x.getMessage());
    }
  }