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
 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 #3
0
 private Document GetXMLDocument(String url) {
   try {
     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
     DocumentBuilder db = dbf.newDocumentBuilder();
     InputStream input = HTMLTools.inputStream_GET(url, 5000);
     InputStreamReader reader = new InputStreamReader(input, ENCODING_UTF8);
     InputSource inSrc = new InputSource(reader);
     inSrc.setEncoding(ENCODING_UTF8);
     return db.parse(inSrc);
   } catch (ParserConfigurationException pce) {
     Print.logError("Parse error: " + pce);
     return null;
   } catch (SAXException se) {
     Print.logError("Parse error: " + se);
     return null;
   } catch (IOException ioe) {
     Print.logError("IO error: " + ioe);
     return null;
   }
 }
Example #4
0
    /** SAX entity resolver */
    public InputSource resolveEntity(String name, String uri) throws IOException, SAXException {

      InputSource retval;
      String mappedURI = name2uri(name);
      InputStream stream = mapResource(name);

      // prefer explicit URI mappings, then bundled resources...
      if (mappedURI != null) {
        retval = new InputSource(mappedURI);
        retval.setPublicId(name);
        return retval;

      } else if (stream != null) {
        uri = "java:resource:" + (String) id2resource.get(name); // NOI18N
        retval = new InputSource(stream);
        retval.setPublicId(name);
        return retval;

      } else {
        return null;
      }
    }
Example #5
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());
    }
  }